Skip to content

Commit

Permalink
gpu: flip y/z in projection
Browse files Browse the repository at this point in the history
Flipping y/z is necessary to go from jagex to gl coordinates. This was
doing it via rotx by over rotating the camera so that it was looking
down at the scene upside down.

This took me a bit to figure out and I think is unintuitive. Flip y/z in
projection() instead. The new matrix is (in row-major order)

2/w      0     0      0
0     -2/h     0      0
0        0     1    -2n
0        0     1      0

Note that, as with the previous behavior, the final z values are [0,1)
instead of [0,-1) like gl uses for NDC. Since we do not use the z values
currently that does not matter.
  • Loading branch information
Adam- committed Dec 20, 2023
1 parent b7d8834 commit 6518013
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ public void draw(int overlayColor)
// Calculate projection matrix
float[] projectionMatrix = Mat4.scale(client.getScale(), client.getScale(), 1);
Mat4.mul(projectionMatrix, Mat4.projection(viewportWidth, viewportHeight, 50));
Mat4.mul(projectionMatrix, Mat4.rotateX((float) -(Math.PI - cameraPitch)));
Mat4.mul(projectionMatrix, Mat4.rotateX((float) cameraPitch));
Mat4.mul(projectionMatrix, Mat4.rotateY((float) cameraYaw));
Mat4.mul(projectionMatrix, Mat4.translate((float) -cameraX, (float) -cameraY, (float) -cameraZ));
GL43C.glUniformMatrix4fv(uniProjectionMatrix, false, projectionMatrix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public static float[] projection(float w, float h, float n)
return new float[]
{
2 / w, 0, 0, 0,
0, 2 / h, 0, 0,
0, 0, -1, -1,
0, -2 / h, 0, 0,
0, 0, 1, 1,
0, 0, -2 * n, 0
};
}
Expand Down

0 comments on commit 6518013

Please sign in to comment.