source.ucregents.playground.physics
Class BaseEntity

java.lang.Object
  extended by source.ucregents.playground.physics.BaseEntity
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
BaseFieldForceEntity, MovingEntity, Terrain

public abstract class BaseEntity
extends java.lang.Object
implements java.lang.Cloneable

The most basic type of Entity. BaseEntity contains the shape, orientation, image, as well as whether it is visible, whether it can be collided with, and what its bounciness is.


Constructor Summary
BaseEntity()
          Constructs a default base entity with position 0,0 and 0 height and width
BaseEntity(PolygonOrCircle shape, float orientation)
          Constructs a BaseEntity with the input shape, orientation, imagelocation, and collidible and visibility properties
 
Method Summary
 void calculateAxes()
          Recalculates all the axes of the given shape.
 java.lang.Object clone()
           
protected  java.lang.String DefaultImageLocation()
          Provides the location of the default image
 void Deserialize(CustomXMLReader reader)
           
 void Draw(java.awt.Graphics2D g, boolean verbose)
          Draws the entity to the screen
 java.awt.geom.Dimension2D getActualFrameDimensions()
          Gets the dimensions of the Bounding Box
 java.util.Vector<javax.vecmath.Vector2d> getAxes()
          Returns the vector of current axes
 java.util.Vector<javax.vecmath.Vector2d> getAxesClone()
          Returns a clone of the vector of current axes
 javax.vecmath.Vector2d getAxis(int whichPolygonSide)
          Determines the axis (in the form of a unit vector) which is formed by the specified side of the polygon.
Note: this method DOES NOT know if there are other axes parallel to the one it is returning
 float getBounciness()
          Accessor for the entity's bounciness
 java.awt.geom.Point2D.Double getCenterPoint()
          Accessor for the current center point
 DrawType getDrawType()
           
 java.util.Vector<UserEvent> getEvents()
          Gets the user events
 java.awt.Color getFrameColor()
          Gets the shape's current frame color
 float getFrictionConstant()
          Gets the friction constant
 java.awt.Color getGradientColor()
          Gets the entity's current graient color
protected  java.awt.geom.Point2D getImageOffset()
          Gets the image offset
 java.lang.String getName()
          Gets the name set by the user for the entity
 double getOrientation()
          Accessor for the entity's current orientation
 java.awt.geom.Rectangle2D getResizingObject()
          Gets the area to show resizing arrows
 double getRoundedShapeMass()
          Gets the Shape's (PolygonOrCircle) Rounded Area and adjusts it for the mass
 double getScale()
          Gets the current scale
 java.awt.Shape getShape()
          Accessor for the entity's shape
 java.awt.Color getShapeColor()
          Gets the shape's current fill color
 java.awt.geom.Rectangle2D getShapeFrame()
          Returns the outer bounding box of the entity
 double getShapeMass()
          Gets the Shape's (PolygonOrCircle) Area and adjusts it for use in Mass.
 java.util.Vector<javax.vecmath.Vector2d> getSideVectors()
          Determines the vectors which connect the vertices of the entity's shape (the sides of the shape).
 java.awt.geom.Point2D.Double getULPoint()
          Accessor for the current upper left point
 java.util.Vector<UserEvent> getUserEvents()
           
 int getVertexCount()
          Determines the number of vertices in the current polygon
 java.util.Vector<java.awt.geom.Point2D.Double> getVerticesCoordinates()
          Determines the coordinates of the Vertices of the shape of this entity.
 boolean isCircle()
          Tells whether the shape is a circle
 boolean isCollidable()
          Determines whether or not this entity can be collided with by other entities.
 javax.vecmath.Vector2d isOverlapping(BaseEntity ent2)
          Determines whether another polygon is overlapping another using the seperate axis theorem.
 boolean isPolygon()
          Tells whether the shape is a polygon
 boolean isSelected()
          Gets if this entity is selected
 boolean isVisible()
          Determines whether or not this entity can be seen by the user.
protected  void OnCenterScale(double s)
           
 void OnCollisionWith(BaseEntity ent2)
          Physics collisions are already handled, this method is called immediately after each collision to determine any special behavior of this entity.
protected  void OnLocationChange(double deltaX, double deltaY)
           
protected  void OnOrientationChange(double deltaTheta)
           
protected  void OnULScale(double s)
           
 void RegisterEvent(int eventType, int eventSubType, java.lang.reflect.Method m, java.lang.Object[] params)
           
 void RegisterEvent(UserEvent u)
           
 void RegisterEvents(java.util.Vector<UserEvent> ue)
           
 void RemoveEvent(UserEvent u)
           
 void RemoveEvents(java.util.Vector<UserEvent> ue)
           
 void resetFrameColor()
          Resets the frame color to black
 void Scale(double s)
          Scale the shape by it's upper left point
 void ScaleAroundCenter(double s)
          Scale the shape around it's center point
 void Serialize(CustomXMLWriter writer)
           
 void setBounciness(float bounciness)
          Mutator for the entitys current bounciness
 void setCenterPoint(double x, double y)
          Sets the center point of the entity to the given x and y coordinates
 void setCenterPoint(java.awt.geom.Point2D.Double p)
          Sets the center point of the entity to the given point
 void setCollidable(boolean collide)
          Sets whether the entity can collide with other entities
 void setDrawType(DrawType drawType)
           
 void setFrameColor(java.awt.Color c)
          Sets the shape's current frame color
 void setFrictionConstant(float friction)
          Sets the friction constant
 void setGradientColor(java.awt.Color c)
          Sets the entity's current gradient color
protected  void setImageOffset(java.awt.geom.Point2D imageOffset)
          Sets the image offset
 void setName(java.lang.String name)
          Sets the name of the entity
 void setOrientation(double orientation)
          Mutator for the entity's orientation
 void setScale(double scale)
          Sets the scale of the entity
 void setSelected(boolean b)
          Set if this entity has been selected by the user
 void setShapeColor(java.awt.Color c)
          Sets the shape's current fill color
 void setULPoint(double x, double y)
          Sets the upperleft point of the entity to the given x and y coordinates
 void setULPoint(java.awt.geom.Point2D.Double p)
          Sets the upperleft point of the entity to the given double accuracy Point2D
 void setVisible(boolean isVisible)
          Mutator for the entity's visibility
 java.lang.String toString()
           
 org.w3c.dom.Node toXMLElement()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BaseEntity

public BaseEntity()
Constructs a default base entity with position 0,0 and 0 height and width


BaseEntity

public BaseEntity(PolygonOrCircle shape,
                  float orientation)
Constructs a BaseEntity with the input shape, orientation, imagelocation, and collidible and visibility properties

Parameters:
shape - The shape
orientation - The angle in degrees of its starting rotation about its center point
Method Detail

calculateAxes

public final void calculateAxes()
Recalculates all the axes of the given shape.
Note: this method knows only stores those axes not parallel to one another. (Axes from two parallel sides are the same value!)


clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

DefaultImageLocation

protected java.lang.String DefaultImageLocation()
Provides the location of the default image

Returns:
Returns the location of the image

Deserialize

public void Deserialize(CustomXMLReader reader)

Draw

public void Draw(java.awt.Graphics2D g,
                 boolean verbose)
Draws the entity to the screen

Parameters:
g - The java.awt.Graphics2D object

getActualFrameDimensions

public final java.awt.geom.Dimension2D getActualFrameDimensions()
Gets the dimensions of the Bounding Box

Returns:
Returns the Dimensions of the Bounding Box

getAxes

public final java.util.Vector<javax.vecmath.Vector2d> getAxes()
Returns the vector of current axes

Returns:
A series of vector values representing all the axes of the polygon of this entity.

getAxesClone

public final java.util.Vector<javax.vecmath.Vector2d> getAxesClone()
Returns a clone of the vector of current axes

Returns:
A series of vector values representing all the axes of the polygon of this entity.

getAxis

public final javax.vecmath.Vector2d getAxis(int whichPolygonSide)
Determines the axis (in the form of a unit vector) which is formed by the specified side of the polygon.
Note: this method DOES NOT know if there are other axes parallel to the one it is returning

Parameters:
whichPolygonSide - integer referring to the side of the polygon from which the axis is extrapolated
Returns:
the unit vector parallel to the axis

getBounciness

public final float getBounciness()
Accessor for the entity's bounciness

Returns:
The entity's current bounciness

getCenterPoint

public final java.awt.geom.Point2D.Double getCenterPoint()
Accessor for the current center point

Returns:
Returns the center of the entity

getDrawType

public final DrawType getDrawType()

getEvents

public java.util.Vector<UserEvent> getEvents()
Gets the user events

Returns:
the vector of user events

getFrameColor

public final java.awt.Color getFrameColor()
Gets the shape's current frame color

Returns:
The frame color

getFrictionConstant

public final float getFrictionConstant()
Gets the friction constant

Returns:
the friction constant

getGradientColor

public final java.awt.Color getGradientColor()
Gets the entity's current graient color

Returns:
Returns the sharpe's gradient color

getImageOffset

protected final java.awt.geom.Point2D getImageOffset()
Gets the image offset

Returns:
the image offset

getName

public final java.lang.String getName()
Gets the name set by the user for the entity

Returns:
The name of the entity

getOrientation

public final double getOrientation()
Accessor for the entity's current orientation

Returns:
The entity's current orientation.

getResizingObject

public java.awt.geom.Rectangle2D getResizingObject()
Gets the area to show resizing arrows

Returns:
Gets the risizing box

getRoundedShapeMass

public double getRoundedShapeMass()
Gets the Shape's (PolygonOrCircle) Rounded Area and adjusts it for the mass

Returns:
Returns the The Rounded Area of the PolygonOrCircle / 100

getScale

public final double getScale()
Gets the current scale

Returns:
the current scale of the entity

getShape

public final java.awt.Shape getShape()
Accessor for the entity's shape

Returns:
Returns the entity's shape

getShapeColor

public final java.awt.Color getShapeColor()
Gets the shape's current fill color

Returns:
Returns the shape's primary color

getShapeFrame

public final java.awt.geom.Rectangle2D getShapeFrame()
Returns the outer bounding box of the entity

Returns:
A rectangle2d that encloses the object

getShapeMass

public double getShapeMass()
Gets the Shape's (PolygonOrCircle) Area and adjusts it for use in Mass.

Returns:
Returns the Area of the PolygonOrCircle / 100

getSideVectors

public final java.util.Vector<javax.vecmath.Vector2d> getSideVectors()
Determines the vectors which connect the vertices of the entity's shape (the sides of the shape).

Returns:
a series of Vectors corresponding to the sides of the shape

getULPoint

public final java.awt.geom.Point2D.Double getULPoint()
Accessor for the current upper left point

Returns:
Returns the upper left position of the entity

getUserEvents

public final java.util.Vector<UserEvent> getUserEvents()

getVertexCount

public final int getVertexCount()
Determines the number of vertices in the current polygon

Returns:
number of vertices

getVerticesCoordinates

public final java.util.Vector<java.awt.geom.Point2D.Double> getVerticesCoordinates()
Determines the coordinates of the Vertices of the shape of this entity. (With respect to the grid coordinates the entity was created in)

Returns:
a series of double accuracy Points corresponding to the location of the vertices of the shape

isCircle

public final boolean isCircle()
Tells whether the shape is a circle

Returns:
If the shape is a circle

isCollidable

public boolean isCollidable()
Determines whether or not this entity can be collided with by other entities.

Returns:
true if can be collided with

isOverlapping

public javax.vecmath.Vector2d isOverlapping(BaseEntity ent2)
Determines whether another polygon is overlapping another using the seperate axis theorem.

Parameters:
ent2 - The entity to check this one against
Returns:
True if it is overlapping the other polygon at its current position

isPolygon

public final boolean isPolygon()
Tells whether the shape is a polygon

Returns:
If the shape is a polygon

isSelected

public final boolean isSelected()
Gets if this entity is selected

Returns:
if this is selected

isVisible

public final boolean isVisible()
Determines whether or not this entity can be seen by the user.

Returns:
true is can be seen with

OnCenterScale

protected void OnCenterScale(double s)

OnCollisionWith

public void OnCollisionWith(BaseEntity ent2)
Physics collisions are already handled, this method is called immediately after each collision to determine any special behavior of this entity. The other object is given only to determine what special event will happen to this entity and in most cases should not be modified. collideSpecial is called twice with reference to both objects in opposite order.

Parameters:
ent2 - The entity that collision has occured with

OnLocationChange

protected void OnLocationChange(double deltaX,
                                double deltaY)

OnOrientationChange

protected void OnOrientationChange(double deltaTheta)

OnULScale

protected void OnULScale(double s)

RegisterEvent

public void RegisterEvent(int eventType,
                          int eventSubType,
                          java.lang.reflect.Method m,
                          java.lang.Object[] params)

RegisterEvent

public void RegisterEvent(UserEvent u)

RegisterEvents

public void RegisterEvents(java.util.Vector<UserEvent> ue)

RemoveEvent

public void RemoveEvent(UserEvent u)

RemoveEvents

public void RemoveEvents(java.util.Vector<UserEvent> ue)

resetFrameColor

public final void resetFrameColor()
Resets the frame color to black


Scale

public final void Scale(double s)
Scale the shape by it's upper left point

Parameters:
s - The ratio to scale it by

ScaleAroundCenter

public final void ScaleAroundCenter(double s)
Scale the shape around it's center point

Parameters:
s - The ratio to scale it by

Serialize

public void Serialize(CustomXMLWriter writer)

setBounciness

public final void setBounciness(float bounciness)
Mutator for the entitys current bounciness

Parameters:
bounciness - The entity's new bounciness from 0-1

setCenterPoint

public final void setCenterPoint(double x,
                                 double y)
Sets the center point of the entity to the given x and y coordinates

Parameters:
x - the x coordinate of the point
y - the y coordinate of the point

setCenterPoint

public final void setCenterPoint(java.awt.geom.Point2D.Double p)
Sets the center point of the entity to the given point

Parameters:
p - the point to set to

setCollidable

public void setCollidable(boolean collide)
Sets whether the entity can collide with other entities

Parameters:
collide - True if it can collide with other entities

setDrawType

public final void setDrawType(DrawType drawType)

setFrameColor

public final void setFrameColor(java.awt.Color c)
Sets the shape's current frame color

Parameters:
c - The new frame color

setFrictionConstant

public final void setFrictionConstant(float friction)
Sets the friction constant

Parameters:
friction - the new friction constant

setGradientColor

public final void setGradientColor(java.awt.Color c)
Sets the entity's current gradient color

Parameters:
c - The new gradient color

setImageOffset

protected final void setImageOffset(java.awt.geom.Point2D imageOffset)
Sets the image offset

Parameters:
imageOffset -

setName

public final void setName(java.lang.String name)
Sets the name of the entity

Parameters:
name - name of the entity

setOrientation

public final void setOrientation(double orientation)
Mutator for the entity's orientation

Parameters:
orientation - The orientation to be set

setScale

public final void setScale(double scale)
Sets the scale of the entity

Parameters:
scale - the new scale of the entity

setSelected

public final void setSelected(boolean b)
Set if this entity has been selected by the user

Parameters:
b - the isSelected value

setShapeColor

public final void setShapeColor(java.awt.Color c)
Sets the shape's current fill color

Parameters:
c - The new fill color of the shape

setULPoint

public final void setULPoint(double x,
                             double y)
Sets the upperleft point of the entity to the given x and y coordinates

Parameters:
x - the x coordinate of the point
y - the y coordinate of the point

setULPoint

public final void setULPoint(java.awt.geom.Point2D.Double p)
Sets the upperleft point of the entity to the given double accuracy Point2D

Parameters:
p - the point to set the upperleft corner of the entity

setVisible

public final void setVisible(boolean isVisible)
Mutator for the entity's visibility

Parameters:
isVisible - Returns if the entity is currently visible or not

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toXMLElement

public final org.w3c.dom.Node toXMLElement()