LonelyStar
02-04-2007, 07:55 AM
Hello dear Community,
I am having trouble on how to designe the Interface for a Physic-Engine for games.
The Idea so far:
- I have a rigidBody class, which is a general class for objects in the physics world.
- I have a Physic class handling the rigid bodies and stuff.
The engine should not only handle physics but also general collision detection. In a game one has different types of objects. In example:
-Players
-Opponents
- Bullets
-Walls/Obstacles
-Pickups (like Ammo, Health e.t.c.)
Now the physics object needs to know which objects can collide with which and needs a way of reporting such collisions. It also needs to know, if it should calculate collision response. In example:
- If a Player collides with a Health-Pack, the physics Engine needs to report this, so that the player gains Health and the Health-Pack is deletet.
- If a player collides with the wall, the physics Engine needs to calculate the collision response and apply it.
- Bullets can not collide with Pickups.
e.t.c.
The problem is now how to make a Interface which can provide this functionality. My Idea is to put bodies into "groups" and tell the Phyics object, which groups can collide with which and when we need to know about a collision.
Example:
Group 1=Players
Group 2=Walls
Group 4=Pickups
PhysicEngine.GroupsCollideWithResponse(Players,Wal ls);
PhysicObject.GroupsCollideWithoutResponse(Players, Pickup);
The biggest Problem is, how to give the feedback, if a collision occured.
One could add a virtual function:
RigidBody.OnCollision(RigidBody* ThOther);
But I think this interface would be not so good because there are always to bodies in a collision, so that the collision would be reported twice!
How would you designe this?
I am looking for Ideas on how to replace the group-system and what the best way of reporting a collision would be.
Thanks,
Nathan
I am having trouble on how to designe the Interface for a Physic-Engine for games.
The Idea so far:
- I have a rigidBody class, which is a general class for objects in the physics world.
- I have a Physic class handling the rigid bodies and stuff.
The engine should not only handle physics but also general collision detection. In a game one has different types of objects. In example:
-Players
-Opponents
- Bullets
-Walls/Obstacles
-Pickups (like Ammo, Health e.t.c.)
Now the physics object needs to know which objects can collide with which and needs a way of reporting such collisions. It also needs to know, if it should calculate collision response. In example:
- If a Player collides with a Health-Pack, the physics Engine needs to report this, so that the player gains Health and the Health-Pack is deletet.
- If a player collides with the wall, the physics Engine needs to calculate the collision response and apply it.
- Bullets can not collide with Pickups.
e.t.c.
The problem is now how to make a Interface which can provide this functionality. My Idea is to put bodies into "groups" and tell the Phyics object, which groups can collide with which and when we need to know about a collision.
Example:
Group 1=Players
Group 2=Walls
Group 4=Pickups
PhysicEngine.GroupsCollideWithResponse(Players,Wal ls);
PhysicObject.GroupsCollideWithoutResponse(Players, Pickup);
The biggest Problem is, how to give the feedback, if a collision occured.
One could add a virtual function:
RigidBody.OnCollision(RigidBody* ThOther);
But I think this interface would be not so good because there are always to bodies in a collision, so that the collision would be reported twice!
How would you designe this?
I am looking for Ideas on how to replace the group-system and what the best way of reporting a collision would be.
Thanks,
Nathan