Package com.csse3200.game.physics
Class PhysicsEngine
java.lang.Object
com.csse3200.game.physics.PhysicsEngine
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
Process game physics using the Box2D library. See the Box2D documentation for examples or use
cases.
-
Constructor Summary
ConstructorDescriptionPhysicsEngine
(com.badlogic.gdx.physics.box2d.World world, GameTime timeSource) -
Method Summary
Modifier and TypeMethodDescriptionvoid
com.badlogic.gdx.physics.box2d.Body
createBody
(com.badlogic.gdx.physics.box2d.BodyDef bodyDef) com.badlogic.gdx.physics.box2d.Joint
createJoint
(com.badlogic.gdx.physics.box2d.JointDef jointDef) void
destroyBody
(com.badlogic.gdx.physics.box2d.Body body) void
destroyJoint
(com.badlogic.gdx.physics.box2d.Joint joint) void
dispose()
com.badlogic.gdx.physics.box2d.World
getWorld()
boolean
raycast
(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask, RaycastHit hit) Cast a ray in a straight line from one point to another, checking for a collision against colliders in the specified layers.boolean
raycast
(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, RaycastHit hit) Cast a ray in a straight line from one point to another, checking for a collision against any colliders.raycastAll
(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to) Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.raycastAll
(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask) Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.com.badlogic.gdx.physics.box2d.Fixture
raycastGetHit
(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask) Cast a ray in a straight line from one point to another, checking for a collision against colliders in the specified layers.void
update()
-
Constructor Details
-
PhysicsEngine
public PhysicsEngine() -
PhysicsEngine
-
-
Method Details
-
update
public void update() -
createBody
public com.badlogic.gdx.physics.box2d.Body createBody(com.badlogic.gdx.physics.box2d.BodyDef bodyDef) -
destroyBody
public void destroyBody(com.badlogic.gdx.physics.box2d.Body body) -
createJoint
public com.badlogic.gdx.physics.box2d.Joint createJoint(com.badlogic.gdx.physics.box2d.JointDef jointDef) -
destroyJoint
public void destroyJoint(com.badlogic.gdx.physics.box2d.Joint joint) -
checkAndDeleteBodies
public void checkAndDeleteBodies() -
getWorld
public com.badlogic.gdx.physics.box2d.World getWorld() -
raycast
public boolean raycast(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, RaycastHit hit) Cast a ray in a straight line from one point to another, checking for a collision against any colliders.- Parameters:
from
- The starting point of the ray.to
- The end point of the ray.hit
- The raycast result will be stored in this class- Returns:
- true if a collider was hit, false otherwise.
-
raycast
public boolean raycast(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask, RaycastHit hit) Cast a ray in a straight line from one point to another, checking for a collision against colliders in the specified layers.- Parameters:
from
- The starting point of the ray.to
- The end point of the ray.hit
- The hit of the closest collider will be stored in this.layerMask
- The physics layer mask which specifies layers that can be hit. Other layers will be ignored.- Returns:
- true if a collider was hit, false otherwise.
-
raycastGetHit
public com.badlogic.gdx.physics.box2d.Fixture raycastGetHit(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask) Cast a ray in a straight line from one point to another, checking for a collision against colliders in the specified layers.- Parameters:
from
- The starting point of the ray.to
- The end point of the ray.layerMask
- The physics layer mask which specifies layers that can be hit. Other layers will be ignored.- Returns:
- The fixture of the closest collider hit by the ray, or null if no collider was hit.
-
raycastAll
public RaycastHit[] raycastAll(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to) Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.- Parameters:
from
- The starting point of the ray.to
- The end point of the ray.- Returns:
- All hits made by the ray, unordered. Empty if no hits were made.
-
raycastAll
public RaycastHit[] raycastAll(com.badlogic.gdx.math.Vector2 from, com.badlogic.gdx.math.Vector2 to, short layerMask) Cast a ray in a straight line from one point to another, checking for all collision against colliders in the specified layers.- Parameters:
from
- The starting point of the ray.to
- The end point of the ray.layerMask
- The physics layer mask which specifies layers that can be hit. Other layers will be ignored.- Returns:
- All hits made by the ray, unordered. Empty if no hits were made.
-
dispose
public void dispose()- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
-