关于3d效果的实现!

      技术交流 2004-12-29 0:55
这是我最近完成的一个demo.
用移动鼠标控制蛇的位置,滚动滑轮控制z轴距离。
演示地址:http://lgqn.sdut.edu.cn/ipage/victboy/3dRopeDemo5.html

源文件下载地址:http://lgqn.sdut.edu.cn/ipage/victboy/3dRopeDemo5.zip

在主影片第一帧添加如下as代码:
/**************初始化变量******************/
//x,y,z方向的偏移量;
xoff = 0;
yoff = 0;
zoff = 0;
//投影面与观察着的距离;
d = 800;
//投影位置;
centerX = 275;
centerY = 200;
//余玄函数角度;
ang = 0;
//实现函数;
function project() {
if ((this.z-zoff)<40) {
this._visible = false;
} else {
this._visible = true;
var zfactor = d/(this.z-zoff);
//计算物体x,y的投影距离和大小;
this._x = (this.x-xoff)*zfactor+centerX;
this._y = (this.y-yoff)*zfactor+centerY;
this._xscale = 100*zfactor;
this._yscale = 100*zfactor;
//修正深度;
this.swapDepths(Math.floor(100000-(this.z-zoff)));
//计算物体颜色;
var percentage = 100-((this.z-zoff)/2000*100);
this.ctrans.ra = percentage;
this.ctrans.ga = percentage;
this.ctrans.ba = percentage;
this.c.setTransform(this.ctrans);
}
}
//将库中的物体元件读入舞台;
for (var i = 0; i<40; i++) {
var nm = "sphere"+i;
_root.attachMovie("sphere", nm, i);
_root[nm].x = Math.cos(ang)*200;
ang += 0.2;
_root[nm].y = 100+Math.cos(i/3)*100;
_root[nm].y = 400;
_root[nm].z = (i*50)+d;
_root[nm].project = project;
_root[nm].myAngle = i;
var percentage = 100-(_root[nm].z/2000*100);
_root[nm].c = new Color(_root[nm]);
_root[nm].ctrans = new Object();
_root[nm].ctrans.ra = percentage;
_root[nm].ctrans.ga = percentage;
_root[nm].ctrans.ba = percentage;
_root[nm].c.setTransform(_root[nm].ctrans);
_root[nm].onEnterFrame = function() {
this.y = 100+Math.cos(this.myAngle/3)*100;
this.myAngle -= 0.4;
this.project();
};
}
//创建鼠标听诊器;
mouseListener = new Object();
mouseListener.onMouseWheel = function(diff) {
zoff += (diff*50);
};
mouseListener.onMouseMove = function() {
xoff = _xmouse-centerX;
yoff = _ymouse-centerY;
};
Mouse.addListener(mouseListener);
_quality = "LOW";
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}