Показать сообщение отдельно
Старый 27.06.2009, 23:58   #8
Genius
Знающий
 
Аватар для Genius
 
Регистрация: 02.11.2007
Сообщений: 255
Написано 27 полезных сообщений
(для 43 пользователей)
Вот ещё немного расширил:
class Car;
class Human;

static std::vector<GameObject*> gameWorld;

void insertGameObject( GameObject* object )
{
     gameWorld.push_back(object);
}

class GameObject
{
public:
     float x,y,z,pitch,yaw,roll;
     bool alive;

     GameObject(){ insertGameObject(this); }
     virtual ~GameObject(){}

     bool isAlive() { return alive; }

     Car* getCar(){return 0;}
     Human* getHuman(){return 0;}

    virtual void setPosition(float _x,float _y,float _z){ x=_x;y=_y;z=_z; }
    virtual void setOrientation(float _pitch,float _yaw,float _roll){ pitch=_pitch;yaw=_yaw;roll=_roll;}

    virtual void update(float ifps){}
};

class Car : public GameObject
{
public:
     int model;
     float max_speed;

     Car()
     {
          max_speed=0;
     }

     virtual ~Car()
     {
         xFreeEntity(model);
     }

     Car* getCar(){return this;}
  
     void setPosition(float x,float y,float z) 
     {
          GameObject::setPosition(x,y,z);
          ....
     }

     void setOrientation(float pitch,float yaw,float roll)
     {
         GameObject::setOrientation(pitch,yaw,roll);
         ...
     }

     void update()
     {
        car physic update...
     }
};

class Human : public GameObject
{
public:

     int health;
     int model;

     Human()
     {
         model = xLoadAnimMesh("human.b3d");
         health=100;
     }

     ~Human()
     {
         xFreeEntity(model);
     }

     Human* getHuman(){return this;}
  
     void setPosition(float x,float y,float z) 
     {
          GameObject::setPosition(x,y,z);
          ....
     }

     void setOrientation(float pitch,float yaw,float roll)
     {
         GameObject::setOrientation(pitch,yaw,roll);
         ...
     }

     void update(float ifps)
     {
         if(health <= 0)alive=false;
     }
};

class CarDriver : public Human
{
....
};

void updateGameWorld(float ifps)
{
        for(unsigned int i = 0; i < gameWorld.size(); i++)
        {
               GameObject* obj = gameWorld[i];
               if(obj->isAlive())
               {
                     obj->update(ifps);
               }
        }
}

....

GameObject* car = new Car();
GameObject* human = new Humman();

if(car->getCar() != 0)car->setPosition(40,10,0);
if(human->getHuman() != 0)human->setPosition(40,15,0);

while(!xKeyDown(1))
{
....
updateGameWorld(deltaTime);
xUpdateWorld(deltaTime);
xRenderWorld();
}
Сообщение от Mr_F_ Посмотреть сообщение
не, xyz у меня тут случайно совпали, в реале могут быть абсолютно разные штуки там)

говнокод тоже не хочется

Гениус чето совсем не по теме вроде.

посоветовали мне тут уже два человека юзать Vector.
запихну его в родительский класс и попробую)
А что мешает юзать Вектор,так даже удобнее,я просто изначально по твоему посту сделал xyz.

А вообще тогда бы было что-то типа

void Car::setPosition(const Vector& pos)
{
position = pos;
бла бла бла,ставим тело в позицию...
А вообще невижу смысла сохранять позицию так как есть же фунекции типа xPositionEntity,pxBodyPosition,xEntityX,pxBodyPosi tionX,etc.
}

Вот те многофункциональный 3D Вектор
Вложения
Тип файла: txt Vector.txt (3.6 Кб, 812 просмотров)

Последний раз редактировалось Genius, 28.06.2009 в 00:09.
(Offline)
 
Ответить с цитированием
Сообщение было полезно следующим пользователям:
Mr_F_ (28.06.2009)