I have an FPS camera, and the yaw and pitch and capping and everything is working 100% accurately on the debug. I'll post the initalization code, it's a bit jumbled though, I initalize some stuff, then make some instances of other classes, then initalize some more stuff. So I'll eliminate the middle stuff.
try {
Display.setDisplayMode(new DisplayMode(800,600));
Display.create();
//Display.setVSyncEnabled(true);
}catch(LWJGLException e){
e.printStackTrace();
System.exit(0);
}
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_TEXTURE);
GL11.glEnable(GL11.GL_3D_COLOR_TEXTURE);
GL11.glEnable(GL11.GL_ALPHA);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45.0F, (800F) / (600F), 0.1F, 100.0F);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
I'll also give you my FPS camera so you may be able to tell what's going on:
package org.ic3d;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;
public class FPSCameraControl{
public Vector3f position = null;
public float yaw = 0.0f;
public float pitch = 0.0f;
public FPSCameraControl(float x, float y, float z)
{
position = new Vector3f(x, y, z);
}
public void yaw(float amount)
{
yaw += amount;
if(yaw>360){
yaw=0+(yaw-360);
}
if(yaw<0){
yaw=360-(0-yaw);
}
}
public void pitch(float amount)
{
pitch += amount;
if(pitch>=180){
pitch=180;
}
if(pitch<=0){
pitch=0;
}
}
public void walkForward(float distance)
{
position.x -= distance * (float)Math.sin(Math.toRadians(yaw));
position.z += distance * (float)Math.cos(Math.toRadians(yaw));
}
public void walkBackwards(float distance)
{
position.x += distance * (float)Math.sin(Math.toRadians(yaw));
position.z -= distance * (float)Math.cos(Math.toRadians(yaw));
}
public void strafeLeft(float distance)
{
position.x -= distance * (float)Math.sin(Math.toRadians(yaw-90));
position.z += distance * (float)Math.cos(Math.toRadians(yaw-90));
}
public void strafeRight(float distance)
{
position.x -= distance * (float)Math.sin(Math.toRadians(yaw+90));
position.z += distance * (float)Math.cos(Math.toRadians(yaw+90));
}
public void lookThrough()
{
GL11.glRotatef(pitch, 1.0f, 0.0f, 0.0f);
GL11.glRotatef(yaw, 0.0f, 1.0f, 0.0f);
GL11.glTranslatef(position.x, position.y, position.z);
}
public void onUpdate()
{
//Calculate Sensitivity
float sen = (0.02F*Settings.SENSITIVITY);
//Get Center Of Screen
int cx = Display.getDisplayMode().getWidth()/2;
int cy = Display.getDisplayMode().getHeight()/2;
//Get Mouse Position From Center
int x = Mouse.getX()-cx;
int y = Mouse.getY()-cy;
//Apply Inverting If Set
if(Settings.invert_y){
y = -y;
}
if(Settings.invert_x){
x = -x;
}
//Apply Sensitivity
float _yaw = (x*sen);
float _pitch = (y*sen);
yaw(_yaw);
pitch(_pitch);
UpdatePosition();
//SET MOUSE TO CENTER
Mouse.setCursorPosition(cx, cy);
lookThrough();
}
public void printROT(){
System.out.println("Pitch : "+pitch);
System.out.println("Yaw : "+yaw);
System.out.println();
System.out.println("XYZ : "+position.x+", "+position.y+", "+position.z);
}
public void UpdatePosition(){
float f=0;
float b=0;
float r=0;
float l=0;
boolean moved =false;
boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT);
if(Keyboard.isKeyDown(Settings.key_forward)){
if(shift){
f=0.07F;
}else{
f=0.04F;
}
moved=true;
}
if(Keyboard.isKeyDown(Settings.key_back)){
if(shift){
b=0.07F;
}else{
b=0.04F;
}
moved=true;
}
if(Keyboard.isKeyDown(Settings.key_right)){
if(shift){
r=0.05F;
}else{
r=0.035F;
}
moved=true;
}
if(Keyboard.isKeyDown(Settings.key_left)){
if(shift){
l=0.05F;
}else{
l=0.035F;
}
moved=true;
}
walkForward(f);
walkBackwards(b);
strafeLeft(l);
strafeRight(r);
}
}
So there. the entire initalizing and the controling of the camera. If you need anything else I'll post it. If it makes it easier I can zip the entire source and upload it.