cs2110.collision
Class Block

java.lang.Object
  extended by cs2110.collision.Block

public class Block
extends java.lang.Object

An instance is a square block/pixel primitive for representing image-based rigid objects and resolving contacts. Each Block is wrapped by a disk and used for contact generation.

Author:
Doug James, March 2007.

Method Summary
 boolean contains(Vector2D p)
          Return true iff this block contains point p
 void display(java.awt.Graphics g, double scale, Vector2D d, boolean clicked, boolean overlaps)
          Draw this block using g, which must be a Graphics2D object.
 BoundingBox getBBox()
          Return the bounding box of this block.
 int getCol()
          Return the Image column.
 double getColorMass()
          Return the color-based mass on [0,1] with white having 0 mass and darker colors approaching 1 (feel free to modify).
 double getHalfwidth()
          Return the halfwidth of block.
 javax.vecmath.Point2d getPosition()
          Return the center position of Block (in body coordinates).
 int getRow()
          Return the Image row.
static boolean overlaps(Block b, Vector2D u, Block c, Vector2D v)
          Return true iff block b displaced by u overlaps block c displaced by v
 java.lang.String toString()
          Return a representation of this Block.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

overlaps

public static boolean overlaps(Block b,
                               Vector2D u,
                               Block c,
                               Vector2D v)
Return true iff block b displaced by u overlaps block c displaced by v

Parameters:
b - A block.
u - Displacement vector for block a.
c - A block.
v - Displacement vector for block b.
Returns:
True iff (block b displaced by vector u) overlaps (block c displaced by vector v).

contains

public boolean contains(Vector2D p)
Return true iff this block contains point p


display

public void display(java.awt.Graphics g,
                    double scale,
                    Vector2D d,
                    boolean clicked,
                    boolean overlaps)
Draw this block using g, which must be a Graphics2D object. It is scaled using scale and is displaced using d. clicked indicates whether it has been clicked on, in which case it appears differently. overlaps indicates whether it overlaps with some other shape.

Parameters:
g - A Graphics2D object.
scale - Scale factor from image coordinate system to canvas coordinate system.
d - Displacement vector for the block.
clicked - Indicates whether the shape containing the block has been clicked on.
overlaps - Indicates whether the shape containing the block overlaps another shape.

getBBox

public BoundingBox getBBox()
Return the bounding box of this block.

Returns:
The bounding box of this block.

getColorMass

public double getColorMass()
Return the color-based mass on [0,1] with white having 0 mass and darker colors approaching 1 (feel free to modify).

Returns:
The color-based mass described above

getHalfwidth

public double getHalfwidth()
Return the halfwidth of block. Note that the block radius is sqrt(2)*h.

Returns:
the Halfwidth

getPosition

public javax.vecmath.Point2d getPosition()
Return the center position of Block (in body coordinates).

Returns:
the center position

toString

public java.lang.String toString()
Return a representation of this Block.

Overrides:
toString in class java.lang.Object

getCol

public int getCol()
Return the Image column.


getRow

public int getRow()
Return the Image row.