PDA

View Full Version : the best way to animate



!!!!!!
07-11-2009, 03:05 PM
I guys i'm new around were and i'm doing a project similiar like this game here http://miniclip.sapo.pt/games/bloxorz/pt/ the game is almost done but now i need do animate the moves, i'm rotating the block by it's center, the block it's made with

glScalef(BLOCO_W,BLOCO_H,BLOCO_W);
glEnable(GL_DEPTH_TEST);
glutSolidCube(1.0f);

and i need to make the block go from this position

http://www.ortit.net/images/cubo1.jpg

to this one

http://www.ortit.net/images/cubo2.jpg

with some soft moviment, can someone help, i need to make this until tuesday

Ilian Dinev
07-11-2009, 04:18 PM
On every frame, you vary a glRotatef param. That's it.

Do not double-post, as we visit all sub-forums. This thread doesn't belong to the Advanced section.

!!!!!!
07-11-2009, 04:32 PM
that's why i put them is two sections, because i didn't now where it belong, sorry and thanks

!!!!!!
07-11-2009, 04:37 PM
but it have to rotate from it's base not from is middle, just with glrotate it won't give the desired efect

Ilian Dinev
07-11-2009, 05:37 PM
then do a glTranslate around it :)

Ilian Dinev
07-11-2009, 06:03 PM
Addendum:
To change the center of rotation of an object, first translate it so that (0,0,0) is the center, then do the rotation, and finally make the inverse translation of that first one. Something like


glTranslatef(0,-1,0); // un-translates
glRotatef(angle,1,0,0);
glTranslatef(0,1,0); // translates to position center

!!!!!!
07-11-2009, 06:22 PM
Addendum:
To change the center of rotation of an object, first translate it so that (0,0,0) is the center, then do the rotation, and finally make the inverse translation of that first one. Something like


glTranslatef(0,-1,0); // un-translates
glRotatef(angle,1,0,0);
glTranslatef(0,1,0); // translates to position center

yes thanks a lot, i made the first move well, but now i wanto to rotate again, from the last positon and not from the start position? The problem is that after make the first move, when you want to make the second move, the object will rotate, centered in the start/initial position? how to change that??

k_szczech
07-13-2009, 01:39 AM
It will not be as easy as few glRotate/glTranslate calls.

After you rotate a block, two axes are swapped. You should delete it and create a new one in it's place.

What I mean is, if you have 2x1x1 block and rotate it - you'll get a "rotated 2x1x1 block" - remove it and place "unrotated 1x2x1 block" in it's place.
You do that after each move (not after each frame).