This topic is now archived and is closed to further replies.


newbie vector rotation grief

Recommended Posts

I''m using this formula to rotate a vector about the Y axis: X = X*cos(Rads) + Z*sin(Rads) Y = Y Z = -X*sin(Rads) + Z*cos(Rads) I want to use the vector to keep track of the orientation of an md2 model as I rotate it and I want to use the vector in my subsequent transformation so that the model moves off in the direction its facing. My problem is the results don''t bear any relation to the models orientation. This is from my calcModelTrans function, which is called from the render function. I convert from degrees to radians before this bit of code and back again afterwards: if (DirVector.point[0] == 0.0) //to avoid multiplying by zero DirVector.point[0] = 0.1; if (DirVector.point[2] == 0.0) DirVector.point[2] = 0.1; float XX = DirVector.point[0]; //X DirVector.point[0] = DirVector.point[0] * cos(rads) + DirVector.point[2] * sin(rads); //Z DirVector.point[2] = -XX * sin(rads) + DirVector.point[2] * cos(rads); ////////////////// and this is from the Render part, DirVector is initialised to {0.,0.0,-1.0} because the model is facing away from the camera to -Z when its first rendered: if (forward) { calcModelTrans(keyrotate); holdTrans.point[0] += DirVector.point[0]; //X holdTrans.point[2] += DirVector.point[2]; //Z forward = false; } glTranslatef(holdTrans.point[0]/10, //X 0.0, //Y holdTrans.point[2]/10); //Z glRotatef(keyrotate, 0.0f,1.0f,0.0f); myModel->RenderFrame(5); /////////////////// Can anyone help? please?

Share this post

Link to post
Share on other sites