View Full Version : How to rotate a surface so it has a given normal?
09-20-2009, 11:59 AM
Say I have a triangle with normal X. How do I rotate so it has a given normal Y?
09-21-2009, 07:46 AM
The rotation from X to Y is the same as the desired rotation of the triangle. X x Y = Z is some vector perpendicular to both of those, around which you want to rotate. Assuming the normals are, in fact, normalized, the magnitude Z is the sine of the angle between them. So, you essentially need to use the following call:
glRotatef(arcsin(Z.mag())*180/pi, Z.x, Z.y, Z.z);
Depending on where/how you choose to implement this transformation, there may be a better way that avoids the arcsin. You could go straight to the transformation matrix.
09-23-2009, 07:32 PM
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.