package classes.matuto.mt3d
{
	import classes.away3d.cameras.Camera3D;
	import classes.away3d.containers.Scene3D;
	import classes.away3d.containers.View3D;
	import classes.away3d.core.base.Object3D;
	import classes.away3d.core.render.Renderer;
	import classes.away3d.primitives.Trident;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	
	import classes.matuto.utils.display.Texturize;
	
	public class Mt3d extends Sprite
	{
		
		protected var view		:View3D;
		protected var scene		:Scene3D;
		protected var camera	:Camera3D;
		
		private   var trident	:Trident;
		
		private   var rootStage	:Stage;
		
		private var alvoBg		:Sprite;
		
		public function Mt3d()
		{
			super();
			
			addEventListener(Event.ADDED_TO_STAGE,onStage);
		}
		
		protected function onStage(e:Event):void
		{
			rootStage            = stage;
			

			
			initUI();
			initEngine();
			initScene();
			initRENDER();
			
			stage.align			 = "TL";
			stage.scaleMode 	 = "noScale";
			stage.addEventListener(Event.RESIZE, resize);
			resize(null);
		}
		
		protected function initUI():void
		{
			
			alvoBg = new Sprite();
			addChild(alvoBg);
			
			
			return void;	
		}
		
		protected function initEngine():void
		{
		    view 			= new View3D();
			scene 			= view.scene;
		    camera			= view.camera;
			view.renderer 	= Renderer.INTERSECTING_OBJECTS;
			
			camera.z		= -1000;
			view.x  		= (stage.stageWidth/2);
			view.y  		= (stage.stageHeight/2);
			
			this.addChild(view);
		}
		
		protected function initScene():void
		{
			return void;	
		}
		
		protected function initRENDER():void
		{
			this.addEventListener(Event.ENTER_FRAME,onRENDER);
			return void;	
		}
		
		protected function onRENDER(event:Event):void
		{
			 view.render();
		}
		
		//########################################################
		//DISPLAY
		//########################################################

		public function addChildScene(value:Object3D):void
		{
		   return scene.addChild(value);
		}
		
		public function addTrident():void
		{
		   trident = new Trident(300);
		   scene.addChild(trident);
		}
		
		public function removeTrident():void
		{
			scene.removeChild(trident);
			trident = null;
		}
		
		public function get getTrident():Trident
		{
		    return trident;
		}

		//########################################################
		//########################################################

		protected function resize(e:Event=null):void
		{
			view.x  		= (stage.stageWidth/2);
			view.y  		= (stage.stageHeight/2);
		}
		
		
		
	}//end class
}