快速导航:   教程资源  | 经典范例  | 友情链接  | 联系我们  | 官方微博
登陆 | 注册

 flash 3d 研究所
flash3d 研究所 pv3d 教程 研究所小贴士: 用colladaMax导出DAE的兄弟们,一定记得先去下载cg-toolkit










最近更新:
● wan925446570阁下在讨论区里 回复“怎么配置away3d 4.0运行环境啊?...”(15:12:45)
● wan925446570阁下在讨论区里 回复“怎么配置away3d 4.0运行环境啊?...”(10:01:38)
● DDM君阁下在讨论区里 回复“怎么配置away3d 4.0运行环境啊?...”(19:07:43)
浏览主题:问个基础的问题;

问个基础的问题;
中华 (2009-10-17 17:06:26)

d = 700;
var homeRx = 0;
var homeRy = 0;
var homeRz = 0;

var groundRx = 0;
var groundRy = 0;
var groundRz = 0;

centerX = Stage.width/2;
centerY = Stage.height/2;

xObj = [70, -70, -70, 70, 70, -70, -70, 70, 75, -75, -75, 75, 75, -75, -75, 75, 120, -120, 120, -120];
yObj = [-50, -50, 50, 50, -50, -50, 50, 50, -50, -50, 50, 50, -50, -50, 50, 50, 50, 50, 50, 50];
zObj = [-50, -50, -50, -50, 50, 50, 50, 50, -55, -55, -55, -55, 55, 55, 55, 55];

groundX = [100, -100, -100, 100];
groundY = [50, 50, 50, 50];
groundZ = [-100, -100, 100, 100];

