Emini Physics Engine 1.3.5a API Documentation

at.emini.physics2D
Class Motor

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

public class Motor
extends java.lang.Object
implements Constraint

The Motor class represents a motor constraint for a body.
The constraint is applied to a single body. The body is held at a constant velocity (either translational or rotational) with a maximum force. If the force is not sufficient, the body slows down. This can happen if the body collides with a wall or has to work against gravity. If one direction of the target velocities is zero (for translational), it is not considered. That means that the body behaves unconstrained in that direction.

Author:
Alexander Adensamer

Field Summary
protected  UserData mUserData
          User data
 
Fields inherited from interface at.emini.physics2D.Constraint
JOINT, MOTOR, SCRIPT, SPRING
 
Constructor Summary
Motor(Body b, float targetRotation2FX, float maxForceFX)
          Constructor for a rotational motor.
Motor(Body b, float targetXFX, float targetYFX, float maxForceFX)
          Constructor for a translational motor.
Motor(Motor other, Body[] bodyMapping)
          Copy constructor.
 
Method Summary
 boolean applyMomentum(float invTimestepFX)
          Applies the impulse of the motor.
 Body body()
          Gets the body, that the motor applies to.
 boolean concernsBody(Body b)
          Checks if the constraint applies to a body.
 Constraint copy(Body[] bodyMapping)
          Copies the motor constraint.
 boolean equals(Constraint other)
          Checks for equality of two constraints.
 float getImpulseFX()
          Gets the last impulse.
 float getMaxForceFX()
          Gets the maximum force.
protected  float getTargetAFX()
          gets the target X.
protected  float getTargetBFX()
          gets the target Y.
 UserData getUserData()
          Get user data.
 boolean isFixOrthogonal()
          Checks if the orthogonal movement is treated as well by the motor.
 boolean isRelative()
          Checks if the velocity is applied relative.
 boolean isRotation()
          Checks if the constraint type is rotation.
static Motor loadMotor(PhysicsFileReader reader, java.util.Vector bodies, UserData userData)
          Loads a motor from a stream.
 void postStep()
          Empty.
 void precalculate(float invTimestepFX)
          Performs the warmstarting.
protected  void setFixOrthogonal(boolean fixOrthogonal)
          Sets the fix orthogonal flag.
protected  void setIsRelative(boolean isRelative)
          Sets the relative flag.
 void setMaxForceFX(float maxForceFX)
          Sets the maximum force.
 void setParameter(float targetAFX, float targetBFX, boolean rotate, boolean isRelative, boolean isOrthogonal)
          Sets the motor parameters directly.
protected  void setRotation(boolean isRotation)
          Sets the rotation mode.
protected  void setTargetAFX(float targetAFX)
          Sets the target velocity X.
protected  void setTargetBFX(float targetBFX)
          Sets the target velocity Y.
 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

Motor

public Motor(Body b,
             float targetRotation2FX,
             float maxForceFX)
Constructor for a rotational motor.

Parameters:
b - the body that is affected by the motor.
targetRotation2FX - the target angular velocity (2FX).
maxForceFX - the maximum force that the motor can apply (FX).

Motor

public Motor(Body b,
             float targetXFX,
             float targetYFX,
             float maxForceFX)
Constructor for a translational motor.

Parameters:
b - the body that is affected by the motor.
targetXFX - the target speed in x direction (FX).
targetYFX - the target speed in y direction (FX).
maxForceFX - the maximum force that the motor can apply (FX).

Motor

public Motor(Motor other,
             Body[] bodyMapping)
Copy constructor.

Parameters:
other - the motor constraint to copy.
bodyMapping - the mapping of bodies in the new world (null if not used).
Method Detail

setParameter

public void setParameter(float targetAFX,
                         float targetBFX,
                         boolean rotate,
                         boolean isRelative,
                         boolean isOrthogonal)
Sets the motor parameters directly.

Parameters:
targetAFX - the x velocity component or rotational velocity.
targetBFX - the y velocity component.
rotate - whether the motor is rotational of translational.
isRelative - if not rotate: whether the motor is working in absolute coordinates or relative to the body it's applied to.
isOrthogonal - if not rotate: whether the motor forces the orthogonal direction to zero.

copy

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

Specified by:
copy in interface Constraint
Parameters:
bodyMapping - A mapping of the body indices from the old world to the new
Returns:
a deep copy of the constraint.

loadMotor

public static Motor loadMotor(PhysicsFileReader reader,
                              java.util.Vector bodies,
                              UserData userData)
Loads a motor from a stream.

Parameters:
reader - the physics reader.
bodies - the body vector with the correct indexing.
Returns:
the loaded Motor constraint.

precalculate

public void precalculate(float invTimestepFX)
Performs the warmstarting.
Applies last force(= warmstarting for iteration process). No precalculation required.

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

applyMomentum

public boolean applyMomentum(float invTimestepFX)
Applies the impulse of the motor.
The motor does actual work due to a bias component: Jv + bias.

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

concernsBody

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

Specified by:
concernsBody in interface Constraint
Parameters:
b - the body the check.
Returns:
true if the body matches the constraint body.

equals

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

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

getImpulseFX

public float getImpulseFX()
Gets the last impulse.

Specified by:
getImpulseFX in interface Constraint
Returns:
the last acted impulse (FX).

body

public Body body()
Gets the body, that the motor applies to.

Returns:
the body

isRotation

public boolean isRotation()
Checks if the constraint type is rotation.

Returns:
true if the motor acts rotational.

isRelative

public boolean isRelative()
Checks if the velocity is applied relative.

Returns:
true if velocity is applied relative.

isFixOrthogonal

public boolean isFixOrthogonal()
Checks if the orthogonal movement is treated as well by the motor.

Returns:
true if orthogonal movement is fixed to zero.

getMaxForceFX

public float getMaxForceFX()
Gets the maximum force.

Returns:
the maximum force.

getTargetAFX

protected float getTargetAFX()
gets the target X.

Returns:
the x component of the target velocity.

getTargetBFX

protected float getTargetBFX()
gets the target Y.

Returns:
the y component of the target velocity.

setTargetAFX

protected void setTargetAFX(float targetAFX)
Sets the target velocity X.

Parameters:
targetAFX - the x component of the target velocity.

setTargetBFX

protected void setTargetBFX(float targetBFX)
Sets the target velocity Y.

Parameters:
targetBFX - the x component of the target velocity.

setMaxForceFX

public void setMaxForceFX(float maxForceFX)
Sets the maximum force.

Parameters:
maxForceFX - the maximum allowed force by the motor.

setRotation

protected void setRotation(boolean isRotation)
Sets the rotation mode.

Parameters:
isRotation - the rotation mode.

setIsRelative

protected void setIsRelative(boolean isRelative)
Sets the relative flag. This determines whether the velocity is applied relative to the current body rotation.

Parameters:
isRelative - flag whether to apply the velocity relative.

setFixOrthogonal

protected void setFixOrthogonal(boolean fixOrthogonal)
Sets the fix orthogonal flag. This determines whether the orthogonal is fixed to zero.

Parameters:
fixOrtogonal - flag deciding whether to apply the orthogonal correction.

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