毕业论文 论文提纲 论文写作 公文范例 教育论文 教育学论文 师范教育 学术论文     论文指导*
                     
 
   
   
   
   
           
 

当前位置:课件115学培吧(kj115.com)→flash网侠教程(助你成为顶尖课件高手)→系列文章

 
 
标题:Flash Mx编程与创意实现:二维、三维矢量类
 
展示台

文章来源 作者:admin 密码:admin 整理:湖北金鹰

◇网侠教程栏目简介
    提供FLASH侠客教程和网页制作侠客教程,高手进阶教程。
    浏览过这些资源的还浏览过经典教程图文教程游戏开发教程等相关资源。

---------------

湖北金鹰课件吧

论文相关服务
 

 

声明:切务用于商业用途,只供学习和参考
二维矢量
//Vector 构造函数
_global.Vector = function(x, y) {
this.x = x;
this.y = y;
};
//对矢量重新赋值
Vector.prototype.reset = function(x, y) {
this.constrUCtor(x, y);
}
//向量相加,原向量改变;
Vector.prototype.plus = function(v) {
this.x += v.x;
this.y += v.y;
};
//向量向量相加,返回新向量,原向量不变
Vector.prototype.plusNew = function(v) {
with (this) {
return new constructor(x+v.x, y+v.y);
}
};
//向量相减,原向量改变;
Vector.prototype.minus = function(v) {
this.x -= v.x;
this.y -= v.y;
};
//向量向量相减,返回新向量,原向量不变
Vector.prototype.minusNew = function(v) {
with (this) {
return new constructor(x-v.x, y-v.y);
}
};
//向量求逆,返回新向量
Vector.prototype.negateNew = function() {
with (this) {
return new constructor(x=-x, y=-y);
}
};
//向量求逆,改变原向量
Vector.prototype.negate = function() {
with (this) {
x = -x;
y = -y;
}
};
//向量缩放,改变原向量
Vector.prototype.scale = function(s) {
this.x *= s;
this.y *= s;
};
//向量缩放,返回新向量
Vector.prototype.scaleNew = function(s) {
with (this) {
return new constructor(x*s, y*s);
}
};
//向量的长度
Vector.prototype.getLength = function() {
with (this) {
return Math.sqrt(x*x+y*y);
}
};
//设置向量的长度
Vector.prototype.setLength = function(length) {
var l = this.getLength();
if (l) {
this.x *= (length/l);
this.y *= (length/l);
} else {
(this.x=length);
}
};
//向量的角度
Vector.prototype.getAngle = function() {
return Math.atan2(this.y, this.x)*180/Math.PI;
};
//角度制▲函数
cosD = function (angle) {
return Math.cos(angle*Math.PI/180);
};
sinD = function (angle) {
return Math.sin(angle*Math.PI/180);
}
//向量的旋转,原向量改变
Vector.prototype.rotate = function(angle) {
var ca = cosD(angle);
var sa = sinD(angle);
with (this) {
var rx = x*ca-y*sa;
var ry = x*sa+y*ca;
x = rx;
y = ry;
}
};
//向量旋转,返回新向量
Vector.prototype.rotateNew1 = function(angle) {
var ca = cosD(angle);
var sa = sinD(angle);
with (this) {
var rx = x*ca-y*sa;
var ry = x*sa+y*ca;
return new constructor(rx, ry);
}
}
//向量旋转,返回新向量的第二种方法;
Vector.prototype.rotateNew = function(angle) {
var v = new this.constructor(this.x, this.y);
v.rotate(angle);
return v;
};
//点积
Vector.prototype.dot = function(v) {
with (this) {
return x*v.x+y*v.y;
}
};
//向量夹角
Vector.prototype.angleBetween = function(v) {
var d = this.dot(v);
var r1 = this.getLength();
var r2 = v.getLength();
return Math.acos(d/(r1*r2))*180/Math.PI;
};
三维矢量
_global.Vector3d = function(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
};
Vector3d.prototype.reset = function(x, y, z) {
return this.constructor(x, y, z);
};
//向量相加
Vector3d.prototype.plus = function(v) {
this.x += v.x;
this.y += v.y;
this.z += v.z;
};
Vector3d.prototype.plusNew = function(v) {
with (this) {
return new constructor(x+v.x, y+v.y, z+v.z);
}
};
// 向量相减
Vector3d.prototype.minus = function(v) {
this.x -= v.x;
this.y -= v.y;

this.z -= v.z;
};
Vector3d.prototype.minusNew = function(v) {
with (this) {
return new constructor(x-v.x, y-v.y, z-v.z);
}
};
//向量逆转
Vector3d.prototype.negate = function() {
        this.x *= -1;
        this.y *= -1;
        this.z *= -1;
};
Vector.prototype.negateNw = function() {
        wirh(this);
        return new constructor(-x, -y, -z);
};
//向量缩放
Vector3d.prototype.scale = function(s) {
        this.x *= s;
        this.y*s;
        this.z*s;
};
Vector3d.prototype.scaleNew = function(s) {
        with (this) {
                return new constructor(x*s, y*s, z*s);
}
};
//向量的长度
Vector3d.prototype.getLength = function() {
with (this) {
return Math.sqrt(x*x+y*y+z*z);
}
};
Vector3d.prototype.setLength = function(len) {
var r = this.getLength();
if (r) {
with (this) {
return new constructor(x*len/r, y*len/r, z*len/r);
}
} else {
this.x = len; }
};
//向量的点积
Vector3d.prototype.dot = function(v) {
with (this) {

return x*v.x+y*v.y+z*v.z;
}
};
//向量的叉积
Vector3d.prototype.cross = function(v) {
with (this) {
var cx = y*v.z-z*v.y;
var cy = z*v.x-x*v.z;
var cz = x*v.y-y*v.x;
return new constructor(cx, cy, cz);
}
};
//向量的夹角
Vector3d.prototype.angleBetween = function(v) {
var dp = this.dot(v);
var r1 = this.getLength();
var r2 = v.getLength();
return Math.acos(dp/(r1*r2))*180/Math.PI;
};
Vector3d.prototype.angleBetween1 = function(v) {
var a = this.cross(v);
var dp = a.getLength();
var r1 = this.getLength();
var r2 = v.getLength();
return Math.asin(dp/(r1*r2))*180/Math.PI;
};

