/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

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