From b6fe46f2ea0e8cf808e12941a17f40cd7417cd1b Mon Sep 17 00:00:00 2001 From: Kenneth VanderLinde Date: Fri, 27 Sep 2024 01:56:36 -0700 Subject: [PATCH] Grid.getShapedArea() and overrides no longer modifies token facing The implementation also uses `Token.getFacingInDegrees()` for easier case handling, though it requires shifting the result by 90. --- src/main/java/net/rptools/maptool/model/Grid.java | 5 +++-- .../java/net/rptools/maptool/model/IsometricGrid.java | 9 +++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/rptools/maptool/model/Grid.java b/src/main/java/net/rptools/maptool/model/Grid.java index 145b861ca2..f3458ebd4e 100644 --- a/src/main/java/net/rptools/maptool/model/Grid.java +++ b/src/main/java/net/rptools/maptool/model/Grid.java @@ -411,6 +411,7 @@ public void setSize(int size) { } int visionDistance = zone.getTokenVisionInPixels(); double visionRange = (range == 0) ? visionDistance : range * getSize() / zone.getUnitsPerCell(); + int tokenFacing = token.getFacingInDegrees() + 90; if (scaleWithToken) { double footprintWidth = token.getFootprint(this).getBounds(this).getWidth() / 2; @@ -453,7 +454,7 @@ public void setSize(int size) { visibleArea = new Area( AffineTransform.getRotateInstance( - Math.toRadians(offsetAngle) - Math.toRadians(token.getFacing())) + Math.toRadians(offsetAngle) + Math.toRadians(tokenFacing)) .createTransformedShape(visibleShape)); break; case CONE: @@ -475,7 +476,7 @@ public void setSize(int size) { // Rotate tempvisibleArea = tempvisibleArea.createTransformedArea( - AffineTransform.getRotateInstance(-Math.toRadians(token.getFacing()))); + AffineTransform.getRotateInstance(Math.toRadians(tokenFacing))); Rectangle footprint = token.getFootprint(this).getBounds(this); footprint.x = -footprint.width / 2; diff --git a/src/main/java/net/rptools/maptool/model/IsometricGrid.java b/src/main/java/net/rptools/maptool/model/IsometricGrid.java index 2e9d174227..50d65a52a5 100644 --- a/src/main/java/net/rptools/maptool/model/IsometricGrid.java +++ b/src/main/java/net/rptools/maptool/model/IsometricGrid.java @@ -281,6 +281,7 @@ public Area getShapedArea( int visionDistance = getZone().getTokenVisionInPixels(); double visionRange = (range == 0) ? visionDistance : range * getSize() / getZone().getUnitsPerCell(); + int tokenFacing = token.getFacingInDegrees() + 90; if (scaleWithToken) { Rectangle footprint = token.getFootprint(this).getBounds(this); @@ -311,7 +312,7 @@ public Area getShapedArea( Shape visibleShape = new Rectangle2D.Double(0, -pixelWidth / 2, visionRange, pixelWidth); // new angle, corrected for isometric view - double theta = Math.toRadians(offsetAngle) + Math.toRadians(token.getFacing()); + double theta = Math.toRadians(offsetAngle) - Math.toRadians(tokenFacing); Point2D angleVector = new Point2D.Double(Math.cos(theta), Math.sin(theta)); AffineTransform at = new AffineTransform(); at.rotate(Math.PI / 4); @@ -331,17 +332,13 @@ public Area getShapedArea( visionRange = (float) Math.sin(Math.toRadians(45)) * visionRange; // Get the cone, use degreesFromIso to convert the facing from isometric to plan - // Area tempvisibleArea = new Area(new Arc2D.Double(-visionRange * 2, -visionRange, - // visionRange * 4, visionRange * 2, token.getFacing() - (arcAngle / 2.0) + (offsetAngle * - // 1.0), arcAngle, - // Arc2D.PIE)); Arc2D cone = new Arc2D.Double( -visionRange * 2, -visionRange, visionRange * 4, visionRange * 2, - token.getFacing() - (arcAngle / 2.0) + (offsetAngle * 1.0), + -tokenFacing - (arcAngle / 2.0) + (offsetAngle * 1.0), arcAngle, Arc2D.PIE); GeneralPath path = new GeneralPath();