@@ -73,35 +73,53 @@ public void draw(Color color, float width, boolean fade){
73
73
float lastAngle = 0 ;
74
74
float [] items = points .items ;
75
75
float size = width / (int )(points .size / 4 );
76
+ float vz = Perspective .viewportZ ();
77
+ boolean calcLast = true ;
76
78
77
79
for (int i = 0 ; i < points .size ; i += 4 ){
78
80
float px1 = items [i ], py1 = items [i + 1 ], z1 = items [i + 3 ];
81
+ float z2 = i < points .size - 4 ? items [i + 4 + 3 ] : lastZ ;
82
+
83
+ if (z1 > vz && z2 > vz ){
84
+ calcLast = true ;
85
+ continue ;
86
+ }
87
+
88
+ if (z1 > vz ){ //Scale to near plane
89
+ Vec3 pos = Perspective .scaleToViewport (px1 , py1 , z1 );
90
+ px1 = pos .x ;
91
+ py1 = pos .y ;
92
+ z1 = pos .z ;
93
+ }
94
+
79
95
Vec2 pos1 = Perspective .drawPos (px1 , py1 , z1 );
80
96
float x1 = pos1 .x , y1 = pos1 .y , w1 = Perspective .scale (items [i ], items [i + 1 ], z1 );
81
- float x2 , y2 , px2 , py2 , w2 , z2 ;
97
+ float px2 , py2 , x2 , y2 , w2 ;
82
98
83
99
//last position is always lastX/Y/W
84
100
if (i < points .size - 4 ){
85
101
px2 = items [i + 4 ];
86
102
py2 = items [i + 4 + 1 ];
87
- z2 = items [i + 4 + 3 ];
88
- Vec2 pos2 = Perspective .drawPos (px2 , py2 , z2 );
89
- x2 = pos2 .x ;
90
- y2 = pos2 .y ;
91
- w2 = Perspective .scale (items [i + 4 ], items [i + 4 + 1 ], z2 );
92
103
}else {
93
104
px2 = lastX ;
94
105
py2 = lastY ;
95
- z2 = lastZ ;
96
- Vec2 pos2 = Perspective .drawPos (px2 , py2 , z2 );
97
- x2 = pos2 .x ;
98
- y2 = pos2 .y ;
99
- w2 = Perspective .scale (lastX , lastY , z2 );
100
106
}
101
107
108
+ if (z2 > vz ){ //Scale to near plane
109
+ Vec3 pos = Perspective .scaleToViewport (px2 , py2 , z2 );
110
+ px2 = pos .x ;
111
+ py2 = pos .y ;
112
+ z2 = pos .z ;
113
+ }
114
+
115
+ Vec2 pos2 = Perspective .drawPos (px2 , py2 , z2 );
116
+ x2 = pos2 .x ;
117
+ y2 = pos2 .y ;
118
+ w2 = Perspective .scale (px2 , py2 , z2 );
119
+
102
120
float a2 = -Angles .angleRad (x1 , y1 , x2 , y2 );
103
121
//end of the trail (i = 0) has the same angle as the next.
104
- float a1 = i == 0 ? a2 : lastAngle ;
122
+ float a1 = calcLast ? a2 : lastAngle ;
105
123
if (w1 <= 0.001f || w2 <= 0.001f ) continue ;
106
124
107
125
float
@@ -125,6 +143,7 @@ public void draw(Color color, float width, boolean fade){
125
143
);
126
144
127
145
lastAngle = a2 ;
146
+ calcLast = false ;
128
147
}
129
148
130
149
Draw .color ();
0 commit comments