I'm using a view matrix to do camera movement and rotation.
viewMatrix = new Matrix4f(); viewMatrix.setIdentity(); Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), viewMatrix, viewMatrix); Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), viewMatrix, viewMatrix); Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), viewMatrix, viewMatrix); Matrix4f.translate(new Vector3f(x * (-1), y * (-1), z * (-1)), viewMatrix, viewMatrix); I'm manipulating the rotation values around each axis here:
//left and right public void rotateY(float amount) { ry += amount; } //Up and down public void rotateUp(float amount) { rx += amount; if(rx < -90) rx = -90; if(rx > 90) rx = 90; } This all works fine. Now i'm trying to create a more "free" camera so that i always turn left an right and don't simply rotate around the Y-Axis.
For the rotation up you simply remove the if-cause. But for the rotation sidewards you need to calculate the parts for the x- and the z-axis using sin and cos. That's where i get confused. How can i rotate sidewards correctly?