Login  Register

Camera Direction Messup

Posted by OliverY on Nov 26, 2014; 1:02am
URL: https://forum.jogamp.org/Camera-Direction-Messup-tp4033636.html

EDIT 1: So I noticed that the camera can only move forward and backward on the z axis. Why not the X?

Hi everyone, so I'm working on a camera class for my 3d game. I think some of my calculations of off. So if I strafe left or right then move forward it doesn't consider that strafed movement, if that makes sense... Also the camera rotation gets messed up.

Here's my code:
switch (direction)
{
        case DONT_MOVE:
                break;
        case FORWARD:
                x -= 0.1 * (float)Math.sin(Math.toRadians(yaw));
                z += 0.1 * (float)Math.cos(Math.toRadians(yaw));
                break;
        case BACKWARD:
                x += 0.1 * (float)Math.sin(Math.toRadians(yaw));
                z -= 0.1 * (float)Math.cos(Math.toRadians(yaw));
                break;
        case STRAFE_L:
                x -= 0.1 * (float)Math.sin(Math.toRadians(yaw - 90));
                z += 0.1 * (float)Math.cos(Math.toRadians(yaw - 90));
                break;
        case STRAFE_R:
                x -= 0.1 * (float)Math.sin(Math.toRadians(yaw + 90));
                z += 0.1 * (float)Math.cos(Math.toRadians(yaw + 90));
                break;
        default:
                break;
}

dx += mouseCenter.x - MouseInfo.getPointerInfo().getLocation().x;
dy += mouseCenter.y - MouseInfo.getPointerInfo().getLocation().y;

pitch = dy * 0.05f;
yaw = dx * 0.05f;

gl.glLoadIdentity();

gl.glTranslatef(x, y, z);
gl.glRotatef(-pitch, 1, 0, 0);
gl.glRotatef(-yaw, 0, 1, 0);

try
{
        new Robot().mouseMove(mouseCenter.x, mouseCenter.y);
} catch (final AWTException e) {
        e.printStackTrace();
}

Anyone have an idea? Is it my calculations?