# Rotation without using glRotatef

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

## 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 on other sites
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).

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009808
• ### Who's Online (See full list)

There are no registered users currently online

×