Mungo
May 10, 2004, 3:33am
1
I’m having problems with implementing animations that are controlled by equations.
Im currently doing simple rotations. When rotating in x it seems to work fine but when rotating in y or z it turns a but and then just stops. Ive checked the values being returned from my maths and they all increase as they should, so i cant figure out why its doing this.
Can anyone help??
can you display some code? it would help a lot.
:regards:
Mungo
May 10, 2004, 5:12am
3
well this is the code i use to work out the rotations for the x y z angles
if(animTime>=0){
object.animRotate.x=object.rotation.x+(animations.axis.x*(animTime*animations.speed));
object.animRotate.y=object.rotation.y+(animations.axis.y*(animTime*animations.speed));
object.animRotate.z=object.rotation.z+(animations.axis.z*(animTime*animations.speed));
}
its pretty much initial rotation +speedtime. The mutltiplication before speed time is the axis that the rotation is being performed on.
Put glPushMatrix() - glPopMatrix() around your glRotate() maybe ?
Mungo
May 11, 2004, 11:02am
5
yeah i have glpush and glpop. heres my drawing code:
void Recursive_Draw(TreeStorageNode object)
{
int i;
TreeStorageNode animatedObject;
glPushMatrix();
for(i=0; i<animationData->controllerCount;i++){
if(strcmp(animationData->controllers[i].controlledObject, object.objectName)==0){
animatedObject=Update_Animation(object, animationData->controllers[i], newSimTime);
i=animationData->controllerCount;
printf("ROTX %.2f ROTY %.2f ROTZ %.2f
", animatedObject.animRotate.x, animatedObject.animRotate.y, animatedObject.animRotate.z);
glRotatef(animatedObject.animRotate.x, animatedObject.animRotate.y, animatedObject.animRotate.z, object.rotation.w);
}
}
printf("EXIT
");
glTranslatef(animPosition.x, animPosition.y, animPosition.z);
glVertexPointer(3, GL_FLOAT, sizeof(VectorStorage), &object.mesh[0].pos);
glNormalPointer(GL_FLOAT, sizeof(VectorStorage), &object.mesh[0].normal);
glTexCoordPointer(2, GL_FLOAT, sizeof(VectorStorage), &object.mesh[0].texCoord);
glDrawElements(GL_TRIANGLES, 3*object.mesh->triangleCount, GL_UNSIGNED_INT, object.mesh->indices);
if(object.childCount!=0){
for(i=0; i<object.childCount; i++)
Recursive_Draw(object.childrenPointers[i]);
}
glPopMatrix();
}
its not great but it reflects my rather rubbish programming techniques
>> glRotatef(animatedObject.animRotate.x, animatedObject.animRotate.y, animatedObject.animRotate.z, object.rotation.w);
Hehe, don’t forget to read the docs
glRotate is defined as :
glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
So you need to use :
glRotatef( rotate.z , 0,0,1);
glRotatef( rotate.x , 1,0,0);
glRotatef( rotate.y , 0,1,0);
The correct order will depend of your case.
Mungo
May 12, 2004, 12:21am
7
ohh im so dumb. thanks very much, most problems i come across are ones like these it gets a bit tiresome hehehe.
ps it works like a dream
Mungo
May 12, 2004, 8:35am
8
ok so i have the animations working just perfectly but now things are rotating around the axis of other objects axis. I was thinking it was my pop push matrices being in the wrong place but ive looked over it and i cant see that its wrong.
can someone with a fresh pair of eyes see if this is the problem. the code from above hasnt changed much from what i currently have. so if there is a problem it will be in there.
cheers for any help