Skip to content

Commit

Permalink
Grid.getShapedArea() and overrides no longer modifies token facing
Browse files Browse the repository at this point in the history
The implementation also uses `Token.getFacingInDegrees()` for easier case handling, though it requires shifting the
result by 90.
  • Loading branch information
kwvanderlinde committed Oct 2, 2024
1 parent 59bac50 commit b6fe46f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/main/java/net/rptools/maptool/model/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/net/rptools/maptool/model/IsometricGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit b6fe46f

Please sign in to comment.