public class PhysicsComponent
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
class |
PhysicsComponent.AABB
a rectangular bounding volume
|
class |
PhysicsComponent.BoundingVolume
a super class for bounding volumes
|
static class |
PhysicsComponent.Collision
reflects the type or position of a collision
|
class |
PhysicsComponent.Sphere
a spherical bounding volume
|
Modifier and Type | Field and Description |
---|---|
float |
acceleration |
PhysicsComponent.BoundingVolume |
boundingVolume |
float |
gravity |
static int |
RECTANGULAR |
static int |
SPHERE |
float |
x_Vel |
float |
y_Vel |
Constructor and Description |
---|
PhysicsComponent(int boundingVolume,
float x,
float y,
float scale)
creates a new physics component
|
Modifier and Type | Method and Description |
---|---|
float[] |
getCollisionPoint(PhysicsComponent.Sphere a,
PhysicsComponent.Sphere b)
returns the point to which to reset the first object in case of collision
|
void |
handlePhysics(GameObject object,
double elapsedTime)
updates an objects bounding volume, position and reactes to collisions
|
PhysicsComponent.Collision |
intersects(PhysicsComponent.BoundingVolume a,
PhysicsComponent.BoundingVolume b)
checking for intersection between two bounding volumes
|
PhysicsComponent.Collision |
intersects(PhysicsComponent.Sphere sphere,
PhysicsComponent.AABB rect)
collision detection between a sphere and an axis aligned rectangle
|
PhysicsComponent.Collision |
intersects(PhysicsComponent.Sphere a,
PhysicsComponent.Sphere b)
checks for collsions between two spherical bounding volumes
|
void |
leapFrogIntegration(GameObject object,
double elapsedTime,
float damping)
updates an objects position using leap frog integration for more stable results than euler
|
void |
resolveSolidCollision(PhysicsComponent.Collision col,
GameObject player,
GameObject o)
resolves a collision with a solid object and a spherical one
|
public static final int SPHERE
public static final int RECTANGULAR
public float x_Vel
public float y_Vel
public float gravity
public float acceleration
public PhysicsComponent.BoundingVolume boundingVolume
public PhysicsComponent(int boundingVolume, float x, float y, float scale)
boundingVolume
- indicates the objects bounding volume, either spherical or rectangularx
- the x position of the bounding volume, should match the objects oney
- the y position of the bounding volume, should match the objects onescale
- the scale of the bounding volumepublic void handlePhysics(GameObject object, double elapsedTime)
object
- the object to updateelapsedTime
- the elapsed time since the last updatepublic void leapFrogIntegration(GameObject object, double elapsedTime, float damping)
object
- the object whose position should be updatedelapsedTime
- the elapsed time since the last updatedamping
- a damping factor that can be used to slow down the object eg. incase of jumpingpublic void resolveSolidCollision(PhysicsComponent.Collision col, GameObject player, GameObject o)
col
- the type of collision to resolveplayer
- the object with a spherical bounding volumeo
- the solid object, can be spherical or rectangularpublic PhysicsComponent.Collision intersects(PhysicsComponent.BoundingVolume a, PhysicsComponent.BoundingVolume b)
a
- the first bounding volumeb
- the second bounding volumepublic PhysicsComponent.Collision intersects(PhysicsComponent.Sphere sphere, PhysicsComponent.AABB rect)
sphere
- a spherical bounding volumerect
- an axis aligned rectangular bounding volumepublic PhysicsComponent.Collision intersects(PhysicsComponent.Sphere a, PhysicsComponent.Sphere b)
a
- the first sphereb
- the second spherepublic float[] getCollisionPoint(PhysicsComponent.Sphere a, PhysicsComponent.Sphere b)
a
- the first colliding sphere which should be moved out of the second objectb
- the second bounding volume which remains in place