Advertisement

Rotations

Started by January 05, 2003 06:21 AM
0 comments, last by Tagamoga 22 years, 1 month ago
Hello. I try to program rotation, that can be managed by mouse imput. Evereything works fine, when I roted only round the y-axis (horizontal mouse movement) or round the x-axis(vertical mouse movement. After I genereated each functionality for themself, I put them together so that I could rotated my face around two axis with one mousemove, but then the output is all nonsense. float laenge = m_KameraPosition.x*m_KameraPosition.x + m_KameraPosition.y*m_KameraPosition.y + m_KameraPosition.z*m_KameraPosition.z ; laenge = (float)sqrt(laenge); //This is the length of the vector, which represent the camera // this is rotation around y-axis m_KameraPosition.x = laenge * (float)sin(angleY); m_KameraPosition.z = laenge * (float)cos(angleY); // this is rotation aroun x-axis m_KameraPosition.y = laenge * (float)sin(angleX); m_KameraPosition.z = laenge * (float)cos(angleX); Can somebody eplain me, why these two part works fine when only one is used, but together my face disaper? Oh, I am porgramming in C++ and DirectX8 Taggi
look at these two lines:

quote:
Original post by Tagamoga
m_KameraPosition.y = laenge * (float)sin(angleX);
m_KameraPosition.z = laenge * (float)cos(angleX);



btw: you could leave out laenge because this sould be a direction vector I guess.

you''re assigning the y and z coordinates to pure x rotation of a base vector, the x coordinate is assigned to pure y rotation - this produces nonsense.

I''m assuming you want to do x rotation before y rotation like it''s done in common 3d games.

you could do the following things:

do x - rotation with a base vector like you did, then y - rotate the resulting point:
temppoint = point;

point.x = temppoint.x*cos(yAngle) + temppoint.z*sin(yAngle)
point.y = temppoint.y;
point.z = -temppoint.x*sin(yAngle) + temppoint.z*cos(yAngle)


a more advanced solution is to set up matrices for each rotation, multiply the matrices to concatenate rotations and transform tthe points which you want to rotate with the matrix.


GA
Visit our homepage: www.rarebyte.de.stGA

This topic is closed to new replies.

Advertisement