Sign in to follow this  
Forrest Smith

Appying an Impulse to a 3d object

Recommended Posts

Ok, so I'm apparently stupid and haven't been to figure this out. Assume a box, a world space collision point (probably a corner of the box), and a world space impulse vector. I will warn you this is NOT a copy paste of code, but it should be extremely clear. The basic issue is that, well, it doesn't work! Objects improperly rotate (as in about a completely wrong axis and with an improper magnitude) when the objects orientation is not about a single axis.
//Everything in World space
MyAwesomeBox::ApplyImpulseInWorld(Vec3 collOrig, Vec3 impulse)
{
Vec3 rad = collOrig - m_position;
Vec3 torque = rad ^ impulse; // Cross product for those unsure
Matrix3 worldInverseInertia = m_orientation * (bodyInverseInertia * m_orientationInverse); // orientInverse is simply the transpote of the regular orient

Vec3 changeInAngularVel = worldInverseInertia * torque;
}

//Convert to body space, calculate change in angular vel, convert back
//Note: collOrig/impulse still in world frame
MyAwesomeBox::ApplyImpulseInBody(Vec3 collOrig, Vec3 impulse)
{
Vec3 rad = collOrig - m_position;
Vec3 radBody = m_orientationInverse * rad;
Vec3 impBody = m_orientationInverse * impulse;

Vec3 torqueBody = radBody ^ impBody;
Vec3 changeInAngularVelBody = bodyInverseInertia * torqueBody;
Vec3 changeInAngularVel = m_orientation * changeInAngularVelBody;
}

It is important to note that both ways of applying the impulse come up with the exact same answer in all cases. So thats some code, let's discuss the actual problem. First, imagine a box laying flat on the ground of dimension (1,1,4) where the y-axis is up, and we're in openGl not that it matters. Imagine the box is in the air with a velocity of (10,0,0). Let the box move and it will hit the ground 'flat' and bounce up, no rotation and it will keep on moving horizontally bouncing up and down with zero rotation. Hurray! Imagine the box rotating 30 degrees about the z-axis. Now when it bounces off the ground it will rotate, only about the z-axis, and it will be 'rollin in the direction that it's travelling, at least after the first bounce. Now imagine the box instead rotated 30 degrees about the x-axis (the direction it is moving). Now when it hits it will just kind of rotate back and forth rotating entirely about the x-axis. Finally, imagine the box rotated about the z-axis and then the x-axis so it will hit with just a single corner. When it does so the resulting rotation, assuming no friction, should be about the x and the z-axis. However, in my case it rotates about the y-axis! This is most definately not what we want to have happen at all. The rotation about the y-axis should be zero. So, despite all of those words I doubt anyone read, anyone see an issue? It has something to do with getting the worldInertiaTensor perhaps. Because in my case the impulse is (0,some number,0) because the box is bouncing off the ground and the normal to the ground is simply (0,1,0). So the torque I get, in the world frame, is properly on the x-z plane. But then when I multiply it with the worldInvTensor I get something terribly wrong because it has rotation about the y-axis and that should not happen. The tensor itself is quite simple - since it's a box it's diagonal and thus the inverse is diagonal as well each non-zero element being 1/regularTensorValue. So I'm not sure what the issue is, but if you think the issue is matrix multiplication being non-communative you're wrong...I think. Yes the orientation is a concenation of matrices - infact it's many concenations over many frames after many collisions. But you can still get it's inverse so I dunno. =[

Share this post


Link to post
Share on other sites
Humor me. Assuming that all of your matrix implementation is correct, I want you to put everything on the same line, with no parenthesis, equivalent to this:


W = R * mJBodyInverse * R.Transpose() * L;


Where w is the angular velocity, R is the orientation matrix, and L is the angular momentum (or change in momentum, whether you choose to use it as an impulse or continuous).

I've had this same problem before, the problem is that although the appear equivalent, they probably aren't underneath the hood.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this