Entity/physics..

Started by
2 comments, last by yodaman 21 years ago
I want to make a entity class, but dont know how to go about incorporating the physics engine to it later... ex: class Centity { Vector3 org; Vector3 pos; Vector3 Direction; Vector3 Velocity; etc... } or should I just wait for the physics and do it more like: class Centity { Physics phys; ... } or even class Physics { ... void Accelorate(Centity *e); ... }
www.jinx.com www.thebroken.org www.suprnova.org www.mozilla.org
Advertisement
depends on the complexity of your physics engine i guess.

if it''s relatively simple then u can incorporate your vectors directly into your entity base class and even provide the operators to manipulate them. then your physics class (singleton?) could manipulate them via a pointer list.

if you wait until you have finished the physics engine then you will find it difficult to do tests and such. And if centity is the only thing incorporating the physics class, should they really be seperate? and if there are more classes that utilise the physics class should these classes all derive from some base entity class?


Alrighty, so Im thinking maybe I should just make it more like

class PHYSICS
{
...
Cvector3 Acceleration(Cvector3 *velocity, float time);
...
};

Make it more universal.

thanx.

www.jinx.com www.thebroken.org www.suprnova.org www.mozilla.org
you need a bit of Object oriented design. It''s easier if you put on paper everything you need. You can ask simple questions.

For example.
is a cEntity a cPhysics?
does a cEntity have a cPhysics object?
does a cEntity have a cRender Object?
does a cRender uses a cPhsyics?

so, on paper, you draw all those objects, and draw specific arrows to represent their dependancies ("Is a" arrows, verus "Has a" arrows, and maybe "Uses a"). You don''t need to go too far in detail, just on the things you are not sure about. On paper, you''ll see exactly what you need, and how to implement them in respect to each others. You can even start writing an interface between objects (like for cPhysics objects and cRender objects). After a while, it will become very natural.

So if a cEntity "is a" cPhysics,

class cEntity: public cPhysics
{

};

if a cEntity is more global, and should "have a" cPhysics, a cRender, ... then

class cEntity
{
cPhysics m_Physics;
cRender m_Render;
};

a cRender "uses a" cPhysics a lot, so maybe store a pointer to it would be useful.

class cRender
{
cPhysics* m_pPhysics;
};


ect...



I''m not a specialist of OO design by a long shot(and I''ll probably get flamed), but when I first started C++ lectures, that''s the first thing we learned, even before starting coding. I''d better get back to it though, it''s very ''rusty''.

Everything is better with Metal.

This topic is closed to new replies.

Advertisement