Collision System – Final

For this project I was successful in implementing a simple collision detection system. As an overview for what I did, the collision system uses sphere colliders created from mesh data (center and radius) which are then used to detect overlap events.

Interface

Since the collision system relies directly on the physics system, you will have to update your Physics project (replace it with mine to be exact). For your game objects to work with the physics system, have your game object inherit from the cPhysicsObject class.

InheritanceScreeshot

This base class takes care of collider information as well as the sRigidBodyStruct so if you have that in your game object, remove it.

The cPhysicsObject has 3 virtual functions namely OnColliderBeginOverlap, OnColliderEndOverlap and OnColliderOverlapStay which you can override in your game object and add your own implementation.

cPhysicsObject

As for how to set up the physics system itself, inside your MyGame.cpp class declare a physics object. Moreover you will have to change your game object declarations into smart pointers (shared_ptr), this is for reference tracking.

PhysicsDeclaration

And for initialization do this.

Initialize

For game objects registered as physics objects you will not call their individual update functions as the physics system will take care of it.

PhysicsUpdate

Problems and Drawbacks

In one of my previous posts I mentioned that I would use function pointers for implementing the interface. However, I had to switch to using inheritance because functions inside a class cannot be pointed to by function pointers outside it. In fact function pointers can only be used if the function they point to is declared in the same scope. (I might be wrong and missed something, but based on what I found, this seems to be the case.)

The bigger cause for concern was getting collider data that could reasonably approximate the mesh it represents. I implemented a quick and dirty fix which involved modifying my cMesh class to store center and radius approximations for the mesh it represents.

cMeshModification

Once the game object is assigned a mesh, I update the collider data with that stored inside the mesh. This of course is not the best way to do this, and I will leave it to you to decide how you want to approximate this information.

For testing the system I have an executable which shows the begin and end overlap functions in action.

Here is the executable MyGame_

Here is the physics project you need to use Physics

1 Comment »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s