org.piratis.j2me.core
Class BBox2D

java.lang.Object
  extended byorg.piratis.j2me.core.BBox2D

public class BBox2D
extends java.lang.Object

BBox2D: surrounding box with basic square features used by sprite, canvas and so on.

Version:
$Id: BBox2D.java,v 1.4 2004/07/01 22:14:38 piratis Exp $
Author:
Jordi Martín

Field Summary
 int height
           
 int width
           
 int x
          BBox data.
 int y
           
 
Constructor Summary
BBox2D()
          Void constructor
BBox2D(BBox2D other)
          Create a BBox based on another's size
BBox2D(int x, int y, int width, int height)
          Main constructor
 
Method Summary
 boolean collide(BBox2D other)
          Check if the current BBox collides with another one.
 boolean collide(int oX, int oY, int oW, int oH)
          Check if this BBox collides with given area
 int getArea()
           
 int getCenterX()
          Gets the center on the X axis
 int getCenterY()
          Gets the center on the Y axis
 boolean isVoid()
          Checks if the bounding box is not null 0x0
 BBox2D merge(BBox2D other)
          Merges the current bbox with another, returning the minimal bbox containing both (overwritting current one)
 void nullify()
          Voids the current BBox2D
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

x

public int x
BBox data. Public visibility to speed up access speed (without the overhead of a gets methods.


y

public int y

width

public int width

height

public int height
Constructor Detail

BBox2D

public BBox2D()
Void constructor


BBox2D

public BBox2D(BBox2D other)
Create a BBox based on another's size

Parameters:
other - the basis BBox

BBox2D

public BBox2D(int x,
              int y,
              int width,
              int height)
Main constructor

Parameters:
x - top left corner X
y - top left corner Y
width - of the box
height - of the box
Method Detail

getCenterX

public int getCenterX()
Gets the center on the X axis

Returns:
the X-axis center

getCenterY

public int getCenterY()
Gets the center on the Y axis

Returns:
the Y-axis center

collide

public boolean collide(BBox2D other)
Check if the current BBox collides with another one.

Parameters:
other -
Returns:
whether the objects collide

collide

public boolean collide(int oX,
                       int oY,
                       int oW,
                       int oH)
Check if this BBox collides with given area

Parameters:
oX - top-left x-coordinate area corner
oY - top-left y-coordinate area corner
oW - area width
oH - area height
Returns:
whether the area and the BBox collide

merge

public BBox2D merge(BBox2D other)
Merges the current bbox with another, returning the minimal bbox containing both (overwritting current one)

Parameters:
other - the merged bbox
Returns:
the minimal bbox containing both of them

isVoid

public boolean isVoid()
Checks if the bounding box is not null 0x0

Returns:

getArea

public int getArea()
Returns:
the area of the sprite (pixel^2)

nullify

public void nullify()
Voids the current BBox2D


Copyright(c) 2003-2004 Jordi Martin