接着上面的例子,我们分析一下设计的思路。
首先,我们假设存在一个三维坐标世界。
【http://www.newflash3d.com---flash3D先锋队:北京贝武易科技公司】
有疑问请联系我QQ:363596350
基本思路:
1、假设三维坐标系存在;
2、构造三维坐标的点;
3、由三维的点构造二维的点(以三维的点作为参数);
4、根据二维的点绘制图形;
1、假设三维坐标系存在:
我们把这个坐标系的基本物体构造为一个Object:
package hjh3dcom
{
public class Object3d extends Object
{
private var _x3din:Number;
private var _y3din:Number;
private var _z3din:Number;
public function Object3d()
{
super();
init();
}
private function init():void{
_x3din=0;
_y3din=0;
_z3din=0;
}
//----------------------------------------
public function set x3d(x3din:Number):void
{
_x3din = x3din;
}
public function get x3d():Number
{
return _x3din;
}
//----------------------------------------
public function set y3d(y3din:Number):void
{
_y3din = y3din;
}
public function get y3d():Number
{
return _y3din;
}
//----------------------------------------
public function set z3d(z3din:Number):void
{
_z3din = z3din;
}
public function get z3d():Number
{
return _z3din;
}
}
}
这里为了区别与Flex本身的坐标特性,我们用了x3d、y3d、z3d来代替X、Y、Z,其实他们的意义是一样的,只不过是一个符合代表而已,你也可以规定为其他的形式。
他们具有三个坐标值:X、Y、Z
在这个坐标中存在一个点的集合,我们可以理解为点阵。
2、构造三维坐标的点;
我们用这个方法来生成点:
private function MakeA3DPoint(x3d:Number,y3d:Number,z3d:Number):Object3d{
point=new Object3d();
point.x3d=x3d;
point.y3d=y3d;
point.z3d=z3d;
return point;
}//注意,这里函数返回的结果是一个point物体,它是属于Object3d类的物体,这个物体我们给它定义了三个三维坐标属性;
有一点需要注意的,这个点只是我们虚构想像的空中的点,它实际上是不存在的。
好,有了生产点的方法,那么我们就通过它来构成一个空间的点的集合,如果我们要构成一个方体,我们都知道方体有8个点顶,所以我们通过一个数组来存储这8个顶点,然后再对这些顶点进行运算操作。
生成点集合的数组:
pointsArray = [
MakeA3DPoint(-20, -40, -20), /* bottom half of box (low y value) */
MakeA3DPoint(20, -40, -20),
MakeA3DPoint(20, -40, 20),
MakeA3DPoint(-20, -40, 20),
MakeA3DPoint(-20, 80, -20), /* top half of box (high y value) */
MakeA3DPoint(20, 80, -20),
MakeA3DPoint(20, 80, 20),
MakeA3DPoint(-20, 80, 20)
];
它落实为空间的点为:
把三维的点转换到二维的点的方法:
private function ConvertPointIn3DToPointIn2D(pointIn3D:Object3d, focalLength:Number):Object{
// make an object to act as the 2D point on the screen
pointIn2D = new Object();
// develop a scale ratio based on focal length and the
// z value of this point
scaleRatio = focalLength/(focalLength + pointIn3D.z3d);
// appropriately scale each x and y position of the 3D point based
// on the scale ratio to determine the point in 2D.
pointIn2D.x = pointIn3D.x3d * scaleRatio;
pointIn2D.y = pointIn3D.y3d * scaleRatio;
// return the new 2D point
return pointIn2D;
}
在输入三维的点和定义好的焦距后,
只要执行ConvertPointIn3DToPointIn2D方法,就会获得一个二维点物体。
最后就是实现绘制物体了。
private function backAndForthAndSideToSide(evt:Event):void{
screenPoints=new Array();
for (var i=0; i<pointsArray.length; i++){
thisPoint = pointsArray[i];
if (direction == "left"){
thisPoint.x3d -= speed;
// only check if this is the last point in pointsArray
if (i == pointsArray.length-1 && thisPoint.x3d <= -100) direction = "backward";
}else if (direction == "backward"){
thisPoint.z3d += speed;
// only check if this is the last point in pointsArray
if (i == pointsArray.length-1 && thisPoint.z3d >= 150) direction = "right";
}else if (direction == "right"){
thisPoint.x3d += speed;
// only check if this is the last point in pointsArray
if (i == pointsArray.length-1 && thisPoint.x3d >= 60) direction = "forward";
}else if (direction == "forward"){
thisPoint.z3d -= speed;
// only check if this is the last point in pointsArray
if (i == pointsArray.length-1 && thisPoint.z3d <= 0) direction = "left";
}
// now that the point has been moved, convert it
// and save it to the screenPoints array
screenPoints[i] = ConvertPointIn3DToPointIn2D(thisPoint, FocalLength);
// now that its a screen point, we can throw in
// the origin offset to center it on the screen
//screenPoints[i].x += Origin.x;
//screenPoints[i].y += Origin.y;
screenPoints[i].x ++;
screenPoints[i].y ++;
}// end of loop
container.graphics.clear(); // clear any previously drawn box
container.graphics.lineStyle(2,0xFF0000,100); // make the drawn lines to be red
// this part can be tedious since it maps out each line - wheeew
// this is where having drawn out the image on paper really helps
// you can always reference the pointsArray to figure out where
// your points are in 3D space so you know where to connect them
// top
container.graphics.moveTo(screenPoints[0].x, screenPoints[0].y);
container.graphics.lineTo(screenPoints[1].x, screenPoints[1].y);
container.graphics.lineTo(screenPoints[2].x, screenPoints[2].y);
container.graphics.lineTo(screenPoints[3].x, screenPoints[3].y);
container.graphics.lineTo(screenPoints[0].x, screenPoints[0].y);
// bottom
container.graphics.moveTo(screenPoints[4].x, screenPoints[4].y);
container.graphics.lineTo(screenPoints[5].x, screenPoints[5].y);
container.graphics.lineTo(screenPoints[6].x, screenPoints[6].y);
container.graphics.lineTo(screenPoints[7].x, screenPoints[7].y);
container.graphics.lineTo(screenPoints[4].x, screenPoints[4].y);
// connecting bottom and top
container.graphics.moveTo(screenPoints[0].x, screenPoints[0].y);
container.graphics.lineTo(screenPoints[4].x, screenPoints[4].y);
container.graphics.moveTo(screenPoints[1].x, screenPoints[1].y);
container.graphics.lineTo(screenPoints[5].x, screenPoints[5].y);
container.graphics.moveTo(screenPoints[2].x, screenPoints[2].y);
container.graphics.lineTo(screenPoints[6].x, screenPoints[6].y);
container.graphics.moveTo(screenPoints[3].x, screenPoints[3].y);
container.graphics.lineTo(screenPoints[7].x, screenPoints[7].y);
}
backAndForthAndSideToSide方法是一个根据Flash的时间来绘制物体了。
- 大小: 93.2 KB
分享到:
相关推荐
3dmax插件神器-003-线框图.mse
行业资料-电子功用-基于线框电极进行电火花套料加工的方法
Wires - Web线框图套件AdobeXD源码下载设计素材UI设计
Wires - Mobile 线框图套件AdobeXD源码下载设计素材UI设计
数字绘-----在线线框图、流程图、网络图、组织结构图、UML、BPMN绘制网站,绘制完成之后可以导出成图片、SVG、XML,也可以保存在云端并能分享给其他用户。
3ds-max-插件教程3DMAX渲染线框动画
图形学实验-立方体线框模型透视投影图形学实验-立方体线框模型透视投影图形学实验-立方体线框模型透视投影
获取食物() Kris、Koko、Kritika、Rodrigo、Zac '减少食物浪费的人' 数字线框: : 部署了?! (cheeeeeeers Kris!): ://getfoodeda.herokuapp.com/ // ------------------------------------------------ // -...
html-to-wireframe被创建为一种易于使用的工具,可以从本地或远程html文件生成线框,以进行类似于Facebook的操作,以便用户可以在加载整个页面之前查看应用程序的结构。 该工具基于: Wirify书签-> PhantomJS-> ...
如何在Linux上运行Balsamiq线框有关如何使用Wine和Lutris在Linux上运行Balsamiq线框的说明。前提条件一个主流Linux发行版(Ubuntu / Debian / Fedora / Mint),其中包含curl , wine和wine32 。 lutris -Lutris使...
一个单文件Python库,用于生成SVG格式的3D线框
ProjectCost 是一种工具,可帮助签约人员根据历史定价信息估算合同的每小时人工成本,并汇总此信息以得出总项目人工成本。 网络资源 projects/ - 项目列表 projects/foo -- foo 项目 projects/foo/positions/ -- foo...
:magnifying_glass_tilted_right: Nx是用于Monorepos的一组可扩展开发工具。 向您的工作区添加功能 Nx支持许多插件,这些插件添加了用于开发不同类型的应用程序和不同工具的功能。 这些功能包括生成应用程序,库等...
掌厅登陆之周末有礼-转盘抽奖-线框图-20141210.jpg
针对座椅识别归类问题提出一种由单幅线框图生成三维座椅模型的方法。首先对大量座椅的形态和结构进行学习和归纳,根据座椅在固定观察视点下的线框图,提取出能抽象表达座椅的基本图元集合,如线段、四边形和椭圆形等...
资源名称:3d max中如何渲染模型的线框资源截图: 资源太大,传百度网盘了,链接在附件中,有需要的同学自取。
类目改造-需求及线框图_产品矩阵线框图,介绍类目和发布类目
Unity3D 模型的几种线框 shader。 模型的几种线框shader。 模型的几种线框shader,需要线框化模型的时候使用,比如选中模型线框化,只能看到模型线,看不到三角面 Unity3d Shader
掌厅登陆之周末有礼-线框图-20141205.jpg
-Wirefame-绘制游戏外观-包括图片-或使用线框工具-用户故事-措辞应围绕用户与游戏互动的方式注意:-项目说明-使用的技术-采用的方法-安装说明-未解决的问题-其他组件? README文件示例: : 一般提示:-分解成较小的...