I have just began with LWJGL and have ended up with a problem, I can’t get a Matrix4f camera to work, no matter what I’m using. All the tutorials I have seen have loads of other codes with shaders, and calculations for FPS movement, which confuses me. I just want a simple camera that I can move in X, Y, and Z.
Thats why LWJGL is called a low level library, you have to do everything yourself.
When you have a Matrix4f, you need to send this matrix to an shader and apply the transformations there.
To set x,y,z in a matrix, you could simply do this:
public void Move(float x, float y, float z){
m03 = x;
m13 = y;
m23 = z;
}
I don’t mind doing things myself, It’s just when I don’t find any tutorials that explain things clearly for me.
With that code you gave me nothing happens, and with the code I got from the tutorials, nothing happens. I can move the test cube I have with the cubeLocation variable. But not the camera itself.
while(!Display.isCloseRequested()){
inputUpdate();
view.setIdentity();
Matrix4f.translate(location, view, view);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(cubeLocation.x, cubeLocation.y, cubeLocation.z);
glBegin(GL_QUADS);
/* Lots of glVertex3f calls */
glEnd();
glPopMatrix();
System.out.println(location);
Display.update();
}
Display.destroy();
}
I tried with and without glLoadIdentity() but again, whatever I do I cant back away from the cube.
EDIT: I when I tested you code I replaced Matrix4f.translate(location, view, view); with
view.m03 = location.x;
view.m13 = location.y;
view.m23 = location.z;
Thats because you dont use the view matrix.
If you want to use this, you should convert the matrix to a float buffer and upload it like this:
GL11.glLoadMatrix(viewbuffer);
However putting everything into the opengl state is depricated, you should use shaders instead (then you would have known the camera matrix is not passed).