@@ -50,7 +50,7 @@ public static void line(float x1, float y1, float z1, float x2, float y2, float
50
50
}
51
51
52
52
public static void line (float x1 , float y1 , float z1 , float x2 , float y2 , float z2 , boolean scale ){
53
- line (x1 , y1 , z1 , x2 , y2 , z2 , linePointCounts (x1 , y1 , z1 , x2 , y2 , z2 ), scale );
53
+ line (x1 , y1 , z1 , x2 , y2 , z2 , linePointCount (x1 , y1 , z1 , x2 , y2 , z2 ), scale );
54
54
}
55
55
56
56
public static void line (float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ){
@@ -62,21 +62,36 @@ public static void lineAngleBase(float x, float y, float z, float length, float
62
62
line (x , y , z , x + Tmp .v31 .x , y + Tmp .v31 .y , z + Tmp .v31 .z );
63
63
}
64
64
65
- public static int linePointCounts (float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ){
65
+ public static int linePointCount (float x1 , float y1 , float z1 , float x2 , float y2 , float z2 ){
66
66
return (int )(Math3D .dst (x1 , y1 , z1 , x2 , y2 , z2 ) / tilesize / tilesize );
67
67
}
68
68
69
69
public static float [] linePoints (float x1 , float y1 , float z1 , float x2 , float y2 , float z2 , int pointCount ){
70
70
if (z1 > z2 ){ //Always return from bottom to top
71
- return linePoints (x2 , y2 , z2 , x1 , y1 , z1 , pointCount );
71
+ float tx = x1 , ty = y1 , tz = z1 ;
72
+ x1 = x2 ;
73
+ y1 = y2 ;
74
+ z1 = z2 ;
75
+ x2 = tx ;
76
+ y2 = ty ;
77
+ z2 = tz ;
78
+ }
79
+
80
+ float vz = Perspective .viewportZ ();
81
+ if (z2 > vz ){ //If line goes above viewport height, scale to viewport height.
82
+ float scl = vz / (z2 - z1 );
83
+ x2 = x1 + (x2 - x1 ) * scl ;
84
+ y2 = y1 + (y2 - y1 ) * scl ;
85
+ z2 = vz ;
86
+ pointCount = Mathf .ceil (pointCount * scl );
72
87
}
73
88
74
89
float [] points = new float [pointCount * 3 ];
75
90
float px = (x2 - x1 ) / (pointCount - 1 );
76
91
float py = (y2 - y1 ) / (pointCount - 1 );
77
92
float pz = (z2 - z1 ) / (pointCount - 1 );
78
93
79
- for (int i = 0 ; i < pointCount ; i ++){ //TODO check if goes above viewport z. If so, limit to viewport and cut short.
94
+ for (int i = 0 ; i < pointCount ; i ++){
80
95
points [i * 3 ] = x1 + px * i ;
81
96
points [i * 3 + 1 ] = y1 + py * i ;
82
97
points [i * 3 + 2 ] = z1 + pz * i ;
0 commit comments