hermes.hshape
Class HShape

java.lang.Object
  extended by hermes.hshape.HShape
Direct Known Subclasses:
HCircle, HPolygon, HRectangle

public abstract class HShape
extends java.lang.Object

An abstraction for a 2D shape, used for collision detection and response.

When the shape is linked to a being, shape's position should be a reference to the being's position.

In order for collision to work, all shapes must know how to collide with all other shapes.


Field Summary
protected  PVector _position
           
 
Constructor Summary
protected HShape(PVector position)
          Creates a new shape.
 
Method Summary
 boolean collide(HShape other)
          Detects a collision with another shape
abstract  boolean contains(float x, float y)
           
abstract  boolean contains(PVector point)
          Whether the Shape contains the given point coordinates (boundary is inclusive).
abstract  void draw()
          Shortcut method for drawing the shape on screen
abstract  HRectangle getBoundingBox()
          Finds the smallest Rectangle that encloses the shape.
 PVector getPosition()
          Returns the shape's position.
abstract  PVector projectionVector(HCircle other)
           
abstract  PVector projectionVector(HPolygon other)
           
abstract  PVector projectionVector(HRectangle other)
           
abstract  PVector projectionVector(HShape other)
          Finds the projection vector for a collision with another shape.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_position

protected PVector _position
Constructor Detail

HShape

protected HShape(PVector position)
Creates a new shape. When the shape represents a Being's collision area, the shape's position should reference the being's position.

Parameters:
position - the shape's position
Method Detail

collide

public boolean collide(HShape other)
Detects a collision with another shape

Parameters:
other - the shape to collide with
Returns:
whether the shapes have collided

projectionVector

public abstract PVector projectionVector(HShape other)
Finds the projection vector for a collision with another shape.

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.

Parameters:
other - the shape to collide with
Returns:
the projection vector from this body to other, or null if they aren't colliding

projectionVector

public abstract PVector projectionVector(HRectangle other)

projectionVector

public abstract PVector projectionVector(HCircle other)

projectionVector

public abstract PVector projectionVector(HPolygon other)

contains

public abstract boolean contains(PVector point)
Whether the Shape contains the given point coordinates (boundary is inclusive).

Parameters:
point - the point vector
Returns:
true if (x,y) lies within the Shape

contains

public abstract boolean contains(float x,
                                 float y)
Parameters:
x - the x coordinate
y - the y coordinate
Returns:
true if (x,y) lies within the Shape

getBoundingBox

public abstract HRectangle getBoundingBox()
Finds the smallest Rectangle that encloses the shape.

Returns:
the bounding box

getPosition

public PVector getPosition()
Returns the shape's position. Note, this is a reference, if you change this vector it will move the shape.

Returns:
the shape's position

draw

public abstract void draw()
Shortcut method for drawing the shape on screen