|
|
@@ -0,0 +1,88 @@
|
|
|
+package model.objects;
|
|
|
+
|
|
|
+import java.awt.Graphics2D;
|
|
|
+import java.awt.geom.AffineTransform;
|
|
|
+import java.awt.geom.Point2D;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+
|
|
|
+public class DrawObject {
|
|
|
+
|
|
|
+ protected Point2D position;
|
|
|
+ protected double scale;
|
|
|
+ protected double rotation;
|
|
|
+
|
|
|
+ BufferedImage image;
|
|
|
+
|
|
|
+ public DrawObject(BufferedImage image)
|
|
|
+ {
|
|
|
+ this.image = image;
|
|
|
+
|
|
|
+ position = new Point2D.Double(0,0);
|
|
|
+ scale = 1;
|
|
|
+ rotation = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void paint(Graphics2D g2d)
|
|
|
+ {
|
|
|
+ g2d.drawImage(image, getTransform(), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private AffineTransform getTransform()
|
|
|
+ {
|
|
|
+ AffineTransform tx = new AffineTransform();
|
|
|
+ tx.translate(position.getX(), position.getY());
|
|
|
+ tx.scale(scale, scale);
|
|
|
+ tx.rotate(rotation, image.getWidth()/2, image.getHeight()/2);
|
|
|
+ return tx;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* HELPER FUNCTIONS */
|
|
|
+ public void setX(double x)
|
|
|
+ {
|
|
|
+ position.setLocation(x, position.getY());
|
|
|
+ }
|
|
|
+ public void setY(double y)
|
|
|
+ {
|
|
|
+ position.setLocation(position.getX(), y);
|
|
|
+ }
|
|
|
+ public void setPosition(Point2D p)
|
|
|
+ {
|
|
|
+ position.setLocation(p);
|
|
|
+ }
|
|
|
+ public void setPosition(double x, double y)
|
|
|
+ {
|
|
|
+ position.setLocation(x, y);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRotation(double r)
|
|
|
+ {
|
|
|
+ this.rotation = r;
|
|
|
+ }
|
|
|
+ public void setScale(double s)
|
|
|
+ {
|
|
|
+ this.scale = s;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public double getX()
|
|
|
+ {
|
|
|
+ return position.getX();
|
|
|
+ }
|
|
|
+ public double getY()
|
|
|
+ {
|
|
|
+ return position.getY();
|
|
|
+ }
|
|
|
+ public Point2D getPosition()
|
|
|
+ {
|
|
|
+ return position;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getRotation()
|
|
|
+ {
|
|
|
+ return rotation;
|
|
|
+ }
|
|
|
+ public double getScale()
|
|
|
+ {
|
|
|
+ return scale;
|
|
|
+ }
|
|
|
+}
|