Hi, i try to rotate camera by setLookAt, and set matrix to ml matrix but it doesn't work.
I try search in google, but i don't saw actual sample.
It's my camera code:
public class Camera {
private Vector3f position;
private Vector3f rotation;
private Matrix4f viewMatrix;
private Matrix4f positionMatrix;
private final Vector3f xAxis = new Vector3f( 1, 0, 0 );
private final Vector3f yAxis = new Vector3f( 0, 1, 0 );
private final Vector3f up = new Vector3f( 0, 1, 0 );
private final Vector3f zAxis = new Vector3f( 0, 0, 1 );
Shader shader;
public Camera(Vector3f position) {
this.position = position;
this.rotation = new Vector3f();
this.viewMatrix = new Matrix4f();
this.positionMatrix = new Matrix4f();
build();
}
public void build() {
glActiveTexture(GL_TEXTURE1);
glEnable(GL_DEPTH_TEST);
shader = ShaderManager.getDefaultShader();
shader.enable();
Matrix4f perspectiveMatrix = new Matrix4f();
perspectiveMatrix.perspective(1, Syswow.graphics.getAspectRatio(), -10, 0);
positionMatrix.identity();
positionMatrix.translate(position);
shader.setUniformMat4f("pr_matrix", perspectiveMatrix);
shader.setUniformMat4f("vw_matrix", positionMatrix);
shader.setUniform1i("tex", 1);
shader.disable();
}
public void update (float deltaTime) {
}
public void render() {
shader.enable();
positionMatrix.identity();
positionMatrix.translate(position);
viewMatrix.setLookAt(rotation, position, up);
shader.setUniformMat4f("vw_matrix", positionMatrix);
shader.setUniformMat4f("ml_matrix", viewMatrix);
shader.disable();
}
public Vector3f getPosition() {
return position;
}
public void setPosition(Vector3f position) {
this.position = position;
}
public void setFPSRotation(double xpos, double ypos) {
xpos = xpos - Syswow.graphics.getWindowWight() / 2;
Syswow.debug.log("xpos" + xpos );
xpos = xpos / 100;
rotation.x = rotation.x + (float)xpos;
rotation.y = rotation.y + (float)ypos;
if(rotation.x >= 360.0f || rotation.x <= -360.0f)
rotation.x = rotation.x % 360.0f;
if(rotation.y >= 360.0f || rotation.y <= -360.0f)
rotation.y = rotation.y % 360.0f;
if(rotation.z >= 360.0f || rotation.z <= -360.0f)
rotation.z = rotation.z % 360.0f;
if(rotation.x <= -90.0f)
rotation.x = -90.0f;
else if(rotation.x >= 90.0f)
rotation.x = 90.0f;
Syswow.debug.log(rotation.x + " " + rotation.y + " " + rotation.z);
}
}
my shader code:
#version 330 core
layout ( location = 0 ) in vec4 position;
layout ( location = 1 ) in vec2 tc;
uniform mat4 pr_matrix;
uniform mat4 vw_matrix;
uniform mat4 ml_matrix = mat4(1.0);
out DATA
{
vec2 tc;
} vs_out;
void main()
{
gl_Position = pr_matrix * vw_matrix * ml_matrix * position;
vs_out.tc = tc;
}