-
- Type Parameters:
T
- theFixture
type
- All Superinterfaces:
DataContainer
,Ownable
,Rotatable
,Shiftable
,Transformable
,Translatable
- All Known Subinterfaces:
Collidable<T>
,PhysicsBody
- All Known Implementing Classes:
AbstractCollidable
,AbstractCollisionBody
,AbstractPhysicsBody
,Body
public interface CollisionBody<T extends Fixture> extends Transformable, Shiftable, DataContainer, Ownable
Represents an object that can collide with other objects.- Since:
- 4.0.0
- Version:
- 4.0.0
- Author:
- William Bittle
- See Also:
AbstractCollisionBody
-
-
Field Summary
Fields Modifier and Type Field Description static int
TYPICAL_FIXTURE_COUNT
Number of fixtures typically attached to aCollisionBody
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
addFixture(Convex convex)
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
getLocalCenter()
Returns the center for thisCollisionBody
in local coordinates.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.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
.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
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
setTransform(Transform transform)
Sets thisCollisionBody
's local to world spaceTransform
.void
translateToOrigin()
Translates the center of theCollisionBody
to the world space origin (0,0).-
Methods inherited from interface DataContainer
getUserData, setUserData
-
Methods inherited from interface Translatable
translate, translate
-
-
-
-
Field Detail
-
TYPICAL_FIXTURE_COUNT
static final int TYPICAL_FIXTURE_COUNT
Number of fixtures typically attached to aCollisionBody
- See Also:
- Constant Field Values
-
-
Method Detail
-
addFixture
CollisionBody<T> addFixture(T fixture)
Adds the givenFixture
to thisCollisionBody
.- Parameters:
fixture
- theFixture
to add- Returns:
CollisionBody
this body- Throws:
NullPointerException
- if fixture is null- Since:
- 3.2.0
-
addFixture
T addFixture(Convex convex)
- Parameters:
convex
- theConvex
Shape
to add- Returns:
- T the fixture created
- Throws:
NullPointerException
- if convex is null- Since:
- 3.2.0
-
getFixture
T getFixture(int index)
Returns theFixture
at the given index.- Parameters:
index
- the index of theFixture
- Returns:
- T the fixture
- Throws:
IndexOutOfBoundsException
- if index is out of bounds- Since:
- 2.0.0
-
containsFixture
boolean containsFixture(T fixture)
Returns true if thisCollisionBody
contains the givenFixture
.- Parameters:
fixture
- the fixture- Returns:
- boolean
- Since:
- 3.2.0
-
getFixture
T getFixture(Vector2 point)
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
.- Parameters:
point
- a world space point- Returns:
- T the fixture or null
- Throws:
NullPointerException
- if point is null- Since:
- 3.2.0
-
getFixtures
List<T> getFixtures(Vector2 point)
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
.- Parameters:
point
- a world space point- Returns:
- List<T>
- Throws:
NullPointerException
- if point is null- Since:
- 3.2.0
-
removeFixture
boolean removeFixture(T fixture)
Removes the givenFixture
from thisCollisionBody
.- Parameters:
fixture
- theFixture
- Returns:
- boolean true if the
Fixture
was removed from thisCollisionBody
- Since:
- 3.2.0
-
removeFixture
T removeFixture(int index)
Removes theFixture
at the given index.- Parameters:
index
- the index- Returns:
- T the fixture removed
- Throws:
IndexOutOfBoundsException
- if index is out of bounds- Since:
- 3.2.0
-
removeAllFixtures
List<T> removeAllFixtures()
Removes all fixtures from thisCollisionBody
and returns them.- Returns:
- List<T>
- Since:
- 3.2.0
-
removeFixture
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.Returns null if the point is not contained in any
Fixture
in thisCollisionBody
.- Parameters:
point
- a world space point- Returns:
- T the fixture or null
- Throws:
NullPointerException
- if point is null- Since:
- 3.2.0
-
removeFixtures
List<T> removeFixtures(Vector2 point)
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
.- Parameters:
point
- a world space point- Returns:
- List<T>
- Throws:
NullPointerException
- if point is null- Since:
- 3.2.0
-
getFixtureCount
int getFixtureCount()
Returns the number ofFixture
s attached to thisCollisionBody
object.- Returns:
- int
- Since:
- 2.0.0
-
getFixtures
List<T> getFixtures()
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
getFixtureIterator()
method instead.- Returns:
- List<T>
- Since:
- 3.1.5
- See Also:
getFixtureIterator()
-
getFixtureIterator
Iterator<T> getFixtureIterator()
Returns an iterator for this body's fixtures.The returned iterator supports the
remove
method.- Returns:
- Iterator<T>
- Since:
- 3.2.0
-
contains
boolean contains(Vector2 point)
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.- Parameters:
point
- the world space test point- Returns:
- boolean
- Throws:
NullPointerException
- if point is null- Since:
- 3.2.0
-
getLocalCenter
Vector2 getLocalCenter()
Returns the center for thisCollisionBody
in local coordinates.- Returns:
Vector2
the center in local coordinates- Since:
- 3.2.0
-
getWorldCenter
Vector2 getWorldCenter()
Returns the center for thisCollisionBody
in world coordinates.- Returns:
Vector2
the center in world coordinates- Since:
- 3.2.0
-
getLocalPoint
Vector2 getLocalPoint(Vector2 worldPoint)
Returns a new point in local coordinates of thisCollisionBody
given a point in world coordinates.- Parameters:
worldPoint
- a world space point- Returns:
Vector2
local space point- Throws:
NullPointerException
- if the given point is null- Since:
- 3.2.0
-
getWorldPoint
Vector2 getWorldPoint(Vector2 localPoint)
Returns a new point in world coordinates given a point in the local coordinates of thisCollisionBody
.- Parameters:
localPoint
- a point in the local coordinates of thisCollisionBody
- Returns:
Vector2
world space point- Throws:
NullPointerException
- if the given point is null- Since:
- 3.2.0
-
getLocalVector
Vector2 getLocalVector(Vector2 worldVector)
Returns a new vector in local coordinates of thisCollisionBody
given a vector in world coordinates.- Parameters:
worldVector
- a world space vector- Returns:
Vector2
local space vector- Throws:
NullPointerException
- if the given vector is null- Since:
- 3.2.0
-
getWorldVector
Vector2 getWorldVector(Vector2 localVector)
Returns a new vector in world coordinates given a vector in the local coordinates of thisCollisionBody
.- Parameters:
localVector
- a vector in the local coordinates of thisCollisionBody
- Returns:
Vector2
world space vector- Throws:
NullPointerException
- if the given vector is null- Since:
- 3.2.0
-
getRotationDiscRadius
double getRotationDiscRadius()
Returns the maximum radius of the disk that theCollisionBody
creates if rotated 360 degrees about its center.- Returns:
- double the maximum radius of the rotation disk
-
getTransform
Transform getTransform()
Returns the local to world spaceTransform
of thisCollisionBody
.- Returns:
Transform
-
getPreviousTransform
Transform getPreviousTransform()
Returns the transform of the last iteration.This transform represents the last frame's position and orientation.
- Returns:
Transform
-
setTransform
void setTransform(Transform transform)
Sets thisCollisionBody
's local to world spaceTransform
.If the given transform is null, nothing is done and this method returns immediately.
- Parameters:
transform
- the transform- Since:
- 3.2.0
-
rotateAboutCenter
void rotateAboutCenter(double theta)
Rotates theCollisionBody
about its center.- Parameters:
theta
- the angle of rotation in radians
-
translateToOrigin
void translateToOrigin()
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.- Since:
- 3.2.0
-
createAABB
AABB createAABB()
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.
- Returns:
AABB
- Since:
- 3.0.0
-
createAABB
AABB createAABB(Transform transform)
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.
- Parameters:
transform
- the world spaceTransform
- Returns:
AABB
- Throws:
NullPointerException
- if the given transform is null- Since:
- 3.2.0
-
setEnabled
void setEnabled(boolean enabled)
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.- Parameters:
enabled
- true if theCollisionBody
should be enabled- Since:
- 4.0.0
-
isEnabled
boolean isEnabled()
Returns true if thisCollisionBody
is enabled.- Returns:
- boolean
- Since:
- 4.0.0
-
getFixtureModificationHandler
FixtureModificationHandler<T> getFixtureModificationHandler()
Returns theFixtureModificationHandler
for this body.- Returns:
FixtureModificationHandler
- Since:
- 4.0.0
-
setFixtureModificationHandler
void setFixtureModificationHandler(FixtureModificationHandler<T> handler)
Sets theFixtureModificationHandler
for this body.- Parameters:
handler
- the handler- Since:
- 4.0.0
-
-