Giter VIP home page Giter VIP logo

Comments (4)

RandyGaul avatar RandyGaul commented on July 17, 2024

It's a good learning exercise to try and implement an iterative solver that converges to the global minimum. This code intentionally does not implement such a solver, and instead naively applies impulses in isolation. Read more of Erin Catto's resources if you'd like to delve deeper into this topic. A good test would be to convert ImpulseEngine into an iterative solver.

from impulseengine.

mtear avatar mtear commented on July 17, 2024

Ah yes that seems to be what Box2D is doing. Any pointers in the right direction to resources would be very appreciated :) I have been porting Impulse to C# but wanted to make the solving more accurate.
It may just be my ignorance but why would taking the vectors rA and rB and adding them and applying the impulse to just the sum not work?

from impulseengine.

RandyGaul avatar RandyGaul commented on July 17, 2024

rA and rB should be pointing to the same location in world space. They are used to transform from rigid body local space, to world space, or vise versa. Since we compute an impulse along a world space direction, and want to apply this impulse in an equal and opposite manner across both bodies, we must rA and rB from each body respectively.

As for tips I'd suggest looking into Box2D Lite (not the full version). Try to implement the iterative solver without warm starting. The difficult part is tracking touching bodies over multiple frames, and tracking different contact points over multiple frames. From here it's a matter of clamping the accumulated impulse.

from impulseengine.

RandyGaul avatar RandyGaul commented on July 17, 2024

Found some pseudo code from an old email of someone implementing an iterative solver in ImpulseEngine:

// calculate j scalar
float j = calculate( );

// Clamp j to the accumulated impulse
float temp = contact->cache;
contact->cache = Max( temp + j, 0.0f );
j = contact->cache - temp;

// Apply j like normal

And then once this is working make sure to remove the old position projection in ImpulseEngine. You will now see constraint drift if implemented properly. This can be solved with the Baumgarte technique:

const float k_baumgarte = 0.2f;
const float k_slop = 0.05f;

// Calculate bias term
float b = k_baumgarte * (1.0f / dt) * min( 0.0f, penetration + k_slop );

// calculate j scalar
float j = calculate( ) + b;

// Clamp j to the accumulated impulse
float temp = contact->cache;
contact->cache = Max( temp + j, 0.0f );
j = contact->cache - temp;
// Apply j like normal

You can check out my other 3D code example here on github as well as Box2D Lite for additional references.

from impulseengine.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.