@@ -71,9 +71,7 @@ public class SceneEditorHandleOverlay {
7171 private final Vector3f handleWorldScratch = new Vector3f ();
7272 private final Vector3f planeArmAScratch = new Vector3f ();
7373 private final Vector3f planeArmBScratch = new Vector3f ();
74- private final Vector3f axisBoundsCenterScratch = new Vector3f ();
7574 private final Vector3f axisBoundsTipScratch = new Vector3f ();
76- private final AxisArrowGeometry axisArrowScratch = new AxisArrowGeometry ();
7775
7876 public boolean supportsPointHandle (@ Nullable SceneEditorElementModel element ) {
7977 return getHandleIds (element ).length > 0 ;
@@ -327,18 +325,9 @@ private Vector3f projectWorldPoint(CameraSettings camera, LytRect viewport, floa
327325
328326 private LytRect getAxisHandleBounds (SceneEditorElementModel element , CameraSettings camera , LytRect viewport ,
329327 String handleId ) {
330- Vector3f center = projectHandlePoint (element , camera , viewport , CENTER_HANDLE_ID , axisBoundsCenterScratch );
331328 Vector3f tip = projectHandlePoint (element , camera , viewport , handleId , axisBoundsTipScratch );
332- AxisArrowGeometry geometry = createAxisArrowGeometry (center , tip , axisArrowScratch );
333- float minX = Math .min (tip .x , Math .min (geometry .leftX , geometry .rightX ));
334- float minY = Math .min (tip .y , Math .min (geometry .leftY , geometry .rightY ));
335- float maxX = Math .max (tip .x , Math .max (geometry .leftX , geometry .rightX ));
336- float maxY = Math .max (tip .y , Math .max (geometry .leftY , geometry .rightY ));
337- return new LytRect (
338- (int ) Math .floor (minX ) - 2 ,
339- (int ) Math .floor (minY ) - 2 ,
340- Math .max (AXIS_HANDLE_DIAMETER , (int ) Math .ceil (maxX - minX ) + 5 ),
341- Math .max (AXIS_HANDLE_DIAMETER , (int ) Math .ceil (maxY - minY ) + 5 ));
329+ int radius = Math .max (AXIS_HANDLE_RADIUS , Math .round (ARROW_LENGTH ));
330+ return new LytRect (Math .round (tip .x ) - radius , Math .round (tip .y ) - radius , radius * 2 + 1 , radius * 2 + 1 );
342331 }
343332
344333 private Vector3f projectPlaneHandlePoint (SceneEditorElementModel element , CameraSettings camera , LytRect viewport ,
@@ -433,38 +422,32 @@ private float distanceSqToSegment(float px, float py, float ax, float ay, float
433422 }
434423
435424 private void drawAxisArrow (Vector3f from , Vector3f to , int color ) {
436- AxisArrowGeometry geometry = createAxisArrowGeometry (from , to , axisArrowScratch );
437- drawFilledTriangle (to .x , to .y , geometry .leftX , geometry .leftY , geometry .rightX , geometry .rightY , color );
438- }
439-
440- private AxisArrowGeometry createAxisArrowGeometry (Vector3f from , Vector3f to , AxisArrowGeometry dest ) {
441425 float dx = to .x - from .x ;
442426 float dy = to .y - from .y ;
443427 float length = (float ) Math .sqrt (dx * dx + dy * dy );
444428 if (length < 1e-4f ) {
445- return dest . set ( to . x , to . y , to . x , to . y , to . x , to . y ) ;
429+ return ;
446430 }
447431 float ux = dx / length ;
448432 float uy = dy / length ;
449433 float px = -uy ;
450434 float py = ux ;
451435 float arrowLength = Math .min (ARROW_LENGTH , Math .max (3f , length * 0.55f ));
452- if (arrowLength > length ) {
453- arrowLength = length ;
454- }
436+ arrowLength = Math .min (arrowLength , length );
455437 float arrowHalfWidth = Math .min (ARROW_HALF_WIDTH , Math .max (2f , arrowLength * 0.5f ));
456438 float baseX = to .x - ux * arrowLength ;
457439 float baseY = to .y - uy * arrowLength ;
458- return dest .set (
459- baseX + px * arrowHalfWidth ,
460- baseY + py * arrowHalfWidth ,
461- baseX - px * arrowHalfWidth ,
462- baseY - py * arrowHalfWidth ,
463- baseX ,
464- baseY );
465- }
440+ float tipZ = 0.08f ;
441+ float baseZ = -0.08f ;
442+ float leftX = baseX + px * arrowHalfWidth ;
443+ float leftY = baseY + py * arrowHalfWidth ;
444+ float rightX = baseX - px * arrowHalfWidth ;
445+ float rightY = baseY - py * arrowHalfWidth ;
446+ float upX = baseX + ux * arrowHalfWidth * 0.35f ;
447+ float upY = baseY + uy * arrowHalfWidth * 0.35f ;
448+ float downX = baseX - ux * arrowHalfWidth * 0.35f ;
449+ float downY = baseY - uy * arrowHalfWidth * 0.35f ;
466450
467- private void drawFilledTriangle (float ax , float ay , float bx , float by , float cx , float cy , int color ) {
468451 float a = ((color >>> 24 ) & 0xFF ) / 255f ;
469452 float r = ((color >>> 16 ) & 0xFF ) / 255f ;
470453 float g = ((color >>> 8 ) & 0xFF ) / 255f ;
@@ -477,16 +460,24 @@ private void drawFilledTriangle(float ax, float ay, float bx, float by, float cx
477460 GL11 .glBlendFunc (GL11 .GL_SRC_ALPHA , GL11 .GL_ONE_MINUS_SRC_ALPHA );
478461 GL11 .glColor4f (r , g , b , a );
479462 GL11 .glBegin (GL11 .GL_TRIANGLES );
480- GL11 .glVertex3f (ax , ay , 0f );
481- GL11 .glVertex3f (bx , by , 0f );
482- GL11 .glVertex3f (cx , cy , 0f );
463+ drawTriangle (to .x , to .y , tipZ , leftX , leftY , baseZ , upX , upY , 0f );
464+ drawTriangle (to .x , to .y , tipZ , upX , upY , 0f , rightX , rightY , baseZ );
465+ drawTriangle (to .x , to .y , tipZ , rightX , rightY , baseZ , downX , downY , 0f );
466+ drawTriangle (to .x , to .y , tipZ , downX , downY , 0f , leftX , leftY , baseZ );
483467 GL11 .glEnd ();
484468 } finally {
485469 GL11 .glPopAttrib ();
486470 GL11 .glColor4f (1f , 1f , 1f , 1f );
487471 }
488472 }
489473
474+ private void drawTriangle (float ax , float ay , float az , float bx , float by , float bz , float cx , float cy ,
475+ float cz ) {
476+ GL11 .glVertex3f (ax , ay , az );
477+ GL11 .glVertex3f (bx , by , bz );
478+ GL11 .glVertex3f (cx , cy , cz );
479+ }
480+
490481 private void drawLine (Vector3f from , Vector3f to , int color , float lineWidth ) {
491482 float a = ((color >>> 24 ) & 0xFF ) / 255f ;
492483 float r = ((color >>> 16 ) & 0xFF ) / 255f ;
@@ -509,27 +500,4 @@ private void drawLine(Vector3f from, Vector3f to, int color, float lineWidth) {
509500 }
510501 }
511502
512- public static class AxisArrowGeometry {
513-
514- private float leftX ;
515- private float leftY ;
516- private float rightX ;
517- private float rightY ;
518- @ SuppressWarnings ("unused" )
519- private float baseX ;
520- @ SuppressWarnings ("unused" )
521- private float baseY ;
522-
523- private AxisArrowGeometry () {}
524-
525- private AxisArrowGeometry set (float leftX , float leftY , float rightX , float rightY , float baseX , float baseY ) {
526- this .leftX = leftX ;
527- this .leftY = leftY ;
528- this .rightX = rightX ;
529- this .rightY = rightY ;
530- this .baseX = baseX ;
531- this .baseY = baseY ;
532- return this ;
533- }
534- }
535503}
0 commit comments