org.dolben.anim
Class Body

java.lang.Object
  extended by org.dolben.anim.Body
All Implemented Interfaces:
java.lang.Comparable

public class Body
extends java.lang.Object
implements java.lang.Comparable

Body moves a solid around in 3D space; rotating it, translating it, and bouncing it off of other bodies and the walls of its enclosure.


Constructor Summary
Body(Solid s)
          Creates a new Body for a given solid.
 
Method Summary
 void collide(Body other)
           Bounces this body off of another when they collide.
 int compareTo(java.lang.Object object)
          Orders Bodies from farthest to nearest to an observer, presumed to be at a large z coordinate, making the class Comparable.
 double getCollisionRadius()
          Gets the solid's collision radius (a hack)
 void paint(Projector projector, java.awt.Graphics graphics)
          Draws the solid.
 void setRotation(double[][] r)
          Sets the rotation to be done with each step of motion.
 void setVelocity(double[] v, double[] limit)
          Sets the velocity and limit of translation.
 void step()
          Moves the polyhedron one step.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Body

public Body(Solid s)
Creates a new Body for a given solid.

Parameters:
s - the solid to be moved
Method Detail

paint

public void paint(Projector projector,
                  java.awt.Graphics graphics)
Draws the solid.

Parameters:
projector - the projector that maps 3D to Graphics coordinates
graphics - the drawing context

getCollisionRadius

public double getCollisionRadius()
Gets the solid's collision radius (a hack)


compareTo

public int compareTo(java.lang.Object object)
Orders Bodies from farthest to nearest to an observer, presumed to be at a large z coordinate, making the class Comparable.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
object - another body to compare to
Returns:
-1 when this is farther than the other, 1 when this is nearer, or 0 when they are the same distance

setRotation

public void setRotation(double[][] r)
Sets the rotation to be done with each step of motion.

Parameters:
r - the 3D rotation matrix

setVelocity

public void setVelocity(double[] v,
                        double[] limit)
Sets the velocity and limit of translation.

Parameters:
v - the 3D velocity vector
limit - the limit of displacement from the origin in each dimension

step

public void step()
Moves the polyhedron one step.


collide

public void collide(Body other)

Bounces this body off of another when they collide.

The objects are considered to be spheres of the same mass.

The threshhold distance for a collision is less than the sum of the radii of the circumspheres, since the objects often appear to miss at greater distance.

Parameters:
other - the other body in a collision