function TD(x, y, z, rotx, roty, rotz) {
     var sx = Math.sin(rotx);
     var cx = Math.cos(rotx);
     var sy = Math.sin(roty);
     var cy = Math.cos(roty);
     var sz = Math.sin(rotz);
     var cz = Math.cos(rotz);
     var xy, xz, yx, yz, zx, zy, ratio;
     xy = cx*y-sx*z;
     xz = sx*y+cx*z;
     yz = cy*xz-sy*x;
     yx = sy*xz+cy*x;
     zx = cz*yx-sz*xy;
     zy = sz*yx+cz*xy;
     var zfactor = _root.d/(_root.d+yz);
     x2 = zx*zfactor;
     y2 = zy*zfactor;
     return [x2, y2];
}
function homeProject() {
     if (this.z-zoff<40) {
           this._visible = false;
     } else {
           this._visible = true;
           A1 = TD(this.x, this.y, this.z, _root.homeRx, _root.homeRy, _root.homeRz);
           this._x = A1[0]+centerX;
           this._y = A1[1]+centerY;
     }
}
function groundProject() {
     if (this.z-zoff<40) {
           this._visible = false;
     } else {
           this._visible = true;
           A1 = TD(this.x, this.y, this.z, _root.groundRx, _root.groundRy, _root.groundRz);
           this._x = A1[0]+centerX;
           this._y = A1[1]+centerY;
     }
}
_root.createEmptyMovieClip("home_mc",100);
_root.createEmptyMovieClip("ground_mc",99);
for (var i = 0; i      var nm = "sphere"+(i-(-1));
     _root.home_mc.attachMovie("sphere",nm,i);
     _root.home_mc[nm].x = xObj[i];
     _root.home_mc[nm].y = yObj[i];
     _root.home_mc[nm].z = zObj[i];
     _root.home_mc[nm].onEnterFrame = homeProject;
     if (i<4) {
           _root.ground_mc.attachMovie("sphere",nm,i);
           _root.ground_mc[nm].x = groundX[i];
           _root.ground_mc[nm].y = groundY[i];
           _root.ground_mc[nm].z = groundZ[i];
           _root.ground_mc[nm].onEnterFrame = groundProject;
     }
}
_root.home_mc.onEnterFrame = function() {
     if (Key.isDown(Key.LEFT)) {
           _root.homeRy += 0.1;
     }
     if (Key.isDown(Key.RIGHT)) {
           _root.homeRy -= 0.1;
     }
     if (Key.isDown(Key.UP)) {
           _root.homeRx += 0.1;
     }
     if (Key.isDown(Key.DOWN)) {
           _root.homeRx -= 0.1;
     }
     this.clear();
     var fangzi_col = 0xFFFCE6;
     var fangzi_alpha = 30;
     this.lineStyle(1,0xC7C196,50);
     //内层
     //前面
     this.beginFill(fangzi_col,fangzi_alpha);
     this.moveTo(this.sphere1._x,this.sphere1._y);
     this.lineTo(this.sphere2._x,this.sphere2._y);
     this.lineTo(this.sphere3._x,this.sphere3._y);
     this.lineTo(this.sphere4._x,this.sphere4._y);
     this.lineTo(this.sphere1._x,this.sphere1._y);
     this.endFill();
     //后面
     this.beginFill(fangzi_col,fangzi_alpha);
     this.moveTo(this.sphere5._x,this.sphere5._y);
     this.lineTo(this.sphere6._x,this.sphere6._y);
     this.lineTo(this.sphere7._x,this.sphere7._y);
     this.lineTo(this.sphere8._x,this.sphere8._y);
     this.lineTo(this.sphere5._x,this.sphere5._y);
     this.endFill();
     //右面
     this.beginFill(fangzi_col,fangzi_alpha);
     this.moveTo(this.sphere1._x,this.sphere1._y);
     this.lineTo(this.sphere4._x,this.sphere4._y);
     this.lineTo(this.sphere8._x,this.sphere8._y);
     this.lineTo(this.sphere5._x,this.sphere5._y);
     this.lineTo(this.sphere1._x,this.sphere1._y);
     this.endFill();
     //左面
     this.beginFill(fangzi_col,fangzi_alpha);
     this.moveTo(this.sphere2._x,this.sphere2._y);
     this.lineTo(this.sphere3._x,this.sphere3._y);
     this.lineTo(this.sphere7._x,this.sphere7._y);
     this.lineTo(this.sphere6._x,this.sphere6._y);
     this.lineTo(this.sphere2._x,this.sphere2._y);
     this.endFill();
     //外层
     //前面
     this.beginFill(fangzi_col,fangzi_alpha);
     this.moveTo(this.sphere9._x,this.sphere9._y);
     this.lineTo(this.sphere10._x,this.sphere10._y);
     this.lineTo(this.sphere11._x,this.sphere11._y);
     this.lineTo(this.sphere12._x,this.sphere12._y);
     this.lineTo(this.sphere9._x,this.sphere9._y);
     this.endFill();
     //后面
     this.beginFill(fangzi_col,fangzi_alpha);
     this.moveTo(this.sphere13._x,this.sphere13._y);
     this.lineTo(this.sphere14._x,this.sphere14._y);
     this.lineTo(this.sphere15._x,this.sphere15._y);
     this.lineTo(this.sphere16._x,this.sphere16._y);
     this.lineTo(this.sphere13._x,this.sphere13._y);
     this.endFill();
     //右面
     this.beginFill(fangzi_col,fangzi_alpha);
     this.moveTo(this.sphere9._x,this.sphere9._y);
     this.lineTo(this.sphere12._x,this.sphere12._y);
     this.lineTo(this.sphere16._x,this.sphere16._y);
     this.lineTo(this.sphere13._x,this.sphere13._y);
     this.lineTo(this.sphere9._x,this.sphere9._y);
     this.endFill();
     //左面
     this.beginFill(fangzi_col,fangzi_alpha);
     this.moveTo(this.sphere10._x,this.sphere10._y);
     this.lineTo(this.sphere11._x,this.sphere11._y);
     this.lineTo(this.sphere15._x,this.sphere15._y);
     this.lineTo(this.sphere14._x,this.sphere14._y);
     this.lineTo(this.sphere10._x,this.sphere10._y);
     this.endFill();
     //底面
     this.beginFill(fangzi_col,fangzi_alpha);
     this.moveTo(this.sphere9._x,this.sphere9._y);
     this.lineTo(this.sphere10._x,this.sphere10._y);
     this.lineTo(this.sphere14._x,this.sphere14._y);
     this.lineTo(this.sphere13._x,this.sphere13._y);
     this.lineTo(this.sphere9._x,this.sphere9._y);
     this.endFill();
     var dimian_col = 0x22AA00;
     var dimian_alpha = 100;
     _root.ground_mc.lineStyle(1,0x22AA00,0);
     _root.ground_mc.beginFill(dimian_col,dimian_alpha);
     _root.ground_mc.moveTo(_root.ground_mc.sphere1._x,_root.ground_mc.sphere1._y);
     _root.ground_mc.lineTo(_root.ground_mc.sphere2._x,_root.ground_mc.sphere2._y);
     _root.ground_mc.lineTo(_root.ground_mc.sphere3._x,_root.ground_mc.sphere3._y);
     _root.ground_mc.lineTo(_root.ground_mc.sphere4._x,_root.ground_mc.sphere4._y);
     _root.ground_mc.lineTo(_root.ground_mc.sphere1._x,_root.ground_mc.sphere1._y);
     _root.ground_mc.endFill();
};
用这样的方式也可以制作出一个3d的图形;
而3d引擎累里面有一大堆的东西;都不知道有什么用。很想了解基础3d引擎到底是基于什么样的基础,各个类之间的一些联系。






