PDA

View Full Version : Rotating a GLXMilkshape3D model



cairnswm
09-05-2004, 06:47 AM
How do I rotate a Milkshape 3D model? I have the following code from the 'Sprites' demo:

glPushMatrix;
glTranslatef(-X,0,-Y);
glScalef(5,5,5);
glRotatef(Anim / 4, 0, 1, 0);
glRotatef(Anim / 5, 1, 0, 0);

Texture.Bind;
Model.Draw;
glPopMatrix;

But I have no idea what it is trying to do :)

I have tried to use this same code in the Startrek Enterprise Milkshape demo to turn the ship without moving the camera but it doesn;t work and quite honestly I dont know what I'm doing let alone what I'm doing wrong :)

Why does the GLXMilkshape3D component not have a Rotate method? I would have thought this would be a common function that everyone would use?

Abened
09-05-2004, 08:48 AM
To rotate milkshape 3D models (as any other bunch of polygons 8) ), there's no other way but to use pure OpenGL. To do so, you have to include opengl if your use clause.
Then the key to rotating is the function glRotate (or glRotatef which uses the single type parameter instead of double...). This function's parameters are the angle of the rotation (in degrees), and the x,y, and z component.
For example if you use glRotatef(90, 0, 0.5, 0) it will execute a 45A¬? rotation around the y axis. Easy, as you see :P

Ok now you're able to rotate, i think the translation (glTranslatef) and the scaling (glScale) are not a problem !

Just remeber some tips :
- Always start by glPushMatrix and end by glPopmatrix : the first function "saves" the matrix used to draw and the second one restores the old matrix to get back your good ol' coordinates :lol:

- Never use Model.Draw(X,Y,Z) when rotating or scaling because the coordinates where the model will be drawn are modified by the previous instructions so your model won't be where expected (at all ;) )

- Always start by tranlating, then scaling and rotating (do not forget to draw your model nevetheless :P). The trick is that translating doesnt affect coordinates, but the other 2 do, so if you use translate after rotating or scaling the result will be... hazardous (i'm not sure there's an order between scaling and rotation though).

- Always have fun making games and exploring the beautiful world of OpengGL and GLXTreem !

Abened, in an inspired day lol (pardon my english i cannot write so much without making mistakes :roll: )

cairnswm
10-05-2004, 05:31 AM
OK! It all makes sense now (sort of :) )

How does OpenGL know which model I'm trying to rotate? If I look at the example I used it doesn't refer to any specific model. If I want to rotate only a single model how would I do it in a game using 3 or 4 models.

Andreaz
10-05-2004, 11:02 AM
OpenGL rotates the whole scene, so it doesn't know what object you are rotating and don't need to either, all commands you are sending to opengl is executed in the oposite order as you sended them, that's why it works as it does. :D