Note that there are some explanatory texts on larger screens.

plurals
  1. POPolygon moves while being rotated
    primarykey
    data
    text
    <p>I'm doing a couple of tests with polygons (rotating them) and I've run into an annoying issue that crops up while I'm rotating them. The issue is, the polygons seem to be moving when they rotate, and eventually they fly out of the screen. I've been using AffineTransform to rotate them, and I haven't been translating them so they shouldn't be moving, right? Here's the code:</p> <pre><code>import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; public class PhysicsProp { Point2D[] OriginalPoints; Point2D[] NewPoints = OriginalPoints; int X; int Y; double rotation = 0.0; public PhysicsProp(Point2D[] Points){ OriginalPoints = Points; NewPoints = Points; } public Polygon PointsToPoly(Point2D[] Points){ Polygon p = new Polygon(); for (int i = 0; i &lt; Points.length; i++){ p.addPoint((int) Points[i].getX(), (int) Points[i].getY()); } return p; } public void rotateModel(double theta){ AffineTransform.getRotateInstance(Math.toDegrees(theta), PointsToPoly(NewPoints).getBounds().getCenterX(), PointsToPoly(NewPoints).getBounds().getCenterY()).transform(OriginalPoints, 0, NewPoints, 0, OriginalPoints.length); } public Polygon getModel(){ return PointsToPoly(NewPoints); } public void setModel(Point[] points){ OriginalPoints = points; } public Rectangle getBounds(){ return PointsToPoly(NewPoints).getBounds(); } } </code></pre> <p>I'd like to know what's actually going wrong with this code, and if there's a better way around what I'm trying to achieve (rotating polygons). Here's where I render and rotate the polygons:</p> <pre><code>g2.setColor(Color.pink); for (PhysicsProp p : CurrentLevel.PhysicsObjects){ g2.drawPolygon(p.PointsToPoly(p.NewPoints)); p.rotateModel(0.001); } </code></pre> <p>Thanks for any help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload