PageRenderTime 392ms CodeModel.GetById 120ms app.highlight 112ms RepoModel.GetById 79ms app.codeStats 0ms

/src/away3d/events/MouseEvent3D.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 285 lines | 127 code | 43 blank | 115 comment | 11 complexity | 546387a7927c5f5d1d13c1939cfaab27 MD5 | raw file
  1package away3d.events
  2{
  3	import away3d.arcane;
  4	import away3d.containers.ObjectContainer3D;
  5	import away3d.containers.View3D;
  6	import away3d.core.base.IRenderable;
  7	import away3d.core.math.Matrix3DUtils;
  8	import away3d.materials.MaterialBase;
  9	
 10	import flash.events.Event;
 11	import flash.geom.Point;
 12	import flash.geom.Vector3D;
 13	
 14	use namespace arcane;
 15	
 16	/**
 17	 * A MouseEvent3D is dispatched when a mouse event occurs over a mouseEnabled object in View3D.
 18	 * todo: we don't have screenZ data, tho this should be easy to implement
 19	 */
 20	public class MouseEvent3D extends Event
 21	{
 22		// Private.
 23		arcane var _allowedToPropagate:Boolean = true;
 24		arcane var _parentEvent:MouseEvent3D;
 25		
 26		/**
 27		 * Defines the value of the type property of a mouseOver3d event object.
 28		 */
 29		public static const MOUSE_OVER:String = "mouseOver3d";
 30		
 31		/**
 32		 * Defines the value of the type property of a mouseOut3d event object.
 33		 */
 34		public static const MOUSE_OUT:String = "mouseOut3d";
 35		
 36		/**
 37		 * Defines the value of the type property of a mouseUp3d event object.
 38		 */
 39		public static const MOUSE_UP:String = "mouseUp3d";
 40		
 41		/**
 42		 * Defines the value of the type property of a mouseDown3d event object.
 43		 */
 44		public static const MOUSE_DOWN:String = "mouseDown3d";
 45		
 46		/**
 47		 * Defines the value of the type property of a mouseMove3d event object.
 48		 */
 49		public static const MOUSE_MOVE:String = "mouseMove3d";
 50		
 51		/**
 52		 * Defines the value of the type property of a rollOver3d event object.
 53		 */
 54		//		public static const ROLL_OVER : String = "rollOver3d";
 55		
 56		/**
 57		 * Defines the value of the type property of a rollOut3d event object.
 58		 */
 59		//		public static const ROLL_OUT : String = "rollOut3d";
 60		
 61		/**
 62		 * Defines the value of the type property of a click3d event object.
 63		 */
 64		public static const CLICK:String = "click3d";
 65		
 66		/**
 67		 * Defines the value of the type property of a doubleClick3d event object.
 68		 */
 69		public static const DOUBLE_CLICK:String = "doubleClick3d";
 70		
 71		/**
 72		 * Defines the value of the type property of a mouseWheel3d event object.
 73		 */
 74		public static const MOUSE_WHEEL:String = "mouseWheel3d";
 75		
 76		/**
 77		 * The horizontal coordinate at which the event occurred in view coordinates.
 78		 */
 79		public var screenX:Number;
 80		
 81		/**
 82		 * The vertical coordinate at which the event occurred in view coordinates.
 83		 */
 84		public var screenY:Number;
 85		
 86		/**
 87		 * The view object inside which the event took place.
 88		 */
 89		public var view:View3D;
 90		
 91		/**
 92		 * The 3d object inside which the event took place.
 93		 */
 94		public var object:ObjectContainer3D;
 95		
 96		/**
 97		 * The renderable inside which the event took place.
 98		 */
 99		public var renderable:IRenderable;
100		
101		/**
102		 * The material of the 3d element inside which the event took place.
103		 */
104		public var material:MaterialBase;
105		
106		/**
107		 * The uv coordinate inside the draw primitive where the event took place.
108		 */
109		public var uv:Point;
110		
111		/**
112		 * The index of the face where the event took place.
113		 */
114		public var index:uint;
115		
116		/**
117		 * The index of the subGeometry where the event took place.
118		 */
119		public var subGeometryIndex:uint;
120		
121		/**
122		 * The position in object space where the event took place
123		 */
124		public var localPosition:Vector3D;
125		
126		/**
127		 * The normal in object space where the event took place
128		 */
129		public var localNormal:Vector3D;
130		
131		/**
132		 * Indicates whether the Control key is active (true) or inactive (false).
133		 */
134		public var ctrlKey:Boolean;
135		
136		/**
137		 * Indicates whether the Alt key is active (true) or inactive (false).
138		 */
139		public var altKey:Boolean;
140		
141		/**
142		 * Indicates whether the Shift key is active (true) or inactive (false).
143		 */
144		public var shiftKey:Boolean;
145		
146		/**
147		 * Indicates how many lines should be scrolled for each unit the user rotates the mouse wheel.
148		 */
149		public var delta:int;
150		
151		/**
152		 * Create a new MouseEvent3D object.
153		 * @param type The type of the MouseEvent3D.
154		 */
155		public function MouseEvent3D(type:String)
156		{
157			super(type, true, true);
158		}
159		
160		/**
161		 * @inheritDoc
162		 */
163		public override function get bubbles():Boolean
164		{
165			var doesBubble:Boolean = super.bubbles && _allowedToPropagate;
166			_allowedToPropagate = true;
167			// Don't bubble if propagation has been stopped.
168			return doesBubble;
169		}
170		
171		/**
172		 * @inheritDoc
173		 */
174		public override function stopPropagation():void
175		{
176			super.stopPropagation();
177			_allowedToPropagate = false;
178			if (_parentEvent)
179				_parentEvent.stopPropagation();
180		}
181		
182		/**
183		 * @inheritDoc
184		 */
185		public override function stopImmediatePropagation():void
186		{
187			super.stopImmediatePropagation();
188			_allowedToPropagate = false;
189			if (_parentEvent)
190				_parentEvent.stopImmediatePropagation();
191		}
192		
193		/**
194		 * Creates a copy of the MouseEvent3D object and sets the value of each property to match that of the original.
195		 */
196		public override function clone():Event
197		{
198			var result:MouseEvent3D = new MouseEvent3D(type);
199			
200			if (isDefaultPrevented())
201				result.preventDefault();
202			
203			result.screenX = screenX;
204			result.screenY = screenY;
205			
206			result.view = view;
207			result.object = object;
208			result.renderable = renderable;
209			result.material = material;
210			result.uv = uv;
211			result.localPosition = localPosition;
212			result.localNormal = localNormal;
213			result.index = index;
214			result.subGeometryIndex = subGeometryIndex;
215			result.delta = delta;
216			
217			result.ctrlKey = ctrlKey;
218			result.shiftKey = shiftKey;
219			
220			result._parentEvent = this;
221			result._allowedToPropagate = _allowedToPropagate;
222			
223			return result;
224		}
225		
226		/**
227		 * The position in scene space where the event took place
228		 */
229		public function get scenePosition():Vector3D
230		{
231			if (object is ObjectContainer3D)
232				return Matrix3DUtils.transformVector(ObjectContainer3D(object).sceneTransform,localPosition);
233			else
234				return localPosition;
235		}
236
237		/**
238		 * The position in scene space where the event took place
239		 * @param v destination Vector3D
240		 * @return
241		 */
242		public function getScenePosition(v:Vector3D = null):Vector3D {
243			if(!v) v = new Vector3D();
244			if (object is ObjectContainer3D) {
245				Matrix3DUtils.transformVector(ObjectContainer3D(object).sceneTransform,localPosition,v);
246			}else{
247				v.x = localPosition.x;
248				v.y = localPosition.y;
249				v.z = localPosition.z;
250			}
251			return v;
252		}
253		
254		/**
255		 * The normal in scene space where the event took place
256		 */
257		public function get sceneNormal():Vector3D
258		{
259			if (object is ObjectContainer3D) {
260				var sceneNormal:Vector3D = Matrix3DUtils.deltaTransformVector(ObjectContainer3D(object).sceneTransform,localNormal);
261				sceneNormal.normalize();
262				return sceneNormal;
263			} else
264				return localNormal;
265		}
266
267		/**
268		 * The normal in scene space where the event took place
269		 * @param v destination Vector3D
270		 * @return
271		 */
272		public function getSceneNormal(v:Vector3D = null):Vector3D {
273			if(!v) v = new Vector3D();
274			if (object is ObjectContainer3D) {
275				Matrix3DUtils.deltaTransformVector(ObjectContainer3D(object).sceneTransform,localNormal, v);
276				v.normalize();
277			} else {
278				v.x = localNormal.x;
279				v.y = localNormal.y;
280				v.z = localNormal.z;
281			}
282			return v;
283		}
284	}
285}