public final class PhysicsEngine extends java.lang.Object implements IUpdateable
move
method
group.
collides
method group can detect a collision at a certain location, for rectangles, or collision aware entities.
Also, there's an overload that takes a Line2D
to perform a basic raycast check.Constructor and Description |
---|
PhysicsEngine()
You should never call this manually! Instead use the
Game.physics() instance. |
Modifier and Type | Method and Description |
---|---|
void |
add(ICollisionEntity entity)
Adds the specified collision aware entity to the physics engine which will make it respect the entity's collision box for upcoming calls.
|
void |
clear()
Clears all previously registered participants in the collision process from this instance.
|
boolean |
collides(double x,
double y)
Checks if the point at the given coordinates collides with anything registered in the
PhysicsEngine . |
boolean |
collides(double x,
double y,
Collision collision)
Checks if the point at the given coordinates collides with anything of the given
Collision type. |
boolean |
collides(double x,
double y,
ICollisionEntity entity)
Checks if a given
ICollisionEntity collides with anything that intersects specific coordinates. |
boolean |
collides(ICollisionEntity entity)
Checks if a given
ICollisionEntity collides with anything registered in the PhysicsEngine . |
boolean |
collides(ICollisionEntity entity,
Collision collision)
Checks if a given
ICollisionEntity collides with anything of the given Collision type. |
boolean |
collides(java.awt.geom.Line2D line)
Checks if a given line collides with anything registered in the
PhysicsEngine . |
boolean |
collides(java.awt.geom.Line2D line,
Collision collision)
Checks if a line collides with anything of the given
Collision type. |
boolean |
collides(java.awt.geom.Line2D line,
Collision collision,
ICollisionEntity entity)
Checks if a given
ICollisionEntity collides with any ICollisionEntities of a given Collision type that intersect a
specific line. |
boolean |
collides(java.awt.geom.Line2D line,
ICollisionEntity entity)
Checks if a given
ICollisionEntity collides with anything that intersects a specific line. |
boolean |
collides(java.awt.geom.Point2D location)
Checks if a given point collides with anything registered in the
PhysicsEngine . |
boolean |
collides(java.awt.geom.Point2D location,
Collision collision)
Checks if a point collides with anything of the given
Collision type. |
boolean |
collides(java.awt.geom.Point2D location,
Collision collision,
ICollisionEntity entity)
Checks if a given
ICollisionEntity collides with any ICollisionEntities of a given Collision type that intersect a
specific point. |
boolean |
collides(java.awt.geom.Point2D location,
ICollisionEntity entity)
Checks if a given
ICollisionEntity collides with anything that intersects a specific point. |
boolean |
collides(java.awt.geom.Rectangle2D rect)
Checks if a given rectangle collides with anything registered in the
PhysicsEngine . |
boolean |
collides(java.awt.geom.Rectangle2D rect,
Collision collision)
Checks if a rectangle collides with anything of the given
Collision type. |
boolean |
collides(java.awt.geom.Rectangle2D rect,
Collision collision,
ICollisionEntity entity)
Checks if a given
ICollisionEntity collides with any ICollisionEntities of a given Collision type that intersect a
specific rectangle. |
boolean |
collides(java.awt.geom.Rectangle2D rect,
ICollisionEntity entity)
Checks if a given
ICollisionEntity collides with anything that intersects a specific rectangle. |
java.awt.geom.Rectangle2D |
getBounds()
Gets the environment bounds that confine the operation area of the
PhysicsEngine . |
java.util.Collection<java.awt.geom.Rectangle2D> |
getCollisionBoxes()
Gets all
CollisionBoxes , regardless of their Collision type. |
java.util.Collection<java.awt.geom.Rectangle2D> |
getCollisionBoxes(Collision type)
Gets all
CollisionBoxes with the given Collision type. |
java.util.Collection<ICollisionEntity> |
getCollisionEntities()
Gets all
ICollisionEntities , regardless of their Collision type. |
java.util.Collection<ICollisionEntity> |
getCollisionEntities(Collision type)
Gets all
ICollisionEntities with the given Collision type. |
boolean |
move(IMobileEntity entity,
Direction direction,
double distance)
Moves the specified entity by a given distance and angle.
|
boolean |
move(IMobileEntity entity,
double angle,
double distance)
Moves the specified entity by a given distance and angle.
|
boolean |
move(IMobileEntity entity,
double x,
double y,
float distance)
Moves the specified entity by a given distance towards the target coordinates.
|
boolean |
move(IMobileEntity entity,
float distance)
Moves the specified entity by a given distance and the entity's angle.
|
boolean |
move(IMobileEntity entity,
java.awt.geom.Point2D target)
Moves the specified entity to a target point.
|
boolean |
move(IMobileEntity entity,
java.awt.geom.Point2D target,
float distance)
Moves the specified entity by a given distance towards the target coordinates.
|
RaycastHit |
raycast(java.awt.geom.Line2D line)
Cast a ray along a given line [from (x1,y1) to (x2,y2)] and see if it hits anything.
|
RaycastHit |
raycast(java.awt.geom.Line2D line,
Collision collision)
Cast a ray along a given line [from (x1,y1) to (x2,y2)] and see if it hits anything with the given
Collision type. |
RaycastHit |
raycast(java.awt.geom.Line2D line,
Collision collision,
ICollisionEntity entity)
Cast a ray along a given line [from (x1,y1) to (x2,y2)] and see if it hits anything with a certain
Collision type that collides with the
given ICollisionEntity . |
RaycastHit |
raycast(java.awt.geom.Line2D line,
ICollisionEntity entity)
Cast a ray along a given line [from (x1,y1) to (x2,y2)] and see if it hits a given
ICollisionEntity . |
RaycastHit |
raycast(java.awt.geom.Point2D start,
double angle)
From a given point, cast a ray of indefinite length with the given angle and see if it hits anything.
|
RaycastHit |
raycast(java.awt.geom.Point2D start,
java.awt.geom.Point2D target)
From a given point, cast a ray to another point and see if it hits anything.
|
RaycastHit |
raycast(java.awt.geom.Point2D start,
java.awt.geom.Point2D target,
Collision collision)
From a given point, cast a ray to another point and see if it hits anything with the given
Collision type. |
void |
remove(ICollisionEntity entity)
Removes the specified entity from any collision processing.
|
void |
setBounds(java.awt.geom.Rectangle2D environmentBounds)
Sets the environment bounds that confine the operation area of the
PhysicsEngine . |
void |
update()
Clears all collision boxes registered on the
PhysicsEngine once per tick and re-adds them with their updated positions. |
public PhysicsEngine()
You should never call this manually! Instead use the Game.physics()
instance.
Game.physics()
public void add(ICollisionEntity entity)
If you add a ICollisionEntiy
to your Environment, it will automatically be added to the the PhysicsEngine. There is typically no
need to call this explicitly.
entity
- The collision entity to be added.ICollisionEntity.getCollisionBox()
,
remove(ICollisionEntity)
public void remove(ICollisionEntity entity)
entity
- The entity that is about to be removed.public void clear()
public java.util.Collection<java.awt.geom.Rectangle2D> getCollisionBoxes()
CollisionBoxes
, regardless of their Collision
type.Collection
of all CollisionBox
es registered on the PhysicsEngine
.public java.util.Collection<java.awt.geom.Rectangle2D> getCollisionBoxes(Collision type)
CollisionBoxes
with the given Collision
type.type
- The Collision
type by which the CollisionBoxes
are selected.Collision
type is NONE
, return an empty set. Otherwise, a Collection
of all CollisionBoxes
registered on the PhysicsEngine
that have the given Collision
type.public java.util.Collection<ICollisionEntity> getCollisionEntities()
ICollisionEntities
, regardless of their Collision
type.Collection
of all ICollisionEntities
registered on the PhysicsEngine
.public java.util.Collection<ICollisionEntity> getCollisionEntities(Collision type)
ICollisionEntities
with the given Collision
type.type
- The Collision
type by which the ICollisionEntities
are selected.Collision
type is NONE
, return an empty set. Otherwise, a Collection
of all ICollisionEntities
registered on the PhysicsEngine
that have the given Collision
type.public java.awt.geom.Rectangle2D getBounds()
PhysicsEngine
.Rectangle2D
confining the operation area of the PhysicsEngine
.public void setBounds(java.awt.geom.Rectangle2D environmentBounds)
PhysicsEngine
.environmentBounds
- The Rectangle2D
confining the operation area of the PhysicsEngine
.public boolean collides(java.awt.geom.Line2D line)
PhysicsEngine
.line
- The Line2D
to check for collision.true
if the line collides with anything. false
otherwise.public boolean collides(java.awt.geom.Line2D line, Collision collision)
Collision
type.line
- The Line2D
to check for collision.collision
- The Collision
type to check for collisions.true
if the line collides with anything of the given Collision
type. false
otherwise.Collision
public boolean collides(java.awt.geom.Line2D line, ICollisionEntity entity)
ICollisionEntity
collides with anything that intersects a specific line.line
- The Line2D
to check for collision.entity
- The ICollisionEntity
to check for collision.true
if any ICollisionEntity
intersecting the line collides with the given ICollisionEntity
. false
otherwise.Collision
,
ICollisionEntity
public boolean collides(java.awt.geom.Line2D line, Collision collision, ICollisionEntity entity)
ICollisionEntity
collides with any ICollisionEntities
of a given Collision
type that intersect a
specific line.line
- The Line2D
to check for collision.collision
- The Collision
type to check for collision.entity
- The ICollisionEntity
to check for collision.true
if the entity collides with any ICollisionEntity
on the given line. false
otherwise.Collision
,
ICollisionEntity
public boolean collides(java.awt.geom.Rectangle2D rect)
PhysicsEngine
.rect
- The Rectangle2D
to check for collision.true
if the rectangle collides with anything. false
otherwise.public boolean collides(java.awt.geom.Rectangle2D rect, ICollisionEntity entity)
ICollisionEntity
collides with anything that intersects a specific rectangle.rect
- The Rectangle2D
to check for collision.entity
- The ICollisionEntity
to check for collision.true
if the entity collides with any ICollisionEntity
in the given rectangle. false
otherwise.ICollisionEntity
public boolean collides(java.awt.geom.Rectangle2D rect, Collision collision)
Collision
type.rect
- The Rectangle2D
to check for collision.collision
- The Collision
type to check for collisions.true
if the rectangle collides with anything of the given Collision
type. false
otherwise.Collision
public boolean collides(java.awt.geom.Rectangle2D rect, Collision collision, ICollisionEntity entity)
ICollisionEntity
collides with any ICollisionEntities
of a given Collision
type that intersect a
specific rectangle.rect
- The Rectangle2D
to check for collision.collision
- The Collision
type to check for collision.entity
- The ICollisionEntity
to check for collision.true
if the entity collides with any ICollisionEntity
in the given rectangle. false
otherwise.Collision
,
ICollisionEntity
public boolean collides(java.awt.geom.Point2D location)
PhysicsEngine
.location
- The Point2D
to check for collision.true
if the point collides with anything. false
otherwise.public boolean collides(java.awt.geom.Point2D location, Collision collision)
Collision
type.location
- The Point2D
to check for collision.collision
- The Collision
type to check for collisions.true
if the point collides with anything of the given Collision
type. false
otherwise.Collision
public boolean collides(java.awt.geom.Point2D location, ICollisionEntity entity)
ICollisionEntity
collides with anything that intersects a specific point.location
- The Point2D
to check for collision.entity
- The ICollisionEntity
to check for collision.true
if the entity collides with any ICollisionEntity
on the given point. false
otherwise.ICollisionEntity
public boolean collides(java.awt.geom.Point2D location, Collision collision, ICollisionEntity entity)
ICollisionEntity
collides with any ICollisionEntities
of a given Collision
type that intersect a
specific point.location
- The Point2D
to check for collision.collision
- The Collision
type to check for collision.entity
- The ICollisionEntity
to check for collision.true
if the entity collides with any ICollisionEntity
on the given point. false
otherwise.Collision
,
ICollisionEntity
public boolean collides(double x, double y)
PhysicsEngine
.x
- The x coordinate to check for collision.y
- The y coordinate to check for collision.true
if the coordinates collide with anything. false
otherwise.public boolean collides(double x, double y, Collision collision)
Collision
type.x
- The x coordinate to check for collision.y
- The y coordinate to check for collision.collision
- The Collision
type to check for collisions.true
if the coordinates collide with anything of the given Collision
type. false
otherwise.Collision
public boolean collides(double x, double y, ICollisionEntity entity)
ICollisionEntity
collides with anything that intersects specific coordinates.x
- The x coordinate to check for collision.y
- The y coordinate to check for collision.entity
- The ICollisionEntity
to check for collision.true
if the entity collides with any ICollisionEntity
on the given coordinates. false
otherwise.ICollisionEntity
public boolean collides(ICollisionEntity entity)
ICollisionEntity
collides with anything registered in the PhysicsEngine
.entity
- The ICollisionEntity
to check for collision.true
if the entity collides with any other ICollisionEntity
. false
otherwise.ICollisionEntity
public boolean collides(ICollisionEntity entity, Collision collision)
ICollisionEntity
collides with anything of the given Collision
type.entity
- The ICollisionEntity
to check for collision.collision
- The Collision
type to check for collisions.true
if the entity collides with anything of the given Collision
type. false
otherwise.Collision
public RaycastHit raycast(java.awt.geom.Point2D start, double angle)
start
- The start point of the raycast.angle
- The angle in degrees.RaycastHit
determining the hit point, ray length, and corresponding ICollisionEntity
, if the ray hit something.public RaycastHit raycast(java.awt.geom.Point2D start, java.awt.geom.Point2D target)
start
- The start point of the raycast.target
- The end point of the raycast.RaycastHit
determining the hit point, ray length, and corresponding ICollisionEntity
, if the ray hit something.public RaycastHit raycast(java.awt.geom.Point2D start, java.awt.geom.Point2D target, Collision collision)
Collision
type.start
- The start point of the raycast.target
- The end point of the raycast.collision
- The Collision
type to check for collision.RaycastHit
determining the hit point, ray length, and corresponding ICollisionEntity
, if the ray hit something.public RaycastHit raycast(java.awt.geom.Line2D line)
line
- The line along which the ray is cast.RaycastHit
determining the hit point, ray length, and corresponding ICollisionEntity
, if the ray hit something.public RaycastHit raycast(java.awt.geom.Line2D line, Collision collision)
Collision
type.line
- The line along which the ray is cast.collision
- The Collision
type to check for collision.RaycastHit
determining the hit point, ray length, and corresponding ICollisionEntity
, if the ray hit something.public RaycastHit raycast(java.awt.geom.Line2D line, ICollisionEntity entity)
ICollisionEntity
.line
- The line along which the ray is cast.entity
- The ICollisionEntity
type to check for collision.RaycastHit
determining the hit point, ray length, and corresponding ICollisionEntity
.public RaycastHit raycast(java.awt.geom.Line2D line, Collision collision, ICollisionEntity entity)
Collision
type that collides with the
given ICollisionEntity
.line
- The line along which the ray is cast.collision
- The Collision
type to check for collision.entity
- The ICollisionEntity
type to check for collision.RaycastHit
determining the hit point, ray length, and corresponding ICollisionEntity
.public boolean move(IMobileEntity entity, double angle, double distance)
entity
- The entity which is movedangle
- The angle in degreesdistance
- The distance to move the entitytrue
, if the entity can be moved without colliding, otherwise false
.GeometricUtilities.project(Point2D, double, double)
public boolean move(IMobileEntity entity, Direction direction, double distance)
entity
- The IMobileEntity
which is moveddirection
- The Direction
in which the entity is moveddistance
- The distance to move the entitytrue
, if the entity can be moved without colliding, otherwise false
.Direction
public boolean move(IMobileEntity entity, double x, double y, float distance)
entity
- The IMobileEntity
which is movedx
- The target x coordinatey
- The target y coordinatedistance
- The distance to move the entitytrue
, if the entity can be moved without colliding, otherwise false
.public boolean move(IMobileEntity entity, float distance)
entity
- The IMobileEntity
which is moveddistance
- The distance to move the entitytrue
, if the entity can be moved without colliding, otherwise false
.Direction
public boolean move(IMobileEntity entity, java.awt.geom.Point2D target)
entity.turnOnMove()
is true
, set the entity's angle towards the target.entity
- The IMobileEntity
which is movedtarget
- The target pointtrue
, if the entity can be moved without colliding, otherwise false
.resolveCollisionForNewPosition(de.gurkenlabs.litiengine.entities.ICollisionEntity, java.awt.geom.Point2D)
public boolean move(IMobileEntity entity, java.awt.geom.Point2D target, float distance)
entity.turnOnMove()
is true
, set the entity's
angle towards the target.entity
- The IMobileEntity
which is movedtarget
- The target pointdistance
- The distance to move the entitytrue
, if the entity can be moved without colliding, otherwise false
.resolveCollisionForNewPosition(de.gurkenlabs.litiengine.entities.ICollisionEntity, java.awt.geom.Point2D)
public void update()
PhysicsEngine
once per tick and re-adds them with their updated positions.update
in interface IUpdateable
ClientConfiguration.setMaxFps(int)