Recommended Posts

Hi there,
I am coding a small app where I drop a few boxes on an irregular floor and I'd like them to be rotated according to the ground normal once they hit the floor but I'm having problems with it, I tried building a quaternion from the normal and getting the rotation from it but didn't work very well... anybody has any ideas of another method to orientate a box given a triangle normal??
Thanks in advance for any help :)

0

Share this post

Link to post

Share on other sites

Advertisement

Guest Anonymous Poster

Use Collision Detection to see when boxes hit the floor. As long as your Collision Responce doesn't make them bounce too much (dampened) then the boxes should end up resting on the ground automatically after a while.

Could there be a problem with gravity in your program? Maybe if gravity was pointed up instead of down the boxes might not want to land flat on the floor...

0

Share this post

Link to post

Share on other sites

Guest Anonymous Poster

Original post by Elefagente_Secreto orientate a box given a triangle normal??

Box.Z=Triangle.Normal ?

that should make them line up....

Or if you have information about what part of the box hits the floor first you could take the normal force, and separate it into separte torque and translation force at the point of contact, then use that to calculate how the box should rotate and bounce.The translation component is whatever part of the normal force aligns with the line from the center of the box to the contact point. the torque component is whatever is left over after translation is subtracted outso its just a matter of some simple vector projections to calculate them

0

Share this post

Link to post

Share on other sites

I'm using the following code in my matrix class (i found somewhere on the net), and it works neatly.

GR::tVector is a 3d-vector, GR::f32 is a float. The code is using a lot of vector and math functions but the name should give them away. One problem though: Orienting along a vector is not enough information; the object can be rotated about that vector as well.

Share this post

Link to post

Share on other sites

It's possible that you are having a problem because a surface normal does not give you enough information compute an orientation. There are an infinite number of orientations that will line up with a surface normal. Luckily, it is easy to compute one of them. You can compute the axis and angle of a rotation that will line up two unit vectors (in your case, the normal of the floor surface and the normal of the box surface) like this:

axis = normalize( cross( v1, v2 ) ) angle = acos( dot( v1, v2 ) )

A note of caution: You should clamp the parameter of acos to [-1,1] just in case the result of the dot product is outside of that range. v1 and v2 must not be parallel (if they are, you can pick any axis).