cs2110.collision
Class Block

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

public class Block
extends Object

Basic 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.

Field Summary
(package private)  int col
          Image column index.
(package private)  Color color
          Pixel color.
(package private) static Random gen
           
(package private)  double halfwidth
          Halfwidth of block (Note: the block radius is sqrt(2)*h).
(package private)  javax.vecmath.Point2d position
          Body-frame position --- needed for contact processing.
(package private)  int row
          Image row index.
 
Constructor Summary
Block(int i, int j, Color color, javax.vecmath.Point2d center, double halfwidth)
          Constructs a Block.
 
Method Summary
 boolean contains(cs2110.collision.Vector2D p)
           
 void display(Graphics g, double scale, cs2110.collision.Vector2D d, boolean clicked, boolean overlaps)
           
 cs2110.collision.BoundingBox getBBox()
           
(package private)  int getCol()
          Image column.
 double getColorMass()
          Color-based mass on [0,1] with white having zero mass, and darker colors approaching one (feel free to modify).
 double getHalfwidth()
          Halfwidth of block.
 javax.vecmath.Point2d getPosition()
          Center position of Block (in body coordinates).
(package private)  int getRow()
          Image row.
static boolean overlaps(Block a, cs2110.collision.Vector2D u, Block b, cs2110.collision.Vector2D v)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

gen

static Random gen

row

int row
Image row index.


col

int col
Image column index.


color

Color color
Pixel color.


halfwidth

double halfwidth
Halfwidth of block (Note: the block radius is sqrt(2)*h).


position

javax.vecmath.Point2d position
Body-frame position --- needed for contact processing.

Constructor Detail

Block

Block(int i,
      int j,
      Color color,
      javax.vecmath.Point2d center,
      double halfwidth)
Constructs a Block.

Method Detail

overlaps

public static boolean overlaps(Block a,
                               cs2110.collision.Vector2D u,
                               Block b,
                               cs2110.collision.Vector2D v)
Parameters:
a - A block.
u - Displacement vector for block a.
b - A block.
v - Displacement vector for block b.
Returns:
True iff (block a displaced by vector u) overlaps (block b displaced by vector v).

contains

public boolean contains(cs2110.collision.Vector2D p)
Parameters:
p - A point.
Returns:
True iff this block contains point p.

display

public void display(Graphics g,
                    double scale,
                    cs2110.collision.Vector2D d,
                    boolean clicked,
                    boolean overlaps)
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 cs2110.collision.BoundingBox getBBox()
Returns:
The bounding box of this block.

getColorMass

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

Returns:
The color-based mass described above

getHalfwidth

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

Returns:
the Halfwidth

getPosition

public javax.vecmath.Point2d getPosition()
Center position of Block (in body coordinates).

Returns:
the center position

toString

public String toString()
Overrides:
toString in class Object

getCol

int getCol()
Image column.


getRow

int getRow()
Image row.