Jump to content
  • Advertisement
Sign in to follow this  

Rotation without using glRotatef

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm creating an arbitrary mirror which needs to reflect an object positioned in the origin (0,0,0). (i'm drawing the whole scene according to this origin) I need to rotate the mirror in a circle around the origin so the object placed in the origin will be seen in the mirror. In order to calculate the reflection i always need to know the mirror's coordinates according to my origin and therefore i'm not using glRotatef. I tried applying a rotation matrix to the mirror's points with no success. Any ideas on how this should be done? or an alternate solution to my problem? Thanks, Idan

Share this post


Link to post
Share on other sites
Advertisement
I assume you'll only be rotating it in 2D, but extending to 3D (spherical coordinates should be easy).

First position your vertices in the default non-rotated position:


[ -S 0 S ]
[ -S H S ]
[ S H S ]
[ S 0 S ]


Where H is the height of the mirror and S is half the width. I assumed it starts from 0 on y.

Just multiply your vertices by this rotation matrix:


| cos_angle -sin_angle |
| sin_angle cos_angle |


The calculation will look like this:

newX = x * cos_angle - z * sin_angle
newZ = x * sin_angle + z * cos_angle

Don't make the mistake of storing the intermediate X result in the old one's place or you'll get newZ wrong.

Keep you Y coordinates the same.

Change your angle each frame by a fixed amount (a rather small one, or even better by a speed that you multiply with the frame duration).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!