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

Started by
6 comments, last by Spa8nky 14 years ago
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?
Advertisement
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
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?
Why not just assign it based on it's position if there is no shape? Why include the radius?

theTroll
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 :)
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?
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
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.

This topic is closed to new replies.

Advertisement