Camera rotation problem

Started by
0 comments, last by Martin Radev 9 years, 6 months ago

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.

Advertisement

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.

Sorry for the thread.

This topic is closed to new replies.

Advertisement