Emini Physics Engine 1.3.5a API Documentation

at.emini.physics2D
Class Spring

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

public class Spring
extends java.lang.Object
implements Constraint

The Spring class represents a spring constraint on two bodies body.
The constraint connects two bodies by a spring. It fixes the distance of two points relative to two bodies like a physical spring. The spring constant can be adjusted. A fixed mode is also possible, where no slack is allowed.

Author:
Alexander Adensamer

Field Summary
protected  float mCoefficientFX
          The spring coefficient (0 = no spring) FX
protected  UserData mUserData
          User data
 
Fields inherited from interface at.emini.physics2D.Constraint
JOINT, MOTOR, SCRIPT, SPRING
 
Constructor Summary
  Spring(Body b1, Body b2, FXVector p1, FXVector p2, int distance)
          Constructor.
protected Spring(Spring other, Body[] bodyMapping)
          Copy constructor.
 
Method Summary
 boolean applyMomentum(float invTimestepFX)
          Applies the momentum of the constraint.
protected  void calcDistance()
          Calculates the default distance.
 boolean concernsBody(Body b)
          Checks if the spring is applied to a body.
 Constraint copy(Body[] bodyMapping)
          Copies the spring.
 boolean equals(Constraint other)
          Checks for equality of two constraints.
 Body getBody1()
          Gets the first body.
 Body getBody2()
          Gets the second body.
 float getCoefficientFX()
          Gets the spring coefficient.
 int getDistance()
          Returns the default distance of the spring.
 float getDistanceFX()
          Returns the default distance of the spring (FX).
 float getImpulseFX()
          Gets the last applied impulse.
 FXVector getPoint1()
          Gets the absolute position of point 1.
 void getPoint1(FXVector target)
          Gets the absolute position of point 1.
 FXVector getPoint2()
          Gets the absolute position of point 2.
 void getPoint2(FXVector target)
          Gets the absolute position of point 2.
 FXVector getRawPoint1()
          Gets the relative position of point 1.
 FXVector getRawPoint2()
          Gets the relative position of point 2.
 UserData getUserData()
          Get user data.
static Spring loadSpring(PhysicsFileReader reader, java.util.Vector bodies, UserData userData)
          Loads a spring from a stream.
 void postStep()
          Empty.
 void precalculate(float invTimestepFX)
          Precalculates the values for the constraint solver iteration.
protected  void setAbsolutePoint1(FXVector absolutePoint)
          Sets the first absolute anchor position.
protected  void setAbsolutePoint2(FXVector absolutePoint)
          Sets the second absolute anchor position.
protected  void setBody1(Body body1)
          Sets the first body.
protected  void setBody2(Body body2)
          Sets the second body.
 void setCoefficient(int coeff)
          Sets the spring coefficient.
 void setCoefficientFX(float coeffFX)
          Sets the spring coefficient (FX).
 void setCollisionLayer(int layer)
          Sets collision layers for joined bodies.
 void setDistanceFX(float distanceFX)
          Sets the default distance of the spring (FX).
 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

mCoefficientFX

protected float mCoefficientFX
The spring coefficient (0 = no spring) FX


mUserData

protected UserData mUserData
User data

Constructor Detail

Spring

public Spring(Body b1,
              Body b2,
              FXVector p1,
              FXVector p2,
              int distance)
Constructor.

Parameters:
b1 - Body 1.
b2 - Body 2.
p1 - relative point 1.
p2 - relative point 2.
distance - default distance of the spring. If -1 is passed, the distance is computed from the current body positions.

Spring

protected Spring(Spring other,
                 Body[] bodyMapping)
Copy constructor.

Parameters:
other - the source spring object.
bodyMapping - the mapping of bodies in the new world (null if not used).
Method Detail

copy

public Constraint copy(Body[] bodyMapping)
Copies the spring.

Specified by:
copy in interface Constraint
Parameters:
bodyMapping - the mapping of bodies in the new world (null if not used).
Returns:
a deep copy of the constraint.

loadSpring

public static Spring loadSpring(PhysicsFileReader reader,
                                java.util.Vector bodies,
                                UserData userData)
Loads a spring from a stream.

Parameters:
reader - the file reader.
bodies - the list of bodies that is references by indices in the stream.
Returns:
the loaded spring constraint.

calcDistance

protected void calcDistance()
Calculates the default distance. The current distance is computed based on the current body positions.


setCoefficient

public void setCoefficient(int coeff)
Sets the spring coefficient.

Parameters:
coeff - the coefficient.
See Also:
mCoefficientFX

setCoefficientFX

public void setCoefficientFX(float coeffFX)
Sets the spring coefficient (FX).

Parameters:
coeffFX - the coefficient (FX)
See Also:
mCoefficientFX

getCoefficientFX

public float getCoefficientFX()
Gets the spring coefficient.

Returns:
the spring coefficient (FX) (see mCoefficientFX)
See Also:
mCoefficientFX

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 position of point 1.

Returns:
the absolute point 1

getPoint1

public void getPoint1(FXVector target)
Gets the absolute position of point 1.

Parameters:
target - the target vector

getPoint2

public FXVector getPoint2()
Gets the absolute position of point 2.

Returns:
the absolute point 2

getPoint2

public void getPoint2(FXVector target)
Gets the absolute position of point 2.

Parameters:
target - the target vector

getRawPoint1

public FXVector getRawPoint1()
Gets the relative position of point 1.

Returns:
the point 1 relative to body 1

getRawPoint2

public FXVector getRawPoint2()
Gets the relative position of point 2.

Returns:
the point 2 relative to body 2

getBody1

public Body getBody1()
Gets the first body.

Returns:
the body 1

getBody2

public Body getBody2()
Gets the second body.

Returns:
the body 2

precalculate

public void precalculate(float invTimestepFX)
Precalculates the values for the constraint solver iteration.

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

applyMomentum

public boolean applyMomentum(float invTimestepFX)
Applies the momentum of 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

getDistance

public int getDistance()
Returns the default distance of the spring.

Returns:
the default distance.

getDistanceFX

public float getDistanceFX()
Returns the default distance of the spring (FX).

Returns:
the default distance (FX)

setDistanceFX

public void setDistanceFX(float distanceFX)
Sets the default distance of the spring (FX).

Parameters:
distanceFX - the new distance (FX) of the spring.

getImpulseFX

public float getImpulseFX()
Gets the last applied impulse.

Specified by:
getImpulseFX in interface Constraint
Returns:
the last impulse (FX) that was used to correct the constraint.

concernsBody

public boolean concernsBody(Body b)
Checks if the spring is applied to a body.

Specified by:
concernsBody in interface Constraint
Parameters:
b - the body to be checked.
Returns:
whether the body is concerned.

equals

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

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

setBody1

protected void setBody1(Body body1)
Sets the first body.

Parameters:
body1 - the body.

setBody2

protected void setBody2(Body body2)
Sets the second body.

Parameters:
body2 - the body.

setAbsolutePoint1

protected void setAbsolutePoint1(FXVector absolutePoint)
Sets the first absolute anchor position.

Parameters:
absolutePoint - the absolute position.

setAbsolutePoint2

protected void setAbsolutePoint2(FXVector absolutePoint)
Sets the second absolute anchor position.

Parameters:
absolutePoint - the absolute position.

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