Rotating an OBB to align with a plane

Started by
2 comments, last by S8N 16 years, 5 months ago
Hi, I have an OBB (oriented bounding box) and need to rotate it so that it is lined up and sitting on a plane. I have the plane normal and the rotate function I have access to for the OBB is of the form void rotate(Quaternion quat). I have no idea how to go around doing this, maths unfortunately isn't my strong point. Can anyone help me? Thanks. [smile]
http://www.thomaswiggins.co.uk (under construction)
Advertisement
First you need to decide which of the box axes you want to align with the plane normal. Then, create an axis-angle rotation (in quaternion form, in this case) from the chosen axis and the plane normal, and submit it to your rotate() function.

Post back if you need further details.
A rotation is defined by an axis and angle.

the axis is the cross product of the two vectors you want to align (which axis of the box you want ot choose), the angle the acos of the dot product of the two vectors.

axis = (box.axis x plane.normal).normalised()
angle = acos(box.axis . plane.normal)

bascially, a quaternion will give you that, but in nice quaternion form. You need to construct a quat given your 'from' and 'to' directions.

Everything is better with Metal.

Well, after much experimentation I seem to have it working almost as I want, theres one minor thing that I may need to come back here for help with later but otherwise its working great. [grin] Thanks for the help!
http://www.thomaswiggins.co.uk (under construction)

This topic is closed to new replies.

Advertisement