Programming - Games - OpenGL and C++

This toturial was written for me by Imran Khan (,
Copyright (c) 2004 is owned by Martin Baker

3D Rotation :

This Section will add rotationally motion to the 3d Objects , we just created in our previous Section. We have to add some lines to the existing method of ' DrawGLScene'.

we will use ' glRotatef ' method for rotation. 'glRotatef ' got 4 arguments , 1 st is the angle of rotation , 2nd is x-axis , 3rd is y-axis,4th is z-axis.

here is the code...


We have just add one line " glRotatef(rtri,0.0f,1.0f,0.0f); " . rtri is an float type variable.We will use this variable so that the pyramid will be in rotation all the time.We only want rotation on Y-axis thats why we pass " 1.0f " in the 3rd argument.

Same as above we add one line for Cube rotation.


We want rotation on X and on Z-axis as well thats why we pass "1.0f" in 2nd and 4th argument.

Now here is the increament and decrement for the 2 variable , " rtri" & "rquad", so that both object remain in rotation.


Simple we increament,decrement everytime when the method run. You can change its value to check the effent.Higer the value more fast it wil rotate.

Here will be the Output.

Download the Source Code.

next: textures

metadata block
see also:
Correspondence about this page

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2022 Martin John Baker - All rights reserved - privacy policy.