Emini Physics Engine 1.3.5a API Documentation

at.emini.physics2D
Class Shape

java.lang.Object
  extended by at.emini.physics2D.Shape
Direct Known Subclasses:
MultiShape

public class Shape
extends java.lang.Object

The Shape class represents the shape and physical properties of a body.
The vertices of the shape are given as a convex polygon. A single vertex is interpreted as a circle. The physical properties are:

Author:
Alexander Adensamer

Field Summary
static float MAX_MASS_FX
          Infinity mass (FX).
protected  FXVector mCcentroid
          Centroid of the shape.
protected  float mElasticityFX
          Elasticity factor (FX) for bodies with this shape.
protected  float mFrictionFX
          Friction factor (FX) for bodies with this shape.
protected  UserData mUserData
          User data
protected  FXVector[] mVertices
          Corners in clockwise direction (x to right, y up).
 
Constructor Summary
protected Shape()
          Used for multi shape
  Shape(FXVector[] corners)
          Constructor.
  Shape(Shape other)
          Copy Constructor.
 
Method Summary
 void correctCentroid()
          Centers the shape.
static Shape createCircle(int radius)
          Creates a circle shape.
static Shape createRectangle(int width, int height)
          Creates a rectangle shape.
static Shape createRegularPolygon(int radius, int vertices)
          Creates a regular polygon shape.
 float getAreaFX()
          Gets the area of the shape (FX).
protected  int getBoundingRadius()
          Gets the bounding radius.
 float getBoundingRadiusFX()
          Gets the bounding radius (FX).
 int getBoundingRadiusSquare()
          Gets the square of the bounding radius.
 FXVector[] getCorners()
          Gets the shape vertices.
 float getElasticityFX()
          Gets the elasticity.
 float getFrictionFX()
          Gets the friction (FX).
 int getId()
          Get the shape id.
 int getMass()
          Gets the mass.
 float getMassFX()
          Gets the mass (FX).
 UserData getUserData()
          Get user data.
protected  void getVerticesFX(FXVector pos, FXMatrix rotation, FXVector[] vertices)
          Computes rotated and shifted vertices.
static Shape loadShape(PhysicsFileReader reader, UserData userData)
          Loads a shape from a stream.
 void setElasticity(int elasticity)
          Set the elasticity (in percent).
 void setElasticityFX(float elasticityFX)
          Set the elasticity (FX).
 void setFriction(int friction)
          Sets the friction (in percent).
 void setFrictionFX(float frictionFX)
          Sets the friction of the shape (FX).
 void setMass(int mass)
          Sets the mass.
 void setMassFX(float massFX)
          Sets the mass (FX).
 void setUserData(UserData userData)
          Set User data
protected  void updateInternals()
          Computes internal values for fast access.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mVertices

protected FXVector[] mVertices
Corners in clockwise direction (x to right, y up). in screen mode (x to right, y down): counterclockwise


mElasticityFX

protected float mElasticityFX
Elasticity factor (FX) for bodies with this shape.
0: no elasticity (all energy is lost during a collision).
1: full elasticity (all energy is conserved during a collision).
For each collision, the product of both involved elasticities is calculated. and used for the restitution part of the momentum


mFrictionFX

protected float mFrictionFX
Friction factor (FX) for bodies with this shape.
0: no friction (tangential momentum is conserved).
1: full friction (tangential momentum is removed completely).
For each collision, the product of both involved frictions is calculated. and used for the tangential part of the momentum


mUserData

protected UserData mUserData
User data


mCcentroid

protected FXVector mCcentroid
Centroid of the shape. Position of the center of mass. This is used for the inertia calculation.


MAX_MASS_FX

public static final float MAX_MASS_FX
Infinity mass (FX).

See Also:
Constant Field Values
Constructor Detail

Shape

public Shape(FXVector[] corners)
Constructor. Creates a shape with the vectors (FX) for the corners centered around the origin. The polygon formed by the points must be convex. If the corners are not centered around the origin (0,0), the body will behave like having a non-uniform density distribution. To avoid this the centroid has to centered by the call correctCentroid().

Parameters:
corners - the corners of the polygon

Shape

public Shape(Shape other)
Copy Constructor.


Shape

protected Shape()
Used for multi shape

Method Detail

createRectangle

public static Shape createRectangle(int width,
                                    int height)
Creates a rectangle shape.

Parameters:
width - width of the rectangle.
height - height of the rectangle.
Returns:
the rectangle shape.

createCircle

public static Shape createCircle(int radius)
Creates a circle shape.

Parameters:
radius - radius of the circle.
Returns:
the circle shape.

createRegularPolygon

public static Shape createRegularPolygon(int radius,
                                         int vertices)
Creates a regular polygon shape.

Parameters:
radius - radius of the polygon.
vertices - number of vertices (max. World.M_SHAPE_MAX_VERTICES).
Returns:
the polygon shape.

loadShape

public static Shape loadShape(PhysicsFileReader reader,
                              UserData userData)
Loads a shape from a stream.

Parameters:
reader - a physics file reader.
Returns:
the loaded shape.

updateInternals

protected void updateInternals()
Computes internal values for fast access.
Computes unique axes for optimized collision detection.
Computes bounding radius.
Computes min/max sizes.
Corrects the centroid (-> places the center of gravity correctly).


correctCentroid

public void correctCentroid()
Centers the shape. Corrects the position of the corners so that the center of the gravity is the origin.


getCorners

public FXVector[] getCorners()
Gets the shape vertices.

Returns:
the corners.

getBoundingRadiusSquare

public int getBoundingRadiusSquare()
Gets the square of the bounding radius.

Returns:
the square of the bounding radius.

getBoundingRadius

protected int getBoundingRadius()
Gets the bounding radius.

Returns:
the bounding radius.

getBoundingRadiusFX

public float getBoundingRadiusFX()
Gets the bounding radius (FX).

Returns:
the bounding radius (FX).

setFriction

public void setFriction(int friction)
Sets the friction (in percent).

Parameters:
friction - - 0 means no friction, 100 max. friction
See Also:
mFrictionFX

setFrictionFX

public void setFrictionFX(float frictionFX)
Sets the friction of the shape (FX).

Parameters:
frictionFX - - 0 means no friction, ONE_FX max friction
See Also:
mFrictionFX

getFrictionFX

public float getFrictionFX()
Gets the friction (FX).

Returns:
the friction (FX).
See Also:
mFrictionFX

setElasticity

public void setElasticity(int elasticity)
Set the elasticity (in percent).

Parameters:
elasticity - - 0 all energy of the collision is lost (no bounce), 100 full energy conserved (high bounce).
See Also:
mElasticityFX

setElasticityFX

public void setElasticityFX(float elasticityFX)
Set the elasticity (FX).

Parameters:
elasticityFX - - 0 all energy of the collision is lost (no bounce), ONE_FX full energy conserved (high bounce).
See Also:
mElasticityFX

getElasticityFX

public float getElasticityFX()
Gets the elasticity.

Returns:
elasticity (FX).
See Also:
mElasticityFX

setMass

public final void setMass(int mass)
Sets the mass. All related values are computed as well: InvMass, Inertia, InvInertia

Parameters:
mass - new mass of the body.

setMassFX

public final void setMassFX(float massFX)
Sets the mass (FX). All related values are computed as well: InvMass, Inertia, InvInertia

Parameters:
massFX - new mass of the body (FX).

getMass

public int getMass()
Gets the mass.

Returns:
the mass.

getMassFX

public float getMassFX()
Gets the mass (FX).

Returns:
the mass (FX).

getId

public int getId()
Get the shape id.
If the shape id is -1, the shape is not registered in the shapeset ShapeSet. That can only happen if no body uses it and it was not registered manually.

Returns:
the shape id as used by the shape set

getAreaFX

public float getAreaFX()
Gets the area of the shape (FX).

Returns:
the area (FX)

getVerticesFX

protected final void getVerticesFX(FXVector pos,
                                   FXMatrix rotation,
                                   FXVector[] vertices)
Computes rotated and shifted vertices.

Parameters:
pos - the center position of the translated shape
rotation - the rotation matrix of the translation
vertices - - the vertices vector, where the vertices in world coordinates are written to

getUserData

public UserData getUserData()
Get user data.

Returns:
the user data.

setUserData

public void setUserData(UserData userData)
Set User data

Parameters:
userData - the user data

Emini Physics Engine 1.3.5a API Documentation

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