- Object
-
- AbstractCollisionBody<T>
-
- Type Parameters:
T
- theFixture
type
- All Implemented Interfaces:
CollisionBody<T>
,DataContainer
,Rotatable
,Shiftable
,Transformable
,Translatable
,Ownable
- Direct Known Subclasses:
AbstractCollidable
,AbstractPhysicsBody
public abstract class AbstractCollisionBody<T extends Fixture> extends Object implements CollisionBody<T>, Transformable, DataContainer, Ownable
A base implementation of theCollisionBody
interface.- Since:
- 4.0.0
- Version:
- 4.0.0
- Author:
- William Bittle
-
-
Field Summary
-
Fields inherited from interface CollisionBody
TYPICAL_FIXTURE_COUNT
-
-
Constructor Summary
Constructors Constructor Description AbstractCollisionBody()
Default constructor.AbstractCollisionBody(int fixtureCount)
Optional constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CollisionBody<T>
addFixture(T fixture)
Adds the givenFixture
to thisCollisionBody
.boolean
contains(Vector2 point)
Returns true if the given world space point is contained in thisCollisionBody
.boolean
containsFixture(T fixture)
Returns true if thisCollisionBody
contains the givenFixture
.AABB
createAABB()
AABB
createAABB(Transform transform)
T
getFixture(int index)
Returns theFixture
at the given index.T
getFixture(Vector2 point)
Returns the firstFixture
in thisCollisionBody
, determined by the order in which they were added, that contains the given point.int
getFixtureCount()
Returns the number ofFixture
s attached to thisCollisionBody
object.Iterator<T>
getFixtureIterator()
Returns an iterator for this body's fixtures.FixtureModificationHandler<T>
getFixtureModificationHandler()
Returns theFixtureModificationHandler
for this body.List<T>
getFixtures()
Returns an unmodifiable list containing theFixture
s attached to thisCollisionBody
.List<T>
getFixtures(Vector2 point)
Returns all theFixture
s in thisCollisionBody
that contain the given point.Vector2
getLocalPoint(Vector2 worldPoint)
Returns a new point in local coordinates of thisCollisionBody
given a point in world coordinates.Vector2
getLocalVector(Vector2 worldVector)
Returns a new vector in local coordinates of thisCollisionBody
given a vector in world coordinates.Object
getOwner()
Returns the owner for this body.Transform
getPreviousTransform()
Returns the transform of the last iteration.double
getRotationDiscRadius()
Returns the maximum radius of the disk that theCollisionBody
creates if rotated 360 degrees about its center.Transform
getTransform()
Returns the local to world spaceTransform
of thisCollisionBody
.Object
getUserData()
Gets the custom user data.Vector2
getWorldCenter()
Returns the center for thisCollisionBody
in world coordinates.Vector2
getWorldPoint(Vector2 localPoint)
Returns a new point in world coordinates given a point in the local coordinates of thisCollisionBody
.Vector2
getWorldVector(Vector2 localVector)
Returns a new vector in world coordinates given a vector in the local coordinates of thisCollisionBody
.boolean
isEnabled()
Returns true if thisCollisionBody
is enabled.List<T>
removeAllFixtures()
Removes all fixtures from thisCollisionBody
and returns them.T
removeFixture(int index)
Removes theFixture
at the given index.T
removeFixture(Vector2 point)
Removes the firstFixture
in thisCollisionBody
, determined by the order in which they were added, that contains the given point and returns it.boolean
removeFixture(T fixture)
Removes the givenFixture
from thisCollisionBody
.List<T>
removeFixtures(Vector2 point)
Removes all theFixture
s in thisCollisionBody
that contain the given point and returns them.void
rotate(double theta)
Rotates the object about the origin.void
rotate(double theta, double x, double y)
Rotates the object about the given coordinates.void
rotate(double theta, Vector2 point)
Rotates the object about the given point.void
rotate(Rotation rotation)
Rotates the object about the origin.void
rotate(Rotation rotation, double x, double y)
Rotates the object about the given point.void
rotate(Rotation rotation, Vector2 point)
Rotates the object about the given point.void
rotateAboutCenter(double theta)
Rotates theCollisionBody
about its center.void
setEnabled(boolean enabled)
Sets theCollisionBody
enabled or not.void
setFixtureModificationHandler(FixtureModificationHandler<T> handler)
Sets theFixtureModificationHandler
for this body.void
setOwner(Object owner)
Sets the owner of this body.void
setTransform(Transform transform)
Sets thisCollisionBody
's local to world spaceTransform
.void
setUserData(Object userData)
Sets the custom user data to the given data.void
shift(Vector2 shift)
Translates the object to match the given coordinate shift.void
translate(double x, double y)
Translates the object the given amounts in the respective directions.void
translate(Vector2 vector)
Translates the object along the given vector.void
translateToOrigin()
Translates the center of theCollisionBody
to the world space origin (0,0).-
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface CollisionBody
addFixture, getLocalCenter
-
-
-
-
Constructor Detail
-
AbstractCollisionBody
public AbstractCollisionBody()
Default constructor.
-
AbstractCollisionBody
public AbstractCollisionBody(int fixtureCount)
Optional constructor.Creates a new
AbstractCollisionBody
using the given estimated fixture count. Assignment of the initial fixture count allows sizing of internal structures for optimal memory/performance. This estimated fixture count is not a limit on the number of fixtures.- Parameters:
fixtureCount
- the estimated number of fixtures
-
-
Method Detail
-
addFixture
public CollisionBody<T> addFixture(T fixture)
Description copied from interface:CollisionBody
Adds the givenFixture
to thisCollisionBody
.- Specified by:
addFixture
in interfaceCollisionBody<T extends Fixture>
- Parameters:
fixture
- theFixture
to add- Returns:
CollisionBody
this body
-
removeFixture
public boolean removeFixture(T fixture)
Description copied from interface:CollisionBody
Removes the givenFixture
from thisCollisionBody
.- Specified by:
removeFixture
in interfaceCollisionBody<T extends Fixture>
- Parameters:
fixture
- theFixture
- Returns:
- boolean true if the
Fixture
was removed from thisCollisionBody
-
removeFixture
public T removeFixture(int index)
Description copied from interface:CollisionBody
Removes theFixture
at the given index.- Specified by:
removeFixture
in interfaceCollisionBody<T extends Fixture>
- Parameters:
index
- the index- Returns:
- T the fixture removed
-
removeAllFixtures
public List<T> removeAllFixtures()
Description copied from interface:CollisionBody
Removes all fixtures from thisCollisionBody
and returns them.- Specified by:
removeAllFixtures
in interfaceCollisionBody<T extends Fixture>
- Returns:
- List<T>
-
removeFixture
public T removeFixture(Vector2 point)
Description copied from interface:CollisionBody
Removes the firstFixture
in thisCollisionBody
, determined by the order in which they were added, that contains the given point and returns it.Returns null if the point is not contained in any
Fixture
in thisCollisionBody
.- Specified by:
removeFixture
in interfaceCollisionBody<T extends Fixture>
- Parameters:
point
- a world space point- Returns:
- T the fixture or null
-
removeFixtures
public List<T> removeFixtures(Vector2 point)
Description copied from interface:CollisionBody
Removes all theFixture
s in thisCollisionBody
that contain the given point and returns them.Returns an empty list if the point is not contained in any
Fixture
in thisCollisionBody
.- Specified by:
removeFixtures
in interfaceCollisionBody<T extends Fixture>
- Parameters:
point
- a world space point- Returns:
- List<T>
-
containsFixture
public boolean containsFixture(T fixture)
Description copied from interface:CollisionBody
Returns true if thisCollisionBody
contains the givenFixture
.- Specified by:
containsFixture
in interfaceCollisionBody<T extends Fixture>
- Parameters:
fixture
- the fixture- Returns:
- boolean
-
getFixture
public T getFixture(int index)
Description copied from interface:CollisionBody
Returns theFixture
at the given index.- Specified by:
getFixture
in interfaceCollisionBody<T extends Fixture>
- Parameters:
index
- the index of theFixture
- Returns:
- T the fixture
-
getFixture
public T getFixture(Vector2 point)
Description copied from interface:CollisionBody
Returns the firstFixture
in thisCollisionBody
, determined by the order in which they were added, that contains the given point.Returns null if the point is not contained in any fixture in this
CollisionBody
.- Specified by:
getFixture
in interfaceCollisionBody<T extends Fixture>
- Parameters:
point
- a world space point- Returns:
- T the fixture or null
-
getFixtures
public List<T> getFixtures(Vector2 point)
Description copied from interface:CollisionBody
Returns all theFixture
s in thisCollisionBody
that contain the given point.Returns an empty list if the point is not contained in any fixture in this
CollisionBody
.- Specified by:
getFixtures
in interfaceCollisionBody<T extends Fixture>
- Parameters:
point
- a world space point- Returns:
- List<T>
-
getFixtureCount
public int getFixtureCount()
Description copied from interface:CollisionBody
Returns the number ofFixture
s attached to thisCollisionBody
object.- Specified by:
getFixtureCount
in interfaceCollisionBody<T extends Fixture>
- Returns:
- int
-
getFixtures
public List<T> getFixtures()
Description copied from interface:CollisionBody
Returns an unmodifiable list containing theFixture
s attached to thisCollisionBody
.The returned list is backed by the internal list, therefore adding or removing fixtures while iterating through the returned list is not permitted. Use the
CollisionBody.getFixtureIterator()
method instead.- Specified by:
getFixtures
in interfaceCollisionBody<T extends Fixture>
- Returns:
- List<T>
- See Also:
CollisionBody.getFixtureIterator()
-
getFixtureIterator
public Iterator<T> getFixtureIterator()
Description copied from interface:CollisionBody
Returns an iterator for this body's fixtures.The returned iterator supports the
remove
method.- Specified by:
getFixtureIterator
in interfaceCollisionBody<T extends Fixture>
- Returns:
- Iterator<T>
-
rotate
public void rotate(double theta, double x, double y)
Description copied from interface:Rotatable
Rotates the object about the given coordinates.
-
rotate
public void rotate(Rotation rotation, double x, double y)
Description copied from interface:Rotatable
Rotates the object about the given point.
-
rotate
public void rotate(double theta, Vector2 point)
Description copied from interface:Rotatable
Rotates the object about the given point.
-
rotate
public void rotate(Rotation rotation, Vector2 point)
Description copied from interface:Rotatable
Rotates the object about the given point.
-
rotate
public void rotate(double theta)
Description copied from interface:Rotatable
Rotates the object about the origin.
-
rotate
public void rotate(Rotation rotation)
Description copied from interface:Rotatable
Rotates the object about the origin.
-
rotateAboutCenter
public void rotateAboutCenter(double theta)
Description copied from interface:CollisionBody
Rotates theCollisionBody
about its center.- Specified by:
rotateAboutCenter
in interfaceCollisionBody<T extends Fixture>
- Parameters:
theta
- the angle of rotation in radians
-
translate
public void translate(double x, double y)
Description copied from interface:Translatable
Translates the object the given amounts in the respective directions.- Specified by:
translate
in interfaceTranslatable
- Parameters:
x
- the translation in the x directiony
- the translation in the y direction
-
translate
public void translate(Vector2 vector)
Description copied from interface:Translatable
Translates the object along the given vector.- Specified by:
translate
in interfaceTranslatable
- Parameters:
vector
- the translation along a vector
-
translateToOrigin
public void translateToOrigin()
Description copied from interface:CollisionBody
Translates the center of theCollisionBody
to the world space origin (0,0).This method is useful if bodies have a number of fixtures and the center is not at the origin. This method will reposition this
CollisionBody
so that the center is at the origin.- Specified by:
translateToOrigin
in interfaceCollisionBody<T extends Fixture>
-
shift
public void shift(Vector2 shift)
Description copied from interface:Shiftable
Translates the object to match the given coordinate shift.
-
getTransform
public Transform getTransform()
Description copied from interface:CollisionBody
Returns the local to world spaceTransform
of thisCollisionBody
.- Specified by:
getTransform
in interfaceCollisionBody<T extends Fixture>
- Returns:
Transform
-
getPreviousTransform
public Transform getPreviousTransform()
Description copied from interface:CollisionBody
Returns the transform of the last iteration.This transform represents the last frame's position and orientation.
- Specified by:
getPreviousTransform
in interfaceCollisionBody<T extends Fixture>
- Returns:
Transform
-
getRotationDiscRadius
public double getRotationDiscRadius()
Description copied from interface:CollisionBody
Returns the maximum radius of the disk that theCollisionBody
creates if rotated 360 degrees about its center.- Specified by:
getRotationDiscRadius
in interfaceCollisionBody<T extends Fixture>
- Returns:
- double the maximum radius of the rotation disk
-
setTransform
public void setTransform(Transform transform)
Description copied from interface:CollisionBody
Sets thisCollisionBody
's local to world spaceTransform
.If the given transform is null, nothing is done and this method returns immediately.
- Specified by:
setTransform
in interfaceCollisionBody<T extends Fixture>
- Parameters:
transform
- the transform
-
getUserData
public Object getUserData()
Description copied from interface:DataContainer
Gets the custom user data.- Specified by:
getUserData
in interfaceDataContainer
- Returns:
- Object will return null if not set
-
setUserData
public void setUserData(Object userData)
Description copied from interface:DataContainer
Sets the custom user data to the given data.- Specified by:
setUserData
in interfaceDataContainer
- Parameters:
userData
- the user data
-
createAABB
public AABB createAABB()
Description copied from interface:CollisionBody
Creates anAABB
from thisCollisionBody
's attachedFixture
s.If there are no fixtures attached, a degenerate AABB, (0.0, 0.0) to (0.0, 0.0), is returned.
- Specified by:
createAABB
in interfaceCollisionBody<T extends Fixture>
- Returns:
AABB
-
createAABB
public AABB createAABB(Transform transform)
Description copied from interface:CollisionBody
Creates anAABB
from thisCollisionBody
's attachedFixture
s using the given world spaceTransform
.If there are no fixtures attached, a degenerate AABB, (0.0, 0.0) to (0.0, 0.0), is returned.
- Specified by:
createAABB
in interfaceCollisionBody<T extends Fixture>
- Parameters:
transform
- the world spaceTransform
- Returns:
AABB
-
getLocalPoint
public Vector2 getLocalPoint(Vector2 worldPoint)
Description copied from interface:CollisionBody
Returns a new point in local coordinates of thisCollisionBody
given a point in world coordinates.- Specified by:
getLocalPoint
in interfaceCollisionBody<T extends Fixture>
- Parameters:
worldPoint
- a world space point- Returns:
Vector2
local space point
-
getWorldPoint
public Vector2 getWorldPoint(Vector2 localPoint)
Description copied from interface:CollisionBody
Returns a new point in world coordinates given a point in the local coordinates of thisCollisionBody
.- Specified by:
getWorldPoint
in interfaceCollisionBody<T extends Fixture>
- Parameters:
localPoint
- a point in the local coordinates of thisCollisionBody
- Returns:
Vector2
world space point
-
getLocalVector
public Vector2 getLocalVector(Vector2 worldVector)
Description copied from interface:CollisionBody
Returns a new vector in local coordinates of thisCollisionBody
given a vector in world coordinates.- Specified by:
getLocalVector
in interfaceCollisionBody<T extends Fixture>
- Parameters:
worldVector
- a world space vector- Returns:
Vector2
local space vector
-
getWorldVector
public Vector2 getWorldVector(Vector2 localVector)
Description copied from interface:CollisionBody
Returns a new vector in world coordinates given a vector in the local coordinates of thisCollisionBody
.- Specified by:
getWorldVector
in interfaceCollisionBody<T extends Fixture>
- Parameters:
localVector
- a vector in the local coordinates of thisCollisionBody
- Returns:
Vector2
world space vector
-
getWorldCenter
public Vector2 getWorldCenter()
Description copied from interface:CollisionBody
Returns the center for thisCollisionBody
in world coordinates.- Specified by:
getWorldCenter
in interfaceCollisionBody<T extends Fixture>
- Returns:
Vector2
the center in world coordinates
-
contains
public boolean contains(Vector2 point)
Description copied from interface:CollisionBody
Returns true if the given world space point is contained in thisCollisionBody
.The point is contained in this
CollisionBody
if and only if the point is contained in one of thisCollisionBody
'sFixture
s.- Specified by:
contains
in interfaceCollisionBody<T extends Fixture>
- Parameters:
point
- the world space test point- Returns:
- boolean
-
isEnabled
public boolean isEnabled()
Description copied from interface:CollisionBody
Returns true if thisCollisionBody
is enabled.- Specified by:
isEnabled
in interfaceCollisionBody<T extends Fixture>
- Returns:
- boolean
-
setEnabled
public void setEnabled(boolean enabled)
Description copied from interface:CollisionBody
Sets theCollisionBody
enabled or not.A disabled
CollisionBody
is completely ignored by the engine.A
CollisionBody
will be disabled by only one condition from within the engine - when it's out of bounds. If there's no bounds detection set, then this state will never be set automatically.- Specified by:
setEnabled
in interfaceCollisionBody<T extends Fixture>
- Parameters:
enabled
- true if theCollisionBody
should be enabled
-
getOwner
public Object getOwner()
Description copied from interface:Ownable
Returns the owner for this body.
-
setOwner
public void setOwner(Object owner)
Description copied from interface:Ownable
Sets the owner of this body.
-
getFixtureModificationHandler
public FixtureModificationHandler<T> getFixtureModificationHandler()
Description copied from interface:CollisionBody
Returns theFixtureModificationHandler
for this body.- Specified by:
getFixtureModificationHandler
in interfaceCollisionBody<T extends Fixture>
- Returns:
FixtureModificationHandler
-
setFixtureModificationHandler
public void setFixtureModificationHandler(FixtureModificationHandler<T> handler)
Description copied from interface:CollisionBody
Sets theFixtureModificationHandler
for this body.- Specified by:
setFixtureModificationHandler
in interfaceCollisionBody<T extends Fixture>
- Parameters:
handler
- the handler
-
-