Jump to content
  • Advertisement
Sign in to follow this  

Predicted position collision impulse

This topic is 1237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there,

i have a particle simulation which uses predicted position to compute the contact points which are instanly solved using a simple projection method right now. This works fine, but there is no bounce or friction at all, but its much more natural if there are at least some sort of bounce and friction and thats the part i am trying to figure out. Unfortunatly the methods i know does not work very well, there is no change at all or the result is invalid, like the particles are falling through the ground or something like that, or is not change at all.


Does anyone know how to deal with restitution and friction in simulations which uses the "predicted position" and "previous position" on every frame for solving the collisions? It looks a bit like verlet integration, but its not the same.


Here is the code for projection the particles against some fixtures - in this part just a circle fixture:

CircleShape circle = (CircleShape) shape;
Vec2f circlePos = new Vec2f(bodyPos.x, bodyPos.y);
Vec2f d = predictedPosition.sub(circlePos);
float lenSq = d.lengthSquared();
float radiusSum = circle.getRadius() + particleRadius;
if (lenSq < radiusSum * radiusSum) {
	float len = (float) Math.sqrt(lenSq);
	Vec2f n;
	if (len == 0) {
	        len = 1;
		n = new Vec2f(1f, 0f);
	} else {
		n = d.div(len);
	float penetration = len - radiusSum;

	// TODO: Calculate velocity impulse for particle
	// Vn = N * (V dot N)
	// Vt = V - Vn
	// Vec2f Vn =  n.mult(v.dot(n));
	// Vec2f Vt = v.sub(Vn);

	// Calculate final projection point

I have a buffer of prediction position and a buffer of last position.

The prediction position are calculated at the start of the simulation to simply force integration like this:

int index = activeParticles[i];
velocityBuffer[index] += forceBuffer[index] * particles[index].invMass * DT;
predictedPositionBuffer[index] = positionBuffer[index] + velocityBuffer[index] * DT;

And of course the final velocity is re-calculated after the simulation like this:

velocityBuffer[index] = (predictedPositionBuffer[index] - positionBuffer[index]) / DT;

Does anyone have some idea?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!