Game Development Reference
In-Depth Information
The initialize function of the class calculates the initialModelMatrix from the
camera matrix, resets the counter and visibility, and initializes the positions array
as shown in the following code:
Grenade.prototype.initialize=function(positions) {
var mMatrix=mat4.clone(this.camera.viewMatrix);
mat4.invert(this.initialModelMatrix,mMatrix);
this.counter=0;
this.visible=true;
this.positions=positions;
//mat4.translate(this.modelMatrix,mMatrix,vec3.
fromValues(0,-3,-8));
}
The update function is exactly the same as the one in the Bullet class. It simply
calculates the model matrix from intialModelMatrix and the current active
position from the positions array on each update call from drawScene .
Grenade.prototype.update=function() {
if(this.counter<this.positions.length-1){
mat4.translate(this.modelMatrix,this.initialModelMatrix,this.
positions[this.counter]);
this.counter=this.counter+1;
}
else{
this.visible=false;
}
}
Open 06-Grenade-Action.html in your editor to understand the implementation
of the preceding classes.
We start with the declaration of variables to hold the objects of the grenade and our
left hand.
var leftHand=null;
var grenade=null;
Then, we define the control points to calculate interpolated values for the grenade
animation and also define the grenadePositions array to store the interpolates.
Note that these control points are in respect to the camera position.
var grenadeControlPoints=[[-1.5,-2,-10],[-1.5,10,-30],[-1.5,15,-40],
[-1.5,10,-60],[-1.5,0,-80]];
var grenadePositions=[];
 
Search WWH ::




Custom Search