5
5
import arc .math .*;
6
6
import arc .math .geom .*;
7
7
import arc .util .*;
8
- import progressed .graphics .*;
9
8
10
9
import static arc .math .Mathf .*;
11
10
@@ -15,6 +14,35 @@ public class Fill3D{
15
14
private static final Vec3 axis = new Vec3 ();
16
15
private static final Vec3 rim = new Vec3 ();
17
16
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
+
18
46
public static void tube (float x , float y , float rad , float z2 , Color baseColorLight , Color baseColorDark , Color topColorLight , Color topColorDark ){
19
47
int vert = Lines .circleVertices (rad );
20
48
float space = 360f / vert ;
@@ -51,50 +79,43 @@ public static void tube(float x, float y, float rad, float z2, Color baseColor,
51
79
tube (x , y , rad , z2 , baseColor , baseColor , topColor , topColor );
52
80
}
53
81
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 ){
55
83
//Draw
56
84
float scl = Perspective .scale (x2 , y2 , z2 );
57
- int verts = Lines .circleVertices (rad * scl );
85
+ if (scl < 0 ) return ;
86
+
58
87
float rotation = Angles .angle (x2 , y2 , x1 , y1 );
59
88
float tilt = 90f - Angles .angle (Mathf .dst (x1 , y1 , x2 , y2 ), z2 );
60
89
Vec2 pos = Perspective .drawPos (x2 , y2 , z2 );
61
90
float startAngle = tubeStartAngle (pos .x , pos .y , x1 , y1 , rad * scl , rad );
91
+
92
+ int verts = Lines .circleVertices (rad * scl );
62
93
float [] castVerts = castVertices (x1 , y1 , rotation , startAngle , tilt , rad , verts );
63
94
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 );
79
96
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
85
106
);
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
+ }
86
118
}
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 );
98
119
}
99
120
100
121
public static float [] diskVertices (float x , float y , float z , float rotation , float startAngle , float tilt , float rad , int verts ){
0 commit comments