2
\$\begingroup\$

This physics does not have to be very complex at all.

There are a number of rectangles and one ball, all of which have the appropriate bounding volumes constrained to them, it would be great if the ball could knock them over and they in turn could knock into each other.

What is the most basic way of doing this?

\$\endgroup\$
6
  • \$\begingroup\$ Adding two questions about the same topic in a row is not constructive. Please remove one of them and ask whatever you need to ask in the other. \$\endgroup\$ Commented Feb 4, 2012 at 9:23
  • \$\begingroup\$ they're two different questions, if you don't like them, you can vote to close them. \$\endgroup\$ Commented Feb 4, 2012 at 13:11
  • \$\begingroup\$ Do you mean cubes, not rectangles? Rectangles are twodimensional. \$\endgroup\$
    – jcora
    Commented Feb 4, 2012 at 13:25
  • \$\begingroup\$ But they are so dependent that an answer to one is almost certainly going to deprecate an answer to the other. I don't want to be a pissed mod, it's just that you in general will get far better answer and waste less time by stating your question as one. If you have decided to use Bullet then this question is already outdated. \$\endgroup\$ Commented Feb 4, 2012 at 13:29
  • \$\begingroup\$ ok, fair enough. \$\endgroup\$ Commented Feb 4, 2012 at 13:51

1 Answer 1

3
\$\begingroup\$

The scenario you describe is already complex enough that I would strongly recommend using an external physics engine. I can't think of any other way of implementing this that I would personally consider as being simple.

The good news is that integrating a physics engine into your game - if done early on - is usually a very straightforward process.

Details will obviously vary from engine to engine but in most of them it consists of:

  1. Instatiating a World object which will manage the simulation
  2. Associating a Body object with each of your game objects, and adding them to the world.
  3. Updating the World and drawing each game object using the information from their Bodys.

Example

So if for instance, you had a class like this:

class GameObject
{
    Vector3 position;
    Quaternion rotation;
    Model model;

    void Draw()
    {
        model.RenderAt(position, rotation);
    }
}

You could replace the transforms information in your object with that of a physics body instead:

class GameObject
{
    Body body;
    Model model;

    void Draw()
    {
        model.RenderAt(body.Position, body.Rotation);
    }
}

Of course when creating the Body you'd need more information about its shape and behavior, e.g. you could specify the shape of the body using the model's bounding box.

Then it's just a matter of registering the bodies in the world and updating it.

// Register bodies in world
foreach(var gameObject in gameObjects)
    world.AddBody(gameObject.Body);

// Update world
world.Update(elapsed);
\$\endgroup\$
1
  • \$\begingroup\$ Thank you for this honest advice, I'm going to try and implement an external engine. \$\endgroup\$ Commented Feb 4, 2012 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .