HTML and CSS Reference
In-Depth Information
moved into this new class, so we can keep our main document clean. Here's the Point3d class we use
throughout this chapter and the next (file point3d.js ):
function Point3d (x, y, z) {
this.x = (x === undefined) ? 0 : x;
this.y = (y === undefined) ? 0 : y;
this.z = (z === undefined) ? 0 : z;
this.fl = 250; //focal length
this.vpX = 0; //vanishing point
this.vpY = 0;
this.cX = 0; //center
this.cY = 0;
this.cZ = 0;
}
Point3d.prototype.setVanishingPoint = function (vpX, vpY) {
this.vpX = vpX;
this.vpY = vpY;
};
Point3d.prototype.setCenter = function (cX, cY, cZ) {
this.cX = cX;
this.cY = cY;
this.cZ = cZ;
};
Point3d.prototype.rotateX = function (angleX) {
var cosX = Math.cos(angleX),
sinX = Math.sin(angleX),
y1 = this.y * cosX - this.z * sinX,
z1 = this.z * cosX + this.y * sinX;
this.y = y1;
this.z = z1;
};
Point3d.prototype.rotateY = function (angleY) {
var cosY = Math.cos(angleY),
sinY = Math.sin(angleY),
x1 = this.x * cosY - this.z * sinY,
z1 = this.z * cosY + this.x * sinY;
this.x = x1;
this.z = z1;
};
Point3d.prototype.rotateZ = function (angleZ) {
var cosZ = Math.cos(angleZ),
sinZ = Math.sin(angleZ),
x1 = this.x * cosZ - this.y * sinZ,
y1 = this.y * cosZ + this.x * sinZ;
this.x = x1;
 
Search WWH ::




Custom Search