Skip to content

Commit

Permalink
Correct line point pos
Browse files Browse the repository at this point in the history
  • Loading branch information
MEEPofFaith committed Nov 21, 2024
1 parent edd9e18 commit 309f4cc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/progressed/graphics/draw3d/Lines3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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, scale to viewport z.
float scl = vz / (z2 - z1);
float scl = (vz - z1) / (z2 - z1);
x2 = x1 + (x2 - x1) * scl;
y2 = y1 + (y2 - y1) * scl;
z2 = vz;
Expand Down
11 changes: 7 additions & 4 deletions src/progressed/graphics/draw3d/Perspective.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
public class Perspective{
private static final Vec2 offsetPos = new Vec2();
/** Viewport offset from the camera height in world units. */
public static float viewportOffset = 8f;
public static float viewportOffset = 16f;
/** Field of View in degrees */
public static float fov = -1f;
public static float fadeDst = 1024f;
public static float maxScale = 8f;

private static float lastScale;
private static float cameraZ;
private static Vec2 viewportSize = new Vec2();
private static final Vec2 viewportSize = new Vec2();

static{
if(!headless){
Expand All @@ -38,7 +38,7 @@ public class Perspective{

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

/** @return Perspective projected coordinates to draw at. */
Expand Down Expand Up @@ -98,13 +98,16 @@ public static float alpha(float x, float y, float z){

if(dst > fade){
return 1f;
}else if(!canDraw(z)){ //Behind viewport, should be 0
}else if(z > vz){ //Behind viewport, should be 0
return 0f;
}else{
return Mathf.clamp(dst / fade);
}
}

/**
* @return camera z coordinate
*/
public static float cameraZ(){
return cameraZ;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package progressed.world.blocks.defence.turret.testing;

import progressed.entities.bullet.pseudo3d.*;
import progressed.graphics.draw3d.*;

import static mindustry.Vars.*;

Expand All @@ -26,7 +27,7 @@ public void draw(){
super.draw();

SkyBeamBulletType type = (SkyBeamBulletType)shootType;
//Draw3D.drawLineDebug(x, y, type.z, targetPos.x, targetPos.y, 0);
Draw3D.drawLineDebug(x, y, type.z, targetPos.x, targetPos.y, 0);
//Draw3D.drawDiskDebug(targetPos.x, targetPos.y, x, y, type.z, type.radius);
}
}
Expand Down

0 comments on commit 309f4cc

Please sign in to comment.