Sign in to follow this  
Spa8nky

[C#] Interface design. How should I deal with this type of physics body?

Recommended Posts

Spa8nky    230
Currently any object that is inserted into my quadtree requires a body:
    public interface IQuadtree_Object
    {
        RigidBody2D Body { get; }           // Body used in physics simulation (Quadtree will reallocate node this frame if the body is awake)

        void Draw();
        void Update(float dt);
    }

Not all objects in the quadtree should be required to have a rigid body though, as some objects maybe passable. When dealing with these types of objects should I add a boolean parameter to Body to say whether it is passable or not (thus skipping collision detection), or should I rethink the entire interface and choose to have null for body should it not be required for collisions and physics simulation but still need to be inserted into the quadtree?

Share this post


Link to post
Share on other sites
TheTroll    883
Have a collision tree and a draw tree. They will be using the same objects so memory won't be too bad because you are just storing refernces. It will speed up your collision detection because you don't have to walk through a tree with non-collision'able items.

theTroll

Share this post


Link to post
Share on other sites
Spa8nky    230
Currently my quadtree relies on the object's radius and position in order to assign it a node:


float delta = o.Body.Shape.Position.Index(i) - node.centre.Index(i);

if (Math.Abs(delta) <= o.Body.Shape.Radius)



If I were to ignore bodies without shapes then I could do the following:


if (o.Body.Shape != null)
{
position = o.Body.Shape.Position;
radius = o.Body.Shape.Radius;
}
else
{
position = o.Body.Position;
radius = o.Body.Radius;
}



The thing is, how would I assign the body a radius if it has no shape on which to base its radius?

So basically I would have:

Actor -> Body -> Shape

An actor can have adjust its size by will always take its rotation and position from its body.
If the body has a shape then it will always take its world transform from its shape.

Does this process make sense or have I over complicated things?

Share this post


Link to post
Share on other sites
Spa8nky    230
Quote:
Original post by TheTroll
Why not just assign it based on it's position if there is no shape? Why include the radius?

theTroll


Of course! I only need the radius for correct collision detection. Why didn't that occur to me? I feel a little foolish now.

Thanks for pointing that out :)

Share this post


Link to post
Share on other sites
Spa8nky    230
Dang, I spoke too soon.

What about non collidable objects that are very large?

If they are represented as points then they won't get drawn if their point(position) is inside a node that is not inside the camera's bounding frustum.


This will be a problem if the objects are much larger than the node in which they are placed?

Share this post


Link to post
Share on other sites
TheTroll    883
Why not add a rough size value for all object. Make it a simple short or something that just gives an approximation of the size of the furthest edge of the object. That will solve your bounding frustum issues.

theTroll

Share this post


Link to post
Share on other sites
Spa8nky    230
Quote:

Why not add a rough size value for all object


If I were to do that then objects with no shape would still be drawn if they are off the screen as they haven't been assigned a node correctly. In other words a large radius value would cover larger objects but it would place all the non collidable objects in the root node.

I still require an accurate radius, even when no shape is present.

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