# Camera rotation problem

This topic is 1523 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have been doing this tutorial http://ogldev.atspace.co.uk/www/tutorial15/tutorial15.html but I have run into problems. I think I did it in a bit different way. The problem is that for some reason at some point the coordinate system seems to change and when I target the bottom and starting going in that direction, I go along another axis.

Basically, I still build a quaternion to the rotation around some axis given some angle.

    Vector3 zAxis(0,0,1);
Vector3 xAxis(1,0,0);
Vector3 yAxis = zAxis.crossProduct(xAxis);

zAxis.rotateAround(yAxis, hAngle);
xAxis = yAxis.crossProduct(zAxis).getNormalizedVector();
zAxis.rotateAround(xAxis, yAngle);
yAxis = zAxis.crossProduct(xAxis).getNormalizedVector();
up = yAxis;
target = zAxis;


Move of mouse:

    if (newMousePosX == mousePosX && newMousePosY == mousePosY) return;
const int deltaX = (mousePosX - newMousePosX);
const int deltaY = (mousePosY - newMousePosY);
hAngle -= deltaX/30.0f;
yAngle -= deltaY/30.0f;
yAngleTotal -= deltaY/30.0f;
if (yAngleTotal > 90.0f) {
yAngle -= (yAngleTotal - 90.0f);
yAngleTotal = 90.0f;
} else if (yAngleTotal < -90.0f) {
yAngle += (-90.0f - yAngleTotal);
yAngleTotal = -90.0f;
}
glutWarpPointer(mousePosX, mousePosY);


I hope I have understood everything correctly. I set the Z-axis and the X-axis and get the Y-axis by the corresponding cross product. Then I rotate the Z-axis around the yAxis given the angle. This is basically, the left-right rotation. I get the new X-axis by the cross product of the new Z-axis and the Y-axis.

Then I rotate the zAxis around the new new X-Axis. This is basically the up-down rotation and get the new Y-axis by the cross product.

Then I store the up and the target vector. However, this doesn't seem to work as I want. It could be so that everything is fine, but it seems incorrect due to the fact that I have only 1 triangle to orientate around.

Do you think that everything is fine?

The rotation around axis is done using a Quaternion as explained there and also read additional material on the internet.

##### Share on other sites

Ok, I am sorry. I think it is ok, but I got a bit confused of how the scene should actually look like. I did some checks and the position was at it should be. The problem was that it seemed like something was going wrong due to a relatively big FOV.

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633696
• Total Posts
3013394
×