Game Development Reference
In-Depth Information
The next set of functions are setters for the clipping planes and field of view. The
near clip plane has to be a positive value. The field of view value has to be between
0 and 180 degrees. The far clipping plane should not be set to an extremely large
value. This can create depth buffer precision problems such as z-fighting. For more
information about the depth buffer, refer to http://www.opengl.org/resources/
faq/technical/depthbuffer.htm .
Camera.prototype.setFarClippingPlane =function (fcp)
{
if (fcp > 0)
{
this.farClippingPlane = fcp;
}
}
Camera.prototype.setFieldOfView =function (fov)
{
if (fov > 0 && fov < 180)
{
this.fieldOfView = fov;
}
}
Camera.prototype.setNearClippingPlane =function (ncp)
{
if (ncp > 0)
{
this.nearClippingPlane = ncp;
}
}
The apply function takes the aspect ratio as a parameter and computes the matrices,
as shown in the following code:
Camera.prototype.apply =function (aspectRatio)
{
var matView=mat4.create();
var lookAtPosition=vec3.create();
vec3.add(lookAtPosition,this.pos, this.dir);
mat4.lookAt(matView, this.pos, lookAtPosition, this.up);
mat4.translate(matView,matView,vec3.fromValues(-this.pos[0], -this.
pos[1], -this.pos[2]));
this.viewMatrix = matView;
// Create a projection matrix and store it inside a globally
accessible place.
this.projMatrix=mat4.create();
mat4.perspective(this.projMatrix, degToRadian(this.fieldOfView),
aspectRatio, this.nearClippingPlane, this.farClippingPlane)));
}
 
Search WWH ::




Custom Search