flash 3d 研究所
(2009-10-17 17:11:11)
在上面那段代码里面也没有Camera这样的类;



flash 3d 研究所
(2009-10-17 17:20:07)
你写了这么多代码,只是能实现一个 Cube。

而真正的3D引擎,可以对任何模型(不只只是 Cube),进行渲染展示。

Cube 只是作为基础类模型的一个实例而已。
在 Pv3d 中就是放在
/org/papervison3d/objects/primitives


flash 3d 研究所
(2009-10-17 18:15:19)
哦,谢谢指点;
最近看一些3D引擎的代码;
总感觉很难和自己写的基础代码联系起来;里面有太多的断代了;
真希望那个高手把3d引擎与像我上面写基础类模型进行一个比较与联系。就好了。


flash 3d 研究所
(2009-10-17 18:26:13)
比如在我上写的那个代码里面;没有Camera这样的类但也可以让图形在屏幕上显示出来;那么在3d引擎中加入Camera有什么好处呢?
在上面的例子中我目前最头大的就是z轴排序的问题;所以填色的时候都是半透明的;
在就是上面的例子中坐标体系好像只有一个;但实际上时不是应该有物体自身的坐标体系;也应该有个世界坐标体系;但这些转换我实在弄不懂;
最近买本3d数学基础的书在看;但书台理论化了,讲得很难看懂;
也许按书的方法最后可以实现我的效果;我很难从那里面找到和自己的思路想一致的结合处;郁闷啊;


flash 3d 研究所
(2009-10-19 17:21:49)
camera的数据是让成像更准确,广度,焦距等等。
camera并不是一个是什么实体, 就是简单的三维模型数据在如果有一个虚拟camera下应该怎么“变形,扭曲”的加乘而已。
所以project,camera,scene,render什么都可以不要也是可以成像的,但问题是成像具体广度,大小怎么样,是很难手工控制的,所以大家发明了真实拍摄一样的参数设置,但实际上全部都是数据的转换而已。


评论人:
邮   箱: (填入邮箱,博客地址均可)

内   容: (广告和垃圾内容可能会被删除,望理解)
链接地址

验证码:(为防止机器人骚扰,请麻烦输入验证码^_^)
  

(目前需登陆方可发表)


不想添加了