T
- the Fixture
typeCollidable<T>
, DataContainer
, Rotatable
, Shiftable
, Transformable
, Translatable
Body
public abstract class AbstractCollidable<T extends Fixture> extends java.lang.Object implements Collidable<T>, Transformable, DataContainer
Collidable
interface.TYPICAL_FIXTURE_COUNT
Constructor | Description |
---|---|
AbstractCollidable() |
Default constructor.
|
AbstractCollidable(int fixtureCount) |
Optional constructor.
|
Modifier and Type | Method | Description |
---|---|---|
boolean |
contains(Vector2 point) |
Returns true if the given world space point is contained in this
Collidable . |
boolean |
containsFixture(T fixture) |
Returns true if this
Collidable contains the given Fixture . |
AABB |
createAABB() |
|
AABB |
createAABB(Transform transform) |
|
boolean |
equals(java.lang.Object obj) |
|
T |
getFixture(int index) |
Returns the
Fixture at the given index. |
T |
getFixture(Vector2 point) |
Returns the first
Fixture in this Collidable , determined by the order in
which they were added, that contains the given point. |
int |
getFixtureCount() |
Returns the number of
Fixture s attached
to this Collidable object. |
java.util.Iterator<T> |
getFixtureIterator() |
Returns an iterator for this collidable's fixtures.
|
java.util.List<T> |
getFixtures() |
Returns an unmodifiable list containing the
Fixture s attached to this Collidable . |
java.util.List<T> |
getFixtures(Vector2 point) |
Returns all the
Fixture s in this Collidable that contain the given point. |
java.util.UUID |
getId() |
Returns a unique identifier for this
Collidable . |
Vector2 |
getLocalPoint(Vector2 worldPoint) |
Returns a new point in local coordinates of this
Collidable given
a point in world coordinates. |
Vector2 |
getLocalVector(Vector2 worldVector) |
Returns a new vector in local coordinates of this
Collidable given
a vector in world coordinates. |
double |
getRotationDiscRadius() |
Returns the maximum radius of the disk that the
Collidable creates if rotated 360 degrees about its center. |
Transform |
getTransform() |
Returns the local to world space
Transform of this Collidable . |
java.lang.Object |
getUserData() |
Gets the custom user data.
|
Vector2 |
getWorldPoint(Vector2 localPoint) |
Returns a new point in world coordinates given a point in the
local coordinates of this
Collidable . |
Vector2 |
getWorldVector(Vector2 localVector) |
Returns a new vector in world coordinates given a vector in the
local coordinates of this
Collidable . |
int |
hashCode() |
|
java.util.List<T> |
removeAllFixtures() |
Removes all fixtures from this
Collidable and returns them. |
T |
removeFixture(int index) |
Removes the
Fixture at the given index. |
T |
removeFixture(Vector2 point) |
Removes the first
Fixture in this Collidable , determined by the order in
which they were added, that contains the given point and returns it. |
boolean |
removeFixture(T fixture) |
Removes the given
Fixture from this Collidable . |
java.util.List<T> |
removeFixtures(Vector2 point) |
Removes all the
Fixture s in this Collidable 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 |
rotateAboutCenter(double theta) |
Rotates the
Collidable about its center of mass. |
void |
setTransform(Transform transform) |
Sets this
Collidable 's local to world space Transform . |
void |
setUserData(java.lang.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 the
Collidable to the world space origin (0,0). |
addFixture, addFixture, getLocalCenter, getWorldCenter
public AbstractCollidable()
public AbstractCollidable(int fixtureCount)
Creates a new AbstractCollidable
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.
fixtureCount
- the estimated number of fixturespublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean removeFixture(T fixture)
Collidable
Fixture
from this Collidable
.removeFixture
in interface Collidable<T extends Fixture>
fixture
- the Fixture
Fixture
was removed from this Collidable
public T removeFixture(int index)
Collidable
Fixture
at the given index.removeFixture
in interface Collidable<T extends Fixture>
index
- the indexpublic java.util.List<T> removeAllFixtures()
Collidable
Collidable
and returns them.removeAllFixtures
in interface Collidable<T extends Fixture>
public boolean containsFixture(T fixture)
Collidable
Collidable
contains the given Fixture
.containsFixture
in interface Collidable<T extends Fixture>
fixture
- the fixturepublic void rotate(double theta, double x, double y)
Rotatable
public void rotate(double theta, Vector2 point)
Rotatable
public void rotate(double theta)
Rotatable
public void rotateAboutCenter(double theta)
Collidable
about its center of mass.rotateAboutCenter
in interface Collidable<T extends Fixture>
theta
- the angle of rotation in radianspublic void translate(double x, double y)
Translatable
translate
in interface Translatable
x
- the translation in the x directiony
- the translation in the y directionpublic void translate(Vector2 vector)
Translatable
translate
in interface Translatable
vector
- the translation along a vectorpublic void translateToOrigin()
Collidable
Collidable
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 Collidable
so
that the center is at the origin.
translateToOrigin
in interface Collidable<T extends Fixture>
public void shift(Vector2 shift)
Shiftable
public T getFixture(int index)
Collidable
Fixture
at the given index.getFixture
in interface Collidable<T extends Fixture>
index
- the index of the Fixture
public T getFixture(Vector2 point)
Collidable
Fixture
in this Collidable
, 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 Collidable
.
getFixture
in interface Collidable<T extends Fixture>
point
- a world space pointpublic java.util.List<T> getFixtures(Vector2 point)
Collidable
Fixture
s in this Collidable
that contain the given point.
Returns an empty list if the point is not contained in any fixture in this Collidable
.
getFixtures
in interface Collidable<T extends Fixture>
point
- a world space pointpublic T removeFixture(Vector2 point)
Collidable
Fixture
in this Collidable
, 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 this Collidable
.
removeFixture
in interface Collidable<T extends Fixture>
point
- a world space pointpublic java.util.List<T> removeFixtures(Vector2 point)
Collidable
Fixture
s in this Collidable
that contain the given point and
returns them.
Returns an empty list if the point is not contained in any Fixture
in this Collidable
.
removeFixtures
in interface Collidable<T extends Fixture>
point
- a world space pointpublic int getFixtureCount()
Collidable
Fixture
s attached
to this Collidable
object.getFixtureCount
in interface Collidable<T extends Fixture>
public java.util.List<T> getFixtures()
Collidable
Fixture
s attached to this Collidable
.
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 Collidable.getFixtureIterator()
method instead.
getFixtures
in interface Collidable<T extends Fixture>
Collidable.getFixtureIterator()
public java.util.Iterator<T> getFixtureIterator()
Collidable
The returned iterator supports the remove
method.
getFixtureIterator
in interface Collidable<T extends Fixture>
public Transform getTransform()
Collidable
Transform
of this Collidable
.getTransform
in interface Collidable<T extends Fixture>
Transform
public double getRotationDiscRadius()
Collidable
Collidable
creates if rotated 360 degrees about its center.getRotationDiscRadius
in interface Collidable<T extends Fixture>
public void setTransform(Transform transform)
Collidable
Collidable
's local to world space Transform
.
If the given transform is null, this method returns immediately.
setTransform
in interface Collidable<T extends Fixture>
transform
- the transformpublic java.lang.Object getUserData()
DataContainer
getUserData
in interface DataContainer
public void setUserData(java.lang.Object userData)
DataContainer
setUserData
in interface DataContainer
userData
- the user datapublic java.util.UUID getId()
Collidable
Collidable
.
This identifier is constant for the life of this Collidable
.
getId
in interface Collidable<T extends Fixture>
public AABB createAABB()
Collidable
AABB
from this Collidable
's attached Fixture
s.
If there are no fixtures attached, a degenerate AABB, (0.0, 0.0) to (0.0, 0.0), is returned.
createAABB
in interface Collidable<T extends Fixture>
AABB
public AABB createAABB(Transform transform)
Collidable
AABB
from this Collidable
's attached Fixture
s using the given
world space Transform
.
If there are no fixtures attached, a degenerate AABB, (0.0, 0.0) to (0.0, 0.0), is returned.
createAABB
in interface Collidable<T extends Fixture>
transform
- the world space Transform
AABB
public Vector2 getLocalPoint(Vector2 worldPoint)
Collidable
Collidable
given
a point in world coordinates.getLocalPoint
in interface Collidable<T extends Fixture>
worldPoint
- a world space pointVector2
local space pointpublic Vector2 getWorldPoint(Vector2 localPoint)
Collidable
Collidable
.getWorldPoint
in interface Collidable<T extends Fixture>
localPoint
- a point in the local coordinates of this Collidable
Vector2
world space pointpublic Vector2 getLocalVector(Vector2 worldVector)
Collidable
Collidable
given
a vector in world coordinates.getLocalVector
in interface Collidable<T extends Fixture>
worldVector
- a world space vectorVector2
local space vectorpublic Vector2 getWorldVector(Vector2 localVector)
Collidable
Collidable
.getWorldVector
in interface Collidable<T extends Fixture>
localVector
- a vector in the local coordinates of this Collidable
Vector2
world space vectorpublic boolean contains(Vector2 point)
Collidable
Collidable
.
The point is contained in this Collidable
if and only if the point is contained
in one of this Collidable
's Fixture
s.
contains
in interface Collidable<T extends Fixture>
point
- the world space test point