//透视比例
Vector3d.prototype.getPerspective = function(viewDist) {
if (viewDiat == undefined) {
viewDist = 300;
}
return viewDist/(viewDist+this.z);
};
//向量的投影到xy平面上
Vector3d.prototype.persProject = function(p) {
if (p == undefined) {
p = this.getPerspective();
}
this.x *= p;
this.y *= p;
this.z = 0;
};
Vector3d.prototype.persProjectNew = function(p) {
if (p=undefined) {
p = this.getPerspective();
}
with (this) {
return new constructor(x*p, y*p, 0);
}
};
//向量的旋转
//绕x轴
Vector3d.prototype.rotateX = function(angle) {
var ca = Math.cos(angle*Math.PI/180);
var sa = Math.sin(angle*Math.PI/180);
with (this) {
y = y*ca-z*sa;
z = y*sa+z*ca;
x = x;
}
};
Vector3d.prototype.rotateXTrig = function(ca, sa) {
with (this) {
y = y*ca-z*sa;
z = y*sa+z*ca;
x = x;
}
};
//绕y轴
Vector3d.prototype.rotateY = function(angle) {
var ca = Math.cos(angle*Math.PI/180);
var sa = Math.sin(angle*Math.PI/180);
with (this) {
var tempz = z*ca-x*sa;
var tempx = z*sa+x*ca;
z = tempz;
x = tempx;
}
};
Vector3d.prototype.rotateYTrig = function(ca, sa) {
with (this) {
var tempz = z*ca-x*sa;
var tempx = z*sa+x*ca;
z = tempz;
x = tempx;
}
};
//绕着Z轴转
Vector3d.prototype.rotateZ = function(angle) {
var ca = Math.cos(angle*Math.PI/180);
var sa = Math.sin(angle*Math.PI/180);
with (this) {
var tempx = x*ca-y*sa;
var tempy = x*sa+y*ca;
x = tempx;
y = tempy;
}
};
Vector3d.prototype.rotateZTrig = function(ca, sa) {
with (this) {
var tempx = x*ca-y*sa;
var tempy = x*sa+y*ca;
x = tempx;
y = tempy;
y = tempy;
}
};
//绕xy旋转
Vector3d.prototype.rotateXY = function(a, b) {
var sa = Math.sin(a*Math.PI/180);
var ca = Math.cos(a*Math.PI/180);
var sb = Math.sin(b*Math.PI/180);
var cb = Math.cos(b*Math.PI/180);
with (this) {
//绕x轴
var rz = y*sa+z*ca;
y = y*ca-z*sa;
//绕y轴转
z = rz*cb-x*sb;
x = rz*sb+x*cb;
}
};
Vector3d.prototype.rotateXYZ = function(a, b, c) {
var sa = Math.sin(a*Math.PI/180), ca = Math.cos(a*Math.PI/180);
var sb = Math.sin(b*Math.PI/180), cb = Math.cos(b*Math.PI/180);
var sc = Math.sin(c*Math.PI/180), cc = Math.cos(c*Math.PI/180);
with (this) {
//绕x轴
var ry = y*ca-z*sa;
var rz = z*sa+z*ca;
//绕y轴
var rx = rz*sb+x*cb;
z = rz*cb-x*sb;
//绕z轴
x = rx*cc-ry*sc;
y = rx*sc+ry*cc;
}
};
Vector3d.prototype.rotateXYZTrig = function(ca, sa, cb, sb, cc, sc) {
with (this) {
var ry = y*ca-z*sa;
var rz = y*sa+z*ca;
var rx = rz*sb+x*cb;
z = rz*cb-x*sb;

x = rx*cc-ry*sc;
y = rx*sc+ry*cc;
}
};
这一部分和二维的是相似的,就不作太多的文字说明了,如有错漏,望见谅,希望大家都能作出漂亮的flash作品

 

 

 
课件115学培吧(湖北金鹰)欢迎您!永久免费服务网址:http://www.kj115.com
   
 

学员众多的FLASH课件学习基地,成万免费FLASH课件制作教程在线学习,还有免费内容课件教程、视频教程、课件技巧、课件探讨、课件欣赏、课件展示、实用教程、课件界面、课件脚本、课件游戏、课件下载、课件封面、课文内容图片、课文人物图片库、课件素材、图片素材、声音素材、动物素材、背景图片、背景资料、背景边框、课件顶栏图片素材、Dreamweaver教程、Dreamweaver网页课件教程、软件下载。承接学习和培训,承接课件订制,课件修改等所有课件相关服务。
本站主要业务:┃flash课件制作视频教程培训┃承接全国竞赛flash课件┃论文代写代发┃代办课件国家级获奖证书┃
联系:QQ:444860709 手机:13339817386


 
 

业务办理
鄂ICP备08005724号