gizmoball.physics
Class PhysicsModel

java.lang.Object
  extended by gizmoball.physics.PhysicsModel
All Implemented Interfaces:
PrimitivesCollection

public class PhysicsModel
extends java.lang.Object
implements PrimitivesCollection

A PhysicsModel represents a collection of non-intersecting 3D physics objects whose centers of mass are fixed relative to each other.

Specification Fields

Constructor Summary
PhysicsModel()
          Create a new empty PhysicsModel
PhysicsModel(java.util.Collection<PhysicsObject> c)
          Create a new PhysicsModel containing the PhysicsObjectS in c
 
Method Summary
 void add(PhysicsModel pm)
          Add each object o in pm.objects to this.objects
 void add(PhysicsObject po)
          Adds po to this
 void addBox(Vect3 corner1, Vect3 corner2, double coeffOfReflection)
          Adds a box to this PhysicsModel, with its sides aligned with the axes, such that corner1 and corner2 are opposite corners.
 void addBox(Vect3 corner1, Vect3 corner2, double coeffOfReflection, java.lang.String texture)
          Adds a textured box to this PhysicsModel, with its sides aligned with the axes, such that corner1 and corner2 are opposite corners.
 void addCylinder(Vect3 bottomCenter, Vect3 topCenter, double radius, double reflectionCoeff)
          Adds a cylinder to this PhysicsModel
 void addCylinder(Vect3 bottomCenter, Vect3 topCenter, double radius, double reflectionCoeff, java.lang.String texture)
          Adds a textured cylinder to this PhysicsModel
 void addPlanePolygon(java.util.List<Vect3> vertices, double mass, double reflectionCoeff)
          Adds a planar polygon to this
 void addPrism(java.util.List<Vect3> vertices, Vect3 dir, double coefficientOfReflection)
          Adds a prism to this, where the prism is defined by one face, and the vector to the other face
 void addPrism(java.util.List<Vect3> vertices, Vect3 dir, double coefficientOfReflection, java.lang.String texture)
          Adds a textured prism to this, where the prism is defined by one face, and the vector to the other face
 void addSphere(double radius, Vect3 center, double reflectionCoeff)
          Adds a sphere to this PhysicsModel
 void addSphere(double radius, Vect3 center, double reflectionCoeff, java.lang.String texture)
          Adds a textured sphere to this PhysicsModel
 void addTorus(double radiusFromCenter, double radiusOfTube, Vect3 center, Vect3 orientation, double reflectionCoeff)
          Adds a torus to this PhysicsModel
 void addTorus(double radiusFromCenter, double radiusOfTube, Vect3 center, Vect3 orientation, double reflectionCoeff, java.lang.String texture)
          Adds a textured torus to this PhysicsModel
 boolean containsPoint(Vect3 p)
          Returns whether p is in this.
 Vect3 getBCenter()
          Returns the center of the bounding sphere
 Vect3Pair getBoundingBox()
           
 double getBRadius()
          Returns the radius of the bounding sphere
 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 orientation()
           
 Vect3 reflect(PhysicsSphere ps)
           
 void rotateAboutAxis(Vect3 center, Vect3 axis, double angle)
           
 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 translateBy(Vect3 dir)
           
 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

PhysicsModel

public PhysicsModel()
Create a new empty PhysicsModel

Effects:
creates a new physics model pm such that: pm.isEmpty = true

PhysicsModel

public PhysicsModel(java.util.Collection<PhysicsObject> c)
Create a new PhysicsModel containing the PhysicsObjectS in c

Requires:
o.velocity, o.rotCenter, o.rotOmega are the same for all o in c
Effects:
Creates a new PhysicsModel pm such that: pm.isEmpty = false && pm.objects = c && pm.rotCenter = o.rotCenter && pm.rotOmega = o.rotOmega && pm.velocity = o.velocity && pm.mass = sum of masses of PhysicsObjects o in c && pm.position = center of mass of PhysicsObjects o in c && for each object o in c, the sphere centered at bcenter with radius bradius contains o
Method Detail

add

public void add(PhysicsObject po)
Adds po to this

Requires:
o.velocity = this.velocity && Same rotating line condition
Effects:
this.objects = this.objects + po ADD bcenter / bradius effects

add

public void add(PhysicsModel pm)
Add each object o in pm.objects to this.objects

Requires:
for all o in pm.objects, o.velocity = this.velocity && Same rotating line condition
Effects:
this.objects = this.objects + pm.objects ADD bcenter / bradius effects

containsPoint

public boolean containsPoint(Vect3 p)
Returns whether p is in this.

Returns:
true if the distance from p to this is less than GameConstants.TOLERANCE
Requires:
p!= null

minDistanceToObjectFromP

public double minDistanceToObjectFromP(Vect3 p)
Returns the minimum distance from p to this

Returns:
the minimum distance from p to this
Requires:
p!= null

getBCenter

public Vect3 getBCenter()
Returns the center of the bounding sphere

Returns:
this.bcenter

getBRadius

public double getBRadius()
Returns the radius of the bounding sphere

Returns:
this.bradius

getVelocity

public Vect3 getVelocity()
Returns:
this.velocity

getRotCenter

public Vect3 getRotCenter()
Returns:
this.rotCenter

getRotOmega

public Vect3 getRotOmega()
Returns:
this.rotOmega

getPosition

public Vect3 getPosition()
Returns:
this.position

getMass

public double getMass()
Returns:
this.mass

getReflectionCoeff

public double getReflectionCoeff()
Returns:
the coefficient of reflection of one of the physics objects in this
Requires:
this is not empty

setVelocity

public void setVelocity(Vect3 vel)
Requires:
vel != null
Effects:
this.velocity = vel

setRotCenter

public void setRotCenter(Vect3 rc)
Requires:
rc != null
Effects:
this.rotCenter = rc

setRotOmega

public void setRotOmega(Vect3 ro)
Requires:
ro != null
Effects:
this.rotOmega = ro

setPosition

public void setPosition(Vect3 pos)
Requires:
pos != null
Effects:
this.position = pos

setReflectionCoeff

public void setReflectionCoeff(double rc)
Requires:
0 <= rc <= 1
Effects:
o.reflectionCoeff = rc for each o in this.objects

translateBy

public void translateBy(Vect3 dir)
Requires:
dir != null
Effects:
this.position_post = this.position_pre + dir

rotateAboutAxis

public void rotateAboutAxis(Vect3 center,
                            Vect3 axis,
                            double angle)
Requires:
center != null && axis != null
Effects:
rotates this by angle CCW about the axis formed by the line between center and axis

update

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

Requires:
timestep >= 0
Effects:
this.rotCenter_post = this.rotCenter_pre + this.velocity * timestep this.position_post = ADD rotational effect

reflect

public Vect3 reflect(PhysicsSphere ps)
Returns:
the velocity of ps reflected off of this

getPlanePolygons

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

getPlaneCircles

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

getSpheres

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

getLateralCylinders

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

getTori

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

timeUntilCollision

public double timeUntilCollision(PhysicsSphere ball,
                                 double lookahead)
Returns the time until a collision between ball and this. It will not spend any extra effort looking for collisions past the time lookahead. This method uses the bounding spheres for this.

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.

addCylinder

public void addCylinder(Vect3 bottomCenter,
                        Vect3 topCenter,
                        double radius,
                        double reflectionCoeff)
Adds a cylinder to this PhysicsModel

Effects:
Adds the specified cylinder to this PhysicsModel. This includes the top and bottom faces and rims

addCylinder

public void addCylinder(Vect3 bottomCenter,
                        Vect3 topCenter,
                        double radius,
                        double reflectionCoeff,
                        java.lang.String texture)
Adds a textured cylinder to this PhysicsModel

Effects:
Adds the specified cylinder to this PhysicsModel. This includes the top and bottom faces and rims

addTorus

public void addTorus(double radiusFromCenter,
                     double radiusOfTube,
                     Vect3 center,
                     Vect3 orientation,
                     double reflectionCoeff)
Adds a torus to this PhysicsModel

Effects:
Adds the specified torus to this PhysicsModel.

addTorus

public void addTorus(double radiusFromCenter,
                     double radiusOfTube,
                     Vect3 center,
                     Vect3 orientation,
                     double reflectionCoeff,
                     java.lang.String texture)
Adds a textured torus to this PhysicsModel

Effects:
Adds the specified torus to this PhysicsModel.

addSphere

public void addSphere(double radius,
                      Vect3 center,
                      double reflectionCoeff)
Adds a sphere to this PhysicsModel

Effects:
Adds the specified sphere to this PhysicsModel.

addSphere

public void addSphere(double radius,
                      Vect3 center,
                      double reflectionCoeff,
                      java.lang.String texture)
Adds a textured sphere to this PhysicsModel

Effects:
Adds the specified sphere to this PhysicsModel.

addBox

public void addBox(Vect3 corner1,
                   Vect3 corner2,
                   double coeffOfReflection)
Adds a box to this PhysicsModel, with its sides aligned with the axes, such that corner1 and corner2 are opposite corners.

Effects:
Adds the specified box to this PhysicsModel This includes both the corners and the edges

addBox

public void addBox(Vect3 corner1,
                   Vect3 corner2,
                   double coeffOfReflection,
                   java.lang.String texture)
Adds a textured box to this PhysicsModel, with its sides aligned with the axes, such that corner1 and corner2 are opposite corners.

Effects:
Adds the specified box to this PhysicsModel This includes both the corners and the edges

addPrism

public void addPrism(java.util.List<Vect3> vertices,
                     Vect3 dir,
                     double coefficientOfReflection)
Adds a prism to this, where the prism is defined by one face, and the vector to the other face

Effects:
Adds this prism to the PhysicsModel This includes both the corners and the edges

addPrism

public void addPrism(java.util.List<Vect3> vertices,
                     Vect3 dir,
                     double coefficientOfReflection,
                     java.lang.String texture)
Adds a textured prism to this, where the prism is defined by one face, and the vector to the other face

Effects:
Adds this prism to the PhysicsModel This includes both the corners and the edges

addPlanePolygon

public void addPlanePolygon(java.util.List<Vect3> vertices,
                            double mass,
                            double reflectionCoeff)
Adds a planar polygon to this

Requires:
the points in vertices are coplanar
Effects:
adds the specified plane polygon to this

orientation

public Vect3 orientation()
Returns:
the orientation of this

getBoundingBox

public Vect3Pair getBoundingBox()
Returns:
a bounding box consisting of one Vect3 with smaller coordinates and one Vect3 with larger coordinates