Skip to content

Commit 309f4cc

Browse files
committed
Correct line point pos
1 parent edd9e18 commit 309f4cc

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/progressed/graphics/draw3d/Lines3D.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static float[] linePoints(float x1, float y1, float z1, float x2, float y
7979

8080
float vz = Perspective.viewportZ();
8181
if(z2 > vz){ //If line goes above viewport, scale to viewport z.
82-
float scl = vz / (z2 - z1);
82+
float scl = (vz - z1) / (z2 - z1);
8383
x2 = x1 + (x2 - x1) * scl;
8484
y2 = y1 + (y2 - y1) * scl;
8585
z2 = vz;

src/progressed/graphics/draw3d/Perspective.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
public class Perspective{
1313
private static final Vec2 offsetPos = new Vec2();
1414
/** Viewport offset from the camera height in world units. */
15-
public static float viewportOffset = 8f;
15+
public static float viewportOffset = 16f;
1616
/** Field of View in degrees */
1717
public static float fov = -1f;
1818
public static float fadeDst = 1024f;
1919
public static float maxScale = 8f;
2020

2121
private static float lastScale;
2222
private static float cameraZ;
23-
private static Vec2 viewportSize = new Vec2();
23+
private static final Vec2 viewportSize = new Vec2();
2424

2525
static{
2626
if(!headless){
@@ -38,7 +38,7 @@ public class Perspective{
3838

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

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

9999
if(dst > fade){
100100
return 1f;
101-
}else if(!canDraw(z)){ //Behind viewport, should be 0
101+
}else if(z > vz){ //Behind viewport, should be 0
102102
return 0f;
103103
}else{
104104
return Mathf.clamp(dst / fade);
105105
}
106106
}
107107

108+
/**
109+
* @return camera z coordinate
110+
*/
108111
public static float cameraZ(){
109112
return cameraZ;
110113
}

src/progressed/world/blocks/defence/turret/testing/SkyLaserTestTurret.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package progressed.world.blocks.defence.turret.testing;
22

33
import progressed.entities.bullet.pseudo3d.*;
4+
import progressed.graphics.draw3d.*;
45

56
import static mindustry.Vars.*;
67

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

2829
SkyBeamBulletType type = (SkyBeamBulletType)shootType;
29-
//Draw3D.drawLineDebug(x, y, type.z, targetPos.x, targetPos.y, 0);
30+
Draw3D.drawLineDebug(x, y, type.z, targetPos.x, targetPos.y, 0);
3031
//Draw3D.drawDiskDebug(targetPos.x, targetPos.y, x, y, type.z, type.radius);
3132
}
3233
}

0 commit comments

Comments
 (0)