jme.entity
Class Entity

java.lang.Object
  extended byjme.entity.Entity
All Implemented Interfaces:
EntityInterface
Direct Known Subclasses:
Camera

public class Entity
extends java.lang.Object
implements EntityInterface

Entity defines a game entity that consists of a piece of geometry, a position and an orientation. An entity can be a collection of children entities. An entity with multiple children create a tree structure, as children can have children. Rendering the entity causes the parent entity to render it's own geometry and then render each child. If the parent of an entity is null, the parent is considered to be the Locale. The entities local coordinate system is relative to the parent. That is, if a position of a entity is (0, 1, 0), it is one unit along the Y-Axis of the parent. An Entity is not required to maintain geometry. If there is no geometry, it will simply not be rendered. This will allow for an Entity to represent something abstract.

Version:
$Id: Entity.java,v 1.8 2003/09/08 20:29:28 mojomonkey Exp $
Author:
Mark Powell

Field Summary
protected  BoundingVolume boundingVolume
           
protected  java.util.List children
           
protected  Geometry geometry
           
static int VISIBILITY_CUBE
          Defines using cube tests for visibility calculations.
static int VISIBILITY_POINT
          Defines using simple point tests for visibility calculations.
static int VISIBILITY_SPHERE
          Defines using sphere tests for visibility calculations.
 
Constructor Summary
Entity(int id)
          Constructor initializes the entity.
Entity(int id, Entity child)
          Constructor intializes the entity with a second entity as a child.
 
Method Summary
 void addChild(Entity child)
          addChild adds an Entity to the entity with this entity the parent.
 void checkVisibility(Frustum frustum)
          checkVisibility updates the visibility of this entity based on the frustum levels.
 float distance(Entity ent)
          distance returns the distance between this entity and a given entity.
 BoundingVolume getBoundingVolume()
          getBoundingVolume returns the volume that contains this entity.
 Geometry getGeometry()
          getGeometry returns the geometry of this entity.
 int getId()
          getId returns the id of the entity.
 PhysicsModule getPhysics()
          getPhysics returns the physics module of the particular entity.
 Vector getPosition()
          getPosition returns the position of the entity in three dimensional space.
 boolean hasCollision(Entity ent)
          hasCollision determines if this entity is colliding with a provided entity.
 boolean hasMoved()
          hasMoved returns true if the entity has moved during the last update, false otherwise.
 boolean isVisible()
          isVisible returns true if the entity is currently visible and false if it is not.
 void removeChild(Entity child)
          removeChild removes the requested child from the list of children.
 void render()
          render translates and rotates the entity based on it's attributes.
 void setBoundingVolume(BoundingVolume volume)
          setBoundingVolume sets the volume that contains this entity.
 void setGeometry(Geometry geometry)
          setGeometry sets the geometry of this entity.
 void setMoved(boolean hasMoved)
          setMoved sets the moved flag.
 void setPhysicsModule(PhysicsModule physics)
          setPhysicsModule sets the module the defines how the physics of the entity are handled.
 void setPitch(float angle)
          setPitch sets the pitch angle of the entity.
 void setPosition(Vector position)
          setPosition sets the position of this entity.
 void setRoll(float angle)
          setRoll sets the roll angle of the entity.
 void setVisibilityType(int type)
          setVisibilityType sets what type of visibility check will be used for this entity.
 void setYaw(float angle)
          setYaw sets the yaw angle of the entity.
 java.lang.String toString()
          toString creates a string representation of the Entity object.
 void update(float time)
          update updates the state of the entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VISIBILITY_POINT

public static final int VISIBILITY_POINT
Defines using simple point tests for visibility calculations.

See Also:
Constant Field Values

VISIBILITY_SPHERE

public static final int VISIBILITY_SPHERE
Defines using sphere tests for visibility calculations.

See Also:
Constant Field Values

VISIBILITY_CUBE

public static final int VISIBILITY_CUBE
Defines using cube tests for visibility calculations.

See Also:
Constant Field Values

children

protected java.util.List children

geometry

protected Geometry geometry

boundingVolume

protected BoundingVolume boundingVolume
Constructor Detail

Entity

public Entity(int id)
Constructor initializes the entity. All attributes of the Entity are empty.

Parameters:
id - the id of the entity
Throws:
MonkeyRuntimeException - if the id is less than 1.

Entity

public Entity(int id,
              Entity child)
Constructor intializes the entity with a second entity as a child.

Parameters:
id - the id of the entity
child - the entities child node.
Throws:
MonkeyRuntimeException - if the id is less than 1.
Method Detail

addChild

public void addChild(Entity child)
addChild adds an Entity to the entity with this entity the parent.

Parameters:
child - the Entity to add to the children list.

removeChild

public void removeChild(Entity child)
removeChild removes the requested child from the list of children.

Parameters:
child - the child to remove from the list.

setBoundingVolume

public void setBoundingVolume(BoundingVolume volume)
setBoundingVolume sets the volume that contains this entity.

Specified by:
setBoundingVolume in interface EntityInterface
Parameters:
volume - the volume that contains this entity.

getBoundingVolume

public BoundingVolume getBoundingVolume()
getBoundingVolume returns the volume that contains this entity.

Specified by:
getBoundingVolume in interface EntityInterface
Returns:
the volume that contains this entity.

hasCollision

public boolean hasCollision(Entity ent)
hasCollision determines if this entity is colliding with a provided entity.

Parameters:
ent - the entity to check.
Returns:
true if a collision has occured, false otherwise.

distance

public float distance(Entity ent)
distance returns the distance between this entity and a given entity.

Parameters:
ent - the entity to check.
Returns:
the distance between this entity and another. -1 is returned if boundingVolume is not set.

setPosition

public void setPosition(Vector position)
setPosition sets the position of this entity.

Parameters:
position - the new position of this entity.

setYaw

public void setYaw(float angle)
setYaw sets the yaw angle of the entity. Where yaw is defined as rotation about the local Y axis.

Parameters:
angle - the angle of yaw.

setRoll

public void setRoll(float angle)
setRoll sets the roll angle of the entity. Where roll is defined as rotation about the local Z axis.

Parameters:
angle - the angle of roll.

setPitch

public void setPitch(float angle)
setPitch sets the pitch angle of the entity. Where pitch is defined as rotation about the local x axis.

Parameters:
angle - the angle of pitch.

setMoved

public void setMoved(boolean hasMoved)
setMoved sets the moved flag.

Parameters:
hasMoved - true if the entity has moved, false otherwise.

setPhysicsModule

public void setPhysicsModule(PhysicsModule physics)
setPhysicsModule sets the module the defines how the physics of the entity are handled. This allows the entity to interact with the world (what ever that may be) in a realistic and appropriate manner.

Parameters:
physics - the physics module for this entity.

hasMoved

public boolean hasMoved()
hasMoved returns true if the entity has moved during the last update, false otherwise.

Returns:
true if the entity has moved, false if it hasn't.

setGeometry

public void setGeometry(Geometry geometry)
setGeometry sets the geometry of this entity. If the geometry object is null, nothing will be rendered for this entity.

Parameters:
geometry - the geometry to set for this entity.

getPosition

public Vector getPosition()
getPosition returns the position of the entity in three dimensional space.

Returns:
the position of the entity.

getPhysics

public PhysicsModule getPhysics()
getPhysics returns the physics module of the particular entity.

Returns:
the physics module of the entity.

getId

public int getId()
getId returns the id of the entity.

Returns:
the id of the entity.

update

public void update(float time)
update updates the state of the entity.

Specified by:
update in interface EntityInterface
Parameters:
time - the amount of time between frames.

render

public void render()
render translates and rotates the entity based on it's attributes. It then renders the geometry of the entity if there is any. Each child is then rendered in turn.

Specified by:
render in interface EntityInterface

isVisible

public boolean isVisible()
isVisible returns true if the entity is currently visible and false if it is not.

Specified by:
isVisible in interface EntityInterface
Returns:
true if the entity is visible, false otherwise.

checkVisibility

public void checkVisibility(Frustum frustum)
checkVisibility updates the visibility of this entity based on the frustum levels.

Specified by:
checkVisibility in interface EntityInterface
Parameters:
frustum - the camera's view frustum.

setVisibilityType

public void setVisibilityType(int type)
setVisibilityType sets what type of visibility check will be used for this entity. Valid parameters are: VISIBILITY_POINT, VISIBILITY_SPHERE, and VISIBILITY_CUBE.

Parameters:
type - what type of test to make for visibilty.
Throws:
MonkeyRuntimeException - if the visibilty flag is not valid.

toString

public java.lang.String toString()
toString creates a string representation of the Entity object. The format is as follows:

-----Entity:
Position: {VECTOR POSITION}

Child 0:
-----Entity:
Position: {VECTOR POSITION}

Geometry: {GEOMETRY STRING}
-----

Geometry: {GEOMETRY STRING}
-----

Returns:
the string representation of this object.

getGeometry

public Geometry getGeometry()
getGeometry returns the geometry of this entity.

Returns:
the geometry of this entity.