Artenus 2D Framework
Artenus Reference
Represents a physical body in physics simulation. As the physical body represented by this entity moves and rotates due to physical simulation, this entity will modify the position and rotation of the underlying Entity, depending on connection preferences.
public class PhysicalBody
extends FilteredEntity

Field Summary

Modifier and TypeField and Description
public static final POSITION
Defines position connection.
public static final ROTATION
Defines rotation connection.

Fields inherited from com.annahid.libs.artenus.entities.FilteredEntity

Constructor Summary

Modifier and TypeConstructor and Description
public PhysicalBody(Entity entity)
public PhysicalBody(Entity target, Shape shapeDesc)
Constructs a PhysicalBody with a given shape.

Method Summary

Modifier and TypeMethod and Description
public final voidadd(JointDescriptor joint)
Adds a joint descriptor to this PhysicalBody.
public voidadvance(float elapsedTime)
Updates this physical body to its new state provided by the physics simulator.
public final voidapplyForce(Point2D force)
Applies a 2-dimensional force to the PhysicalBody.
public final voidapplyForce(Point2D force, Point2D center)
Applies a 2-dimensional force to the PhysicalBody.
public final voidapplyLinearImpulse(Point2D impulse)
Applies a 2-dimensional impulse to the PhysicalBody.
public voidapplyLinearImpulse(Point2D impulse, Point2D center)
Applies a 2-dimensional impulse to the PhysicalBody.
public floatgetAngularDamping()
Gets angular damping for the body.
public final floatgetAngularVelocity()
Sets the angular velocity of the body.
public intgetConnections()
Gets the current connections associated with this physical body.
public floatgetDensity()
Gets the currently assigned density of the body.
public floatgetFriction()
Gets the currently assigned friction of the body.
public floatgetLinearDamping()
Gets linear damping for the body.
public final Point2DgetLinearVelocity()
Gets the linear velocity of the body.
public final floatgetMass()
Gets the mass of the PhysicalBody in kilograms.
public final Point2DgetPosition()
Gets the current position of the body.
public floatgetRestitution()
Gets the currently assigned restitution of the body.
public final floatgetRotation()
Gets the rotational angle of the body.
public final PhysicalBody.BehaviorgetType()
Gets the simulation type of this PhysicalBody.
public final booleanisActive()
Indicates whether the body is active in simulation and is considered in collision detection.
public booleanisBullet()
This method indicated whether the body is a bullet.
public booleanisFixedRotation()
Gets whether the rotational angle of the body is fixed in simulation.
public voidonAttach(Scene scene)
Called when this entity is associated with a scene.
public voidonDetach(Scene scene)
Called when this entity is dissociated with a scene.
public final voidsetActive(boolean active)
Modifies the active state of the body kin simulation.
public final voidsetAngularDamping(float damping)
Sets angular for the body.
public final voidsetAngularVelocity(float velocity)
Sets the angular velocity of the body.
public voidsetBullet(boolean bullet)
Sets whether the body is a bullet.
public voidsetConnections(int conn)
Sets connections for this physical body.
public voidsetDensity(float value)
Sets the density of the body.
public voidsetFixedRotation(boolean flag)
Sets whether the rotational angle of the body is fixed in simulation.
public voidsetFriction(float value)
Sets the friction of the body.
public final voidsetLinearDamping(float damping)
Sets linear damping for the body.
public final voidsetLinearVelocity(Point2D velocity)
Sets the current linear velocity of the object.
public final voidsetLinearVelocity(float vx, float vy)
Sets the current linear velocity of the object.
public voidsetPosition(float x, float y)
Modifies the position of the body.
public voidsetRestitution(float value)
Sets the restitution of the body.
public final voidsetRotation(float rotation)
Sets the rotation angle of the body.
public final voidsetShape(Shape s)
Sets the Shape of this body.
public final voidsetType(PhysicalBody.Behavior type)
Sets the simulation type of the physical body.

Methods inherited from com.annahid.libs.artenus.entities.FilteredEntity

Methods inherited from java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

