繁体中文
设为首页
加入收藏
当前位置:网站制作首页 >> Flash教程 >> 3D Matrix Class

3D Matrix Class

2007-10-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:// ------------------- // 3D Matrix Class // ------------------- //Matrix3Dconstructor //------------------ functionmatrix3D(){ this.element=newArray(); this.createBase(); this.vCount=0; } //Basec...
关键字:Matrix Class 3D

// -------------------

// 3D Matrix Class

// -------------------

//Matrix3Dconstructor

//------------------

functionmatrix3D(){

this.element=newArray();

this.createBase();

this.vCount=0;

}

//Basecreation

//-------------

matrix3D.prototype.createBase=function(){

this.base=newArray();

this.base[1]=newArray(1,0,0);

this.base[2]=newArray(0,1,0);

this.base[3]=newArray(0,0,1);

}

//Addingavector

//---------------

matrix3D.prototype.addVector=function(x,y,z){

this.vCount++;

this.element[this.vCount]=newArray();

this.element[this.vCount][1]=x;

this.element[this.vCount][2]=y;

this.element[this.vCount][3]=z;

}

//Deletingavector

//---------------

matrix3D.prototype.delVector=function(index,count){

if(!count)count=1;

this.element.splice(index,count);

this.vCount-=count;

}

//Gettinganelement’svalue

//--------------------------

matrix3D.prototype.get=function(row,column){

return(this.element[row][column]);

}

//Settinganelement’svalue

//--------------------------

matrix3D.prototype.set=function(row,column,arg){

this.element[row][column]=arg;

}

//RotationaroundtheXaxis

//--------------------------

//Itmultiplicateseachvector(dotmultiplication)bythetransformationmatrix:

//

//100

//0cos?-sin?

//0sin?cos?

//

//So,itwillresultthematrixtransformedby:

//

//x’=x

//y’=(cos?)*y-(sin?)*z

//z’=(sin?)*y+(cos?)*z

//

matrix3D.prototype.Xrotation=function(beta){

for(variVector=1;iVector<=this.vCount;iVector++){

this.element[iVector][2]=((Math.cos(beta))*this.element[iVector][2])-((Math.sin(beta))*this.element[iVector][3]);

this.element[iVector][3]=((Math.sin(beta))*this.element[iVector][2])+((Math.cos(beta))*this.element[iVector][3]);

}

}

//RotationaroundtheYaxis

//--------------------------

//TransformationMatrix:

//

//cos?0sin?

//010

//-sin?0cos?

//

matrix3D.prototype.Yrotation=function(beta){

for(variVector=1;iVector<=this.vCount;iVector++){

this.element[iVector][1]=((Math.cos(beta))*this.element[iVector][1])+((Math.sin(beta))*this.element[iVector][3]);

this.element[iVector][3]=(-(Math.sin(beta))*this.element[iVector][1])+((Math.cos(beta))*this.element[iVector][3]);

}

}

//RotationaroundtheZaxis

//--------------------------

//TransformationMatrix:

//

//cos?-sin?0

//sin?cos?0

//001

//

matrix3D.prototype.Zrotation=function(beta){

for(variVector=1;iVector<=this.vCount;iVector++){

this.element[iVector][1]=((Math.cos(beta))*this.element[iVector][1])-((Math.sin(beta))*this.element[iVector][2]);

this.element[iVector][2]=((Math.sin(beta))*this.element[iVector][1])+((Math.cos(beta))*this.element[iVector][2]);

}

}

//BaseTranslation

//----------------

matrix3D.prototype.translate=function(x,y,z){

this.base[1]=newArray(x,0,0);

this.base[2]=newArray(0,y,0);

this.base[3]=newArray(0,0,z);

}

责任编辑:admin
相关文章