I’ve been trying to get back into 3D for a few days now, and I decided to make the camera. The problem is that when I rotate around the z axis, the rotation is actually applied to my movement in such a way that the y position of the camera rises a little if the z rotation is not 0. I’ll show you my code:
if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
float yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xpos -= (float) (Math.cos(yrotrad)) * strafeSpeed;
zpos -= (float) (Math.sin(yrotrad)) * strafeSpeed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
float yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xpos += (float) (Math.cos(yrotrad)) * strafeSpeed;
zpos += (float) (Math.sin(yrotrad)) * strafeSpeed;
}
if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += (float) (Math.sin(yrotrad) / walkSpeed);
zpos -= ((float) (Math.cos(yrotrad)) / walkSpeed);
ypos -= ((float) (Math.sin(xrotrad)) / walkSpeed);
}
if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos -= (float) (Math.sin(yrotrad) / walkSpeed);
zpos += ((float) (Math.cos(yrotrad)) / walkSpeed);
ypos += ((float) (Math.sin(xrotrad)) / walkSpeed);
}
And my mouse code:
public void updateMouse() {
mouseX = Mouse.getX();
mouseY = 720 - Mouse.getY();
mouseDX = Mouse.getDX();
mouseDY = -Mouse.getDY();
Mouse.setGrabbed(true);
xrot += (((float) mouseDY) * .090);
yrot += (((float) mouseDX) * .090);
if(xrot > 90){
xrot = 90;
}
if(xrot < -90){
xrot = -90;
}
}
Obviously this is a trig question, but I’m not the best at trig (taking it next semester), so I don’t know how to fix it!