Here's the current code that I've been tinkering over the past few days:
public static void setFPSCamera(float[] matrix, int offset, float eyeX, float eyeY, float eyeZ, float pitch, float yaw, boolean isRadians)
{
// if ( pitchDegrees<-90f)
// pitchDegrees=-89.999999f;
// if (pitchDegrees>90f)
// pitchDegrees=89.999999f;
// if (yawDegrees>360f)
// yawDegrees=0f;
// if (yawDegrees<0)
// yawDegrees=360f;
if (!isRadians){
pitch=(float)Math.toRadians(pitch);
yaw=(float)Math.toRadians(yaw);
}
float cosPitch=FloatMath.cos(pitch);
float sinPitch=FloatMath.sin(pitch);
float cosYaw=FloatMath.cos(yaw);
float sinYaw=FloatMath.sin(yaw);
Vector3f xAxis=new Vector3f(cosYaw, -sinPitch*sinYaw, -cosPitch*sinYaw);
Vector3f yAxis=new Vector3f(0, cosPitch, -sinPitch);
Vector3f zAxis=new Vector3f(sinYaw, sinPitch*cosYaw, cosPitch*cosYaw);
Vector3f eye=new Vector3f(eyeX, eyeY, eyeZ);
matrix[0+offset]=cosYaw;
matrix[1+offset]=0;
matrix[2+offset]=sinYaw;
matrix[3+offset]=0;
matrix[4+offset]=-sinPitch*sinYaw;
matrix[5+offset]=cosPitch;
matrix[6+offset]=sinPitch*cosYaw;
matrix[7+offset]=0;
matrix[8+offset]=-cosPitch*sinYaw;
matrix[9+offset]=-sinPitch;
matrix[10+offset]=cosPitch*cosYaw;
matrix[11+offset]=0;
matrix[12+offset]=-xAxis.dotProduct(eye);
matrix[13+offset]=-yAxis.dotProduct(eye);
matrix[14+offset]=-zAxis.dotProduct(eye);
matrix[15+offset]=1;
}
The commented portion of the code is what I thought I'm trying to do.
When the camera is facing north, the pitch values work correctly.
But when the camera is facing in other directions, the pitch values aren't affected by rotation.
Can anyone give me a hint on what I need to do to modify this matrix? Thanks in advance.