Game Development Reference
In-Depth Information
this.vbo.numItems = this.geometry.vertices.length/3;
gl.bindBuffer(gl.ARRAY_BUFFER, this.nbo);
gl.bufferData(gl.ARRAY_BUFFER, new
Float32Array(this.geometry.normals), gl.STATIC_DRAW);
this.nbo.itemSize = 3;
this.nbo.numItems = this.geometry.normals.length/3;
},
The last function of this class is
clone
. This function creates copy of its local variables
and returns a new
StageObject
. The
clone
function invokes the
clone
function
of the
Geometry
class and the later invokes the
clone
function of the
Face
class, as
shown in the following code:
clone:function(){
var stageObject=new StageObject();
stageObject.geometry=this.geometry.clone();
var i;
for(i=0;i<this.diffuseColor.length;++i){
stageObject.diffuseColor[i]=this.diffuseColor[i];
}
for(i=0;i<this.ambientColor.length;++i){
stageObject.ambientColor[i]=this.ambientColor[i];
}
for(i=0;i<this.specularColor.length;++i){
stageObject.specularColor[i]=this.specularColor[i];
}
stageObject.rotationX=this.rotationX;
stageObject.rotationY=this.rotationY;
stageObject.rotationZ=this.rotationZ;
stageObject.loaded=true;
return stageObject;
}
Implementing Stage.js
The
Stage
class holds the array of stage objects as well as the initialized WebGL
context in the variable
gl,
as shown in the following code:
Stage = function (gl) {
this.stageObjects=[];
this.gl=gl;
};