Sign in to follow this  
B026

Help - Designing collision node, node and physics body classes.

Recommended Posts

Hi, this is my first post  :D. I'm writing a 2D game engine in c++ for personal use. Well, let's see....

 

I have the CollisionNode class which has shapes which define it, can be transformed (rotated, moved, scaled, ...) and can check collisions, by AABB and SAT, with other collision nodes.

 

The Node class is the base class of the scene graph, it can be transformed too. I think it must to have a way to check collisions, inherit from CollisionNode can be the best choice (I think :)).

 

Finally the PhysicsBody class is a Collision node affected by physics. To achieve this it can inherit from CollisionNode too.

 

When I want to use both (Node and PhysicsBody), I'd attach a PhysicsBody to a Node.

 

Is my design OK??. How would you do it??

 

Thanks a lot :)

Share this post


Link to post
Share on other sites

Welcome :)

 

I think that your design sounds fine.

 

I would have used a similar approach of having a base class for collision and inheriting off from that to provide different types of collision. For example, BoxCollision and SphereCollision both inherit from Collision, keeping the level of inheritance small, then checking for collisions by testing all Collision type objects (are better ways to find which two objects you need to test rather than cycling over all of them till you find the correct ones!).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this