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.
sep axis theorem & collision response
Started by arctwelve, Sep 05 2005 05:08 PM
6 replies to this topic
#1
Posted 05 September 2005 - 05:08 PM
#2
Posted 06 September 2005 - 05:16 AM
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.
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.
reedbeta.com - developer blog, OpenGL demos, and other projects
#3
Posted 07 September 2005 - 12:24 AM
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);
}
}
}
#4
Posted 07 September 2005 - 03:36 AM
Just curious, but what language is that? It looks a little like a cross between Java and Delphi...
reedbeta.com - developer blog, OpenGL demos, and other projects
#5
Posted 07 September 2005 - 08:42 AM
I think you will find this link usefull: http://www.d6.com/us...er/dynamics.htm
#6
Posted 07 September 2005 - 09:58 AM
Reedbeta said:
It seems more like JScript (a MS extension to JavaScript that has now been ".NETified"
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.
-
Currently working on: the 3D engine for Tomb Raider.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











