java3d立方体_3d立方体贴图

该博客介绍了如何使用Java3D库创建一个3D立方体,并应用纹理贴图。通过定义顶点坐标,形成多个三角面片来构建立方体的表面,同时实现对立方体的旋转操作,根据鼠标位置调整视角。此外,还涉及到了将2D图像作为纹理映射到立方体表面的方法。
摘要由CSDN通过智能技术生成

package com.ddd

{importflash.display.Bitmap;importflash.display.Sprite;importflash.display.StageScaleMode;importflash.events.Event;importflash.geom.Matrix3D;importflash.geom.Vector3D;public class Triangles extendsSprite

{private var points:Vector.;private var triangle:Array=[];private var vpX:Number=stage.stageWidth / 2;private var vpY:Number=stage.stageHeight / 2;

[Embed(source="img/5.jpg")]private varimg:Classprivate varbd:Bitmap;public functionTriangles()

{

stage.scaleMode=StageScaleMode.NO_SCALE;

init();

}private functioninit():void

{

points=new Vector.;

points[0]=new Points3D(-100, -100, -100);

points[1]=new Points3D(100, -100, -100);

points[2]=new Points3D(100, 100, -100);

points[3]=new Points3D(-100, 100, -100);

points[4]=new Points3D(-100, -100, 100);

points[5]=new Points3D(100, -100, 100);

points[6]=new Points3D(100, 100, 100);

points[7]=new Points3D(-100, 100, 100);for (var i:int=0; i < points.length; i++)

{

points[i].setVPoint(vpX, vpY);

points[i].setCenter(0,0,200);

}/**

triangle[0]=new Triangle(points[0],points[1],points[2],0x660000);

triangle[1]=new Triangle(points[0],points[2],points[3],0x660000);

triangle[2]=new Triangle(points[0],points[4],points[5],0x006600);

triangle[3]=new Triangle(points[0],points[5],points[1],0x006600);

triangle[4]=new Triangle(points[0],points[3],points[7],0x000066);

triangle[5]=new Triangle(points[0],points[7],points[4],0x000066);

triangle[6]=new Triangle(points[6],points[1],points[2],0x666600);

triangle[7]=new Triangle(points[6],points[5],points[1],0x666600);

triangle[8]=new Triangle(points[6],points[4],points[5],0x006666);

triangle[9]=new Triangle(points[6],points[7],points[4],0x006666);

triangle[10]=new Triangle(points[6],points[7],points[3],0x660066);

triangle[11]=new Triangle(points[6],points[3],points[2],0x660066);*/triangle[0]=new Triangle(points[0], points[1], points[2], 0x6666cc);

triangle[1]=new Triangle(points[0], points[2], points[3], 0x6666cc);//top

triangle[3]=new Triangle(points[0], points[5], points[1], 0x66cc66);

triangle[2]=new Triangle(points[0], points[4], points[5], 0x66cc66);//back

triangle[5]=new Triangle(points[4], points[6], points[5], 0xcc6666);

triangle[4]=new Triangle(points[4], points[7], points[6], 0xcc6666);//bottom

triangle[6]=new Triangle(points[3], points[2], points[6], 0xcc66cc);

triangle[7]=new Triangle(points[3], points[6], points[7], 0xcc66cc);//right

triangle[8]=new Triangle(points[1], points[5], points[6], 0x66cccc);

triangle[9]=new Triangle(points[1], points[6], points[2], 0x66cccc);//left

triangle[10]=new Triangle(points[4], points[0], points[3], 0xcccc66);

triangle[11]=new Triangle(points[4], points[3], points[7], 0xcccc66);

bd=new img;

this.addEventListener(Event.ENTER_FRAME, onEnterFrame);

}private functiononEnterFrame(e:Event):void

{var angleX:Number=(mouseY - vpY) * .001;var angleY:Number=(mouseX - vpX) * .001;for (var i:int=0; i < points.length; i++)

{var p:Points3D=points[i];

p.rotateX(angleX);

p.rotateY(angleY);

}

triangle.sortOn("depth", Array.DESCENDING |Array.NUMERIC);

graphics.clear();for (i=0; i < triangle.length; i++)

{

triangle[i].draw(graphics,bd.bitmapData.clone());

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值