public
class
PhysicsWorld
extends Object
java.lang.Object | |
↳ | com.viro.core.PhysicsWorld |
The PhysicsWorld encapsulates the physics simulation associated with the Scene
. Each
Scene automatically creates a PhysicsWorld upon construction. This object can be used to set
global physics properties like gravity.
For an extended discussion of physics in Viro, refer to the Physics Guide.
Nested classes | |
---|---|
interface |
PhysicsWorld.HitTestListener
Callback used when hit tests are completed. |
Public methods | |
---|---|
void
|
findCollisionsWithRayAsync(Vector from, Vector to, boolean closest, String tag, PhysicsWorld.HitTestListener callback)
Find collisions between the ray from from to to with any |
void
|
findCollisionsWithShapeAsync(Vector from, Vector to, PhysicsShape shape, String tag, PhysicsWorld.HitTestListener callback)
Find collisions between the |
void
|
setDebugDraw(boolean debugDraw)
Enable or disable physics 'debug draw' mode. |
void
|
setGravity(Vector gravity)
Set the constant gravity force to use in the physics simulation. |
void findCollisionsWithRayAsync (Vector from, Vector to, boolean closest, String tag, PhysicsWorld.HitTestListener callback)
Find collisions between the ray from from to to with any Node
objects
that have physics bodies. Each individual PhysicsBody
will receive in
its PhysicsBody.CollisionListener
a onCollided(String, Vector, Vector)
event upon collision. The event will contain the tag given to this intersection test.
Parameters | |
---|---|
from |
Vector : The source of the ray. |
to |
Vector : The destination of the ray. |
closest |
boolean : True to only collide with the closest object. |
tag |
String : The tag to use to identify this ray test in the onCollision callback of each PhysicsBody . |
callback |
PhysicsWorld.HitTestListener : The PhysicsWorld.HitTestListener to use, which will be invoked when the test is completed.
|
void findCollisionsWithShapeAsync (Vector from, Vector to, PhysicsShape shape, String tag, PhysicsWorld.HitTestListener callback)
Find collisions between the PhysicsShape
cast from from to to with
any Node
objects that have physics bodies. Each individual PhysicsBody
will
receive in its PhysicsBody.CollisionListener
a onCollided(String, Vector, Vector)
event
upon collision. The event will contain the tag given to this intersection test.
Parameters | |
---|---|
from |
Vector : The source of the ray. |
to |
Vector : The destination of the ray. |
shape |
PhysicsShape : The shape to use for the collision test. Only PhysicsShapeSphere and
PhysicsShapeBox are supported. |
tag |
String : The tag to use to identify this ray test in the onCollision callback
of each PhysicsBody . |
callback |
PhysicsWorld.HitTestListener : The PhysicsWorld.HitTestListener to use, which will be invoked when the test is
completed.
|
void setDebugDraw (boolean debugDraw)
Enable or disable physics 'debug draw' mode. When this mode is enabled, the physics shapes will be drawn around each object with a PhysicsBody. This is useful for understanding what approximations the physics simulation is using during its computations.
Parameters | |
---|---|
debugDraw |
boolean : True to enable debug draw mode.
|
void setGravity (Vector gravity)
Set the constant gravity force to use in the physics simulation. Gravity globally accelerates
physics bodies in a specific direction. This defaults to Earth's gravitational force: {0,
-9.81, 0}. Not all physics bodies need to respond to gravity: this can be set via setUseGravity(boolean)
.
Parameters | |
---|---|
gravity |
Vector : The gravity vector to use.
|