gizmoball.physics
Class PhysicsPolygon

java.lang.Object
  extended by gizmoball.physics.PhysicsPolygon
All Implemented Interfaces:
PhysicsObject, PrimitivesCollection

public class PhysicsPolygon
extends java.lang.Object
implements PhysicsObject

A PhysicsPlane is a wrapper class for a three dimensional representation of a plane polygon.

Specification Fields :
polygon : PlanePolygon // the plane polygon wrapped in this

Constructor Summary
PhysicsPolygon(java.util.List<Vect3> vertices, double mass, double reflectionCoeff, Vect3 velocity)
          Creates a new PhysicsPlane without rotation or texture
PhysicsPolygon(java.util.List<Vect3> vertices, double mass, double reflectionCoeff, Vect3 velocity, java.lang.String texture)
          Creates a new PhysicsPlane without rotation
PhysicsPolygon(java.util.List<Vect3> vertices, double mass, double reflectionCoeff, Vect3 rotCenter, Vect3 rotOmega, Vect3 velocity)
          Creates a new PhysicsPolygon without texture
PhysicsPolygon(java.util.List<Vect3> vertices, double mass, double reflectionCoeff, Vect3 rotCenter, Vect3 rotOmega, Vect3 velocity, java.lang.String texture)
          Creates a new PhysicsPolygon
 
Method Summary
 boolean containsPoint(Vect3 p)
          Returns whether p is in this.
 Vect3 getBCenter()
           
 Vect3Pair getBoundingBox()
           
 double getBRadius()
           
 java.util.Collection<LateralCylinder> getLateralCylinders()
           
 double getMass()
           
 java.util.Collection<PlaneCircle> getPlaneCircles()
           
 java.util.Collection<PlanePolygon> getPlanePolygons()
           
 Vect3 getPosition()
           
 double getReflectionCoeff()
           
 Vect3 getRotCenter()
           
 Vect3 getRotOmega()
           
 java.util.Collection<Sphere> getSpheres()
           
 java.util.Collection<Torus> getTori()
           
 Vect3 getVelocity()
           
 double minDistanceToObjectFromP(Vect3 p)
          Returns the minimum distance from p to this
 Vect3 reflect(PhysicsSphere ps)
           
 void rotateAboutAxis(Vect3 center, Vect3 axis, double angle)
           
 void setMass(double mass)
           
 void setPosition(Vect3 pos)
           
 void setReflectionCoeff(double rc)
           
 void setRotCenter(Vect3 rc)
           
 void setRotOmega(Vect3 ro)
           
 void setVelocity(Vect3 vel)
           
 double timeUntilCollision(PhysicsSphere ball, double lookahead)
          Returns the time until a collision between ball and this
 void update(double timestep)
          Updates the state of this after the passage of timestep.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhysicsPolygon

public PhysicsPolygon(java.util.List<Vect3> vertices,
                      double mass,
                      double reflectionCoeff,
                      Vect3 rotCenter,
                      Vect3 rotOmega,
                      Vect3 velocity,
                      java.lang.String texture)
Creates a new PhysicsPolygon

Parameters:
vertices - The vertices, in order, that are to be used. An internal copy is made.
mass - The mass of this polygon.
reflectionCoeff - The coefficient of reflection for this polygon.
rotCenter - The center of rotation
rotOmega - The angular velocity
velocity - The linear velocity
texture - The texture of the torus
Requires:
(vertices != null) && (rotCenter != null) && (rotOmega != null) && (velocity != null) && (vertices.length >= 3) && (mass >= 0) && (0 <= reflectionCoeff <= 1) && (all the points in vertices are coplanar)
Effects:
creates a PhysicsPolygon pp such that: pp.polygon.vertices = vertices && pp.mass = mass && pp.reflectionCoeff = reflectionCoeff && pp.rotCenter = rotCenter && pp.rotOmega = rotOmega && pp.velocity = velocity

PhysicsPolygon

