Rotating an OBB to align with a plane
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]
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement