Esempio: assi di riferimento traslati e ruotati
import flash.display.Sprite; import flash.events.Event; import org.papervision3d.view.*; import org.papervision3d.scenes.Scene3D; import org.papervision3d.cameras.Camera3D; import org.papervision3d.materials.*; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.primitives.*; import org.papervision3d.objects.*; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.materials.shadematerials.*; import org.papervision3d.lights.*; import org.papervision3d.core.geom.Lines3D; import org.papervision3d.materials.special.LineMaterial; import org.papervision3d.core.geom.renderables.*; import caurina.transitions.Tweener; var renderer = new BasicRenderEngine(); var viewport = new Viewport3D(400, 200, false, true); viewport.x = -100; viewport.y = 60; addChild(viewport); var scena = new Scene3D(); var camera = new Camera3D(); camera.near = 30; camera.x = 200; camera.y = 300; // creazione degli assi di riferimento var centro = new Cube(new MaterialsList({all:new ColorMaterial(0xffffff)}), 5, 5, 5); var lineX = addLine( new Vertex3D(0, 0, 0), new Vertex3D(1000, 0, 0), new LineMaterial(0xFF0000,1)); var lineY = addLine( new Vertex3D(0, 0, 0), new Vertex3D(0,1000,0), new LineMaterial(0x00FF00,1)); var lineZ = addLine( new Vertex3D(0, 0, 0), new Vertex3D(0,0,1000), new LineMaterial(0x0000FF,1)); scena.addChild(lineX); scena.addChild(lineY); scena.addChild(lineZ); scena.addChild(centro); // aggiunta della luce var thelight:PointLight3D = new PointLight3D(false); thelight.z = -300; thelight.x = -300; // creazione del sistema di coordinate relativo var containerSolido:DisplayObject3D = new DisplayObject3D("assiDiRiferimento"); var materiale = new FlatShadeMaterial(thelight, 0xff0000, 0x000000); var solido = new Cube(new MaterialsList({all:materiale}), 40, 40, 40); var SolidoLineX = addLine( new Vertex3D(0, 0, 0), new Vertex3D(1000, 0, 0), new LineMaterial(0x666666,1)); var SolidoLineY = addLine( new Vertex3D(0, 0, 0), new Vertex3D(0, 1000, 0), new LineMaterial(0x666666,1)); var SolidoLineZ = addLine( new Vertex3D(0, 0, 0), new Vertex3D(0,0,1000), new LineMaterial(0x666666,1)); containerSolido.addChild(SolidoLineX); containerSolido.addChild(SolidoLineY); containerSolido.addChild(SolidoLineZ); containerSolido.addChild(solido); scena.addChild(containerSolido); containerSolido.x = 20; containerSolido.y = 10; containerSolido.z = 20; containerSolido.rotationZ = 20; containerSolido.rotationX = 20; camera.lookAt(centro); solido.y = 20; anim(); // gestione dell'animazione con caurina Tweener function anim () { if (solido.x == 100) Tweener.addTween(solido, {x:20, time:3, transition:"linear", onComplete:anim}); else Tweener.addTween(solido, {x:100, time:3, transition:"linear", onComplete:anim}); } addEventListener(Event.ENTER_FRAME, onEnterFrame); function onEnterFrame(e:Event):void { renderer.renderScene(scena, camera, viewport); } var _lineCont:int=0; function addLine(_v0:Vertex3D,_v1:Vertex3D,_lineMaterial:LineMaterial,_nome:String = "linea"):Lines3D { var line:Lines3D = new Lines3D(_lineMaterial,_nome+"_"+_lineCont); _lineCont++; line.addNewLine(1,_v0.x,_v0.y,_v0.z,_v1.x,_v1.y,_v1.z); return line; }