public PhysicsPolygon(java.util.List<Vect3> vertices,
                      double mass,
                      double reflectionCoeff,
                      Vect3 rotCenter,
                      Vect3 rotOmega,
                      Vect3 velocity)
Creates a new PhysicsPolygon without texture

Parameters:
vertices - The vertices, in order, that are to be used. An internal copy is made.
mass - The mass of this polygon.
reflectionCoeff - The coefficient of reflection for this polygon.
rotCenter - The center of rotation
rotOmega - The angular velocity
velocity - The linear velocity
Requires:
(vertices != null) && (rotCenter != null) && (rotOmega != null) && (velocity != null) && (vertices.length >= 3) && (mass >= 0) && (0 <= reflectionCoeff <= 1) && (all the points in vertices are coplanar)
Effects:
creates a PhysicsPolygon pp such that: pp.polygon.vertices = vertices && pp.mass = mass && pp.reflectionCoeff = reflectionCoeff && pp.rotCenter = rotCenter && pp.rotOmega = rotOmega && pp.velocity = velocity

PhysicsPolygon

public PhysicsPolygon(java.util.List<Vect3> vertices,
                      double mass,
                      double reflectionCoeff,
                      Vect3 velocity,
                      java.lang.String texture)
Creates a new PhysicsPlane without rotation

Parameters:
vertices - The vertices, in order, that are to be used. An internal copy is made.
mass - The mass of this polygon.
reflectionCoeff - The coefficient of reflection for this polygon.
velocity - The linear velocity
texture - The texture of the torus
Requires:
(vertices != null) && (velocity != null) && (vertices.length >= 3) && (mass >= 0) && (0 <= reflectionCoeff <= 1) && (all the points in vertices are coplanar)
Effects:
Creates a new PhysicsPolygon with the desired parameters such that: rotCenter = Vect3.ZERO && rotOmega = Vect3.ZERO

PhysicsPolygon

public PhysicsPolygon(java.util.List<Vect3> vertices,
                      double mass,
                      double reflectionCoeff,
                      Vect3 velocity)
Creates a new PhysicsPlane without rotation or texture

Parameters:
vertices - The vertices, in order, that are to be used. An internal copy is made.
mass - The mass of this polygon.
reflectionCoeff - The coefficient of reflection for this polygon.
velocity - The linear velocity
Requires:
(vertices != null) && (velocity != null) && (vertices.length >= 3) && (mass >= 0) && (0 <= reflectionCoeff <= 1) && (all the points in vertices are coplanar)
Effects:
Creates a new PhysicsPolygon with the desired parameters such that: rotCenter = Vect3.ZERO && rotOmega = Vect3.ZERO
Method Detail

containsPoint

public boolean containsPoint(Vect3 p)
Description copied from interface: PhysicsObject
Returns whether p is in this.

Specified by:
containsPoint in interface PhysicsObject
Returns:
true if the distance from p to this is less than GameConstants.TOLERANCE

getBCenter

public Vect3 getBCenter()
Specified by:
getBCenter in interface PhysicsObject
Returns:
this.bcenter

getBRadius

public double getBRadius()
Specified by:
getBRadius in interface PhysicsObject
Returns:
this.bradius

getMass

public double getMass()
Specified by:
getMass in interface PhysicsObject
Returns:
this.mass

getPosition

public Vect3 getPosition()
Specified by:
getPosition in interface PhysicsObject
Returns:
this.position

getRotCenter

public Vect3 getRotCenter()
Specified by:
getRotCenter in interface PhysicsObject
Returns:
this.rotCenter

getRotOmega

public Vect3 getRotOmega()
Specified by:
getRotOmega in interface PhysicsObject
Returns:
this.rotOmega

getVelocity

public Vect3 getVelocity()
Specified by:
getVelocity in interface PhysicsObject
Returns:
this.velocity

getReflectionCoeff

public double getReflectionCoeff()
Specified by:
getReflectionCoeff in interface PhysicsObject
Returns:
this.reflectionCoeff

