public class PhysicsSpace
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
PhysicsSpace.BroadphaseType
Enumerate the available acceleration structures for broadphase collision
detection.
|
Modifier and Type | Field and Description |
---|---|
static int |
AXIS_X
index of the X axis
|
static int |
AXIS_Y
index of the Y axis
|
static int |
AXIS_Z
index of the Z axis
|
Constructor and Description |
---|
PhysicsSpace()
Instantiate a PhysicsSpace.
|
PhysicsSpace(PhysicsSpace.BroadphaseType broadphaseType)
Instantiate a PhysicsSpace.
|
PhysicsSpace(Vector3f worldMin,
Vector3f worldMax)
Instantiate a PhysicsSpace.
|
PhysicsSpace(Vector3f worldMin,
Vector3f worldMax,
PhysicsSpace.BroadphaseType broadphaseType)
Instantiate a PhysicsSpace.
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.Object obj)
Add the specified object to this space.
|
void |
addAll(Spatial spatial)
Add all collision objects and joints in the specified subtree of the
scene graph to this space (e.g.
|
void |
addCollisionGroupListener(PhysicsCollisionGroupListener listener,
int collisionGroup)
Register the specified collision-group listener with the specified
collision group of this space.
|
void |
addCollisionListener(PhysicsCollisionListener listener)
Register the specified collision listener with this space.
|
void |
addCollisionObject(PhysicsCollisionObject obj)
Add the specified collision object to this space.
|
void |
addTickListener(PhysicsTickListener listener)
Register the specified tick listener with this space.
|
void |
create()
Must be invoked on the designated physics thread.
|
void |
destroy()
Destroy this space so that a new one can be instantiated.
|
void |
distributeEvents()
Distribute each collision event to all listeners.
|
<V> java.util.concurrent.Future<V> |
enqueue(java.util.concurrent.Callable<V> callable)
Invoke the specified callable during the next physics tick.
|
static <V> java.util.concurrent.Future<V> |
enqueueOnThisThread(java.util.concurrent.Callable<V> callable)
Enqueue a callable on the currently executing thread.
|
protected void |
finalize()
Finalize this physics space just before it is destroyed.
|
float |
getAccuracy()
Read the accuracy (time step) of the physics simulation.
|
PhysicsSpace.BroadphaseType |
getBroadphaseType()
Read the type of acceleration structure used.
|
java.util.Collection<PhysicsCharacter> |
getCharacterList()
Copy the list of physics characters that have been added to this space
and not yet removed.
|
java.util.Collection<PhysicsGhostObject> |
getGhostObjectList()
Copy the list of ghost objects that have been added to this space and not
yet removed.
|
Vector3f |
getGravity(Vector3f gravity)
Copy the gravitational acceleration acting on newly-added bodies.
|
java.util.Collection<PhysicsJoint> |
getJointList()
Copy the list of physics joints that have been added to this space and
not yet removed.
|
static PhysicsSpace |
getPhysicsSpace()
Access the PhysicsSpace running on this thread.
|
int |
GetRayTestFlags()
Reads m_flags used in ray tests.
|
java.util.Collection<PhysicsRigidBody> |
getRigidBodyList()
Copy the list of rigid bodies that have been added to this space and not
yet removed.
|
int |
getSolverNumIterations()
Read the number of iterations used by the contact-and-constraint solver.
|
long |
getSpaceId()
// * used internally //
|
java.util.Collection<PhysicsVehicle> |
getVehicleList()
Copy the list of physics vehicles that have been added to this space and
not yet removed.
|
Vector3f |
getWorldMax()
Access the maximum coordinate values for this space.
|
Vector3f |
getWorldMin()
Access the minimum coordinate values for this space.
|
static void |
initNativePhysics() |
void |
rayTest_native(Vector3f from,
Vector3f to,
long physicsSpaceId,
java.util.List<PhysicsRayTestResult> results,
int flags) |
java.util.List<PhysicsRayTestResult> |
rayTest(Vector3f from,
Vector3f to)
Perform a ray-collision test and return the results as a list of
PhysicsRayTestResults sorted by ascending hitFraction.
|
java.util.List<PhysicsRayTestResult> |
rayTest(Vector3f from,
Vector3f to,
java.util.List<PhysicsRayTestResult> results)
Perform a ray-collision test and return the results as a list of
PhysicsRayTestResults sorted by ascending hitFraction.
|
java.util.List<PhysicsRayTestResult> |
rayTestRaw(Vector3f from,
Vector3f to)
Perform a ray-collision test and return the results as a list of
PhysicsRayTestResults in arbitrary order.
|
java.util.List<PhysicsRayTestResult> |
rayTestRaw(Vector3f from,
Vector3f to,
java.util.List<PhysicsRayTestResult> results)
Perform a ray-collision test and return the results as a list of
PhysicsRayTestResults in arbitrary order.
|
void |
remove(java.lang.Object obj)
Remove the specified object from this space.
|
void |
removeAll(Spatial spatial)
Remove all physics controls and joints in the specified subtree of the
scene graph from the physics space (e.g.
|
void |
removeCollisionGroupListener(int collisionGroup)
De-register the specified collision-group listener.
|
void |
removeCollisionListener(PhysicsCollisionListener listener)
De-register the specified collision listener.
|
void |
removeCollisionObject(PhysicsCollisionObject obj)
Remove the specified collision object from this space.
|
void |
removeTickListener(PhysicsTickListener listener)
De-register the specified tick listener.
|
void |
setAccuracy(float accuracy)
Alter the accuracy (time step) of the physics simulation.
|
void |
setBroadphaseType(PhysicsSpace.BroadphaseType broadphaseType)
Alter the type of acceleration structure used.
|
void |
setGravity(Vector3f gravity)
Alter the gravitational acceleration acting on newly-added bodies.
|
static void |
setLocalThreadPhysicsSpace(PhysicsSpace space)
Used internally
|
void |
setMaxSubSteps(int steps)
Alter the maximum number of physics steps per frame.
|
void |
SetRayTestFlags(int flags)
Alters the m_flags used in ray tests.
|
void |
setSolverNumIterations(int numIterations)
Alter the number of iterations used by the contact-and-constraint solver.
|
void |
setWorldMax(Vector3f worldMax)
only applies for AXIS_SWEEP broadphase
|
void |
setWorldMin(Vector3f worldMin)
Alter the minimum coordinate values for this space.
|
void |
sweepTest_native(long shape,
Transform from,
Transform to,
long physicsSpaceId,
java.util.List<PhysicsSweepTestResult> results,
float allowedCcdPenetration) |
java.util.List<PhysicsSweepTestResult> |
sweepTest(CollisionShape shape,
Transform start,
Transform end)
Perform a sweep-collision test and return the results as a new list.
|
java.util.List<PhysicsSweepTestResult> |
sweepTest(CollisionShape shape,
Transform start,
Transform end,
java.util.List<PhysicsSweepTestResult> results)
Perform a sweep-collision test and store the results in an existing list.
|
java.util.List<PhysicsSweepTestResult> |
sweepTest(CollisionShape shape,
Transform start,
Transform end,
java.util.List<PhysicsSweepTestResult> results,
float allowedCcdPenetration)
Perform a sweep-collision test and store the results in an existing list.
|
void |
update(float time)
Update this space.
|
void |
update(float time,
int maxSteps)
Simulate for the specified time interval, using no more than the
specified number of steps.
|
public static final int AXIS_X
public static final int AXIS_Y
public static final int AXIS_Z
public PhysicsSpace()
public PhysicsSpace(PhysicsSpace.BroadphaseType broadphaseType)
public PhysicsSpace(Vector3f worldMin, Vector3f worldMax)
public PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType)
worldMin
- the desired minimum coordinates values (not null,
unaffected, default=-10k,-10k,-10k)worldMax
- the desired minimum coordinates values (not null,
unaffected, default=10k,10k,10k)broadphaseType
- which broadphase collision-detection algorithm to
use (not null)public static PhysicsSpace getPhysicsSpace()
public static void setLocalThreadPhysicsSpace(PhysicsSpace space)
space
- which physics space to simulate on this threadpublic void create()
public void update(float time)
time
- time-per-frame multiplied by speed (in seconds, ≥0)public void update(float time, int maxSteps)
time
- the time interval (in seconds, ≥0)maxSteps
- the maximum number of steps (≥1)public void distributeEvents()
public static <V> java.util.concurrent.Future<V> enqueueOnThisThread(java.util.concurrent.Callable<V> callable)
V
- the task's result typecallable
- the task to be executedpublic <V> java.util.concurrent.Future<V> enqueue(java.util.concurrent.Callable<V> callable)
V
- the return type of the callablecallable
- which callable to invokepublic void add(java.lang.Object obj)
obj
- the PhysicsControl, Spatial-with-PhysicsControl,
PhysicsCollisionObject, or PhysicsJoint to add (not null, modified)public void addCollisionObject(PhysicsCollisionObject obj)
obj
- the PhysicsCollisionObject to add (not null, modified)public void remove(java.lang.Object obj)
obj
- the PhysicsCollisionObject to add, or null (modified)public void removeCollisionObject(PhysicsCollisionObject obj)
obj
- the PhysicsControl or Spatial with PhysicsControl to removepublic void addAll(Spatial spatial)
spatial
- the root of the subtree (not null)public void removeAll(Spatial spatial)
spatial
- the root of the subtree (not null)public java.util.Collection<PhysicsRigidBody> getRigidBodyList()
public java.util.Collection<PhysicsGhostObject> getGhostObjectList()
public java.util.Collection<PhysicsCharacter> getCharacterList()
public java.util.Collection<PhysicsJoint> getJointList()
public java.util.Collection<PhysicsVehicle> getVehicleList()
public void setGravity(Vector3f gravity)
Whenever a rigid body is added to a space, the body's gravity gets set to that of the space. Thus it makes sense to set the space's vector before adding any bodies to the space.
gravity
- the desired acceleration vector (not null, unaffected)public Vector3f getGravity(Vector3f gravity)
gravity
- storage for the result (not null, modified)public void addTickListener(PhysicsTickListener listener)
Tick listeners are notified before and after each physics step. A physics step is not necessarily the same as a frame; it is more influenced by the accuracy of the physics space.
listener
- the listener to register (not null)setAccuracy(float)
public void removeTickListener(PhysicsTickListener listener)
listener
- the listener to de-register (not null)addTickListener(com.jme3.bullet.PhysicsTickListener)
public void addCollisionListener(PhysicsCollisionListener listener)
Collision listeners are notified when collisions occur in the space.
listener
- the listener to register (not null, alias created)public void removeCollisionListener(PhysicsCollisionListener listener)
listener
- the listener to de-register (not null)addCollisionListener(com.jme3.bullet.collision.PhysicsCollisionListener)
public void addCollisionGroupListener(PhysicsCollisionGroupListener listener, int collisionGroup)
Such a listener can disable collisions when they occur. There can be only one listener per collision group per space.
listener
- the listener to register (not null)collisionGroup
- which group it should listen for (bit mask with
exactly one bit set)public void removeCollisionGroupListener(int collisionGroup)
collisionGroup
- the group of the listener to de-register (bit mask
with exactly one bit set)addCollisionGroupListener(com.jme3.bullet.collision.PhysicsCollisionGroupListener,
int)
public java.util.List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to)
from
- the starting location (physics-space coordinates, not null,
unaffected)to
- the ending location (in physics-space coordinates, not null,
unaffected)public java.util.List<PhysicsRayTestResult> rayTestRaw(Vector3f from, Vector3f to)
from
- the starting location (in physics-space coordinates, not
null, unaffected)to
- the ending location (in physics-space coordinates, not null,
unaffected)public void SetRayTestFlags(int flags)
flags
- the desired flags, ORed together (default=0x4)public int GetRayTestFlags()
public java.util.List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, java.util.List<PhysicsRayTestResult> results)
from
- coordinates of the starting location (in physics space, not
null, unaffected)to
- coordinates of the ending location (in physics space, not null,
unaffected)results
- the list to hold results (not null, modified)public java.util.List<PhysicsRayTestResult> rayTestRaw(Vector3f from, Vector3f to, java.util.List<PhysicsRayTestResult> results)
from
- coordinates of the starting location (in physics space, not
null, unaffected)to
- coordinates of the ending location (in physics space, not null,
unaffected)results
- the list to hold results (not null, modified)public void rayTest_native(Vector3f from, Vector3f to, long physicsSpaceId, java.util.List<PhysicsRayTestResult> results, int flags)
public java.util.List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end)
The starting and ending locations must be at least 0.4f physics-space units apart.
A sweep test will miss a collision if it starts inside an object and sweeps away from the object's center.
shape
- the shape to sweep (not null)start
- the starting physics-space transform (not null)end
- the ending physics-space transform (not null)public java.util.List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, java.util.List<PhysicsSweepTestResult> results)
The starting and ending locations must be at least 0.4f physics-space units apart.
A sweep test will miss a collision if it starts inside an object and sweeps away from the object's center.
shape
- the shape to sweep (not null)start
- the starting physics-space transform (not null)end
- the ending physics-space transform (not null)results
- the list to hold results (not null, modified)public void sweepTest_native(long shape, Transform from, Transform to, long physicsSpaceId, java.util.List<PhysicsSweepTestResult> results, float allowedCcdPenetration)
public java.util.List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, java.util.List<PhysicsSweepTestResult> results, float allowedCcdPenetration)
The starting and ending locations must be at least 0.4f physics-space units apart.
A sweep test will miss a collision if it starts inside an object and sweeps away from the object's center.
shape
- the shape to sweep (not null)start
- the starting physics-space transform (not null)end
- the ending physics-space transform (not null)results
- the list to hold results (not null, modified)allowedCcdPenetration
- true→allow, false→disallowpublic void destroy()
public long getSpaceId()
public PhysicsSpace.BroadphaseType getBroadphaseType()
public void setBroadphaseType(PhysicsSpace.BroadphaseType broadphaseType)
broadphaseType
- the desired algorithm (not null)public void setMaxSubSteps(int steps)
Extra physics steps help maintain determinism when the render fps drops below 1/accuracy. For example a value of 2 can compensate for frame rates as low as 30fps, assuming the physics has an accuracy of 1/60 sec.
Setting this value too high can depress the frame rate.
steps
- the desired maximum number of steps per frame (≥1,
default=4)public float getAccuracy()
public void setAccuracy(float accuracy)
In general, the smaller the time step, the more accurate (and compute-intensive) the simulation will be. Bullet works best with a time step of no more than 1/60 second.
accuracy
- the desired time step (in seconds, >0, default=1/60)public Vector3f getWorldMin()
public void setWorldMin(Vector3f worldMin)
worldMin
- the desired minimum coordinate values (not null,
unaffected)public Vector3f getWorldMax()
public void setWorldMax(Vector3f worldMax)
worldMax
- public void setSolverNumIterations(int numIterations)
Use 4 for low quality, 20 for high quality.
numIterations
- the desired number of iterations (≥1, default=10)public int getSolverNumIterations()
public static void initNativePhysics()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- ignored by the garbage collector