Package net.dermetfan.gdx.physics.box2d
Class PositionController
java.lang.Object
net.dermetfan.gdx.physics.box2d.PositionController
- Direct Known Subclasses:
PositionController.D
,PositionController.P
,PositionController.PD
public abstract class PositionController
extends java.lang.Object
moves a body to a position using forces
- Since:
- 0.11.1
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PositionController.D
the derivative control loop componentstatic class
PositionController.P
the proportional control loop componentstatic class
PositionController.PD
a proportional-derivative controller -
Field Summary
Fields Modifier and Type Field Description static net.dermetfan.utils.Function<java.lang.Object,PositionController>
defaultUserDataAccessor
returns the argument if it is a PositionControllerprotected static com.badlogic.gdx.math.Vector2
vec2
shared instance for internal use -
Constructor Summary
Constructors Constructor Description PositionController()
-
Method Summary
Modifier and Type Method Description com.badlogic.gdx.math.Vector2
applyForce(com.badlogic.gdx.physics.box2d.Body body, com.badlogic.gdx.math.Vector2 point, boolean wake)
applies the necessary force at the given pointcom.badlogic.gdx.math.Vector2
applyForceToCenter(com.badlogic.gdx.physics.box2d.Body body, boolean wake)
applies the necessary force at the center of mass of the Bodystatic void
applyForceToCenter(com.badlogic.gdx.physics.box2d.World world, boolean wake)
CallsapplyForceToCenter
for every Body with a PositionController in its user data.abstract com.badlogic.gdx.math.Vector2
calculateForce(com.badlogic.gdx.physics.box2d.Body body, com.badlogic.gdx.math.Vector2 point)
abstract com.badlogic.gdx.math.Vector2
calculateForceToCenter(com.badlogic.gdx.physics.box2d.Body body)
static net.dermetfan.utils.Function<java.lang.Object,PositionController>
getUserDataAccessor()
static void
setUserDataAccessor(net.dermetfan.utils.Function<java.lang.Object,PositionController> userDataAccessor)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
vec2
protected static final com.badlogic.gdx.math.Vector2 vec2shared instance for internal use -
defaultUserDataAccessor
public static final net.dermetfan.utils.Function<java.lang.Object,PositionController> defaultUserDataAccessorreturns the argument if it is a PositionController
-
-
Constructor Details
-
PositionController
public PositionController()
-
-
Method Details
-
applyForceToCenter
public static void applyForceToCenter(com.badlogic.gdx.physics.box2d.World world, boolean wake)CallsapplyForceToCenter
for every Body with a PositionController in its user data. The PositionController is accessed using theuserDataAccessor
.- Parameters:
world
- the world which Bodies to iterate over
-
calculateForce
public abstract com.badlogic.gdx.math.Vector2 calculateForce(com.badlogic.gdx.physics.box2d.Body body, com.badlogic.gdx.math.Vector2 point)- Parameters:
point
- the world point at which the force should be applied- Returns:
- the force to apply at the given point
-
calculateForceToCenter
public abstract com.badlogic.gdx.math.Vector2 calculateForceToCenter(com.badlogic.gdx.physics.box2d.Body body)- Returns:
- the force to apply at the center of mass of the Body
-
applyForce
public com.badlogic.gdx.math.Vector2 applyForce(com.badlogic.gdx.physics.box2d.Body body, com.badlogic.gdx.math.Vector2 point, boolean wake)applies the necessary force at the given point- Parameters:
point
- the world point at which to apply the force- Returns:
- the force applied, calculated by
calculateForce(Body, Vector2)
-
applyForceToCenter
public com.badlogic.gdx.math.Vector2 applyForceToCenter(com.badlogic.gdx.physics.box2d.Body body, boolean wake)applies the necessary force at the center of mass of the Body- Returns:
- the force applied, calculated by
calculateForceToCenter(Body)
-
getUserDataAccessor
public static net.dermetfan.utils.Function<java.lang.Object,PositionController> getUserDataAccessor()- Returns:
- the
userDataAccessor
-
setUserDataAccessor
public static void setUserDataAccessor(net.dermetfan.utils.Function<java.lang.Object,PositionController> userDataAccessor)- Parameters:
userDataAccessor
- TheuserDataAccessor
to set. If null,defaultUserDataAccessor
is set.
-