Comments (4)
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.
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.
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.
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)
- Manifold::Initialize() sqrt of square not required? HOT 2
- randygaul.net is down. HOT 1
- order of selection of vertices and order of calculating face normal in CircleToPolygon() do not match
- ‘dt’ undeclared
- Wrong friction calculation? HOT 1
- Square inside polygon results in no collision because of BiasGreaterThan. HOT 2
- Repeat simulation with different dt
- About Compilation on Windows HOT 1
- Circle friction not working as intended? Circle never gets any slower. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from impulseengine.