1
\$\begingroup\$

I have a capsule (sphere sweep) that I've computed the collision on a mesh with.

I know the point of impact and normal of the face it collides with.

My moving object - I'm using a capsule to represent it for collision purposes - has a quaternion describing its direction of travel.

How do I compute the new quaternion for the object to travel in on the bounce?

\$\endgroup\$
5
  • \$\begingroup\$ I assume this is in a 3D space? \$\endgroup\$ Oct 7, 2012 at 15:11
  • \$\begingroup\$ @JustinSkiles yes, 3D \$\endgroup\$
    – Will
    Oct 7, 2012 at 15:13
  • \$\begingroup\$ When an object bounces of a wall, it's orientation does not necessarily change. That depends on other physical factors like friction and sometimes elasticity. What does change is the object's velocity Vector. And the velocity is usually independent of pose (oriention) \$\endgroup\$
    – Steve H
    Oct 7, 2012 at 16:55
  • \$\begingroup\$ @SteveH yes, although my velocity vector is a quaternion. I've tried to clean up my terminology \$\endgroup\$
    – Will
    Oct 7, 2012 at 20:24
  • \$\begingroup\$ @SteveH is right, but things are usually more complicated since there are also rotational effects/velocities that can result from a collision. hakenberg.de/diffgeo/collision_resolution.htm (the inertia tensor is the accurate way to describe how a body tends to rotate). \$\endgroup\$
    – teodron
    Oct 8, 2012 at 7:27

2 Answers 2

1
\$\begingroup\$

If your object has a forward direction fwd=(x,y,z) and an up direction in its rest position (they all have in 3D, unless they're points or lines), then your quat orientation gives you the current fwd and up vectors.

Perform collision resolution and obtain fwd' and up'.

These two vectors then give you an orientation (a frame) that you can convert to a matrix and get the quat out of it describing your object's new direction of travel and up direction.

\$\endgroup\$
2
1
\$\begingroup\$

Once you have the collision normal (not the normal of the face because corner collisions won't work right that way), you can just split the velocity (which should really be a vector, not a quaternion) into two: normal velocity and tangent velocity.

normalVelocity = dot( collisionNormal, linearVelocity ) * collisionNormal;
tangentVelocity = linearVelocity - normalVelocity;

Now you can just invert the normal velocity to make the object bounce off the collision and recombine both into the new linear velocity vector.

normalVelocity *= -1;
linearVelocity = normalVelocity + tangentVelocity;

I won't cover quaternion-to-vector (and reverse) transformations in this answer because a quaternion isn't the most effective representation of the data. A simple 3D vector does the job as expected and has been already used practically everywhere.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .