Jump to content
  • Advertisement
Sign in to follow this  
Martin Radev

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.

If you intended to correct an error in the post then please contact us.

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.

Edited by martinradev

Share this post

Link to post
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.

Sorry for the thread.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!