Package ecs
Class PolygonCollider
java.lang.Object
ecs.Component
ecs.PolygonCollider
- All Implemented Interfaces:
Comparable<Component>
,Collider
A polygon collider for a
GameObject
.
Collision detection uses GJK in MathUtils.gjksmCollision(PrimitiveShape, PrimitiveShape)
.
Must not be mixed with other colliders.- Since:
- 06.12.2021
- Author:
- Juyas
-
Nested Class Summary
Nested classes/interfaces inherited from class ecs.Component
Component.ComponentOrder
-
Field Summary
Fields inherited from class ecs.Component
gameObject
-
Constructor Summary
ConstructorDescriptionPolygonCollider
(PrimitiveShape shape) PolygonCollider
(PrimitiveShape shape, boolean passive) -
Method Summary
Modifier and TypeMethodDescriptionboolean
canCollideWith
(Collider other) Determines whether a collider could potentially intersect with another collider ONLY by their collision layers.detectCollision
(Collider collider) Determines whether a collider intersects with another collider IGNORING the collision layers.getShape()
The shape of the collider.boolean
hasMask
(int layer) Determines whether a collision mask for a specified layer is enabled.boolean
isOnLayer
(int layer) Determines whether the collider exists in a specified layer.layer
(int... layers) Sets multiple layers at once for handy usage.short
layers()
A short containing all enabled layers encoded as bit mask.short
mask()
A short containing all enabled masks encoded as bit mask.mask
(int... masks) Sets multiple masks at once for handy usage.boolean
passive()
Defines the behaviour of this collider.void
setLayer
(int layer, boolean active) Change the colliders presence in a specified layer.void
setMask
(int layer, boolean active) Changes the collision mask entry for a specified layer.void
setShape
(PrimitiveShape shape) Overwrite the shape of the collider.void
start()
Called once on Component initialization.void
update
(float dt) Called once per frame for each Component
-
Constructor Details
-
PolygonCollider
-
PolygonCollider
-
-
Method Details
-
layer
Sets multiple layers at once for handy usage.- Parameters:
layers
- all layers that should be set.- Returns:
- the collider itself, to chain the call.
-
mask
Sets multiple masks at once for handy usage.- Parameters:
masks
- all layers that should be set.- Returns:
- the collider itself, to chain the call.
-
setShape
Overwrite the shape of the collider. Use with caution.- Parameters:
shape
- the new shape.
-
start
public void start()Description copied from class:Component
Called once on Component initialization. -
getShape
Description copied from interface:Collider
The shape of the collider. -
detectCollision
Description copied from interface:Collider
Determines whether a collider intersects with another collider IGNORING the collision layers.- Specified by:
detectCollision
in interfaceCollider
- Parameters:
collider
- the other collider- Returns:
- an object containing the result of collision detection
-
canCollideWith
Description copied from interface:Collider
Determines whether a collider could potentially intersect with another collider ONLY by their collision layers. This method can be considered part of the broad phase of collision detection.- Specified by:
canCollideWith
in interfaceCollider
- Parameters:
other
- the other collider- Returns:
- true if and only if both objects could potentially collide
-
layers
public short layers()Description copied from interface:Collider
A short containing all enabled layers encoded as bit mask. Should be usable to compare different masks with each other to check for intersection. -
mask
public short mask()Description copied from interface:Collider
A short containing all enabled masks encoded as bit mask. Should be usable to compare different masks with each other to check for intersection. -
hasMask
public boolean hasMask(int layer) Description copied from interface:Collider
Determines whether a collision mask for a specified layer is enabled. -
isOnLayer
public boolean isOnLayer(int layer) Description copied from interface:Collider
Determines whether the collider exists in a specified layer. -
setLayer
public void setLayer(int layer, boolean active) Description copied from interface:Collider
Change the colliders presence in a specified layer. Making a collider present in a specified layer will it enable to collide with all collider including the specified layer in their collision mask. -
setMask
public void setMask(int layer, boolean active) Description copied from interface:Collider
Changes the collision mask entry for a specified layer. Enabling the mask for layer n will allow this collider to collide with any other collider set in the target layer n vise versa. -
passive
public boolean passive()Description copied from interface:Collider
Defines the behaviour of this collider. A passive collider will never get checked against others colliders, however any collider might get checked against it. -
update
public void update(float dt) Description copied from class:Component
Called once per frame for each Component
-