minDistanceToObjectFromP

public double minDistanceToObjectFromP(Vect3 p)
Description copied from interface: PhysicsObject
Returns the minimum distance from p to this

Specified by:
minDistanceToObjectFromP in interface PhysicsObject
Returns:
the minimum distance between p and this
Requires:
p != null

reflect

public Vect3 reflect(PhysicsSphere ps)
Specified by:
reflect in interface PhysicsObject
Returns:
the velocity of the ball after impacting the given sphere
Effects:
computes the new velocity of a ball reflecting off of a sphere. The velocity resulting from this method corresponds to a collision against a surface with the reflection coefficient of this. A reflection coefficient of 1 indicates a perfectly elastic collision. This method assumes that the ball is at the point of impact.

setMass

public void setMass(double mass)
Specified by:
setMass in interface PhysicsObject
Requires:
mass >= 0
Effects:
this.mass = mass

setPosition

public void setPosition(Vect3 pos)
Specified by:
setPosition in interface PhysicsObject
Requires:
pos != null
Effects:
this.position = pos

setRotCenter

public void setRotCenter(Vect3 rc)
Specified by:
setRotCenter in interface PhysicsObject
Requires:
rc != null
Effects:
this.rotCenter = rc

setRotOmega

public void setRotOmega(Vect3 ro)
Specified by:
setRotOmega in interface PhysicsObject
Requires:
ro != null
Effects:
this.rotOmega = ro

setVelocity

public void setVelocity(Vect3 vel)
Specified by:
setVelocity in interface PhysicsObject
Requires:
vel != null
Effects:
this.velocity = vel

setReflectionCoeff

public void setReflectionCoeff(double rc)
Specified by:
setReflectionCoeff in interface PhysicsObject
Requires:
0 <= rc <= 1
Effects:
this.reflectionCoeff = rc

rotateAboutAxis

public void rotateAboutAxis(Vect3 center,
                            Vect3 axis,
                            double angle)
Specified by:
rotateAboutAxis in interface PhysicsObject

update

public void update(double timestep)
Updates the state of this after the passage of timestep.

Specified by:
update in interface PhysicsObject
Requires:
timestep >= 0
Effects:
this.rotCenter_post = this.rotCenter_pre + this.velocity * timestep this.position_post = this.rotCenter_post + this.rotOmega x (this.position_pre - this.rotCenter_pre)* timestep

timeUntilCollision

public double timeUntilCollision(PhysicsSphere ball,
                                 double lookahead)
Returns the time until a collision between ball and this

Specified by:
timeUntilCollision in interface PhysicsObject
Returns:
the time until collision or POSITIVE_INFINITY if the collision will not occur
Effects:
computes the time until ball and this, travelling at their current specified velocities, collide. If no collision will occur POSITIVE_INFINITY is returned. This method assumes that both objects will travel at constant velocity until impact.

getPlanePolygons

public java.util.Collection<PlanePolygon> getPlanePolygons()
Specified by:
getPlanePolygons in interface PrimitivesCollection
Returns:
this.planePolygons

getPlaneCircles

public java.util.Collection<PlaneCircle> getPlaneCircles()
Specified by:
getPlaneCircles in interface PrimitivesCollection
Returns:
this.planeCircles

getSpheres

public java.util.Collection<Sphere> getSpheres()
Specified by:
getSpheres in interface PrimitivesCollection
Returns:
this.spheres

getLateralCylinders

public java.util.Collection<LateralCylinder> getLateralCylinders()
Specified by:
getLateralCylinders in interface PrimitivesCollection
Returns:
this.lateralCylinders

getTori

public java.util.Collection<Torus> getTori()
Specified by:
getTori in interface PrimitivesCollection
Returns:
this.torii

getBoundingBox

public Vect3Pair getBoundingBox()
Specified by:
getBoundingBox in interface PhysicsObject
Returns:
a bounding box consisting of one Vect3 with smaller coordinates and one Vect3 with larger coordinates