Game Development Reference
In-Depth Information
To tackle the first point, we defined the force by the vector [0, 300, -1200]; 300 will
counter -98 of gravity, and -1200 will move the grenade in the -Z direction with
respect to the camera space.
The second point requires some understanding of the camera matrix. In Chapter 5 ,
Camera and User Interaction , we described the structure of a camera matrix:
Hence, if we want to remove the position element from the camera matrix, we can set
m30 (12), m31 (13), and m32 (14) to 0. This is what the extractOrientation function
does. It removes the position component from the camera matrix.
Now to get the final force applied with the correct direction, we transform the
force vector with the orientation matrix ( initialModelMatrix with the 0 position,
this.extractOrientation(this.initialModelMatrix); var force= jigLib.
GLMatrix.multiplyVec3(this.initialModelMatrix,[0,300,-1200]); ).
The position of the force is the location of the rigid body in the world space ( pos ),
and the function addWordlForce of the rigidBody class is used to apply force
( this.rigidBody.addWorldForce (force,jigLib.Vector3DUtil.create
(pos.x,pos.y,pos.z)); ). The initializePhysics function is shown in the
following code:
Grenade.prototype.initializePhysics=function(){
var sphere = new jigLib.JSphere(null, 10);
sphere.set_mass(10);
this.rigidBody=sphere;
var newPos=jigLib.GLMatrix.multiplyVec3(this.initialModelMatrix,
[-1.5,-2,-10]);
this.rigidBody.moveTo(jigLib.Vector3DUtil.create(newPos[0],
newPos[1],newPos[2]));
var pos = this.rigidBody.get_currentState().position;
this.extractOrientation(this.initialModelMatrix);
// var force=jigLib.GLMatrix.multiplyVec3
(this.initialModelMatrix,[0,300,-1200]);
var impulse=jigLib.GLMatrix.multiplyVec3
(this.initialModelMatrix,[0,180,-800]);
//this.rigidBody.addWorldForce(jigLib.Vector3DUtil.
create(force[0],force[1],force[2]),jigLib.Vector3DUtil.
create(pos.x,pos.y,pos.z));
 
Search WWH ::




Custom Search