Skip to content

Commit

Permalink
cameraZ
Browse files Browse the repository at this point in the history
  • Loading branch information
MEEPofFaith committed Nov 19, 2024
1 parent 6a8c401 commit 74c0c36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/progressed/graphics/draw3d/Lines3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ public static int linePointCounts(float x1, float y1, float z1, float x2, float
}

public static float[] linePoints(float x1, float y1, float z1, float x2, float y2, float z2, int pointCount){
if(z1 > z2){ //Always return from bottom to top
return linePoints(x2, y2, z2, x1, y1, z1, pointCount);
}

float[] points = new float[pointCount * 3];
float px = (x2 - x1) / (pointCount - 1);
float py = (y2 - y1) / (pointCount - 1);
float pz = (z2 - z1) / (pointCount - 1);

for(int i = 0; i < pointCount; i++){
for(int i = 0; i < pointCount; i++){ //TODO check if goes above viewport z. If so, limit to viewport and cut short.
points[i * 3] = x1 + px * i;
points[i * 3 + 1] = y1 + py * i;
points[i * 3 + 2] = z1 + pz * i;
Expand Down
10 changes: 5 additions & 5 deletions src/progressed/graphics/draw3d/Perspective.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Perspective{

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

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

x -= cx;
y -= cy;
Expand All @@ -40,7 +40,7 @@ public static Vec2 drawPos(float x, float y, float z){
/** Multiplicative size scale at a point. */
public static float scale(float x, float y, float z){
float cx = camera.position.x, cy = camera.position.y;
float cz = cameraHeight();
float cz = cameraZ();

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

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

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

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

0 comments on commit 74c0c36

Please sign in to comment.