Advertisement

"Game Physics Engine Development" - resting contacts

Started by January 13, 2015 11:07 PM
10 comments, last by Irlan Robson 9 years, 11 months ago

I have a qeustion regarding the book's content, namely resting contacts. I suppose only people who have read the book might be able to answer my question but if you would like to help me but has not read it I can provide any problem's details if necessary.

I created a very simple sample using your framework. There is a particle
resting on position (0.0, -0.1, 0.0). Collision happens when Y
coordinate is below -0.1 so this contact is indeed resting. I also add
(0.0, -1.0, 0.0) force each frame. Since the contact is resting I
thought the particle would stand on the ground but it appears to be
bouncing. Why is that so?

Here is the Particle Contact Generator:

class CG : public cyclone::ParticleContactGenerator
{
public:
cyclone::Particle *particle;

virtual unsigned addContact(
    cyclone::ParticleContact *contact,
    unsigned limit
    ) const
{
    if (particle->getPosition().y <= -0.1f)
    {
        contact->contactNormal = cyclone::Vector3(0.0f, 1.0f, 0.0f);
        contact->restitution = 1.0f;
        contact->particle[0] = particle;
        contact->particle[1] = nullptr;
        contact->penetration = -0.1 - particle->getPosition().y;

        return 1;
    }

    return 0;
}
};

myPart particle creation:


    cg.particle = &myPart;
    world.getContactGenerators().push_back(&cg);

    myPart.setPosition(0.1f, -0.1f, 0.0f);
    myPart.setVelocity(0.0f, 0.0f, 0.0f);
    myPart.setDamping(1.0f);
    myPart.setAcceleration(0.0f, 0.0f, 0.0f);
    myPart.setMass(1.0f);
    myPart.clearAccumulator();

    world.getParticles().push_back(&myPart);

and force that I apply in the update function:


    myPart.addForce(cyclone::Vector3(0.0f, -1.0f, 0.0f));

Is that correct that particle myPart should be resting instead of
bouncing off the -0.1 ground?

Would need to see the code for what happens with that contact you created.

Inspiration from my tea:

"Never wish life were easier. Wish that you were better" -Jim Rohn

soundcloud.com/herwrathmustbedragons

Advertisement

I don't want to be rude or anything, just trying to help -- That book is pretty outdated and the contents aren't something to take too seriously. It's usually only recommended as an introduction to the overall idea of a physics engine, kind of like a first draft.

I would recomment to implement sequential impulse method which is very well documented and very stable.

There exist some good source examples for this technique in the box2d-lite project. The Math behind is pretty simple.

I have implemented this without any professional math background at all. Of course without any basic vector math knowledge you wont get anywhere.

The only thing which is pretty hard is to create a robust contact generator for conves shapes, but circles and line segments are really simple to implement and a good start i can recommend.


I don't want to be rude or anything, just trying to help -- That book is pretty outdated and the contents aren't something to take too seriously. It's usually only recommended as an introduction to the overall idea of a physics engine, kind of like a first draft.

I second that.
The author didn't did a bad book. He just uses a lot of "hacks" in order to apply sequential impulses to the rigid bodies. Of course such kind of hacks still exist in current physics engines to avoid more robusts methods that are being used in offline rendering (such LCP solvers etc.) but I think that he simple did something based on simple analysis (sorting contacts by penetration was one of it).
You should learn from Erin Catto's or Chris Hecker GDC articles if you want to understand how position constraints, velocity constraints, etc. really works.
To build a physics engine you should know at least how vector calculus or calculus in general works also; you can probably get one 2D physics engine working without "the calculus knowledge" but in order to get into 3D that's a quite good advice.

Hi Irlan,

If I remember correctly, Ian sorted contacts according to "seperating velocity" which is defined as

float sep_vel=((Bvel-Avel)dot(normal) or put another way

float sep_vel=(relative velocity)dot(normal)

The idea being that the contact with the smallest (ie most negative velocity) should get sorted first

After I implemented this function however, and iterated over Ian's suggestion of at least 2x through the contact resolver, I noticed no discernable difference.

Of course, I speak as someone with very limited knowledge.

Mike

Advertisement

Hi Irlan,

If I remember correctly, Ian sorted contacts according to "seperating velocity" which is defined as

float sep_vel=((Bvel-Avel)dot(normal) or put another way

float sep_vel=(relative velocity)dot(normal)

The idea being that the contact with the smallest (ie most negative velocity) should get sorted first

After I implemented this function however, and iterated over Ian's suggestion of at least 2x through the contact resolver, I noticed no discernable difference.

Of course, I speak as someone with very limited knowledge.

Mike

Something like that. Anyway... that book it is outdated and for learning purposes we should use all the GDC slides that was made by authors of current most used engines because they talk a lot about approaches that can reduce CPU overhead while satisfying solving constraints (sequential impulse solvers are quite stable).

At your and Randy's suggestions, I will have a good look at those slides. The advantage with Ian's book of course is its level of comprehensivness and available source code, not to mention proofs in a very tough topic.

Mike

I've already solved the problem with resting contacts.

I guess these (http://box2d.org/downloads/) are the slides you were talking about?

Also, in the book the is an excercie to build a trebuchet using mass-aggregate system. Has anyone tried it and could suggest their solution? So far I have built sort of pendulum but I'm not sure if I'm heading in the correct direction smile.png

EDIT:

On a side note. The author of the books talks about, for instance, separating velocity. Is that correct term? I have doubts as this is a scalar value. So in my code I tend to replace the word "velocity" with "speed". When I read velocity I immediately think about vectors.

I guess these (http://box2d.org/downloads/) are the slides you were talking about?


These and those on Google Project Page.

This topic is closed to new replies.

Advertisement