Game Development Reference
In-Depth Information
We first check whether an active rigidBody variable is assigned to the geometry. If it
is assigned, then we retrieve the position of the rigidBody variable using the this.
rigidBody.get_currentState().position function. We convert the position
of rigidBody to the vec3 object and set the location property of the sphere. The
modelMatrix parameter of the sphere is initialized to the identity matrix and then
the sphere's modelMatrix is translated by the rigidBody variable's position.
So basically, we change the location of the sphere to the rigidBody variable's
location, and if rigidBody for that object does not exist, then we use the object's
location and rotational values.
Open the 07-Simple-Physics-Sphere-Falling.html file in your editor.
We initialize our physics engine in the init_jiglib() function. This function is
invoked when the graphics library is initialized in the start() function:
function start() {
...
init_jiglib();
...
}
function init_jiglib() {
system = jigLib.PhysicsSystem.getInstance();
system.setCollisionSystem(); // CollisionSystemBrute
system.setSolverType("FAST");
system.setGravity(jigLib.Vector3DUtil.create( 0, -9.8, 0, 0 )
);
var ground = new jigLib.JPlane();
ground.set_y(0);
ground.set_rotationX(90);
ground.set_movable(false);
system.addBody(ground);
}
In the init_jiglib() function, we first initialize our physics engine and then
initialize our collision system using the brute force algorithm (each object is checked
for collision) and set the solver type to FAST . Then, we initialize gravity in our system
( system.setGravity(jigLib.Vector3DUtil.create( 0, -9.8, 0, 0 ) ); ). As
the physics system follows the upward direction along the y axis, we set our gravity
to a negative value.
 
Search WWH ::




Custom Search