Integrating physics system w/ graphics engine

Started by
15 comments, last by BMason 24 years ago
I would subclass the actor object within the physics object. That way you can still move the actor but you go through the physics part first, which makes sense since all actors are affected by the same gravity/physics.

float gravity = 9.81f;

CEarthPhysics on_earth;
on_earth.create_system(gravity);
on_earth.create_john();
on_earth.john.walks();

walk is physical property for all actors, and john is a specific actor, one of many that are tied to the same physics system.

Then you could make another physics class, like no gravity and give that system to all its sub actors. Or maybe I don't know what I'm talking about

Jerry

Edited by - JD on 4/10/00 4:05:51 AM
Advertisement
If you''re going to be rendering at a reasonable framerate the timestep on the physics will be considerably larger than a rendering timestep. [maybe linearly interpolating, the values for rendering?]
Similarly the models you use for rendering and collision detection are likely to be quite different; most 3d rigid body demos use highly simplified geometry for collisions.
people.. this is like.. engine design 101.. have a Scene class that encapsulates a set of Object classes. Objects check for collisions with other Objects and either draw themselves or pass the transformed data to the parent Scene, depending on the application. the Scene instance, when rendered, determines which objects can potentially collide (Object::CheckBoundingBoxForCollision(BoundingBox *)) and then calls each Object''s collision detection method for the potential colliding Object. Object::CheckForCollision(Object *).

-goltrpoat
But if you''re going to encapsulate the objects then each object doesn''t know about eachother, only the scene class would know about each object. So the object wouldn''t be able to apply its own collision detection. That''s what I''m getting hung up on.
It compiles! Ship it!
The above anonymous guy is right, its the way that I ended up working things in my engine as well.

On an abstract level, your scene owns all actors. Every actor has a public member function CheckCollide(Actor *other), that checks its bounding box against another actor''s bounding box.

Your scene has a function, say, CheckWorldCollide() that loops through all your actors, calling CheckCollide() for TotalNumObjects/2 (/2 because if you check collision for one pair, you eliminate the inverse check, obj1->obj2 is same as obj2->obj1).

Forgive me if this is a stupid question, but it seems from your question as if in Java an object can''t access another object''s private data even if its the same type. This isn''t the case in C++, which is why your object''s CheckCollide(Actor *other) can "get at" all the needed physics info for Actor other.

-- Remnant (at the Uni)
No, it can''t access another objects data even if it''s the same type of object. The only way to make the private data available is by creating a function that returns that private data, but you can''t let that function give the data to only a certain type of object (as in you can''t limit what objects are allowed to access that method). It''s either totally public to everyone or totally private to everyone.
It compiles! Ship it!

Hrmm. Sounds to me like Java isn''t the best language to be developing in. [I''ll stop before I start a holy war here]

Perhaps you should go ahead and give up public methods to access the private data. Most of what a (simple) collision detect algorithm will need is stuff like position and velocity -- things that someone outside the class could reasonably expect to request from an Actor. For example, if you have your physics data isolated inside a struct inside your Actor class, you could have the following :

struct physic_state;

physic_state *Actor.RequestPhysics();
Actor.SetPhysics(physic_state *newstate);

then :

Actor.CheckBoundingCollision(physic_state *other);

That is, unless Java doesn''t have structs either?
Not having friendship or private-access to your own object type makes it more difficult.

- Remnant
- (Steve Schmitt)
- Remnant- (Steve Schmitt)

This topic is closed to new replies.

Advertisement