Skip to content

Commit 74c0c36

Browse files
committed
cameraZ
1 parent 6a8c401 commit 74c0c36

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/progressed/graphics/draw3d/Lines3D.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,16 @@ public static int linePointCounts(float x1, float y1, float z1, float x2, float
6767
}
6868

6969
public static float[] linePoints(float x1, float y1, float z1, float x2, float y2, float z2, int pointCount){
70+
if(z1 > z2){ //Always return from bottom to top
71+
return linePoints(x2, y2, z2, x1, y1, z1, pointCount);
72+
}
73+
7074
float[] points = new float[pointCount * 3];
7175
float px = (x2 - x1) / (pointCount - 1);
7276
float py = (y2 - y1) / (pointCount - 1);
7377
float pz = (z2 - z1) / (pointCount - 1);
7478

75-
for(int i = 0; i < pointCount; i++){
79+
for(int i = 0; i < pointCount; i++){ //TODO check if goes above viewport z. If so, limit to viewport and cut short.
7680
points[i * 3] = x1 + px * i;
7781
points[i * 3 + 1] = y1 + py * i;
7882
points[i * 3 + 2] = z1 + pz * i;

src/progressed/graphics/draw3d/Perspective.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Perspective{
1515

1616
/** @return If the z coordinate is below the viewport height. */
1717
public static boolean canDraw(float z){
18-
return z < cameraHeight() - viewportOffset;
18+
return z < cameraZ() - viewportOffset;
1919
}
2020

2121
/** @return Perspective projected coordinates to draw at. */
@@ -24,7 +24,7 @@ public static Vec2 drawPos(float x, float y, float z){
2424
Vec2 v = viewportSize();
2525
float vw = v.x, vh = v.y;
2626
float cx = camera.position.x, cy = camera.position.y;
27-
float cz = cameraHeight();
27+
float cz = cameraZ();
2828

2929
x -= cx;
3030
y -= cy;
@@ -40,7 +40,7 @@ public static Vec2 drawPos(float x, float y, float z){
4040
/** Multiplicative size scale at a point. */
4141
public static float scale(float x, float y, float z){
4242
float cx = camera.position.x, cy = camera.position.y;
43-
float cz = cameraHeight();
43+
float cz = cameraZ();
4444

4545
x -= cx;
4646
y -= cy;
@@ -58,7 +58,7 @@ public static float scale(float x, float y, float z){
5858
/** Fade out based on distance to viewport. */
5959
public static float alpha(float x, float y, float z){
6060
float cx = camera.position.x, cy = camera.position.y;
61-
float cz = cameraHeight();
61+
float cz = cameraZ();
6262

6363
float d1 = Math3D.dst(x, y, z, cx, cy, cz); //Distance between camera point
6464

@@ -84,7 +84,7 @@ public static float alpha(float x, float y, float z){
8484
}
8585

8686
/** Calculates the camera height based on FOV and the size of the vanilla camera. */
87-
public static float cameraHeight(){
87+
public static float cameraZ(){
8888
float width = Math.max(camera.width, camera.height) / 2f;
8989
//TOA
9090
return (float)(width / Math.tan(fov / 2f * Mathf.degRad));

0 commit comments

Comments
 (0)