I'm trying to create a camera to navigate through 3D space, and I am having problems setting it up. I am doing this Java and apparently using gluPerspective and gluLookAt together creates a conflict (the screen starts to flicker like crazy).
gluPerspective is installed as follows:
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(50.0f, h, 1.0, 1000.0);
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
Then I create a camera matrix using the coordinates of the eyes, forward and upward along the vectors ( http://people.freedesktop.org/~idr/glu3/form_4.png ) (allows you to take the code for the camera is correct.
Finally, before I draw everything I have:
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glMultMatrixf(camera.matrix);
And then I call my drawing routines (which do some translations / rotations on their own, calling glRotatef and glTranslatef).
glMultMatrixf , , . glMulMatrixf , , . glLoadMatrixf , . - ? - ? , , , , .
EDIT: :
private void createMatrix()
{
float[] f = new float[3];
float[] s = new float[3];
float[] u = new float[3];
for(int i=0;i<3;i++){
f[i] = centre[i]-eye[i];
}
f = Maths.normalize(f);
s = Maths.crossProduct(f,upVec);
u = Maths.crossProduct(s,f);
float[][] mtx = new float[4][4];
float[][] mtx2 = new float[4][4];
for (int i = 0; i < mtx.length; i++) {
for (int j = 0; j < mtx[0].length; j++) {
mtx[i][j] = 0;
mtx2[i][j] = 0;
}
}
for(int i=0;i<3;i++){
mtx[0][i] = s[i];
mtx[1][i] = u[i];
mtx[2][i] = -f[i];
mtx2[i][3]=-eye[i];
mtx2[i][3]=-eye[i];
mtx2[i][3]=-eye[i];
}
mtx[3][3] = 1;
mtx2[0][0]=1;mtx2[1][1] = 1;mtx2[2][2] = 1;mtx2[3][3] = 1;
mtx = Maths.matrixMultiply(mtx,mtx2);
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
this.mtx[i*4+j] = mtx[i][j];
}
}
}
, - , , , , .
EDIT2: , (, , ) , ( gluLookAt, ).