vooga.physicsEngine.geometry.shapes
Class JavaShape

java.lang.Object
  extended by vooga.physicsEngine.geometry.shapes.JavaShape
All Implemented Interfaces:
Shape

public class JavaShape
extends java.lang.Object
implements Shape

Shape implementation that uses the java.awt.Shape framework as the back-end. This allows support for arbitrary closed shapes.

Author:
Peng Shi

Field Summary
 java.awt.Shape javaShape
           
(package private)  double r2IntegralRatio
           
 
Constructor Summary
JavaShape(java.awt.Shape shape)
          Creates a JavaShape from a java.awt.Shape object.
 
Method Summary
 java.awt.image.BufferedImage createBufferedImage(double angularPosition)
          Creates a BufferedImage representing the given Shape.
 BoundingBox getBoundingBox()
          Returns the bounding box of a shape.
 Vector2f getCentroid()
           
 double getR2IntegralEstimate()
          Obtain an estimate of the integral of R^2 over the whole shape, where R is the distance between each point and the centroid.
 Vector2f getSmallestCorner()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

javaShape

public final java.awt.Shape javaShape

r2IntegralRatio

final double r2IntegralRatio
Constructor Detail

JavaShape

public JavaShape(java.awt.Shape shape)
Creates a JavaShape from a java.awt.Shape object.

Parameters:
shape -
Method Detail

createBufferedImage

public java.awt.image.BufferedImage createBufferedImage(double angularPosition)
Description copied from interface: Shape
Creates a BufferedImage representing the given Shape. This image will have the same bounding box as the given shape. The image will have black outline and white interior. This is mostly for simple games and internal testing.

Specified by:
createBufferedImage in interface Shape
Returns:

getBoundingBox

public BoundingBox getBoundingBox()
Description copied from interface: Shape
Returns the bounding box of a shape. The bounding box always contains the shape until all rotations.

Specified by:
getBoundingBox in interface Shape
Returns:

getR2IntegralEstimate

public double getR2IntegralEstimate()
Description copied from interface: Shape
Obtain an estimate of the integral of R^2 over the whole shape, where R is the distance between each point and the centroid. This is used to compute a reasonable estimate for the moment of inertia.

Specified by:
getR2IntegralEstimate in interface Shape
Returns:

getCentroid

public Vector2f getCentroid()
Specified by:
getCentroid in interface Shape
Returns:
the relative Shape coordinate of the centroid

getSmallestCorner

public Vector2f getSmallestCorner()
Specified by:
getSmallestCorner in interface Shape
Returns:
the relative Shape coordinate of the top left corner of the tightest bounding box (this is needed for translating the game position coordinate--based on the smallest corner--to the physics engine coordinate--based on the centroid.