diff --git a/src/progressed/graphics/draw3d/Lines3D.java b/src/progressed/graphics/draw3d/Lines3D.java index ddcc0ab9..3bed6cc0 100644 --- a/src/progressed/graphics/draw3d/Lines3D.java +++ b/src/progressed/graphics/draw3d/Lines3D.java @@ -67,7 +67,7 @@ public static int linePointCount(float x1, float y1, float z1, float x2, float y } 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 + if(z1 > z2){ //Always order from bottom to top. Needed for viewport check. float tx = x1, ty = y1, tz = z1; x1 = x2; y1 = y2; @@ -78,7 +78,7 @@ public static float[] linePoints(float x1, float y1, float z1, float x2, float y } float vz = Perspective.viewportZ(); - if(z2 > vz){ //If line goes above viewport height, scale to viewport height. + if(z2 > vz){ //If line goes above viewport, scale to viewport z. float scl = vz / (z2 - z1); x2 = x1 + (x2 - x1) * scl; y2 = y1 + (y2 - y1) * scl; diff --git a/src/progressed/graphics/draw3d/Perspective.java b/src/progressed/graphics/draw3d/Perspective.java index bc523c92..c9ccedaf 100644 --- a/src/progressed/graphics/draw3d/Perspective.java +++ b/src/progressed/graphics/draw3d/Perspective.java @@ -12,6 +12,8 @@ public class Perspective{ public static float viewportOffset = 8f; /** Field of View in degrees */ public static float fov = settings.getInt("pm-fov", 60); + public static float fadeDst = 128f; + public static float maxScale = 8f; /** @return If the z coordinate is below the viewport height. */ public static boolean canDraw(float z){ @@ -44,15 +46,18 @@ public static float scale(float x, float y, float z){ x -= cx; y -= cy; - z = cz - z; + float zz = cz - z; + + float px = x / zz * cz; //Position scaled to far plane. + float py = y / zz * cz; - float px = x / z * cz; - float py = y / z * cz; + float vx = x / zz * viewportOffset; //Position scaled to near plane. + float vy = y / zz * viewportOffset; - float c1 = Mathf.dst(x, y), c2 = Mathf.dst(px, py); - float d1 = Mathf.dst(z, c1), d2 = Mathf.dst(cz, c2); + float d1 = Math3D.dst(vx, vy, cz - viewportOffset, x, y, z); + float d2 = Math3D.dst(vx, vy, cz - viewportOffset, px, py, 0); - return d2 / d1; + return 1f + (1f - d1 / d2) * (maxScale - 1f); } /** Fade out based on distance to viewport. */ @@ -60,7 +65,7 @@ public static float alpha(float x, float y, float z){ float cx = camera.position.x, cy = camera.position.y; float cz = cameraZ(); - float d1 = Math3D.dst(x, y, z, cx, cy, cz); //Distance between camera point + float d1 = Math3D.dst(x, y, z, cx, cy, cz); //Distance between camera and far point x -= cx; y -= cy; @@ -72,14 +77,14 @@ public static float alpha(float x, float y, float z){ float d2 = Math3D.dst(vx, vy, z); //Distance between camera and viewport pos float dst = d1 - d2; - float fadeDst = (cz - viewportOffset) / 8f; + float fade = Math.min(fadeDst, cz - viewportOffset); - if(dst > fadeDst){ + if(dst > fade){ return 1f; }else if(!canDraw(z)){ //Behind viewport, should be 0 return 0f; }else{ - return Mathf.clamp(dst / fadeDst); + return Mathf.clamp(dst / fade); } }