naisan
12-18-2008, 12:17 PM
Hello friends!
I have the following code to rotate a cube (x&y direction). When I rotate xPosition object rotates on x axis with no problems. When I rotate with yPosition, again object rotates on y axis, remaining stationary with no problems. However, when I combine them together (as the code shows), my x-axis rotation changes to rotate the object around an imaginary line, such that the object comes closer to the screen and further back instead of staying in the same place. What have I done wrong?
fAngle = ((-g_xRotation)/50);
xPosition[0] = 0 + (sin(fAngle));
xPosition[1] = 0;
xPosition[2] = 0 + (cos(fAngle));
Glu::gluLookAt(xPosition[0], 0, xPosition[2], 0, 0, 0, 0, 1, 0);
fAngle = ((-g_yRotation)/50);
yPosition[0] = 0 + (2 * cos(fAngle));
yPosition[1] = 0;
yPosition[2] = 0 + (2 * sin(fAngle));
Glu::gluLookAt(yPosition[2],0,yPosition[0], 0, 0, 0, 1, 0, 0);
I have the following code to rotate a cube (x&y direction). When I rotate xPosition object rotates on x axis with no problems. When I rotate with yPosition, again object rotates on y axis, remaining stationary with no problems. However, when I combine them together (as the code shows), my x-axis rotation changes to rotate the object around an imaginary line, such that the object comes closer to the screen and further back instead of staying in the same place. What have I done wrong?
fAngle = ((-g_xRotation)/50);
xPosition[0] = 0 + (sin(fAngle));
xPosition[1] = 0;
xPosition[2] = 0 + (cos(fAngle));
Glu::gluLookAt(xPosition[0], 0, xPosition[2], 0, 0, 0, 0, 1, 0);
fAngle = ((-g_yRotation)/50);
yPosition[0] = 0 + (2 * cos(fAngle));
yPosition[1] = 0;
yPosition[2] = 0 + (2 * sin(fAngle));
Glu::gluLookAt(yPosition[2],0,yPosition[0], 0, 0, 0, 1, 0, 0);