com.annahid.libs.artenus.physics
PhysicalBody
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 Type | Field 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 Type | Constructor and Description |
---|---|
public | PhysicalBody(Entity entity) |
public | PhysicalBody(Entity target, Shape shapeDesc) Constructs a PhysicalBody with a given shape. |
Method Summary
Modifier and Type | Method and Description |
---|---|
public final void | add(JointDescriptor joint) Adds a joint descriptor to this PhysicalBody. |
public void | advance(float elapsedTime) Updates this physical body to its new state provided by the physics simulator. |
public final void | applyForce(Point2D force) Applies a 2-dimensional force to the PhysicalBody. |
public final void | applyForce(Point2D force, Point2D center) Applies a 2-dimensional force to the PhysicalBody. |
public final void | applyLinearImpulse(Point2D impulse) Applies a 2-dimensional impulse to the PhysicalBody. |
public void | applyLinearImpulse(Point2D impulse, Point2D center) Applies a 2-dimensional impulse to the PhysicalBody. |
public float | getAngularDamping() Gets angular damping for the body. |
public final float | getAngularVelocity() Sets the angular velocity of the body. |
public int | getConnections() Gets the current connections associated with this physical body. |
public float | getDensity() Gets the currently assigned density of the body. |
public float | getFriction() Gets the currently assigned friction of the body. |
public float | getLinearDamping() Gets linear damping for the body. |
public final Point2D | getLinearVelocity() Gets the linear velocity of the body. |
public final float | getMass() Gets the mass of the PhysicalBody in kilograms. |
public final Point2D | getPosition() Gets the current position of the body. |
public float | getRestitution() Gets the currently assigned restitution of the body. |
public final float | getRotation() Gets the rotational angle of the body. |
public final PhysicalBody.Behavior | getType() Gets the simulation type of this PhysicalBody. |
public final boolean | isActive() Indicates whether the body is active in simulation and is considered in collision
detection. |
public boolean | isBullet() This method indicated whether the body is a bullet. |
public boolean | isFixedRotation() Gets whether the rotational angle of the body is fixed in simulation. |
public void | onAttach(Scene scene) Called when this entity is associated with a scene. |
public void | onDetach(Scene scene) Called when this entity is dissociated with a scene. |
public final void | setActive(boolean active) Modifies the active state of the body kin simulation. |
public final void | setAngularDamping(float damping) Sets angular for the body. |
public final void | setAngularVelocity(float velocity) Sets the angular velocity of the body. |
public void | setBullet(boolean bullet) Sets whether the body is a bullet. |
public void | setConnections(int conn) Sets connections for this physical body. |
public void | setDensity(float value) Sets the density of the body. |
public void | setFixedRotation(boolean flag) Sets whether the rotational angle of the body is fixed in simulation. |
public void | setFriction(float value) Sets the friction of the body. |
public final void | setLinearDamping(float damping) Sets linear damping for the body. |
public final void | setLinearVelocity(Point2D velocity) Sets the current linear velocity of the object. |
public final void | setLinearVelocity(float vx, float vy) Sets the current linear velocity of the object. |
public void | setPosition(float x, float y) Modifies the position of the body. |
public void | setRestitution(float value) Sets the restitution of the body. |
public final void | setRotation(float rotation) Sets the rotation angle of the body. |
public final void | setShape(Shape s) Sets the Shape of this body. |
public final void | setType(PhysicalBody.Behavior type) Sets the simulation type of the physical body. |
Methods inherited from com.annahid.libs.artenus.entities.FilteredEntity
advance
, equals
, getAlpha
, getAnimation
, getColorFilter
, getPosition
, getRotation
, getScale
, getUnderlyingEntity
, hasBehavior
, move
, onAttach
, onDetach
, render
, rotate
, setAlpha
, setAnimation
, setColorFilter
, setColorFilter
, setPosition
, setPosition
, setRotation
, setScale
, setScale
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:
|
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:
|
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:
Overrides:
See Also:
|
applyForce | ||
---|---|---|
public final void applyForce( Point2D force ) Applies a 2-dimensional force to the PhysicalBody. Parameters:
|
applyForce | ||||
---|---|---|---|---|
public final void applyForce( Point2D force, Point2D center ) Applies a 2-dimensional force to the PhysicalBody. Parameters:
|
applyLinearImpulse | ||
---|---|---|
public final void applyLinearImpulse( Point2D impulse ) Applies a 2-dimensional impulse to the PhysicalBody. Parameters:
|
applyLinearImpulse | ||||
---|---|---|---|---|
public void applyLinearImpulse( Point2D impulse, Point2D center ) Applies a 2-dimensional impulse to the PhysicalBody. Parameters:
|
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:
|
setAngularDamping | ||
---|---|---|
public final void setAngularDamping( float damping ) Sets angular for the body. Parameters:
|
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:
|
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:
|
setConnections | ||
---|---|---|
public void setConnections( int conn ) Parameters:
|
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:
|
setFixedRotation | ||
---|---|---|
public void setFixedRotation( boolean flag ) Sets whether the rotational angle of the body is fixed in simulation. Parameters:
|
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:
|
setLinearDamping | ||
---|---|---|
public final void setLinearDamping( float damping ) Sets linear damping for the body. Parameters:
|
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:
|
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:
|
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:
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:
|
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:
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:
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:
See Also:
|