Skip to content

Commit 67b4979

Browse files
committed
refactor: create Util3d.getProjectedPoint
1 parent 48ba175 commit 67b4979

File tree

2 files changed

+71
-33
lines changed

2 files changed

+71
-33
lines changed

src/main/java/org/runejs/client/scene/SceneRenderer.java

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -791,47 +791,42 @@ private void renderPlainTile(GenericTile plainTile, int arg1, int tileX, int til
791791
int zC = this.scene.landscape.tile_height[arg1][tileX + 1][tileY + 1] - currentCamera.getPosition().z;
792792
int zD = this.scene.landscape.tile_height[arg1][tileX][tileY + 1] - currentCamera.getPosition().z;
793793

794-
int sinX = currentCamera.getRotation().yawSine;
795-
int cosineX = currentCamera.getRotation().yawCosine;
796-
int sinY = currentCamera.getRotation().pitchSine;
797-
int cosineY = currentCamera.getRotation().pitchCosine;
798-
799-
int temp = yA * sinX + xA * cosineX >> 16;
800-
yA = yA * cosineX - xA * sinX >> 16;
801-
xA = temp;
802-
temp = zA * cosineY - yA * sinY >> 16;
803-
yA = zA * sinY + yA * cosineY >> 16;
804-
zA = temp;
805-
if (yA < 50) {
794+
int[] resultA = Util3d.getProjectedPoint(currentCamera, xA, yA, zA);
795+
if (resultA == null) {
806796
return;
807797
}
808-
temp = yB * sinX + xB * cosineX >> 16;
809-
yB = yB * cosineX - xB * sinX >> 16;
810-
xB = temp;
811-
temp = zB * cosineY - yB * sinY >> 16;
812-
yB = zB * sinY + yB * cosineY >> 16;
813-
zB = temp;
814-
if (yB < 50) {
798+
799+
xA = resultA[0];
800+
yA = resultA[1];
801+
zA = resultA[2];
802+
803+
int[] resultB = Util3d.getProjectedPoint(currentCamera, xB, yB, zB);
804+
if (resultB == null) {
815805
return;
816806
}
817-
temp = yD * sinX + xD * cosineX >> 16;
818-
yD = yD * cosineX - xD * sinX >> 16;
819-
xD = temp;
820-
temp = zC * cosineY - yD * sinY >> 16;
821-
yD = zC * sinY + yD * cosineY >> 16;
822-
zC = temp;
823-
if (yD < 50) {
807+
808+
xB = resultB[0];
809+
yB = resultB[1];
810+
zB = resultB[2];
811+
812+
int[] resultD = Util3d.getProjectedPoint(currentCamera, xD, yD, zC);
813+
if (resultD == null) {
824814
return;
825815
}
826-
temp = yC * sinX + xC * cosineX >> 16;
827-
yC = yC * cosineX - xC * sinX >> 16;
828-
xC = temp;
829-
temp = zD * cosineY - yC * sinY >> 16;
830-
yC = zD * sinY + yC * cosineY >> 16;
831-
zD = temp;
832-
if (yC < 50) {
816+
817+
xD = resultD[0];
818+
yD = resultD[1];
819+
zC = resultD[2];
820+
821+
int[] resultC = Util3d.getProjectedPoint(currentCamera, xC, yC, zD);
822+
if (resultC == null) {
833823
return;
834824
}
825+
826+
xC = resultC[0];
827+
yC = resultC[1];
828+
zD = resultC[2];
829+
835830
int screenXA = Rasterizer3D.center_x + (xA << 9) / yA;
836831
int screenYA = Rasterizer3D.center_y + (zA << 9) / yA;
837832
int screenXB = Rasterizer3D.center_x + (xB << 9) / yB;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.runejs.client.scene;
2+
3+
import org.runejs.client.scene.camera.Camera;
4+
5+
public class Util3d {
6+
/**
7+
* Applies the camera's yaw and pitch rotation to a point in 3D space.
8+
* If the y-coordinate of the rotated point is less than 50, the function returns null,
9+
* indicating that the point should not be processed further.
10+
*
11+
* @param x The x-coordinate of a point.
12+
* @param y The y-coordinate of a point.
13+
* @param z The z-coordinate of a point.
14+
* @param currentCamera The camera object with rotation (yaw and pitch) information.
15+
* @return An array of three integers representing the transformed x, y, z coordinates,
16+
* or null if the y-coordinate of the rotated point is less than 50.
17+
*/
18+
public static int[] getProjectedPoint(Camera camera, int x, int y, int z) {
19+
// Get the sine and cosine of the camera's yaw and pitch rotations
20+
int sinX = camera.getRotation().yawSine;
21+
int cosineX = camera.getRotation().yawCosine;
22+
int sinY = camera.getRotation().pitchSine;
23+
int cosineY = camera.getRotation().pitchCosine;
24+
25+
// Apply the yaw rotation to the point
26+
int temp = (y * sinX + x * cosineX) >> 16;
27+
y = (y * cosineX - x * sinX) >> 16;
28+
x = temp;
29+
30+
// Apply the pitch rotation to the point
31+
temp = (z * cosineY - y * sinY) >> 16;
32+
y = (z * sinY + y * cosineY) >> 16;
33+
z = temp;
34+
35+
// If the y-coordinate of the rotated point is less than 50, return null
36+
if (y < 50) {
37+
return null;
38+
}
39+
40+
// Return the transformed point
41+
return new int[]{x, y, z};
42+
}
43+
}

0 commit comments

Comments
 (0)