Game Development Reference
In-Depth Information
stage=new Stage(gl);
addStageObject("model/Monkey.json",[0.0,0.0,0.0],0.00,0.0,0.0);
initScene();
}
The addStageObject function has three parameters: url , location , and the rotation
of the object. After the JSON file is loaded, we initialize the stageObject , add it
to the main stage object, and invoke the drawScene function, as shown in the
following code:
function addStageObject(url,location,rotationX,
rotationY,rotationZ){
$.getJSON(url,function(data){
var stageObject=new StageObject();
stageObject.loadObject(data);
stageObject.location=location;
stageObject.rotationX=rotationX;
stageObject.rotationY=rotationY;
stageObject.rotationZ=rotationZ;
stage.addModel(stageObject);
//Invoke drawScene once the object is loaded.
drawScene();
});
}
The following code is to initialize general scene uniforms that have been split in two
functions; one for light uniforms and the second for perspective, ModelView matrices:
function setMatrixUniforms() {
gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false,
pMatrix);
gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false,
mvMatrix);
var invertMatrix = mat4.create();
mat4.invert(invertMatrix, mvMatrix);
var normalMatrix=mat4.create();
mat4.transpose(normalMatrix, invertMatrix)
gl.uniformMatrix4fv(shaderProgram.nMatrixUniform, false,
normalMatrix);
}
function setLightUniform(){
gl.uniform3f(shaderProgram.ambientColorUniform,0.1,0.1,0.1);
gl.uniform3f(shaderProgram.specularColorUniform,1.0,1.0,1.0);
var lightingDirection = [0,-1.25,-1.25];
gl.uniform3fv(shaderProgram.lightingDirectionUniform,
lightingDirection);
gl.uniform3f(shaderProgram.directionalColorUniform,0.5,0.5,0.5);
}
 
Search WWH ::




Custom Search