• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# polygon rotation

This topic is 6270 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i need to rotate a polygon so that its normal is 0,0,1. how can i do that?

##### Share on other sites
Let N be your normal and Z = {0,0,1}
Assume N is normalized ||N|| = 1
Let U = N cross Z, and x the angle between N and Z.

cos(x) = N dot Z;
x = arc cos( N dot Z )

You can then call glRotate( -x, U )

##### Share on other sites
sorry, but i dont want to rotate it on the screen, i want to
rotate it by changing its values so that all its z-values are the same (so that the normal is 0,0,1) without deforming it.

##### Share on other sites
quote:
Original post by HyperMan
sorry, but i dont want to rotate it on the screen, i want to
rotate it by changing its values so that all its z-values are the same (so that the normal is 0,0,1) without deforming it.

That''s exactly what Fruny''s code does. Nowhere does he say that Z is a screen Z direction. He defines it to be the normal that you desire, (0,0,1). You rotate about an axis perpendicular to both your current normal N and your desired normal (which Fruny called Z). That''s axis is defined by the U vector that Fruny calculates with the cross product. And the amount you rotate is the angle that he calculates using arc cos(N dot Z). The glRotate() call updates your model view transformation matrix (in OpenGL) to cause the polygon rotation that you desire.

What glRotate() really does is to construct a rotation matrix representing a rotation of angle -x, in radians, about axis U. Then it multiplies that matrix by the current model view matrix to get the updated matrix that when applied to the vertices of your polygon results in the entire polygon being rotated, without deforming its shape.

This information is available elsewhere, in tutorials and articles. Check out the "Articles & Resources" section of this site.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 30
• 16
• 11
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015590
×