Game Development Reference
In-Depth Information
The function simply iterates over the skinIndices and skinWeights arrays in our
data object and stores the four values for each vertex in the corresponding geometry
arrays. Note that although our JSON array has two bones per vertex, we still store
four values (the last two values as zero, {c = 0; d = 0;} ), so that our geometry
class can handle data with two to four bones per vertex.
We also save the data for bones and animation information in the geometry object.
Enhancing the StageObject class
Our StageObject class had two shortcomings:
It did not have any provision to handle child objects or tree hierarchy.
We used the rotation matrix but we know that our bone object in the bones
array uses quaternion rotations.
The following code shows the earlier use of modelMatrix to store rotations in
the x , y , and z axes:
StageObject.prototype.update=function(steps) {
mat4.identity(this.modelMatrix);
mat4.translate(this.modelMatrix, this.modelMatrix,
this.location);
mat4.rotateX(this.modelMatrix, this.modelMatrix,
this.rotationX);
mat4.rotateY(this.modelMatrix, this.modelMatrix,
this.rotationY);
mat4.rotateZ(this.modelMatrix, this.modelMatrix,
this.rotationZ);
}
Let's walk through the changes we have made to overcome the shortcomings. Open
primitive/StageObject.js in your editor, and take a look at the following code:
StageObject=function() {
...
this.parent = undefined;
this.children = [];
this.up = vec3.fromValues( 0, 1, 0 );
this.position = vec3.create();
this.quaternion = quat.create();
this.scale = vec3.fromValues(1,1,1 );
this.matrixWorld = mat4.create();
 
Search WWH ::




Custom Search