package { import flash.display.Sprite; import flash.events.Event; import org.papervision3d.cameras.FreeCamera3D; import org.papervision3d.scenes.MovieScene3D; import org.papervision3d.objects.Plane; import org.papervision3d.materials.BitmapFileMaterial; [SWF(width='800',height='512',backgroundColor='0x000000',frameRate='30')] public class VisionneuseCube extends Sprite { private static const CHEMIN_IMAGES:String = "../assets/"; private static var MAX_X_ROTATION:int = 50; private static var taille:Number = 5000; private var container :Sprite; private var scene :MovieScene3D; private var camera :FreeCamera3D; private var plan:Plane; public function VisionneuseCube() { container = new Sprite(); container.x = stage.stageWidth/2; container.y = stage.stageHeight/2; addChild( container ); scene = new MovieScene3D( container ); camera = new FreeCamera3D(); camera.zoom = 1; camera.focus = 400; camera.z = 0; var centre:Number = taille/2; //Face Avant var texture:BitmapFileMaterial = new BitmapFileMaterial(VisionneuseCube.CHEMIN_IMAGES+"rendu_cubique_FR.jpg"); plan = new Plane( texture , taille, taille, 16, 16); plan.z = centre; scene.addChild( plan ); //Face Droite texture = new BitmapFileMaterial(VisionneuseCube.CHEMIN_IMAGES+"rendu_cubique_RT.jpg"); plan = new Plane( texture , taille, taille, 16, 16); plan.x = -centre; plan.rotationY = -90; scene.addChild( plan ); //Face Gauche texture = new BitmapFileMaterial(VisionneuseCube.CHEMIN_IMAGES+"rendu_cubique_LF.jpg"); plan = new Plane( texture , taille, taille, 16, 16); plan.x = centre; plan.rotationY = 90; scene.addChild( plan ); //Face Bas texture = new BitmapFileMaterial(VisionneuseCube.CHEMIN_IMAGES+"rendu_cubique_DN.jpg"); plan = new Plane( texture , taille, taille, 16, 16); plan.y = -centre; plan.rotationX = -90; scene.addChild( plan ); //Face Haut texture = new BitmapFileMaterial(VisionneuseCube.CHEMIN_IMAGES+"rendu_cubique_UP.jpg"); plan = new Plane( texture , taille, taille, 16, 16); plan.y = centre; plan.rotationX = 90; scene.addChild( plan ); //Face Arriere texture = new BitmapFileMaterial(VisionneuseCube.CHEMIN_IMAGES+"rendu_cubique_BK.jpg"); plan = new Plane( texture , taille, taille, 16, 16); plan.z = -centre; plan.rotationY = -180; scene.addChild( plan ); stage.addEventListener( Event.ENTER_FRAME, onEnterFrame ); } private function onEnterFrame( event: Event ): void { camera.rotationY += (container.mouseX)/60; camera.rotationX -= (container.mouseY)/60; //on limite la rotation vertivale if(camera.rotationX > VisionneuseCube.MAX_X_ROTATION) { camera.rotationX = VisionneuseCube.MAX_X_ROTATION; } if(camera.rotationX < -VisionneuseCube.MAX_X_ROTATION) { camera.rotationX = -VisionneuseCube.MAX_X_ROTATION; } scene.renderCamera( camera ); } } }