POSITION
public static final POSITION
Defines position connection. If this connection is set, the PhysicalBody will lock the position of the underlying entity to that of itself. This connection is set by default for every PhysicalBody.
ROTATION
public static final ROTATION
Defines rotation connection. If this connection is set, the PhysicalBody will lock the rotational angle of the underlying entity to that of itself. This connection is set by default for every PhysicalBody.

Constructor Detail

PhysicalBody
public  PhysicalBody(
    Entity entity
)
PhysicalBody
public  PhysicalBody(
    Entity target,
    Shape shapeDesc
)
Constructs a PhysicalBody with a given shape.
Parameters:
targetThe entity to attach to this physical body
shapeDescThe initial Shape specification of the body

Method Detail

add
public final void add(
    JointDescriptor joint
)
Adds a joint descriptor to this PhysicalBody. For joints to be effective, they should be added to both bodies involved.
Parameters:
jointThe joint to be added
advance
public void advance(
    float elapsedTime
)
Updates this physical body to its new state provided by the physics simulator. The underlying entity may also be modified, depending on selected connections.
Parameters:
elapsedTimeElapsed time in seconds since the last frame
Overrides:
See Also:
applyForce
public final void applyForce(
    Point2D force
)
Applies a 2-dimensional force to the PhysicalBody.
Parameters:
forceThe force given in the SI unit
applyForce
public final void applyForce(
    Point2D force,
    Point2D center
)
Applies a 2-dimensional force to the PhysicalBody.
Parameters:
forceThe force given in the SI unit
centerThe effective point of the force on the PhysicalBody
applyLinearImpulse
public final void applyLinearImpulse(
    Point2D impulse
)
Applies a 2-dimensional impulse to the PhysicalBody.
Parameters:
impulseThe impulse to be applied in SI unit
applyLinearImpulse
public void applyLinearImpulse(
    Point2D impulse,
    Point2D center
)
Applies a 2-dimensional impulse to the PhysicalBody.
Parameters:
impulseThe impulse to be applied in SI unit
centerThe effective point of the impulse on the PhysicalBody
getAngularDamping
public float getAngularDamping()
Gets angular damping for the body.
Returns:
The body's angular damping
getAngularVelocity
public final float getAngularVelocity()
Sets the angular velocity of the body.
Returns:
The current angular velocity
getConnections
public int getConnections()
Gets the current connections associated with this physical body.
Returns:
the bit-masked list of connections
getDensity
public float getDensity()
Gets the currently assigned density of the body.
Returns:
Density of the body
getFriction
public float getFriction()
Gets the currently assigned friction of the body.
Returns:
Friction of the body
getLinearDamping
public float getLinearDamping()
Gets linear damping for the body.
Returns:
The body's linear damping
getLinearVelocity
public final Point2D getLinearVelocity()
Gets the linear velocity of the body.
Returns:
The current linear velocity
getMass
public final float getMass()
Gets the mass of the PhysicalBody in kilograms.
Returns:
The mass of the body
getPosition
public final Point2D getPosition()
Gets the current position of the body. This position changes with simulation. If the parent game object is added to the scene, this method runs slower than it would when isolated.
Overrides:
getRestitution
public float getRestitution()
Gets the currently assigned restitution of the body. Restitution determines how much energy the object loses when bouncing.
Returns:
Restitution of the body
getRotation
public final float getRotation()
Gets the rotational angle of the body.
Overrides:
getType
public final PhysicalBody.Behavior getType()
Gets the simulation type of this PhysicalBody. This type can be one of DYNAMIC, STATIC, or KINEMATIC.
Returns:
The body type
See Also:
isActive
public final boolean isActive()
Indicates whether the body is active in simulation and is considered in collision detection.
Returns:
A value indicating whether the body is active
isBullet
public boolean isBullet()
This method indicated whether the body is a bullet. A bullet is a fast-moving physical body.
Returns:
A value indicating whether the body is a bullet
isFixedRotation
public boolean isFixedRotation()
Gets whether the rotational angle of the body is fixed in simulation.
Returns:
A value indicating whether the body's rotation angle should remain fixed
onAttach
public void onAttach(
    Scene scene
)
Called when this entity is associated with a scene.
Overrides:
onDetach
public void onDetach(
    Scene scene
)
Called when this entity is dissociated with a scene.
Overrides:
setActive
public final void setActive(
    boolean active
)
Modifies the active state of the body kin simulation. If the body is not active, it is not accounted for in collision detection and physics simulation.
Parameters:
activeA value indicating whether the body should be active
setAngularDamping
public final void setAngularDamping(
    float damping
)
Sets angular for the body.
Parameters:
dampingThe new angular damping
setAngularVelocity
public final void setAngularVelocity(
    float velocity
)
Sets the angular velocity of the body. If the object is active in simulation, its current angular velocity will be replaced with the new value.
Parameters:
velocityThe new angular velocity
setBullet
public void setBullet(
    boolean bullet
)
Sets whether the body is a bullet. A bullet is a fast-moving physical body. If you have an object that has this characteristic in your game, you should set this flag for better collision processing.
Parameters:
bulletA new value indicating whether the body is a bullet
setConnections
public void setConnections(
    int conn
)
Sets connections for this physical body. Valid values are POSITION and ROTATION.
Parameters:
connthe bit-masked list of connections
setDensity
public void setDensity(
    float value
)
Sets the density of the body. Density is accounted for whenever you assign a shape to the body. Changing this value has no effect if the parent game object is already added to the scene. But if you change the shape, the value is applied to the new shape.
Parameters:
valueThe new value for density
setFixedRotation
public void setFixedRotation(
    boolean flag
)
Sets whether the rotational angle of the body is fixed in simulation.
Parameters:
flagA value indicating whether the body's rotation angle should remain fixed
setFriction
public void setFriction(
    float value
)
Sets the friction of the body. Friction is accounted for whenever you assign a shape to the body. Changing this value has no effect if the parent game object is already added to the scene. But if you change the shape, the value is applied to the new shape.
Parameters:
valueThe new value for friction
setLinearDamping
public final void setLinearDamping(
    float damping
)
Sets linear damping for the body.
Parameters:
dampingThe new linear damping
setLinearVelocity
public final void setLinearVelocity(
    Point2D velocity
)
Sets the current linear velocity of the object. If the object is active in simulation, its current linear velocity is replaced with the new value.
Parameters:
velocityThe new linear velocity
setLinearVelocity
public final void setLinearVelocity(
    float vx,
    float vy
)
Sets the current linear velocity of the object. If the object is active in simulation, its current linear velocity is replaced with the new value.
Parameters:
vxThe x component of the new linear velocity
vyThe y component of the new linear velocity
setPosition
public void setPosition(
    float x,
    float y
)
Modifies the position of the body. The values are given in pixels, but internally stored in metric format.
Parameters:
xThe x component of the new position in pixels
yThe y component of the new position in pixels
Overrides:
setRestitution
public void setRestitution(
    float value
)
Sets the restitution of the body. Friction is accounted for whenever you assign a shape to the body. Changing this value has no effect if the parent game object is already added to the scene. But if you change the shape, the value is applied to the new shape.
Parameters:
valueThe new value for restitution. Setting this value to 1 ensures that the object will not lose any energy when bouncing.
setRotation
public final void setRotation(
    float rotation
)
Sets the rotation angle of the body. This value is internally stored in Radians, but the method takes it in degrees to be compatible with game object attachments.
Parameters:
rotationThe new rotational angle of the body in degrees
Overrides:
setShape
public final void setShape(
    Shape s
)
Sets the Shape of this body. If the body is already attached to a scene, The shape will change will take effect on the next frame.
Parameters:
sThe new shape for the body
See Also:
setType
public final void setType(
    PhysicalBody.Behavior type
)
Sets the simulation type of the physical body. It can be one of the values STATIC, DYNAMIC, or KINEMATIC.
Parameters:
typeThe desired simulation type
See Also: