|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object hermes.hshape.HShape hermes.hshape.HPolygon
public class HPolygon
Represents an arbitrary convex polygon.
Position represents 'center.'
Vertex Points are positioned relative center. Each point is assumed to be next to points before and after it in list. Make sure your List of points is ordered correctly!
A HPolygon must also be convex, concave polygons will break collision detection.
Field Summary |
---|
Fields inherited from class hermes.hshape.HShape |
---|
_position |
Constructor Summary | |
---|---|
HPolygon(PVector position,
java.util.ArrayList<PVector> points)
Creates a new HPolygon. |
|
HPolygon(PVector position,
PVector... points)
Creates a new HPolygon. |
Method Summary | |
---|---|
void |
addPoint(PVector point)
Adds a point to the polygon. |
boolean |
collide(HCircle other)
|
boolean |
collide(HPolygon other)
|
boolean |
collide(HRectangle other)
|
boolean |
collide(HShape other)
Detects a collision with another shape |
boolean |
contains(float x,
float y)
|
boolean |
contains(PVector point)
Whether the Shape contains the given point coordinates (boundary is inclusive). |
static HPolygon |
createRegularHPolygon(PVector pos,
int sides,
float radius)
Creates a new regular polygon with a given number of sides at the given location. |
void |
draw()
Shortcut method for drawing the shape on screen |
protected java.util.ArrayList<PVector> |
getAxes()
Getter for axes list - only for internal use within shape classes |
java.util.ArrayList<PVector> |
getAxesCopy()
|
HRectangle |
getBoundingBox()
Finds the smallest Rectangle that encloses the shape. |
java.util.ArrayList<PVector> |
getPoints()
|
java.util.ArrayList<PVector> |
getPointsCopy()
|
PVector |
projectionVector(HCircle other)
|
PVector |
projectionVector(HPolygon other)
|
PVector |
projectionVector(HRectangle other)
|
PVector |
projectionVector(HShape other)
Finds the projection vector for a collision with another shape. |
void |
rotate(double theta)
Rotates polygon counter-clockwise around polygon's position ((0,0) in polygon coordinates). |
void |
rotate(PVector pivotLoc,
double theta)
Rotates polygon counter-clockwise around given position in polygon coordinates ((0,0) is polygon's position). |
java.lang.String |
toString()
|
Methods inherited from class hermes.hshape.HShape |
---|
getPosition |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public HPolygon(PVector position, java.util.ArrayList<PVector> points)
List of vertex points must be ordered such that each point is connected to points before and after it in list.
position
- - Reference to Shape's positionpoints
- - List of vertex points defined relative to position, must be orderedpublic HPolygon(PVector position, PVector... points)
Takes a variable number of PVectors (must give at least 3) for vertices.
Vertex points must be given in order such that each point is connected to points given before and after it.
position
- - Reference to Shape's positionpoints
- - the PVectors defining the verticies of the polygonMethod Detail |
---|
public java.util.ArrayList<PVector> getPoints()
public java.util.ArrayList<PVector> getPointsCopy()
public void addPoint(PVector point)
Point is assumed to be connected to the last point added and the first point added.
point
- - point to be addedprotected java.util.ArrayList<PVector> getAxes()
public java.util.ArrayList<PVector> getAxesCopy()
public void rotate(double theta)
theta
- Angle to rotate bypublic void rotate(PVector pivotLoc, double theta)
pivotLoc
- The point to rotate polygon aroundtheta
- Angle to rotate bypublic boolean collide(HShape other)
HShape
collide
in class HShape
other
- the shape to collide with
public boolean collide(HRectangle other)
public boolean collide(HCircle other)
public boolean collide(HPolygon other)
public PVector projectionVector(HShape other)
HShape
The projection vector is the vector by which one body could be displaced such that it no longer intersects the other body, by the shortest possible distance.
Each shape must contain methods for collision with all other types of HShapes. If you create your own type of shape, you will have to modify HShape (as well as its subclasses) to contain methods colliding it with the new type.
projectionVector
in class HShape
other
- the shape to collide with
public PVector projectionVector(HRectangle other)
projectionVector
in class HShape
public PVector projectionVector(HCircle other)
projectionVector
in class HShape
public PVector projectionVector(HPolygon other)
projectionVector
in class HShape
public boolean contains(PVector point)
HShape
contains
in class HShape
point
- the point vector
public boolean contains(float x, float y)
contains
in class HShape
x
- the x coordinatey
- the y coordinate
public HRectangle getBoundingBox()
HShape
getBoundingBox
in class HShape
public void draw()
HShape
draw
in class HShape
public java.lang.String toString()
toString
in class java.lang.Object
public static HPolygon createRegularHPolygon(PVector pos, int sides, float radius)
Radius determines how far away the vertices are from the center.
pos
- position of polygonsides
- number of sides in the polygonradius
- determines size of polygon
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |