Emini Physics Engine 1.3.5a API Documentation

at.emini.physics2D
Class Joint

java.lang.Object
  extended by at.emini.physics2D.Joint
All Implemented Interfaces:
Constraint

public class Joint
extends java.lang.Object
implements Constraint

The Joint class represents a joint connecting two bodies.
The joint is a pin joint at a single position that fixes this point relative to both bodies. This is the pivot point of the connection.
Two types of joints exists: loose joints or fixed joints. For loose joints, the relative angle of the bodies can change. For fixed joints this is fixed as well.

Author:
Alexander Adensamer

Field Summary
protected  UserData mUserData
          User data
 
Fields inherited from interface at.emini.physics2D.Constraint
JOINT, MOTOR, SCRIPT, SPRING
 
Constructor Summary
  Joint(Body b1, Body b2, FXVector p1, FXVector p2, boolean fixed)
          Constructor.
protected Joint(Joint other, Body[] bodyMapping)
          Copy Constructor.
 
Method Summary
 boolean applyMomentum(float invTimestepFX)
          Applies the momentum.
 boolean concernsBody(Body b)
          Checks if the joint applies to a body.
 Constraint copy(Body[] bodyMapping)
          Copy method.
 boolean equals(Constraint other)
          Checks for equality of two constraints.
 Body getBody1()
          Gets the Body 1
 Body getBody2()
          Gets the Body 2
 float getImpulseFX()
          Gets the last impulse of teh joint.
 FXVector getPoint1()
          Gets the absolute joint position (from body1).
 FXVector getPoint2()
          Gets the absolute joint position (from body2).
 FXVector getRawPoint1()
          Gets the relative joint position (from body1).
 FXVector getRawPoint2()
          Gets the relative joint position (from body2).
 UserData getUserData()
          Get user data.
 boolean isFixed()
          Gets the flag if it is a fixed joint.
static Joint loadJoint(PhysicsFileReader reader, java.util.Vector bodies, UserData userData)
          Loads a joint from stream.
 void postStep()
          Empty.
 void precalculate(float invTimestepFX)
          Precalculates the mass matrix.
 void setBody1(Body b)
          Sets the first Body.
protected  void setBody2(Body b)
          Sets the second Body.
 void setCollisionLayer(int layer)
          Sets collision layers for joined bodies.
 void setFixPoint(FXVector absolutePoint)
          Sets the fix point for the joint.
 void setUserData(UserData userData)
          Set User data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mUserData

protected UserData mUserData
User data

Constructor Detail

Joint

public Joint(Body b1,
             Body b2,
             FXVector p1,
             FXVector p2,
             boolean fixed)
Constructor.
Note: If the relative positions and the body positions do not match (=over determined system) the initial movement will exhibit a strong urge to correct the inconsistency.

Parameters:
b1 - First Body
b2 - Second Body
p1 - Relative Position of the pivot to Body 1
p2 - relative Position of the pivot to Body 2

Joint

protected Joint(Joint other,
                Body[] bodyMapping)
Copy Constructor.

Parameters:
other - the source object
bodyMapping - the mapping of bodies in the new world (null if not used). This is required, so that the joint can find the corresponding bodies in the new environment
Method Detail

copy

public Constraint copy(Body[] bodyMapping)
Copy method. Creates a deep copy of the joint.

Specified by:
copy in interface Constraint
Parameters:
bodyMapping - the mapping of bodies in the new world (null if not used). This is required, so that the joint can find the corresponding bodies in the new environment
Returns:
a deep copy of the constraint

loadJoint

public static Joint loadJoint(PhysicsFileReader reader,
                              java.util.Vector bodies,
                              UserData userData)
Loads a joint from stream.

Parameters:
reader - the file reader
bodies - a list of bodies, initially read from the file to match the stored indices
Returns:
the loaded Joint constraint

setCollisionLayer

public void setCollisionLayer(int layer)
Sets collision layers for joined bodies. Convenience method to apply a collision layer to both involved bodies.

Parameters:
layer - the layer number (somewhere between 0 and 32).
See Also:
Body.mColissionBitFlag

getPoint1

public FXVector getPoint1()
Gets the absolute joint position (from body1).

Returns:
the absolute pivot point calculated from the first body.

getPoint2

public FXVector getPoint2()
Gets the absolute joint position (from body2).

Returns:
the absolute pivot point calculated from the second body.

getRawPoint1

public FXVector getRawPoint1()
Gets the relative joint position (from body1).

Returns:
the Pivot point relative to the first body.

getRawPoint2

public FXVector getRawPoint2()
Gets the relative joint position (from body2).

Returns:
the Pivot point relative to the second body.

setBody1

public void setBody1(Body b)
Sets the first Body.

Parameters:
b - the body

setBody2

protected void setBody2(Body b)
Sets the second Body.

Parameters:
b - the body

getBody1

public Body getBody1()
Gets the Body 1

Returns:
the first body

getBody2

public Body getBody2()
Gets the Body 2

Returns:
the second body

isFixed

public boolean isFixed()
Gets the flag if it is a fixed joint.

Returns:
true if the the joint has a fixed angle.

precalculate

public void precalculate(float invTimestepFX)
Precalculates the mass matrix. It combines both implicit constraints: One for the x direction, one for the y direction

Specified by:
precalculate in interface Constraint
Parameters:
invTimestepFX - the inverse timestep of the simulation

applyMomentum

public boolean applyMomentum(float invTimestepFX)
Applies the momentum. Uses the precalculated mass matrix and the current velocities of the bodies to calculate and apply the impulse to satisfy the constraint.

Specified by:
applyMomentum in interface Constraint
Parameters:
invTimestepFX - the inverse timestep of the simulation

postStep

public void postStep()
Empty.

Specified by:
postStep in interface Constraint

getImpulseFX

public float getImpulseFX()
Gets the last impulse of teh joint. THis represents the virtual work by the constraint.

Specified by:
getImpulseFX in interface Constraint
Returns:
the last impulse (FX) acting on the joined bodies.

concernsBody

public boolean concernsBody(Body b)
Checks if the joint applies to a body.

Specified by:
concernsBody in interface Constraint
Parameters:
b - the body to be checked
Returns:
true if the joint applies to the body.

equals

public boolean equals(Constraint other)
Checks for equality of two constraints.

Specified by:
equals in interface Constraint
Parameters:
other - the comparison constraint
Returns:
true if the constraints are equal.

setFixPoint

public void setFixPoint(FXVector absolutePoint)
Sets the fix point for the joint.

Parameters:
absolutePoint - the fix point in absolute coordinates

getUserData

public UserData getUserData()
Get user data.

Specified by:
getUserData in interface Constraint
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