Emini Physics Engine 1.3.5a API Documentation

at.emini.physics2D
Class Landscape

java.lang.Object
  extended by at.emini.physics2D.Landscape

public class Landscape
extends java.lang.Object

The Landscape class represents a collection of static bodies. The bodies are represented as lines and do not have to be closed shapes. They form a landscape for the physical simulation.
Using a landscape, large worlds can be created without shape overhead. This is an efficient alternative to static bodies.
Each line segment consists of a starting point, an end point and a face. The face of each segment can be right, left or none. This Indicates how the segment works.

Author:
Alexander Adensamer

Field Summary
static short FACE_LEFT
          Face type left.
static short FACE_NONE
          Face type none.
static short FACE_RIGHT
          Face type right.
protected  FXVector[] mEndpoints
          End points of the segments.
protected  short[] mFaces
          Faces of the segments.
protected  int mSegmentCount
          Number of landscape segments.
protected  FXVector[] mStartpoints
          Start points of the segments.
 
Constructor Summary
Landscape()
          Default Constructor.
Landscape(Landscape other)
          Copy constructor.
 
Method Summary
protected  void addContact(Contact c)
          Adds a new contact.
 void addSegment(FXVector start, FXVector end, short face)
          Adds a segment to the landscape.
 void collideParticles(ParticleEmitter particles)
           
protected  void collisionCheckBody(World world, Body body)
          Checks collision of the landscape and a body.
 Landscape copy()
          Copy method.
 FXVector[] elementEndPoints()
          Gets the end points of the segments.
 FXVector[] elementStartPoints()
          Gets the starting points of the segments.
 FXVector endPoint(int index)
          Gets the end vector of a segment.
 void fillVertices(FXVector[] vertices, Contact c, int idx)
           
 Body getBody()
          Gets the dummy body.
protected  Contact getContact(Body body, int bodyIndex, int index)
          Finds a contact of a segment with a body.
 Contact[] getContacts()
          Gets all current contacts.
 Shape getShape()
          Gets the shape.
protected  void initCollision()
          Initializes the collision process.
static Landscape loadLandscape(PhysicsFileReader reader)
          Load a landscape from a stream.
 void removeSegment(int index)
          Removes a segment from the landscape.
protected  void resetContacts()
          Clears all contacts from the previous step.
 int segmentCount()
          Gets the number of landscape segments.
protected  void sortArrays()
          Sorts the segment arrays.
 FXVector startPoint(int index)
          Gets the start vector of a segment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mSegmentCount

protected int mSegmentCount
Number of landscape segments.


mStartpoints

protected FXVector[] mStartpoints
Start points of the segments.


mEndpoints

protected FXVector[] mEndpoints
End points of the segments.


mFaces

protected short[] mFaces
Faces of the segments.


FACE_NONE

public static final short FACE_NONE
Face type none. The segment is considered a line from both sides

See Also:
Constant Field Values

FACE_LEFT

public static final short FACE_LEFT
Face type left. The segment is considered to be the left border of a solid, always assuming colliding objects to come from left.

See Also:
Constant Field Values

FACE_RIGHT

public static final short FACE_RIGHT
Face type right. The segment is considered to be the right border of a solid, always assuming colliding objects to come from right.

See Also:
Constant Field Values
Constructor Detail

Landscape

public Landscape()
Default Constructor.


Landscape

public Landscape(Landscape other)
Copy constructor. Creates a deep copy of the landscape.

Parameters:
other - copy source
Method Detail

loadLandscape

public static Landscape loadLandscape(PhysicsFileReader reader)
Load a landscape from a stream.

Parameters:
reader - the physics reader
Returns:
the loaded landscape object

copy

public Landscape copy()
Copy method. Creates a deep copy of the landscape.

Returns:
the copied landscape.

addSegment

public void addSegment(FXVector start,
                       FXVector end,
                       short face)
Adds a segment to the landscape.

Parameters:
start - start point of the segment line
end - end point of the segment line
face - the face direction

removeSegment

public void removeSegment(int index)
Removes a segment from the landscape.

Parameters:
index - index of teh segment

sortArrays

protected final void sortArrays()
Sorts the segment arrays. When the segment vector is changed (externally), it has to sorted for the collision to work. Consistently sorted arrays are always required for fast collision detection.


initCollision

protected final void initCollision()
Initializes the collision process. Resets the state required for the collision detection.


collisionCheckBody

protected final void collisionCheckBody(World world,
                                        Body body)
Checks collision of the landscape and a body. The algorithm assumes that the method is called sequentially for each body in the correct order. If a single body has to be tested, the initCollision() method should be called first.

Parameters:
body - the body to check for collision with landscape

resetContacts

protected void resetContacts()
Clears all contacts from the previous step.


addContact

protected void addContact(Contact c)
Adds a new contact.

Parameters:
c - the determined contact.

getContacts

public Contact[] getContacts()
Gets all current contacts.

Returns:
all current contacts.

fillVertices

public final void fillVertices(FXVector[] vertices,
                               Contact c,
                               int idx)

getContact

protected Contact getContact(Body body,
                             int bodyIndex,
                             int index)
Finds a contact of a segment with a body.

Parameters:
body - the body.
index - the index of the involved body segment.
Returns:
the contact if exists, null otherwise.

collideParticles

public void collideParticles(ParticleEmitter particles)

getBody

public Body getBody()
Gets the dummy body.

Returns:
the dummy body.

getShape

public Shape getShape()
Gets the shape.

Returns:
the shap.

segmentCount

public int segmentCount()
Gets the number of landscape segments.

Returns:
the segment count

elementStartPoints

public FXVector[] elementStartPoints()
Gets the starting points of the segments. The returned array is sorted by the x value of the start points. Note: The array might longer than the segment count (use segmentCount()).

Returns:
the array containing the starting points.

elementEndPoints

public FXVector[] elementEndPoints()
Gets the end points of the segments. The returned array is sorted by the x value of the corresponding start points. Note: The array might longer than the element count (see segmentCount()

Returns:
the array containing the end points.

startPoint

public FXVector startPoint(int index)
Gets the start vector of a segment.

Parameters:
index - the index of the segment.
Returns:
the start vector of the segment at index.

endPoint

public FXVector endPoint(int index)
Gets the end vector of a segment.

Parameters:
index - the index of the segment.
Returns:
the end vector of the segment at index.

Emini Physics Engine 1.3.5a API Documentation

Emini Physics Engine 1.3.5a API Documentation - Copyright 2014 Alexander Adensamer