PDA

View Full Version : sep axis theorem & collision response


arctwelve
09-05-2005, 11:08 AM
In 2D, using the sep. axis theorem, a collision leaves me with a vector that represents the distance I need to move to get out of collision. this works fine, but I'm not clear on how I apply surface friction and restitution. If I simply project out of collision I have a dead, but very slipperly surface.

Anyone have a code examples of what to do after you have the distance vector of the collision. This is in a Verlet system.

Reedbeta
09-05-2005, 11:16 PM
Do you also have a normal vector for the surface of collision? If so, then you can do friction by dampening the objects' velocities in the directions perpendicular to the normal (this is a little tricky to do in Verlet, since it doesn't have explicit velocities, but just needs a bit of math).

For restitution, move the object out by twice the distance vector (fully elastic collision), or by somewhere between 1 and 2 times the distance vector for partially inelastic collisions.

arctwelve
09-06-2005, 06:24 PM
Thanks, this is what I ended up with :


public function resolveParticleCollision(p:Particle, sysObj:ParticleSystem):Void {

if (isParticleColliding(p)) {

// the projection vector is also our normal for collision response
var normal:Vector = new Vector(p.mtd.x, p.mtd.y);
normal.normalize();

// get the velocity
var vel:Vector = p.curr.minusNew(p.prev);
var sDotV:Number = normal.dot(vel);

// is the particle moving towards the surface
if (sDotV < 0) {

// compute momentum of particle perpendicular to normal
var velProjection:Vector = vel.minusNew(normal.multNew(sDotV));
var perpMomentum:Vector = velProjection.multNew(sysObj.coeffFric);

// compute momentum of particle in direction of normal
var normMomentum:Vector = normal.multNew(sDotV * sysObj.coeffRest);
var totalMomentum:Vector = normMomentum.plusNew(perpMomentum);

// set new velocity w/ total momentum
var newVel:Vector = vel.minusNew(totalMomentum);

// project out of collision
p.curr.plus(p.mtd);

// apply new velocity
p.prev = p.curr.minusNew(newVel);
}
}
}

Reedbeta
09-06-2005, 09:36 PM
Just curious, but what language is that? It looks a little like a cross between Java and Delphi...

nanaki
09-07-2005, 02:42 AM
I think you will find this link usefull: http://www.d6.com/users/checker/dynamics.htm

.oisyn
09-07-2005, 03:58 AM
Just curious, but what language is that? It looks a little like a cross between Java and Delphi...
20941


It seems more like JScript (a MS extension to JavaScript that has now been ".NETified" :)

arctwelve
09-09-2005, 01:40 PM
Just curious, but what language is that? It looks a little like a cross between Java and Delphi...
20941


It's Actionscript 2, used in Flash. I like to think of it as Java's retarded little brother.