Skip to content

Commit 99c5889

Browse files
committed
Proper slantTube draw
1 parent 21f2d67 commit 99c5889

File tree

5 files changed

+65
-42
lines changed

5 files changed

+65
-42
lines changed

src/progressed/entities/bullet/pseudo3d/SkyBeamBulletType.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
public class SkyBeamBulletType extends BulletType{
1414
public float z = 50f * tilesize;
15-
public float offset = 0.25f;
1615
public float radius = tilesize;
1716
public boolean bloom = true;
1817
public Color baseColor = PMPal.nexusLaserDark;
@@ -41,6 +40,6 @@ public void init(){
4140
public void draw(Bullet b){
4241
super.draw(b);
4342

44-
Draw3D.highBloom(bloom, () -> Fill3D.slantTube(b.x, b.y, b.originX, b.originY, z, radius, baseColor, topColor, offset));
43+
Draw3D.highBloom(bloom, () -> Fill3D.slantTube(b.x, b.y, b.originX, b.originY, z, radius, baseColor, topColor));
4544
}
4645
}

src/progressed/graphics/draw3d/Draw3D.java

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public static void drawDiskDebug(float x1, float y1, float x2, float y2, float z
102102
Lines.stroke(3f);
103103
Draw.color(Color.white);
104104
int vertCount = Lines.circleVertices(rad * Perspective.scale(x2, y2, z2));
105+
if(vertCount < 0) return;
105106
float[] verts = Fill3D.diskVertices(x2, y2, z2, rotation, 0f, tilt, rad, vertCount);
106107
for(int i = 0; i <= vertCount; i += 3){
107108
float px2, py2, pz2;

src/progressed/graphics/draw3d/Fill3D.java

+55-34
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import arc.math.*;
66
import arc.math.geom.*;
77
import arc.util.*;
8-
import progressed.graphics.*;
98

109
import static arc.math.Mathf.*;
1110

@@ -15,6 +14,35 @@ public class Fill3D{
1514
private static final Vec3 axis = new Vec3();
1615
private static final Vec3 rim = new Vec3();
1716

17+
public static void quad(float x1, float y1, float z1, Color c1,
18+
float x2, float y2, float z2, Color c2,
19+
float x3, float y3, float z3, Color c3,
20+
float x4, float y4, float z4, Color c4){
21+
Vec2 pos = Perspective.drawPos(x1, y1, z1);
22+
float dx1 = pos.x, dy1 = pos.y, a1 = Perspective.alpha(x1, y1, z1);
23+
pos = Perspective.drawPos(x2, y2, z2);
24+
float dx2 = pos.x, dy2 = pos.y, a2 = Perspective.alpha(x2, y2, z2);
25+
pos = Perspective.drawPos(x3, y3, z3);
26+
float dx3 = pos.x, dy3 = pos.y, a3 = Perspective.alpha(x3, y3, z3);
27+
pos = Perspective.drawPos(x4, y4, z4);
28+
float dx4 = pos.x, dy4 = pos.y, a4 = Perspective.alpha(x4, y4, z4);
29+
30+
Fill.quad(
31+
dx1, dy1, tmpCol.set(c1).mulA(a1).toFloatBits(),
32+
dx2, dy2, tmpCol.set(c2).mulA(a2).toFloatBits(),
33+
dx3, dy3, tmpCol.set(c3).mulA(a3).toFloatBits(),
34+
dx4, dy4, tmpCol.set(c4).mulA(a4).toFloatBits()
35+
);
36+
}
37+
38+
public static void quad(float x1, float y1, float z1,
39+
float x2, float y2, float z2,
40+
float x3, float y3, float z3,
41+
float x4, float y4, float z4){
42+
Color color = Draw.getColor();
43+
quad(x1, y1, z1, color, x2, y2, z2, color, x3, y3, z3, color, x4, y4, z4, color);
44+
}
45+
1846
public static void tube(float x, float y, float rad, float z2, Color baseColorLight, Color baseColorDark, Color topColorLight, Color topColorDark){
1947
int vert = Lines.circleVertices(rad);
2048
float space = 360f / vert;
@@ -51,50 +79,43 @@ public static void tube(float x, float y, float rad, float z2, Color baseColor,
5179
tube(x, y, rad, z2, baseColor, baseColor, topColor, topColor);
5280
}
5381

54-
public static void slantTube(float x1, float y1, float x2, float y2, float z2, float rad, Color baseColor, Color topColor, float offset){
82+
public static void slantTube(float x1, float y1, float x2, float y2, float z2, float rad, Color baseColor, Color topColor){
5583
//Draw
5684
float scl = Perspective.scale(x2, y2, z2);
57-
int verts = Lines.circleVertices(rad * scl);
85+
if(scl < 0) return;
86+
5887
float rotation = Angles.angle(x2, y2, x1, y1);
5988
float tilt = 90f - Angles.angle(Mathf.dst(x1, y1, x2, y2), z2);
6089
Vec2 pos = Perspective.drawPos(x2, y2, z2);
6190
float startAngle = tubeStartAngle(pos.x, pos.y, x1, y1, rad * scl, rad);
91+
92+
int verts = Lines.circleVertices(rad * scl);
6293
float[] castVerts = castVertices(x1, y1, rotation, startAngle, tilt, rad, verts);
6394
float[] diskVerts = diskVertices(x2, y2, z2, rotation, startAngle, tilt, rad, verts);
64-
float hAlpha = Perspective.alpha(x2, y2, z2 * offset);
65-
float baseCol = Tmp.c1.set(baseColor).mulA(hAlpha).toFloatBits();
66-
float topCol = Tmp.c1.set(topColor).mulA(hAlpha).toFloatBits();
67-
for(int i = 0; i < verts - 1; i++){
68-
int i2 = i + 1;
69-
float bx1 = castVerts[i * 2],
70-
by1 = castVerts[i * 2 + 1],
71-
bx2 = castVerts[i2 * 2],
72-
by2 = castVerts[i2 * 2 + 1];
73-
Tmp.v1.set(Perspective.drawPos(diskVerts[i * 3], diskVerts[i * 3 + 1], diskVerts[i * 3 + 2]));
74-
Tmp.v2.set(Perspective.drawPos(diskVerts[i2 * 3], diskVerts[i2 * 3 + 1], diskVerts[i2 * 3 + 2]));
75-
if(offset > 0f){
76-
Tmp.v1.lerp(bx1, by1, offset);
77-
Tmp.v2.lerp(bx2, by2, offset);
78-
}
95+
int segments = Lines3D.linePointCount(x1, y1, 0, x2, y2, z2);
7996

80-
Fill.quad(
81-
bx1, by1, baseCol,
82-
bx2, by2, baseCol,
83-
Tmp.v2.x, Tmp.v2.y, topCol,
84-
Tmp.v1.x, Tmp.v1.y, topCol
97+
for(int i = 0; i < verts; i++){
98+
float[] v1 = Lines3D.linePoints(
99+
castVerts[i * 2], castVerts[i * 2 + 1], 0,
100+
diskVerts[i * 3], diskVerts[i * 3 + 1], diskVerts[i * 3 + 2], segments
101+
);
102+
int i2 = i == verts - 1 ? 0 : i + 1;
103+
float[] v2 = Lines3D.linePoints(
104+
castVerts[i2 * 2], castVerts[i2 * 2 + 1], 0,
105+
diskVerts[i2 * 3], diskVerts[i2 * 3 + 1], diskVerts[i2 * 3 + 2], segments
85106
);
107+
for(int j = 0; j < segments - 3; j++){
108+
int jj = j * 3;
109+
Color c1 = Tmp.c1.set(baseColor).lerp(topColor, (float)jj / segments);
110+
Color c2 = Tmp.c2.set(baseColor).lerp(topColor, (float)(jj + 3) / segments);
111+
quad(
112+
v1[jj], v1[jj + 1], v1[jj + 2], c1,
113+
v2[jj], v2[jj + 1], v2[jj + 2], c1,
114+
v2[jj + 3], v2[jj + 3 + 1], v2[jj + 3 + 2], c2,
115+
v1[jj + 3], v1[jj + 3 + 1], v1[jj + 3 + 2], c2
116+
);
117+
}
86118
}
87-
//Debug
88-
Draw.z(PMLayer.skyBloom + 10);
89-
Lines.stroke(4);
90-
Draw.color(Color.black);
91-
Lines.line(x1, y1, castVerts[0], castVerts[1]);
92-
Lines3D.line(x2, y2, z2, diskVerts[0], diskVerts[1], diskVerts[2]);
93-
Lines3D.line(castVerts[0], castVerts[1], 0, diskVerts[0], diskVerts[1], diskVerts[2]);
94-
}
95-
96-
public static void slantTube(float x1, float y1, float x2, float y2, float z, float rad, Color baseColor, Color topColor){
97-
slantTube(x1, y1, x2, y2, z, rad, baseColor, topColor, 0f);
98119
}
99120

100121
public static float[] diskVertices(float x, float y, float z, float rotation, float startAngle, float tilt, float rad, int verts){

src/progressed/graphics/draw3d/Lines3D.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import arc.util.*;
88
import progressed.util.*;
99

10-
import static mindustry.Vars.tilesize;
10+
import static mindustry.Vars.*;
1111

1212
public class Lines3D{
1313
public static void line(float x1, float y1, float z1, float x2, float y2, float z2, int pointCount, boolean scale){
@@ -83,7 +83,6 @@ public static float[] linePoints(float x1, float y1, float z1, float x2, float y
8383
x2 = x1 + (x2 - x1) * scl;
8484
y2 = y1 + (y2 - y1) * scl;
8585
z2 = vz;
86-
pointCount = Mathf.ceil(pointCount * scl);
8786
}
8887

8988
float[] points = new float[pointCount * 3];
@@ -99,4 +98,8 @@ public static float[] linePoints(float x1, float y1, float z1, float x2, float y
9998

10099
return points;
101100
}
101+
102+
public static float[] linePoints(float x1, float y1, float z1, float x2, float y2, float z2){
103+
return linePoints(x1, y1, z1, x2, y2, z2, linePointCount(x1, y1, z1, x2, y2, z2));
104+
}
102105
}

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

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

33
import progressed.entities.bullet.pseudo3d.*;
4-
import progressed.graphics.draw3d.*;
54

65
import static mindustry.Vars.*;
76

@@ -15,7 +14,7 @@ public SkyLaserTestTurret(String name){
1514
lifetime = bRange / speed;
1615
radius = 1.5f * tilesize;
1716
drag = -0.01f;
18-
z = 1200;
17+
z = 2000;
1918
}};
2019
reload = 45f;
2120
shootY = 0f;
@@ -27,8 +26,8 @@ public void draw(){
2726
super.draw();
2827

2928
SkyBeamBulletType type = (SkyBeamBulletType)shootType;
30-
Draw3D.drawLineDebug(x, y, type.z, targetPos.x, targetPos.y, 0);
31-
Draw3D.drawDiskDebug(targetPos.x, targetPos.y, x, y, type.z, type.radius);
29+
//Draw3D.drawLineDebug(x, y, type.z, targetPos.x, targetPos.y, 0);
30+
//Draw3D.drawDiskDebug(targetPos.x, targetPos.y, x, y, type.z, type.radius);
3231
}
3332
}
3433
}

0 commit comments

Comments
 (0)