用编程方式实现3D效果
作者 佚名技术
来源 服务器技术
浏览
发布时间 2012-07-11
点击浏览该文件 [全屏欣赏] 这是源文件 点击浏览该文件 //照相机和屏幕的距离 d = 350; //原点坐标 X center_x = 0; //原点坐标 Y center_y = 0; pmx = 0; pmy = 0; jl = 0; //得到景深 function GetRatio(z) { return d/(d+z); } function ChangeJl(newvalue) { jl = newvalue; } //改变坐标轴原点 function ChangeOx(newx, newy) { var ox = center_x; var oy = center_y; var opmx = pmx; var opmy = pmy; center_x = newx; center_y = newy; ChangeMd((ox+opmx)-newx, newy-(oy-opmy)); } function ChangeMd(newx, newy) { pmx = newx; ey._x = center_x+newx; pmy = newy; ex._y = center_y-newy; } function Change(v, z) { return GetRatio(z)*v; } //变换坐标3D-2D function ChangeX(x, z) { z += jl; return center_x+(d*x+z*pmx)/(z+d); } //function ChangeX(x, z) { // return center_x+GetRatio(z)*x; //} //function ChangeY(y, z) { // return center_y-GetRatio(z)*y+pmy; //} function ChangeY(y, z) { z += jl; return center_y-(d*y+z*pmy)/(z+d); } //取得弧度值 function GetFuduFxy(x, y) { return Math.atan2(y, x); } //取得弧度值 function GetFudu(a) { return a*Math.PI/180; } //取得角度值 function GetJiaodu(fd) { return fu*180/Math.PI; } //定义2维点 对象 function point2d(x, y) { this.x = x; this.y = y; } //定义3维点 对象 function point3d(x, y, z) { this.x = x; this.y = y; this.z = z; } //按X轴旋转 function RotateX(p3d, a) { var x1 = p3d.x; var y1 = p3d.y*Math.cos(GetFudu(a))-p3d.z*Math.sin(GetFudu(a)); var z1 = p3d.z*Math.cos(GetFudu(a))+p3d.y*Math.sin(GetFudu(a)); //return new point2d(ChangeX(x1, z1), ChangeY(y1, z1)); return new point3d(x1, y1, z1); } //按Y轴旋转 function RotateY(p3d, a) { var x1 = p3d.x*Math.cos(GetFudu(a))-p3d.z*Math.sin(GetFudu(a)); //var x1=Math.sin(GetFudu(a))*p3d.z; //var z1=Math.cos(GetFudu(a))*p3d.z; var y1 = p3d.y; var z1 = p3d.z*Math.cos(GetFudu(a))+p3d.x*Math.sin(GetFudu(a)); //return new point2d(ChaneX(x1, z1), ChangeY(y1, z1)); return new point3d(x1, y1, z1); } //按Z轴旋转 function RotateZ(p3d, a) { var x1 = p3d.x*Math.cos(GetFudu(a))-p3d.y*Math.sin(GetFudu(a)); var y1 = p3d.y*Math.cos(GetFudu(a))+p3d.x*Math.sin(GetFudu(a)); var z1 = p3d.z; // return new point2d(ChaneX(x1, z1), ChangeY(y1, z1)); return new point3d(x1, y1, z1); } function mMoveTo(p) { moveTo(ChangeX(p.x, p.z), ChangeY(p.y, p.z)); } //3维中画线 function Line(p1, p2) { moveTo(ChangeX(p1.x, p1.z), ChangeY(p1.y, p1.z)); lineTo(ChangeX(p2.x, p2.z), ChangeY(p2.y, p2.z)); } function aLineTo(p1) { lineTo(ChangeX(p1.x, p1.z), ChangeY(p1.y, p1.z)); } //3维中画矩形 function DrawBox(p1, p2, p3, p4) { Line(p1, p2); Line(p2, p3); Line(p3, p4); Line(p4, p1); } function DrawLFT(pos_x, pos_y, pos_z) { clear(); lineStyle(1, 0xff0000); mMoveTo(new point3d(pos_x[0], pos_y[0], pos_z[0])); aLineTo(new point3d(pos_x[1], pos_y[1], pos_z[1])); aLineTo(new point3d(pos_x[2], pos_y[2], pos_z[2])); aLineTo(new point3d(pos_x[3], pos_y[3], pos_z[3])); aLineTo(new point3d(pos_x[0], pos_y[0], pos_z[0])); mMoveTo(new point3d(pos_x[4], pos_y[4], pos_z[4])); aLineTo(new point3d(pos_x[5], pos_y[5], pos_z[5])); aLineTo(new point3d(pos_x[6], pos_y[6], pos_z[6])); aLineTo(new point3d(pos_x[7], pos_y[ |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: 利用AS控制声音教程下一篇: 文本框滚动缓冲效果
关于用编程方式实现3D效果的所有评论