Hi. This should be a square, instea it is a rectangle:
https://streamable.com/nympw7Isn't that why we are using projection matrices?
public static mat4 perspective(float fov, float aspect, float zNear, float zFar) {
mat4 Result = new mat4();
float tanHalfFovy = (float) Math.tan(fov / 2);
Result.mat[0][0] = 1 / (aspect * tanHalfFovy);
Result.mat[1][1] = 1 / (tanHalfFovy);
Result.mat[2][2] = - (zFar + zNear) / (zFar - zNear);
Result.mat[2][3] = - 1;
Result.mat[3][2] = - (2 * zFar * zNear) / (zFar - zNear);
return Result;
}
This is the perspective code. I copied it from c++ glm and adapt it to java. The code works, the camera movement feels good, the distances between object are normal, just it stretches objects sides.
My window is 1024:768 which is 4/3
methods.perspective((float)(Math.toRadians(45f)), (float)(4/3), 0.01f , 2000f);
I know that because the window is a rectangle it fits a square in it and that cause the stretch. I would prefer to render more of the scene instead of stretching the square.