Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merge with dev branch

  • Loading branch information...
commit 386eabe24f23135adf05608230339eb75534df8e 1 parent 7e9b058
@muzerly muzerly authored
Showing with 30,456 additions and 0 deletions.
  1. BIN  AwayPhysics/lib/AwayPhysics.swc
  2. +11 −0 AwayPhysics/src/awayphysics/AWPBase.as
  3. +498 −0 AwayPhysics/src/awayphysics/collision/dispatch/AWPCollisionObject.as
  4. +46 −0 AwayPhysics/src/awayphysics/collision/dispatch/AWPCollisionWorld.as
  5. +15 −0 AwayPhysics/src/awayphysics/collision/dispatch/AWPGhostObject.as
  6. +48 −0 AwayPhysics/src/awayphysics/collision/dispatch/AWPManifoldPoint.as
  7. +14 −0 AwayPhysics/src/awayphysics/collision/dispatch/AWPRay.as
  8. +26 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPBoxShape.as
  9. +60 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPBvhTriangleMeshShape.as
  10. +25 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPCapsuleShape.as
  11. +69 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPCollisionShape.as
  12. +129 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPCompoundShape.as
  13. +25 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPConeShape.as
  14. +52 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPConvexHullShape.as
  15. +32 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPCylinderShape.as
  16. +51 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPHeightfieldTerrainShape.as
  17. +18 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPSphereShape.as
  18. +36 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPStaticPlaneShape.as
  19. +44 −0 AwayPhysics/src/awayphysics/collision/shapes/AWPTriangleShape.as
  20. +12 −0 AwayPhysics/src/awayphysics/data/AWPCollisionFilterGroups.as
  21. +10 −0 AwayPhysics/src/awayphysics/data/AWPCollisionFlags.as
  22. +10 −0 AwayPhysics/src/awayphysics/data/AWPCollisionObjectTypes.as
  23. +15 −0 AwayPhysics/src/awayphysics/data/AWPCollisionShapeType.as
  24. +10 −0 AwayPhysics/src/awayphysics/data/AWPTypedConstraintType.as
  25. +653 −0 AwayPhysics/src/awayphysics/debug/AWPDebugDraw.as
  26. +355 −0 AwayPhysics/src/awayphysics/dynamics/AWPDynamicsWorld.as
  27. +270 −0 AwayPhysics/src/awayphysics/dynamics/AWPRigidBody.as
  28. +202 −0 AwayPhysics/src/awayphysics/dynamics/character/AWPKinematicCharacterController.as
  29. +86 −0 AwayPhysics/src/awayphysics/dynamics/constraintsolver/AWPAngularLimit.as
  30. +175 −0 AwayPhysics/src/awayphysics/dynamics/constraintsolver/AWPConeTwistConstraint.as
  31. +115 −0 AwayPhysics/src/awayphysics/dynamics/constraintsolver/AWPGeneric6DofConstraint.as
  32. +121 −0 AwayPhysics/src/awayphysics/dynamics/constraintsolver/AWPHingeConstraint.as
  33. +47 −0 AwayPhysics/src/awayphysics/dynamics/constraintsolver/AWPPoint2PointConstraint.as
  34. +144 −0 AwayPhysics/src/awayphysics/dynamics/constraintsolver/AWPRotationalLimitMotor.as
  35. +163 −0 AwayPhysics/src/awayphysics/dynamics/constraintsolver/AWPTranslationalLimitMotor.as
  36. +36 −0 AwayPhysics/src/awayphysics/dynamics/constraintsolver/AWPTypedConstraint.as
  37. +53 −0 AwayPhysics/src/awayphysics/dynamics/vehicle/AWPRaycastInfo.as
  38. +96 −0 AwayPhysics/src/awayphysics/dynamics/vehicle/AWPRaycastVehicle.as
  39. +19 −0 AwayPhysics/src/awayphysics/dynamics/vehicle/AWPVehicleTuning.as
  40. +235 −0 AwayPhysics/src/awayphysics/dynamics/vehicle/AWPWheelInfo.as
  41. +29 −0 AwayPhysics/src/awayphysics/events/AWPEvent.as
  42. +57 −0 AwayPhysics/src/awayphysics/extend/AWPTerrain.as
  43. +43 −0 AwayPhysics/src/awayphysics/math/AWPMath.as
  44. +66 −0 AwayPhysics/src/awayphysics/math/AWPMatrix3x3.as
  45. +141 −0 AwayPhysics/src/awayphysics/math/AWPTransform.as
  46. +68 −0 AwayPhysics/src/awayphysics/math/AWPVector3.as
  47. +28 −0 AwayPhysics/src/com/adobe/flascc/Console.as
  48. +1,060 −0 Bullet/AwayPhysics.c
  49. +176 −0 Bullet/Bullet-C-Api.h
  50. +37 −0 Bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp
  51. +1,051 −0 Bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h
  52. +82 −0 Bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h
  53. +17 −0 Bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp
  54. +270 −0 Bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
  55. +23 −0 Bullet/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp
  56. +81 −0 Bullet/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h
  57. +1,295 −0 Bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp
  58. +1,270 −0 Bullet/BulletCollision/BroadphaseCollision/btDbvt.h
  59. +796 −0 Bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
  60. +146 −0 Bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h
  61. +22 −0 Bullet/BulletCollision/BroadphaseCollision/btDispatcher.cpp
  62. +110 −0 Bullet/BulletCollision/BroadphaseCollision/btDispatcher.h
  63. +489 −0 Bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp
  64. +151 −0 Bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h
  65. +633 −0 Bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
  66. +469 −0 Bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
  67. +40 −0 Bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h
  68. +1,393 −0 Bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
  69. +581 −0 Bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h
  70. +349 −0 Bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp
  71. +171 −0 Bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
  72. +279 −0 Bullet/BulletCollision/CMakeLists.txt
  73. +200 −0 Bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
  74. +51 −0 Bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.h
  75. +47 −0 Bullet/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp
  76. +36 −0 Bullet/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h
  77. +421 −0 Bullet/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp
  78. +66 −0 Bullet/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h
  79. +84 −0 Bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp
  80. +66 −0 Bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h
  81. +718 −0 Bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp
  82. +44 −0 Bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.h
  83. +48 −0 Bullet/BulletCollision/CollisionDispatch/btCollisionConfiguration.h
  84. +45 −0 Bullet/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h
  85. +314 −0 Bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
  86. +171 −0 Bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
  87. +116 −0 Bullet/BulletCollision/CollisionDispatch/btCollisionObject.cpp
  88. +534 −0 Bullet/BulletCollision/CollisionDispatch/btCollisionObject.h
  89. +40 −0 Bullet/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h
  90. +1,539 −0 Bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
  91. +522 −0 Bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h
  92. +366 −0 Bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
  93. +86 −0 Bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h
  94. +247 −0 Bullet/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp
  95. +95 −0 Bullet/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h
  96. +329 −0 Bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
  97. +121 −0 Bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
  98. +784 −0 Bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
  99. +108 −0 Bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
  100. +174 −0 Bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
  101. +84 −0 Bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
  102. +309 −0 Bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp
  103. +135 −0 Bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h
  104. +34 −0 Bullet/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp
  105. +54 −0 Bullet/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h
  106. +171 −0 Bullet/BulletCollision/CollisionDispatch/btGhostObject.cpp
  107. +175 −0 Bullet/BulletCollision/CollisionDispatch/btGhostObject.h
  108. +842 −0 Bullet/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
  109. +47 −0 Bullet/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h
  110. +154 −0 Bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp
  111. +150 −0 Bullet/BulletCollision/CollisionDispatch/btManifoldResult.h
  112. +450 −0 Bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
  113. +81 −0 Bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.h
  114. +214 −0 Bullet/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
  115. +75 −0 Bullet/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h
  116. +106 −0 Bullet/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
  117. +66 −0 Bullet/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h
  118. +84 −0 Bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp
  119. +69 −0 Bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h
  120. +82 −0 Bullet/BulletCollision/CollisionDispatch/btUnionFind.cpp
  121. +129 −0 Bullet/BulletCollision/CollisionDispatch/btUnionFind.h
  122. +42 −0 Bullet/BulletCollision/CollisionShapes/btBox2dShape.cpp
  123. +371 −0 Bullet/BulletCollision/CollisionShapes/btBox2dShape.h
  124. +51 −0 Bullet/BulletCollision/CollisionShapes/btBoxShape.cpp
  125. +314 −0 Bullet/BulletCollision/CollisionShapes/btBoxShape.h
  126. +466 −0 Bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
  127. +139 −0 Bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
  128. +171 −0 Bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp
  129. +184 −0 Bullet/BulletCollision/CollisionShapes/btCapsuleShape.h
  130. +27 −0 Bullet/BulletCollision/CollisionShapes/btCollisionMargin.h
  131. +119 −0 Bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp
  132. +159 −0 Bullet/BulletCollision/CollisionShapes/btCollisionShape.h
  133. +354 −0 Bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp
  134. +213 −0 Bullet/BulletCollision/CollisionShapes/btCompoundShape.h
  135. +27 −0 Bullet/BulletCollision/CollisionShapes/btConcaveShape.cpp
  136. +62 −0 Bullet/BulletCollision/CollisionShapes/btConcaveShape.h
  137. +143 −0 Bullet/BulletCollision/CollisionShapes/btConeShape.cpp
  138. +122 −0 Bullet/BulletCollision/CollisionShapes/btConeShape.h
  139. +92 −0 Bullet/BulletCollision/CollisionShapes/btConvex2dShape.cpp
  140. +82 −0 Bullet/BulletCollision/CollisionShapes/btConvex2dShape.h
  141. +245 −0 Bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp
  142. +122 −0 Bullet/BulletCollision/CollisionShapes/btConvexHullShape.h
  143. +151 −0 Bullet/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
  144. +224 −0 Bullet/BulletCollision/CollisionShapes/btConvexInternalShape.h
  145. +139 −0 Bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
  146. +105 −0 Bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h
Sorry, we could not display the entire diff because too many files (538) changed.
View
BIN  AwayPhysics/lib/AwayPhysics.swc
Binary file not shown
View
11 AwayPhysics/src/awayphysics/AWPBase.as
@@ -0,0 +1,11 @@
+package awayphysics {
+ public class AWPBase {
+ /**
+ * 1 visual units equal to 0.01 bullet meters by default, this value is inversely with physics world scaling
+ * refer to http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Scaling_The_World
+ */
+ protected static var _scaling : Number = 100;
+ protected var _cleanup:Boolean = false;
+ public var pointer : uint;
+ }
+}
View
498 AwayPhysics/src/awayphysics/collision/dispatch/AWPCollisionObject.as
@@ -0,0 +1,498 @@
+package awayphysics.collision.dispatch {
+ import AWPC_Run.addRayInC;
+ import AWPC_Run.createCollisionObjectInC;
+ import AWPC_Run.removeRayInC;
+ import AWPC_Run.disposeCollisionObjectInC;
+ import AWPC_Run.CModule;
+
+ import away3d.containers.ObjectContainer3D;
+
+ import awayphysics.AWPBase;
+ import awayphysics.collision.shapes.AWPCollisionShape;
+ import awayphysics.data.AWPCollisionFlags;
+ import awayphysics.events.AWPEvent;
+ import awayphysics.math.AWPMath;
+ import awayphysics.math.AWPTransform;
+ import awayphysics.math.AWPVector3;
+
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+ import flash.events.IEventDispatcher;
+ import flash.geom.Matrix3D;
+ import flash.geom.Vector3D;
+
+ public class AWPCollisionObject extends AWPBase implements IEventDispatcher {
+ public static const ACTIVE_TAG : int = 1;
+ public static const ISLAND_SLEEPING : int = 2;
+ public static const WANTS_DEACTIVATION : int = 3;
+ public static const DISABLE_DEACTIVATION : int = 4;
+ public static const DISABLE_SIMULATION : int = 5;
+
+ private var m_shape : AWPCollisionShape;
+ private var m_skin : ObjectContainer3D;
+ private var m_worldTransform : AWPTransform;
+ private var m_anisotropicFriction : AWPVector3;
+
+ private var _rays:Vector.<AWPRay>;
+
+ private var _originScale:Vector3D = new Vector3D(1, 1, 1);
+ private var _dispatcher : EventDispatcher;
+
+ public function AWPCollisionObject(shape : AWPCollisionShape, skin : ObjectContainer3D, ptr : uint = 0) {
+ m_shape = shape;
+ m_skin = skin;
+
+ m_shape.retain();
+
+ if(ptr>0){
+ pointer = ptr;
+ m_worldTransform = new AWPTransform(ptr + 4);
+ m_anisotropicFriction = new AWPVector3(ptr + 164);
+ }else{
+ pointer = createCollisionObjectInC(shape.pointer);
+
+ m_worldTransform = new AWPTransform(pointer + 4);
+ m_anisotropicFriction = new AWPVector3(pointer + 164);
+ }
+ if (m_skin) {
+ _originScale.setTo(m_skin.scaleX, m_skin.scaleY, m_skin.scaleZ);
+ }
+
+ _rays = new Vector.<AWPRay>();
+ _dispatcher = new EventDispatcher(this);
+ }
+
+ public function get shape() : AWPCollisionShape {
+ return m_shape;
+ }
+
+ public function get skin() : ObjectContainer3D {
+ return m_skin;
+ }
+
+ public function set skin(value:ObjectContainer3D):void {
+ m_skin = value;
+ _originScale.setTo(m_skin.scaleX, m_skin.scaleY, m_skin.scaleZ);
+ }
+
+ public function dispose():void {
+ if (!_cleanup) {
+ _cleanup = true;
+ removeAllRays();
+ m_shape.dispose();
+ disposeCollisionObjectInC(pointer);
+ }
+ }
+
+ /**
+ * update the transform of skin mesh
+ * called by dynamicsWorld
+ */
+ public function updateTransform() : void {
+ if (!m_skin) return;
+
+ var vec:Vector3D = m_shape.localScaling;
+ m_skin.scaleX = _originScale.x * vec.x;
+ m_skin.scaleY = _originScale.y * vec.y;
+ m_skin.scaleZ = _originScale.z * vec.z;
+ vec = AWPMath.radians2degreesV3D(m_worldTransform.rotation);
+ m_skin.rotateTo(vec.x,vec.y,vec.z);
+ m_skin.position = m_worldTransform.position;
+ }
+
+ /**
+ * set the position in world coordinates
+ */
+ public function set position(pos : Vector3D) : void {
+ m_worldTransform.position = pos;
+ updateTransform();
+ }
+ /**
+ * get the position in world coordinates
+ */
+ public function get position() : Vector3D {
+ return m_worldTransform.position;
+ }
+
+ /**
+ * set the position in x axis
+ */
+ public function set x(v:Number):void {
+ m_worldTransform.position = new Vector3D(v, m_worldTransform.position.y, m_worldTransform.position.z);
+ updateTransform();
+ }
+ /**
+ * get the position in x axis
+ */
+ public function get x():Number {
+ return m_worldTransform.position.x;
+ }
+
+ /**
+ * set the position in y axis
+ */
+ public function set y(v:Number):void {
+ m_worldTransform.position = new Vector3D(m_worldTransform.position.x, v, m_worldTransform.position.z);
+ updateTransform();
+ }
+ /**
+ * get the position in y axis
+ */
+ public function get y():Number {
+ return m_worldTransform.position.y;
+ }
+
+ /**
+ * set the position in z axis
+ */
+ public function set z(v:Number):void {
+ m_worldTransform.position = new Vector3D(m_worldTransform.position.x, m_worldTransform.position.y, v);
+ updateTransform();
+ }
+ /**
+ * get the position in z axis
+ */
+ public function get z():Number {
+ return m_worldTransform.position.z;
+ }
+
+ /**
+ * set the euler angle in degrees
+ */
+ public function set rotation(rot : Vector3D) : void {
+ m_worldTransform.rotation = AWPMath.degrees2radiansV3D(rot);
+ updateTransform();
+ }
+ /**
+ * get the euler angle in degrees
+ */
+ public function get rotation() : Vector3D {
+ return AWPMath.radians2degreesV3D(m_worldTransform.rotation);
+ }
+
+ /**
+ * set the angle of x axis in degree
+ */
+ public function set rotationX(angle:Number):void {
+ m_worldTransform.rotation = new Vector3D(angle * AWPMath.DEGREES_TO_RADIANS, m_worldTransform.rotation.y, m_worldTransform.rotation.z);
+ updateTransform();
+ }
+ /**
+ * get the angle of x axis in degree
+ */
+ public function get rotationX():Number {
+ return m_worldTransform.rotation.x * AWPMath.RADIANS_TO_DEGREES;
+ }
+
+ /**
+ * set the angle of y axis in degree
+ */
+ public function set rotationY(angle:Number):void {
+ m_worldTransform.rotation = new Vector3D(m_worldTransform.rotation.x, angle * AWPMath.DEGREES_TO_RADIANS, m_worldTransform.rotation.z);
+ updateTransform();
+ }
+ /**
+ * get the angle of y axis in degree
+ */
+ public function get rotationY():Number {
+ return m_worldTransform.rotation.y * AWPMath.RADIANS_TO_DEGREES;
+ }
+
+ /**
+ * set the angle of z axis in degree
+ */
+ public function set rotationZ(angle:Number):void {
+ m_worldTransform.rotation = new Vector3D(m_worldTransform.rotation.x, m_worldTransform.rotation.y, angle * AWPMath.DEGREES_TO_RADIANS);
+ updateTransform();
+ }
+ /**
+ * get the angle of z axis in degree
+ */
+ public function get rotationZ():Number {
+ return m_worldTransform.rotation.z * AWPMath.RADIANS_TO_DEGREES;
+ }
+
+ /**
+ * set the scaling of collision shape
+ */
+ public function set scale(sc:Vector3D):void {
+ m_shape.localScaling = sc;
+ updateTransform();
+ }
+ /**
+ * get the scaling of collision shape
+ */
+ public function get scale():Vector3D {
+ return m_shape.localScaling;
+ }
+
+ /**
+ * set the transform in world coordinates
+ */
+ public function set transform(tr:Matrix3D) : void {
+ m_worldTransform.transform = tr;
+ m_shape.localScaling = tr.decompose()[2];
+ updateTransform();
+ }
+ /**
+ * get the transform in world coordinates
+ */
+ public function get transform():Matrix3D {
+ return m_worldTransform.transform;
+ }
+
+ public function get worldTransform():AWPTransform {
+ return m_worldTransform;
+ }
+
+ /**
+ * get the front direction in world coordinates
+ */
+ public function get front():Vector3D {
+ return m_worldTransform.basis.column3;
+ }
+ /**
+ * get the up direction in world coordinates
+ */
+ public function get up():Vector3D {
+ return m_worldTransform.basis.column2;
+ }
+ /**
+ * get the right direction in world coordinates
+ */
+ public function get right():Vector3D {
+ return m_worldTransform.basis.column1;
+ }
+
+ /**
+ * add a ray in local space
+ */
+ public function addRay(from:Vector3D, to:Vector3D):void {
+ var vec1:AWPVector3 = new AWPVector3();
+ vec1.sv3d = from;
+ var vec2:AWPVector3 = new AWPVector3();
+ vec2.sv3d = to;
+ var ptr:uint = addRayInC(pointer, vec1.pointer, vec2.pointer);
+ _rays.push(new AWPRay(from, to, ptr));
+
+ CModule.free(vec1.pointer);
+ CModule.free(vec2.pointer);
+ }
+ /**
+ * remove a ray by index
+ */
+ public function removeRay(index:uint):void {
+ if(index<_rays.length){
+ removeRayInC(_rays[index].pointer);
+ _rays.splice(index, 1);
+ }
+ }
+ /**
+ * remove all rays in this collision object
+ */
+ public function removeAllRays():void {
+ while (_rays.length > 0){
+ removeRay(0);
+ }
+ _rays.length = 0;
+ }
+
+ /**
+ * get all rays
+ */
+ public function get rays():Vector.<AWPRay> {
+ return _rays;
+ }
+
+ public function get anisotropicFriction() : Vector3D {
+ return m_anisotropicFriction.v3d;
+ }
+
+ public function set anisotropicFriction(v : Vector3D) : void {
+ m_anisotropicFriction.v3d = v;
+ hasAnisotropicFriction = (v.x != 1 || v.y != 1 || v.z != 1) ? 1 : 0;
+ }
+
+ public function get friction() : Number {
+ return CModule.readFloat(pointer + 224);
+ }
+
+ public function set friction(v : Number) : void {
+ CModule.writeFloat(pointer + 224, v);
+ }
+
+ public function get rollingFriction() : Number {
+ return CModule.readFloat(pointer + 232);
+ }
+
+ public function set rollingFriction(v : Number) : void {
+ CModule.writeFloat(pointer + 232, v);
+ }
+
+ public function get restitution() : Number {
+ return CModule.readFloat(pointer + 228);
+ }
+
+ public function set restitution(v : Number) : void {
+ CModule.writeFloat(pointer + 228, v);
+ }
+
+ public function get hasAnisotropicFriction() : int {
+ return CModule.read32(pointer + 180);
+ }
+
+ public function set hasAnisotropicFriction(v : int) : void {
+ CModule.write32(pointer + 180, v);
+ }
+
+ public function get contactProcessingThreshold() : Number {
+ return CModule.readFloat(pointer + 184);
+ }
+
+ public function set contactProcessingThreshold(v : Number) : void {
+ CModule.writeFloat(pointer + 184, v);
+ }
+
+ public function get collisionFlags() : int {
+ return CModule.read32(pointer + 204);
+ }
+
+ public function set collisionFlags(v : int) : void {
+ CModule.write32(pointer + 204, v);
+ }
+
+ public function get islandTag() : int {
+ return CModule.read32(pointer + 208);
+ }
+
+ public function set islandTag(v : int) : void {
+ CModule.write32(pointer + 208, v);
+ }
+
+ public function get companionId() : int {
+ return CModule.read32(pointer + 212);
+ }
+
+ public function set companionId(v : int) : void {
+ CModule.write32(pointer + 212, v);
+ }
+
+ public function get deactivationTime() : Number {
+ return CModule.readFloat(pointer + 220);
+ }
+
+ public function set deactivationTime(v : Number) : void {
+ CModule.writeFloat(pointer + 220, v);
+ }
+
+ public function get activationState() : int {
+ return CModule.read32(pointer + 216);
+ }
+
+ public function set activationState(newState : int) : void {
+ if (activationState != AWPCollisionObject.DISABLE_DEACTIVATION && activationState != AWPCollisionObject.DISABLE_SIMULATION) {
+ CModule.write32(pointer + 216, newState);
+ }
+ }
+
+ public function forceActivationState(newState : int) : void {
+ CModule.write32(pointer + 216, newState);
+ }
+
+ public function activate(forceActivation : Boolean = false) : void {
+ if (forceActivation || (collisionFlags != AWPCollisionFlags.CF_STATIC_OBJECT && collisionFlags != AWPCollisionFlags.CF_KINEMATIC_OBJECT)) {
+ this.activationState = AWPCollisionObject.ACTIVE_TAG;
+ this.deactivationTime = 0;
+ }
+ }
+
+ public function get isActive() : Boolean {
+ return (activationState != AWPCollisionObject.ISLAND_SLEEPING && activationState != AWPCollisionObject.DISABLE_SIMULATION);
+ }
+
+ /**
+ * reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
+ * the values defined by AWPCollisionObjectTypes
+ */
+ public function get internalType() : int {
+ return CModule.read32(pointer + 236);
+ }
+
+ public function get hitFraction() : Number {
+ return CModule.readFloat(pointer + 244);
+ }
+
+ public function set hitFraction(v : Number) : void {
+ CModule.writeFloat(pointer + 244, v);
+ }
+
+ public function get ccdSweptSphereRadius() : Number {
+ return CModule.readFloat(pointer + 248);
+ }
+
+ /**
+ * used to motion clamping
+ * refer to http://bulletphysics.org/mediawiki-1.5.8/index.php/Anti_tunneling_by_Motion_Clamping
+ */
+ public function set ccdSweptSphereRadius(v : Number) : void {
+ CModule.writeFloat(pointer + 248, v);
+ }
+
+ public function get ccdMotionThreshold() : Number {
+ return CModule.readFloat(pointer + 252);
+ }
+
+ /**
+ * used to motion clamping
+ * refer to http://bulletphysics.org/mediawiki-1.5.8/index.php/Anti_tunneling_by_Motion_Clamping
+ */
+ public function set ccdMotionThreshold(v : Number) : void {
+ CModule.writeFloat(pointer + 252, v);
+ }
+
+ public function addEventListener(type : String, listener : Function, useCapture : Boolean = false, priority : int = 0, useWeakReference : Boolean = false) : void {
+ this.collisionFlags |= AWPCollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK;
+ _dispatcher.addEventListener(type, listener, useCapture, priority);
+ }
+
+ public function dispatchEvent(evt : Event) : Boolean {
+ return _dispatcher.dispatchEvent(evt);
+ }
+
+ public function hasEventListener(type : String) : Boolean {
+ return _dispatcher.hasEventListener(type);
+ }
+
+ public function removeEventListener(type : String, listener : Function, useCapture : Boolean = false) : void {
+ this.collisionFlags &= (~AWPCollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
+ _dispatcher.removeEventListener(type, listener, useCapture);
+ }
+
+ public function willTrigger(type : String) : Boolean {
+ return _dispatcher.willTrigger(type);
+ }
+
+ /**
+ * this function just called by alchemy
+ */
+ public function collisionCallback(mpt : uint, obj : AWPCollisionObject) : void {
+ var pt : AWPManifoldPoint = new AWPManifoldPoint(mpt);
+ var event : AWPEvent = new AWPEvent(AWPEvent.COLLISION_ADDED);
+ event.manifoldPoint = pt;
+ event.collisionObject = obj;
+
+ this.dispatchEvent(event);
+ }
+ /**
+ * this function just called by alchemy
+ */
+ public function rayCastCallback(mpt : uint, obj : AWPCollisionObject) : void {
+ var pt : AWPManifoldPoint = new AWPManifoldPoint(mpt);
+ var event : AWPEvent = new AWPEvent(AWPEvent.RAY_CAST);
+ event.manifoldPoint = pt;
+ event.collisionObject = obj;
+
+ this.dispatchEvent(event);
+ }
+ }
+}
View
46 AwayPhysics/src/awayphysics/collision/dispatch/AWPCollisionWorld.as
@@ -0,0 +1,46 @@
+package awayphysics.collision.dispatch {
+ import AWPC_Run.addCollisionObjectInC;
+ import AWPC_Run.removeCollisionObjectInC;
+
+ import awayphysics.AWPBase;
+ import awayphysics.collision.dispatch.AWPCollisionObject;
+
+ import flash.utils.Dictionary;
+
+ public class AWPCollisionWorld extends AWPBase{
+
+ protected var m_collisionObjects:Dictionary;
+
+ public function AWPCollisionWorld(){
+ m_collisionObjects = new Dictionary(true);
+ }
+
+ public function get collisionObjects() : Dictionary {
+ return m_collisionObjects;
+ }
+
+ /**
+ * add a collisionObject to collision world
+ */
+ public function addCollisionObject(obj:AWPCollisionObject, group:int = 1, mask:int = -1):void{
+ if(!m_collisionObjects.hasOwnProperty(obj.pointer.toString())){
+ m_collisionObjects[obj.pointer.toString()] = obj;
+ addCollisionObjectInC(obj.pointer, group, mask);
+ }
+ }
+
+ /**
+ * remove a collisionObject from collision world, if cleanup is true, release pointer in memory.
+ */
+ public function removeCollisionObject(obj:AWPCollisionObject, cleanup:Boolean = false) : void {
+ if(m_collisionObjects.hasOwnProperty(obj.pointer.toString())){
+ delete m_collisionObjects[obj.pointer.toString()];
+ removeCollisionObjectInC(obj.pointer);
+
+ if (cleanup) {
+ obj.dispose();
+ }
+ }
+ }
+ }
+}
View
15 AwayPhysics/src/awayphysics/collision/dispatch/AWPGhostObject.as
@@ -0,0 +1,15 @@
+package awayphysics.collision.dispatch {
+ import AWPC_Run.createGhostObjectInC;
+ import away3d.containers.ObjectContainer3D;
+ import awayphysics.collision.shapes.AWPCollisionShape;
+
+ /**
+ *used for create the character controller
+ */
+ public class AWPGhostObject extends AWPCollisionObject {
+ public function AWPGhostObject(shape : AWPCollisionShape, skin : ObjectContainer3D = null) {
+ pointer = createGhostObjectInC(shape.pointer);
+ super(shape, skin, pointer);
+ }
+ }
+}
View
48 AwayPhysics/src/awayphysics/collision/dispatch/AWPManifoldPoint.as
@@ -0,0 +1,48 @@
+package awayphysics.collision.dispatch {
+ import AWPC_Run.CModule;
+ import awayphysics.AWPBase;
+ import awayphysics.math.AWPVector3;
+
+ import flash.geom.Vector3D;
+
+ public class AWPManifoldPoint extends AWPBase {
+ private var m_localPointA : AWPVector3;
+ private var m_localPointB : AWPVector3;
+ private var m_normalWorldOnB : AWPVector3;
+
+ public function AWPManifoldPoint(ptr : uint) {
+ pointer = ptr;
+ m_localPointA = new AWPVector3(ptr + 0);
+ m_localPointB = new AWPVector3(ptr + 16);
+ m_normalWorldOnB = new AWPVector3(ptr + 64);
+ }
+
+ /**
+ *get the collision position in objectA's local coordinates
+ */
+ public function get localPointA() : Vector3D {
+ return m_localPointA.sv3d;
+ }
+
+ /**
+ *get the collision position in objectB's local coordinates
+ */
+ public function get localPointB() : Vector3D {
+ return m_localPointB.sv3d;
+ }
+
+ /**
+ *get the collision normal in world coordinates
+ */
+ public function get normalWorldOnB() : Vector3D {
+ return m_normalWorldOnB.v3d;
+ }
+
+ /**
+ *get the value of collision impulse
+ */
+ public function get appliedImpulse() : Number {
+ return CModule.readFloat(pointer + 120);
+ }
+ }
+}
View
14 AwayPhysics/src/awayphysics/collision/dispatch/AWPRay.as
@@ -0,0 +1,14 @@
+package awayphysics.collision.dispatch {
+ import flash.geom.Vector3D;
+ import awayphysics.AWPBase;
+ public class AWPRay extends AWPBase {
+ public var rayFrom:Vector3D;
+ public var rayTo:Vector3D;
+
+ public function AWPRay(from:Vector3D, to:Vector3D, ptr:uint = 0) {
+ rayFrom = from;
+ rayTo = to;
+ pointer = ptr;
+ }
+ }
+}
View
26 AwayPhysics/src/awayphysics/collision/shapes/AWPBoxShape.as
@@ -0,0 +1,26 @@
+package awayphysics.collision.shapes {
+ import flash.geom.Vector3D;
+
+ import AWPC_Run.createBoxShapeInC;
+ import AWPC_Run.CModule;
+
+ import awayphysics.math.AWPVector3;
+
+ public class AWPBoxShape extends AWPCollisionShape {
+
+ private var _dimensions:Vector3D;
+
+ public function AWPBoxShape(width : Number = 100, height : Number = 100, depth : Number = 100) {
+ _dimensions = new Vector3D(width, height, depth);
+ var vec:AWPVector3 = new AWPVector3();
+ vec.sv3d = new Vector3D(width, height, depth);
+ pointer = createBoxShapeInC(vec.pointer);
+ CModule.free(vec.pointer);
+ super(pointer, 0);
+ }
+
+ public function get dimensions():Vector3D {
+ return new Vector3D(_dimensions.x * m_localScaling.x, _dimensions.y * m_localScaling.y, _dimensions.z * m_localScaling.z);
+ }
+ }
+}
View
60 AwayPhysics/src/awayphysics/collision/shapes/AWPBvhTriangleMeshShape.as
@@ -0,0 +1,60 @@
+package awayphysics.collision.shapes {
+ import AWPC_Run.*;
+
+ import away3d.core.base.*;
+
+ public class AWPBvhTriangleMeshShape extends AWPCollisionShape {
+ private var indexDataPtr : uint;
+ private var vertexDataPtr : uint;
+
+ private var _geometry:Geometry;
+
+ /**
+ *create a static triangle mesh shape with a 3D mesh object
+ */
+ public function AWPBvhTriangleMeshShape(geometry : Geometry, useQuantizedAabbCompression : Boolean = true) {
+ _geometry = geometry;
+ var indexData : Vector.<uint> = geometry.subGeometries[0].indexData;
+ var indexDataLen : int = indexData.length;
+ indexDataPtr = createTriangleIndexDataBufferInC(indexDataLen);
+
+ for (var i : int = 0; i < indexDataLen; i++ ) {
+ CModule.write32(indexDataPtr+i*4,indexData[i]);
+ }
+
+ var vertexData : Vector.<Number> = geometry.subGeometries[0].vertexData;
+ var vertexDataLen : int = vertexData.length/13;
+ vertexDataPtr = createTriangleVertexDataBufferInC(vertexDataLen*3);
+
+ for (i = 0; i < vertexDataLen; i++ ) {
+ CModule.writeFloat(vertexDataPtr+i*12,vertexData[i*13] / _scaling);
+ CModule.writeFloat(vertexDataPtr+i*12 + 4,vertexData[i*13+1] / _scaling);
+ CModule.writeFloat(vertexDataPtr+i*12 + 8,vertexData[i*13+2] / _scaling);
+ }
+
+ var triangleIndexVertexArrayPtr : uint = createTriangleIndexVertexArrayInC(int(indexDataLen / 3), indexDataPtr, int(vertexDataLen), vertexDataPtr);
+
+ pointer = createBvhTriangleMeshShapeInC(triangleIndexVertexArrayPtr, useQuantizedAabbCompression ? 1 : 0, 1);
+ super(pointer, 9);
+ }
+
+ override public function dispose() : void {
+ m_counter--;
+ if (m_counter > 0) {
+ return;
+ }else {
+ m_counter = 0;
+ }
+ if (!_cleanup) {
+ _cleanup = true;
+ removeTriangleIndexDataBufferInC(indexDataPtr);
+ removeTriangleVertexDataBufferInC(vertexDataPtr);
+ disposeCollisionShapeInC(pointer);
+ }
+ }
+
+ public function get geometry():Geometry {
+ return _geometry;
+ }
+ }
+}
View
25 AwayPhysics/src/awayphysics/collision/shapes/AWPCapsuleShape.as
@@ -0,0 +1,25 @@
+package awayphysics.collision.shapes {
+ import AWPC_Run.createCapsuleShapeInC;
+ public class AWPCapsuleShape extends AWPCollisionShape {
+
+ private var _radius:Number;
+ private var _height:Number;
+
+ public function AWPCapsuleShape(radius : Number = 50, height : Number = 100) {
+
+ _radius = radius;
+ _height = height;
+
+ pointer = createCapsuleShapeInC(radius / _scaling, height / _scaling);
+ super(pointer, 3);
+ }
+
+ public function get radius():Number {
+ return _radius * m_localScaling.x;
+ }
+
+ public function get height():Number {
+ return _height * m_localScaling.y;
+ }
+ }
+}
View
69 AwayPhysics/src/awayphysics/collision/shapes/AWPCollisionShape.as
@@ -0,0 +1,69 @@
+package awayphysics.collision.shapes {
+ import AWPC_Run.CModule;
+ import AWPC_Run.setShapeScalingInC;
+ import AWPC_Run.disposeCollisionShapeInC;
+
+ import awayphysics.AWPBase;
+ import awayphysics.math.AWPVector3;
+
+ import flash.geom.Vector3D;
+
+ public class AWPCollisionShape extends AWPBase {
+
+ protected var m_shapeType:int;
+ protected var m_localScaling:Vector3D;
+
+ protected var m_counter:int = 0;
+
+ public function AWPCollisionShape(ptr:uint, type:int) {
+ pointer = ptr;
+ m_shapeType = type;
+
+ m_localScaling = new Vector3D(1, 1, 1);
+ }
+
+ /**
+ * the values defined by AWPCollisionShapeType
+ */
+ public function get shapeType():int {
+ return m_shapeType;
+ }
+
+ public function get localScaling():Vector3D {
+ return m_localScaling;
+ }
+
+ public function set localScaling(scale:Vector3D):void {
+ m_localScaling.setTo(scale.x, scale.y, scale.z);
+ if(scale.w == 0){
+ var vec:AWPVector3 = new AWPVector3();
+ vec.v3d = scale;
+ setShapeScalingInC(pointer, vec.pointer);
+ CModule.free(vec.pointer);
+ }
+ }
+
+ /**
+ * this function just called by internal
+ */
+ public function retain():void {
+ m_counter++;
+ }
+
+ /**
+ * this function just called by internal
+ */
+ public function dispose():void {
+ m_counter--;
+ if (m_counter > 0) {
+ return;
+ }else {
+ m_counter = 0;
+ }
+ if (!_cleanup) {
+ _cleanup = true;
+ disposeCollisionShapeInC(pointer);
+ }
+ }
+ }
+}
View
129 AwayPhysics/src/awayphysics/collision/shapes/AWPCompoundShape.as
@@ -0,0 +1,129 @@
+package awayphysics.collision.shapes {
+ import AWPC_Run.addCompoundChildInC;
+ import AWPC_Run.createCompoundShapeInC;
+ import AWPC_Run.removeCompoundChildInC;
+ import AWPC_Run.setShapeScalingInC;
+ import AWPC_Run.disposeCollisionShapeInC;
+ import AWPC_Run.CModule;
+
+ import awayphysics.math.AWPMath;
+ import awayphysics.math.AWPMatrix3x3;
+ import awayphysics.math.AWPTransform;
+ import awayphysics.math.AWPVector3;
+
+ import flash.geom.Matrix3D;
+ import flash.geom.Vector3D;
+
+ public class AWPCompoundShape extends AWPCollisionShape {
+ private var _children : Vector.<AWPCollisionShape>;
+ private var _allChildren:Vector.<AWPCollisionShape>;
+ private var _transforms:Vector.<AWPTransform>;
+ private var _childTransform:AWPTransform;
+
+ /**
+ *create a compound shape use the other primitive shapes
+ */
+ public function AWPCompoundShape() {
+ pointer = createCompoundShapeInC();
+ super(pointer, 7);
+ _children = new Vector.<AWPCollisionShape>();
+ _allChildren = new Vector.<AWPCollisionShape>();
+ _transforms = new Vector.<AWPTransform>();
+
+ _childTransform = new AWPTransform();
+ }
+
+ /**
+ *add a child shape and set its position and rotation in local coordinates
+ */
+ public function addChildShape(child : AWPCollisionShape, localPos : Vector3D = null, localRot : Vector3D = null) : void {
+
+ if ( localPos == null )
+ localPos = new Vector3D();
+
+ if ( localRot == null )
+ localRot = new Vector3D();
+
+ var tr:AWPTransform = new AWPTransform();
+ tr.position = localPos;
+ tr.rotation = AWPMath.degrees2radiansV3D(localRot);
+ _transforms.push(tr);
+
+ var rot:Matrix3D = AWPMath.euler2matrix(AWPMath.degrees2radiansV3D(localRot));
+ var vec:AWPVector3 = new AWPVector3();
+ vec.sv3d = localPos;
+ var mat:AWPMatrix3x3 = new AWPMatrix3x3();
+ mat.m3d = rot;
+ addCompoundChildInC(pointer, child.pointer, vec.pointer, mat.pointer);
+
+ CModule.free(vec.pointer);
+ CModule.free(mat.pointer);
+
+ _children.push(child);
+ _allChildren.push(child);
+ }
+
+ /**
+ *remove a child shape from compound shape
+ */
+ public function removeChildShapeByIndex(childShapeindex : int) : void {
+ removeCompoundChildInC(pointer, childShapeindex);
+
+ _children.splice(childShapeindex, 1);
+ _transforms.splice(childShapeindex, 1);
+ }
+
+ /**
+ *remove all children shape from compound shape
+ */
+ public function removeAllChildren() : void {
+ while (_children.length > 0){
+ removeChildShapeByIndex(0);
+ }
+ _children.length = 0;
+ _transforms.length = 0;
+ }
+
+ /**
+ *get the children list
+ */
+ public function get children() : Vector.<AWPCollisionShape> {
+ return _children;
+ }
+
+ public function getChildTransform(index:int):AWPTransform {
+ _childTransform.position=AWPMath.vectorMultiply(_transforms[index].position, m_localScaling);
+ _childTransform.rotation=_transforms[index].rotation;
+ return _childTransform;
+ }
+
+ override public function set localScaling(scale:Vector3D):void {
+ m_localScaling.setTo(scale.x, scale.y, scale.z);
+ var vec:AWPVector3 = new AWPVector3();
+ vec.v3d = scale;
+ setShapeScalingInC(pointer, vec.pointer);
+ CModule.free(vec.pointer);
+ for each(var shape:AWPCollisionShape in _children) {
+ shape.localScaling = new Vector3D(scale.x, scale.y, scale.z, 1);
+ }
+ }
+
+ override public function dispose():void {
+ m_counter--;
+ if (m_counter > 0) {
+ return;
+ }else {
+ m_counter = 0;
+ }
+ if (!_cleanup) {
+ _cleanup = true;
+ removeAllChildren();
+ for each(var shape:AWPCollisionShape in _allChildren) {
+ shape.dispose();
+ }
+ _allChildren.length = 0;
+ disposeCollisionShapeInC(pointer);
+ }
+ }
+ }
+}
View
25 AwayPhysics/src/awayphysics/collision/shapes/AWPConeShape.as
@@ -0,0 +1,25 @@
+package awayphysics.collision.shapes {
+ import AWPC_Run.createConeShapeInC;
+ public class AWPConeShape extends AWPCollisionShape {
+
+ private var _radius:Number;
+ private var _height:Number;
+
+ public function AWPConeShape(radius : Number = 50, height : Number = 100) {
+
+ _radius = radius;
+ _height = height;
+
+ pointer = createConeShapeInC(radius / _scaling, height / _scaling);
+ super(pointer, 4);
+ }
+
+ public function get radius():Number {
+ return _radius * m_localScaling.x;
+ }
+
+ public function get height():Number {
+ return _height * m_localScaling.y;
+ }
+ }
+}
View
52 AwayPhysics/src/awayphysics/collision/shapes/AWPConvexHullShape.as
@@ -0,0 +1,52 @@
+package awayphysics.collision.shapes
+{
+ import AWPC_Run.CModule;
+ import AWPC_Run.createTriangleVertexDataBufferInC;
+ import AWPC_Run.removeTriangleVertexDataBufferInC;
+ import AWPC_Run.createConvexHullShapeInC;
+ import AWPC_Run.disposeCollisionShapeInC
+ import away3d.core.base.Geometry;
+
+ public class AWPConvexHullShape extends AWPCollisionShape
+ {
+ private var vertexDataPtr : uint;
+
+ private var _geometry:Geometry;
+
+ public function AWPConvexHullShape(geometry : Geometry)
+ {
+ _geometry = geometry;
+ var vertexData : Vector.<Number> = geometry.subGeometries[0].vertexData;
+ var vertexDataLen : int = vertexData.length/13;
+ vertexDataPtr = createTriangleVertexDataBufferInC(vertexDataLen*3);
+
+ for (var i:int = 0; i < vertexDataLen; i++ ) {
+ CModule.writeFloat(vertexDataPtr+i*12,vertexData[i*13] / _scaling);
+ CModule.writeFloat(vertexDataPtr+i*12+ 4,vertexData[i*13+1] / _scaling);
+ CModule.writeFloat(vertexDataPtr+i*12 + 8,vertexData[i*13+2] / _scaling);
+ }
+
+ pointer = createConvexHullShapeInC(int(vertexDataLen), vertexDataPtr);
+ super(pointer, 5);
+ }
+
+ override public function dispose() : void
+ {
+ m_counter--;
+ if (m_counter > 0) {
+ return;
+ }else {
+ m_counter = 0;
+ }
+ if (!_cleanup) {
+ _cleanup = true;
+ removeTriangleVertexDataBufferInC(vertexDataPtr);
+ disposeCollisionShapeInC(pointer);
+ }
+ }
+
+ public function get geometry():Geometry {
+ return _geometry;
+ }
+ }
+}
View
32 AwayPhysics/src/awayphysics/collision/shapes/AWPCylinderShape.as
@@ -0,0 +1,32 @@
+package awayphysics.collision.shapes {
+ import flash.geom.Vector3D;
+ import AWPC_Run.CModule;
+ import AWPC_Run.createCylinderShapeInC;
+ import awayphysics.math.AWPVector3;
+
+ public class AWPCylinderShape extends AWPCollisionShape {
+
+ private var _radius:Number;
+ private var _height:Number;
+
+ public function AWPCylinderShape(radius : Number = 50, height : Number = 100) {
+
+ _radius = radius;
+ _height = height;
+
+ var vec:AWPVector3 = new AWPVector3();
+ vec.v3d = new Vector3D(radius * 2 / _scaling, height / _scaling, radius * 2 / _scaling)
+ pointer = createCylinderShapeInC(vec.pointer);
+ CModule.free(vec.pointer);
+ super(pointer, 2);
+ }
+
+ public function get radius():Number {
+ return _radius * m_localScaling.x;
+ }
+
+ public function get height():Number {
+ return _height * m_localScaling.y;
+ }
+ }
+}
View
51 AwayPhysics/src/awayphysics/collision/shapes/AWPHeightfieldTerrainShape.as
@@ -0,0 +1,51 @@
+package awayphysics.collision.shapes {
+ import AWPC_Run.CModule;
+ import AWPC_Run.createHeightmapDataBufferInC;
+ import AWPC_Run.removeHeightmapDataBufferInC;
+ import AWPC_Run.createTerrainShapeInC;
+ import AWPC_Run.disposeCollisionShapeInC;
+
+ import away3d.core.base.Geometry;
+ import awayphysics.extend.AWPTerrain;
+
+ public class AWPHeightfieldTerrainShape extends AWPCollisionShape {
+ private var dataPtr : uint;
+
+ private var _geometry:Geometry;
+
+ /**
+ * create terrain with the heightmap data
+ */
+ public function AWPHeightfieldTerrainShape(terrain : AWPTerrain) {
+ _geometry = terrain.geometry;
+ var dataLen : int = terrain.sw * terrain.sh;
+ dataPtr = createHeightmapDataBufferInC(dataLen);
+
+ var data : Vector.<Number> = terrain.heights;
+ for (var i : int = 0; i < dataLen; i++ ) {
+ CModule.writeFloat(dataPtr+i*4,data[i] / _scaling);
+ }
+
+ pointer = createTerrainShapeInC(dataPtr, terrain.sw, terrain.sh, terrain.lw / _scaling, terrain.lh / _scaling, 1, -terrain.maxHeight / _scaling, terrain.maxHeight / _scaling, 1);
+ super(pointer, 10);
+ }
+
+ override public function dispose() : void {
+ m_counter--;
+ if (m_counter > 0) {
+ return;
+ }else {
+ m_counter = 0;
+ }
+ if (!_cleanup) {
+ _cleanup = true;
+ removeHeightmapDataBufferInC(dataPtr);
+ disposeCollisionShapeInC(pointer);
+ }
+ }
+
+ public function get geometry():Geometry {
+ return _geometry;
+ }
+ }
+}
View
18 AwayPhysics/src/awayphysics/collision/shapes/AWPSphereShape.as
@@ -0,0 +1,18 @@
+package awayphysics.collision.shapes {
+ import AWPC_Run.createSphereShapeInC;
+ public class AWPSphereShape extends AWPCollisionShape {
+
+ private var _radius:Number;
+
+ public function AWPSphereShape(radius : Number = 50) {
+ _radius = radius;
+
+ pointer = createSphereShapeInC(radius / _scaling);
+ super(pointer, 1);
+ }
+
+ public function get radius():Number {
+ return _radius * m_localScaling.x;
+ }
+ }
+}
View
36 AwayPhysics/src/awayphysics/collision/shapes/AWPStaticPlaneShape.as
@@ -0,0 +1,36 @@
+package awayphysics.collision.shapes {
+ import AWPC_Run.CModule;
+ import AWPC_Run.createStaticPlaneShapeInC;
+
+ import awayphysics.math.AWPVector3;
+
+ import flash.geom.Vector3D;
+
+ public class AWPStaticPlaneShape extends AWPCollisionShape {
+
+ private var _normal:Vector3D;
+ private var _constant:Number;
+
+ public function AWPStaticPlaneShape(normal : Vector3D = null, constant : Number = 0) {
+ if (!normal) {
+ normal = new Vector3D(0, 1, 0);
+ }
+ _normal = normal;
+ _constant = constant;
+
+ var vec:AWPVector3 = new AWPVector3();
+ vec.v3d = normal;
+ pointer = createStaticPlaneShapeInC(vec.pointer, constant / _scaling);
+ CModule.free(vec.pointer);
+ super(pointer, 8);
+ }
+
+ public function get normal():Vector3D {
+ return _normal;
+ }
+
+ public function get constant():Number {
+ return _constant;
+ }
+ }
+}
View
44 AwayPhysics/src/awayphysics/collision/shapes/AWPTriangleShape.as
@@ -0,0 +1,44 @@
+package awayphysics.collision.shapes
+{
+ import AWPC_Run.CModule;
+ import AWPC_Run.createTriangleShapeInC;
+ import awayphysics.math.AWPVector3;
+ import flash.geom.Vector3D;
+
+ public class AWPTriangleShape extends AWPCollisionShape
+ {
+ private var _point0:Vector3D;
+ private var _point1:Vector3D;
+ private var _point2:Vector3D;
+
+ public function AWPTriangleShape(p0:Vector3D, p1:Vector3D, p2:Vector3D)
+ {
+ _point0 = p0.clone();
+ _point1 = p1.clone();
+ _point2 = p2.clone();
+ var vec1:AWPVector3 = new AWPVector3();
+ vec1.sv3d = p0;
+ var vec2:AWPVector3 = new AWPVector3();
+ vec2.sv3d = p1;
+ var vec3:AWPVector3 = new AWPVector3();
+ vec3.sv3d = p2;
+ pointer = createTriangleShapeInC(vec1.pointer, vec2.pointer, vec3.pointer);
+ CModule.free(vec1.pointer);
+ CModule.free(vec2.pointer);
+ CModule.free(vec3.pointer);
+ super(pointer, 6);
+ }
+
+ public function get point0():Vector3D{
+ return _point0;
+ }
+
+ public function get point1():Vector3D{
+ return _point1;
+ }
+
+ public function get point2():Vector3D{
+ return _point2;
+ }
+ }
+}
View
12 AwayPhysics/src/awayphysics/data/AWPCollisionFilterGroups.as
@@ -0,0 +1,12 @@
+package awayphysics.data {
+ public class AWPCollisionFilterGroups {
+ public static const DefaultFilter : int = 1;
+ public static const StaticFilter : int = 2;
+ public static const KinematicFilter : int = 4;
+ public static const DebrisFilter : int = 8;
+ public static const SensorTrigger : int = 16;
+ public static const CharacterFilter : int = 32;
+ public static const AllFilter : int = -1;
+ // all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
+ }
+}
View
10 AwayPhysics/src/awayphysics/data/AWPCollisionFlags.as
@@ -0,0 +1,10 @@
+package awayphysics.data {
+ public class AWPCollisionFlags {
+ public static const CF_STATIC_OBJECT : int = 1;
+ public static const CF_KINEMATIC_OBJECT : int = 2;
+ public static const CF_NO_CONTACT_RESPONSE : int = 4;
+ public static const CF_CUSTOM_MATERIAL_CALLBACK : int = 8;
+ public static const CF_CHARACTER_OBJECT : int = 16;
+ public static const CF_DISABLE_VISUALIZE_OBJECT : int = 32;
+ }
+}
View
10 AwayPhysics/src/awayphysics/data/AWPCollisionObjectTypes.as
@@ -0,0 +1,10 @@
+package awayphysics.data {
+ public class AWPCollisionObjectTypes {
+ public static const CO_COLLISION_OBJECT : int = 1;
+ public static const CO_RIGID_BODY : int = 2;
+ public static const CO_GHOST_OBJECT : int = 4;
+ public static const CO_SOFT_BODY : int = 8;
+ public static const CO_HF_FLUID : int = 16;
+ public static const CO_USER_TYPE : int = 32;
+ }
+}
View
15 AwayPhysics/src/awayphysics/data/AWPCollisionShapeType.as
@@ -0,0 +1,15 @@
+package awayphysics.data {
+ public class AWPCollisionShapeType {
+ public static const BOX_SHAPE : int = 0;
+ public static const SPHERE_SHAPE : int = 1;
+ public static const CYLINDER_SHAPE : int = 2;
+ public static const CAPSULE_SHAPE : int = 3;
+ public static const CONE_SHAPE : int = 4;
+ public static const CONVEX_HULL_SHAPE : int = 5;
+ public static const TRIANGLE_SHAPE : int = 6;
+ public static const COMPOUND_SHAPE : int = 7;
+ public static const STATIC_PLANE : int = 8;
+ public static const TRIANGLE_MESH_SHAPE : int = 9;
+ public static const HEIGHT_FIELD_TERRAIN : int = 10;
+ }
+}
View
10 AwayPhysics/src/awayphysics/data/AWPTypedConstraintType.as
@@ -0,0 +1,10 @@
+package awayphysics.data
+{
+ public class AWPTypedConstraintType
+ {
+ public static const POINT2POINT_CONSTRAINT_TYPE : int = 0;
+ public static const HINGE_CONSTRAINT_TYPE : int = 1;
+ public static const CONETWIST_CONSTRAINT_TYPE : int = 2;
+ public static const D6_CONSTRAINT_TYPE : int = 3;
+ }
+}
View
653 AwayPhysics/src/awayphysics/debug/AWPDebugDraw.as
@@ -0,0 +1,653 @@
+package awayphysics.debug
+{
+ import away3d.containers.View3D;
+ import away3d.core.base.Geometry;
+ import away3d.entities.SegmentSet;
+ import away3d.primitives.LineSegment;
+
+ import awayphysics.collision.dispatch.AWPRay;
+ import awayphysics.collision.dispatch.AWPCollisionObject;
+ import awayphysics.collision.shapes.*;
+ import awayphysics.data.AWPCollisionShapeType;
+ import awayphysics.data.AWPTypedConstraintType;
+ import awayphysics.dynamics.AWPDynamicsWorld;
+ import awayphysics.dynamics.constraintsolver.*;
+ import awayphysics.math.AWPTransform;
+
+ import flash.geom.Matrix3D;
+ import flash.geom.Vector3D;
+
+ public class AWPDebugDraw
+ {
+ public static const DBG_NoDebug : int = 0;
+ public static const DBG_DrawCollisionShapes : int = 1;
+ public static const DBG_DrawConstraints : int = 2;
+ public static const DBG_DrawConstraintLimits : int =4;
+ public static const DBG_DrawTransform:int = 8;
+ public static const DBG_DrawRay : int = 16;
+
+ private var _view:View3D;
+ private var _physicsWorld:AWPDynamicsWorld;
+ private var _segmentSet:SegmentSet;
+
+ private var m_debugMode:int;
+
+ public function AWPDebugDraw(view:View3D, physicsWorld:AWPDynamicsWorld)
+ {
+ _segmentSet = new SegmentSet();
+ view.scene.addChild(_segmentSet);
+
+ _view = view;
+ _physicsWorld = physicsWorld;
+ m_debugMode = 1;
+ }
+
+ public function get debugMode():int {
+ return m_debugMode;
+ }
+ public function set debugMode(mode:int):void {
+ m_debugMode = mode;
+ }
+
+ private function drawLine(from:Vector3D, to:Vector3D, color:uint):void {
+ var line:LineSegment = new LineSegment(from.subtract(_segmentSet.position), to.subtract(_segmentSet.position), color, color, 2);
+ _segmentSet.addSegment(line);
+ }
+
+ private function drawSphere(radius:Number, transform:AWPTransform, color:uint):void {
+ var pos:Vector3D = transform.position;
+ var rot:Matrix3D = transform.rotationWithMatrix;
+
+ var xoffs:Vector3D = rot.transformVector(new Vector3D(radius, 0, 0));
+ var yoffs:Vector3D = rot.transformVector(new Vector3D(0, radius, 0));
+ var zoffs:Vector3D = rot.transformVector(new Vector3D(0, 0, radius));
+
+ drawLine(pos.subtract(xoffs), pos.add(yoffs), color);
+ drawLine(pos.add(yoffs), pos.add(xoffs), color);
+ drawLine(pos.add(xoffs), pos.subtract(yoffs), color);
+ drawLine(pos.subtract(yoffs), pos.subtract(xoffs), color);
+
+ drawLine(pos.subtract(xoffs), pos.add(zoffs), color);
+ drawLine(pos.add(zoffs), pos.add(xoffs), color);
+ drawLine(pos.add(xoffs), pos.subtract(zoffs), color);
+ drawLine(pos.subtract(zoffs), pos.subtract(xoffs), color);
+
+ drawLine(pos.subtract(yoffs), pos.add(zoffs), color);
+ drawLine(pos.add(zoffs), pos.add(yoffs), color);
+ drawLine(pos.add(yoffs), pos.subtract(zoffs), color);
+ drawLine(pos.subtract(zoffs), pos.subtract(yoffs), color);
+ }
+
+ private function drawTriangle(v0:Vector3D, v1:Vector3D, v2:Vector3D, color:uint):void {
+ drawLine(v0, v1, color);
+ drawLine(v1, v2, color);
+ drawLine(v2, v0, color);
+ }
+
+ private function drawAabb(from:Vector3D, to:Vector3D, color:uint):void {
+ var halfExtents:Vector3D = to.subtract(from);
+ halfExtents.scaleBy(0.5);
+ var center:Vector3D = to.subtract(from);
+ center.scaleBy(0.5);
+ var i:int, j:int, othercoord:int;
+
+ var edgecoord:Vector.<Number> = new Vector.<Number>(3, true);
+ edgecoord[0] = 1;
+ edgecoord[1] = 1;
+ edgecoord[2] = 1;
+
+ var pa:Vector3D = new Vector3D();
+ var pb:Vector3D = new Vector3D();
+ for (i = 0; i < 4; i++)
+ {
+ for (j = 0; j < 3; j++)
+ {
+ pa.setTo(edgecoord[0] * halfExtents.x, edgecoord[1] * halfExtents.y, edgecoord[2] * halfExtents.z);
+ pa = pa.add(center);
+
+ othercoord = j % 3;
+ edgecoord[othercoord] *= -1;
+ pb.setTo(edgecoord[0] * halfExtents.x, edgecoord[1] * halfExtents.y, edgecoord[2] * halfExtents.z);
+ pb += center;
+
+ drawLine(pa,pb,color);
+ }
+ edgecoord[0] = -1;
+ edgecoord[1] = -1;
+ edgecoord[2] = -1;
+ if (i<3)
+ edgecoord[i] *= -1;
+ }
+ }
+
+ private function drawTransform(transform:AWPTransform, orthoLen:Number):void {
+ var pos:Vector3D = transform.position;
+ var rot:Matrix3D = transform.rotationWithMatrix;
+
+ drawLine(pos, pos.add(rot.transformVector(new Vector3D(orthoLen, 0, 0))), 0xff0000);
+ drawLine(pos, pos.add(rot.transformVector(new Vector3D(0, orthoLen, 0))), 0x00ff00);
+ drawLine(pos, pos.add(rot.transformVector(new Vector3D(0, 0, orthoLen))), 0x0000ff);
+ }
+
+ private function drawArc(center:Vector3D, normal:Vector3D, axis:Vector3D, radiusA:Number, radiusB:Number, minAngle:Number, maxAngle:Number, color:uint, drawSect:Boolean, stepDegrees:Number = 10):void {
+ var vx:Vector3D = axis;
+ var vy:Vector3D = normal.crossProduct(axis);
+ var step:Number = stepDegrees * 2 * Math.PI / 360;
+ var nSteps:int = int((maxAngle - minAngle) / step);
+ if (!nSteps) nSteps = 1;
+
+ var temp:Vector3D;
+ temp = vx.clone();
+ temp.scaleBy(radiusA * Math.cos(minAngle));
+ var prev:Vector3D = center.add(temp);
+ temp = vy.clone();
+ temp.scaleBy(radiusB * Math.sin(minAngle));
+ prev = prev.add(temp);
+ if(drawSect)
+ {
+ drawLine(center, prev, color);
+ }
+
+ var angle:Number;
+ var next:Vector3D;
+ for(var i:int = 1; i <= nSteps; i++)
+ {
+ angle = minAngle + (maxAngle - minAngle) * i / nSteps;
+ temp = vx.clone();
+ temp.scaleBy(radiusA * Math.cos(angle));
+ next = center.add(temp);
+ temp = vy.clone();
+ temp.scaleBy(radiusB * Math.sin(angle));
+ next = next.add(temp);
+ drawLine(prev, next, color);
+ prev = next;
+ }
+ if(drawSect)
+ {
+ drawLine(center, prev, color);
+ }
+ }
+ /*
+ private function drawSpherePatch(center:Vector3D, up:Vector3D, axis:Vector3D, radius:Number, minTh:Number, maxTh:Number, minPs:Number, maxPs:Number, color:uint, stepDegrees:Number = 10):void {
+
+ }*/
+
+
+ private function drawBox(bbMin:Vector3D, bbMax:Vector3D, transform:AWPTransform, color:uint):void {
+ var from:Vector3D = new Vector3D();
+ var to:Vector3D = new Vector3D();
+
+ var pos:Vector3D = transform.position;
+ var rot:Matrix3D = transform.rotationWithMatrix;
+
+ from.setTo(bbMin.x, bbMin.y, bbMin.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMax.x, bbMin.y, bbMin.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMax.x, bbMin.y, bbMin.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMax.x, bbMax.y, bbMin.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMax.x, bbMax.y, bbMin.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMin.x, bbMax.y, bbMin.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMin.x, bbMax.y, bbMin.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMin.x, bbMin.y, bbMin.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMin.x, bbMin.y, bbMin.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMin.x, bbMin.y, bbMax.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMax.x, bbMin.y, bbMin.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMax.x, bbMin.y, bbMax.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMax.x, bbMax.y, bbMin.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMax.x, bbMax.y, bbMax.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMin.x, bbMax.y, bbMin.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMin.x, bbMax.y, bbMax.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMin.x, bbMin.y, bbMax.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMax.x, bbMin.y, bbMax.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMax.x, bbMin.y, bbMax.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMax.x, bbMax.y, bbMax.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMax.x, bbMax.y, bbMax.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMin.x, bbMax.y, bbMax.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+
+ from.setTo(bbMin.x, bbMax.y, bbMax.z);
+ from = rot.transformVector(from);
+ from = from.add(pos);
+ to.setTo(bbMin.x, bbMin.y, bbMax.z);
+ to = rot.transformVector(to);
+ to = to.add(pos);
+ drawLine(from, to, color);
+ }
+
+ private function drawCapsule(radius:Number, halfHeight:Number, transform:AWPTransform, color:uint):void {
+ var pos:Vector3D = transform.position;
+ var rot:Matrix3D = transform.rotationWithMatrix;
+
+ var capStart:Vector3D = new Vector3D();
+ capStart.y = -halfHeight;
+
+ var capEnd:Vector3D = new Vector3D();
+ capEnd.y = halfHeight;
+
+ var tr:AWPTransform = transform.clone();
+ tr.position = transform.transform.transformVector(capStart);
+ drawSphere(radius, tr, color);
+ tr.position = transform.transform.transformVector(capEnd);
+ drawSphere(radius, tr, color);
+
+ // Draw some additional lines
+ capStart.z = radius;
+ capEnd.z = radius;
+ drawLine(pos.add(rot.transformVector(capStart)), pos.add(rot.transformVector(capEnd)), color);
+ capStart.z = -radius;
+ capEnd.z = -radius;
+ drawLine(pos.add(rot.transformVector(capStart)), pos.add(rot.transformVector(capEnd)), color);
+
+ capStart.z = 0;
+ capEnd.z = 0;
+
+ capStart.x = radius;
+ capEnd.x = radius;
+ drawLine(pos.add(rot.transformVector(capStart)), pos.add(rot.transformVector(capEnd)), color);
+ capStart.x = -radius;
+ capEnd.x = -radius;
+ drawLine(pos.add(rot.transformVector(capStart)), pos.add(rot.transformVector(capEnd)), color);
+ }
+
+ private function drawCylinder(radius:Number, halfHeight:Number, transform:AWPTransform, color:uint):void {
+ var pos:Vector3D = transform.position;
+ var rot:Matrix3D = transform.rotationWithMatrix;
+
+ var offsetHeight:Vector3D = new Vector3D(0, halfHeight, 0);
+ var offsetRadius:Vector3D = new Vector3D(0, 0, radius);
+ drawLine(pos.add(rot.transformVector(offsetHeight.add(offsetRadius))), pos.add(rot.transformVector(offsetRadius.subtract(offsetHeight))), color);
+
+ var vec:Vector3D = offsetHeight.add(offsetRadius);
+ vec.scaleBy(-1);
+ drawLine(pos.add(rot.transformVector(offsetHeight.subtract(offsetRadius))), pos.add(rot.transformVector(vec)), color);
+
+ // Drawing top and bottom caps of the cylinder
+ var yaxis:Vector3D = new Vector3D(0, 1, 0);
+ var xaxis:Vector3D = new Vector3D(0, 0, 1);
+ drawArc(pos.subtract(rot.transformVector(offsetHeight)), rot.transformVector(yaxis), rot.transformVector(xaxis), radius, radius, 0, 2 * Math.PI, color, false, 10);
+ drawArc(pos.add(rot.transformVector(offsetHeight)), rot.transformVector(yaxis), rot.transformVector(xaxis), radius, radius, 0, 2 * Math.PI, color, false, 10);
+ }
+
+ private function drawCone(radius:Number, height:Number, transform:AWPTransform, color:uint):void {
+ var pos:Vector3D = transform.position;
+ var rot:Matrix3D = transform.rotationWithMatrix;
+
+ var offsetHeight:Vector3D = new Vector3D(0, 0.5 * height, 0);
+ var offsetRadius:Vector3D = new Vector3D(0, 0, radius);
+ var offset2Radius:Vector3D = new Vector3D(radius, 0, 0);
+
+ var vec:Vector3D;
+ drawLine(pos.add(rot.transformVector(offsetHeight)), pos.add(rot.transformVector(offsetRadius.subtract(offsetHeight))), color);
+ vec = offsetHeight.add(offsetRadius);
+ vec.scaleBy(-1);
+ drawLine(pos.add(rot.transformVector(offsetHeight)), pos.add(rot.transformVector(vec)), color);
+ drawLine(pos.add(rot.transformVector(offsetHeight)), pos.add(rot.transformVector(offset2Radius.subtract(offsetHeight))), color);
+ vec = offsetHeight.add(offset2Radius);
+ vec.scaleBy(-1);
+ drawLine(pos.add(rot.transformVector(offsetHeight)), pos.add(rot.transformVector(vec)), color);
+
+ // Drawing the base of the cone
+ var yaxis:Vector3D = new Vector3D(0, 1, 0);
+ var xaxis:Vector3D = new Vector3D(0, 0, 1);
+ drawArc(pos.subtract(rot.transformVector(offsetHeight)), rot.transformVector(yaxis), rot.transformVector(xaxis), radius, radius, 0, 2 * Math.PI, color, false, 10);
+ }
+
+ private function drawPlane(planeNormal:Vector3D, planeConst:Number, transform:AWPTransform, color:uint):void {
+ var pos:Vector3D = transform.position;
+ var rot:Matrix3D = transform.rotationWithMatrix;
+
+ var planeOrigin:Vector3D = planeNormal.clone();
+ planeOrigin.scaleBy(planeConst);
+ var vec0:Vector3D = new Vector3D();
+ var vec1:Vector3D = new Vector3D();
+ btPlaneSpace1(planeNormal, vec0, vec1);
+ var vecLen:Number = 100*_physicsWorld.scaling;
+ vec0.scaleBy(vecLen);
+ vec1.scaleBy(vecLen);
+ var pt0:Vector3D = planeOrigin.add(vec0);
+ var pt1:Vector3D = planeOrigin.subtract(vec0);
+ var pt2:Vector3D = planeOrigin.add(vec1);
+ var pt3:Vector3D = planeOrigin.subtract(vec1);
+
+ pt0 = rot.transformVector(pt0);
+ pt0 = pt0.add(pos);
+ pt1 = rot.transformVector(pt1);
+ pt1 = pt1.add(pos);
+ drawLine(pt0, pt1, color);
+
+ pt2 = rot.transformVector(pt2);
+ pt2 = pt2.add(pos);
+ pt3 = rot.transformVector(pt3);
+ pt3 = pt3.add(pos);
+ drawLine(pt2, pt3, color);
+ }
+
+ private function btPlaneSpace1(n:Vector3D, p:Vector3D, q:Vector3D):void {
+ if (Math.abs(n.z) > 0.707) {
+ var a:Number = n.y * n.y + n.z * n.z;
+ var k:Number = 1 / Math.sqrt(a);
+ p.x = 0;
+ p.y = -n.z * k;
+ p.z = n.y * k;
+ // set q = n x p
+ q.x = a*k;
+ q.y = -n.x * p.z;
+ q.z = n.x * p.y;
+ } else {
+ a = n.x * n.x + n.y * n.y;
+ k = 1 / Math.sqrt(a);
+ p.x = -n.y * k;
+ p.y = n.x * k;
+ p.z = 0;
+ q.x = -n.z * p.y;
+ q.y = n.z * p.x;
+ q.z = a * k;
+ }
+ }
+
+ private function drawTriangles(geometry:Geometry, scale:Vector3D, transform:AWPTransform, color:uint):void {
+ var indexData:Vector.<uint> = geometry.subGeometries[0].indexData;
+ var vertexData:Vector.<Number> = geometry.subGeometries[0].vertexData;
+ var indexDataLen:int = indexData.length;
+
+ var m:int = 0;
+ var v0:Vector3D = new Vector3D();
+ var v1:Vector3D = new Vector3D();
+ var v2:Vector3D = new Vector3D();
+ for (var i:int = 0; i < indexDataLen; i += 3 ) {
+ v0.setTo(vertexData[13*indexData[m]] * scale.x, vertexData[13*indexData[m]+1] * scale.y, vertexData[13*indexData[m]+2] * scale.z);
+ m++;
+ v1.setTo(vertexData[13*indexData[m]] * scale.x, vertexData[13*indexData[m]+1] * scale.y, vertexData[13*indexData[m]+2] * scale.z);
+ m++;
+ v2.setTo(vertexData[13*indexData[m]] * scale.x, vertexData[13*indexData[m]+1] * scale.y, vertexData[13*indexData[m]+2] * scale.z);
+ m++;
+ drawTriangle(transform.transform.transformVector(v0), transform.transform.transformVector(v1), transform.transform.transformVector(v2), color);
+ }
+ }
+
+ private function debugDrawObject(transform:AWPTransform, shape:AWPCollisionShape, color:uint):void {
+ if (m_debugMode & AWPDebugDraw.DBG_DrawTransform) {
+ drawTransform(transform, 200);
+ }
+
+ if (shape.shapeType == AWPCollisionShapeType.COMPOUND_SHAPE) {
+ var i:int = 0;
+ var childTrans:AWPTransform;
+ var compoundShape:AWPCompoundShape = shape as AWPCompoundShape;
+ for each (var sp:AWPCollisionShape in compoundShape.children) {
+ childTrans = compoundShape.getChildTransform(i).clone();
+ childTrans.appendTransform(transform);
+ debugDrawObject(childTrans, sp, color);
+ i++;
+ }
+ }else if (shape.shapeType == AWPCollisionShapeType.BOX_SHAPE) {
+ var boxShape:AWPBoxShape = shape as AWPBoxShape;
+ var halfExtents:Vector3D = boxShape.dimensions;
+ halfExtents.scaleBy(0.5);
+ drawBox(new Vector3D( -halfExtents.x, -halfExtents.y, -halfExtents.z), halfExtents, transform, color);
+ }else if (shape.shapeType == AWPCollisionShapeType.SPHERE_SHAPE) {
+ var sphereShape:AWPSphereShape = shape as AWPSphereShape;
+ drawSphere(sphereShape.radius, transform, color);
+ }else if (shape.shapeType == AWPCollisionShapeType.CAPSULE_SHAPE) {
+ var capsuleShape:AWPCapsuleShape = shape as AWPCapsuleShape;
+ drawCapsule(capsuleShape.radius, capsuleShape.height / 2, transform, color);
+ }else if (shape.shapeType == AWPCollisionShapeType.CONE_SHAPE) {
+ var coneShape:AWPConeShape = shape as AWPConeShape;
+ drawCone(coneShape.radius, coneShape.height, transform, color);
+ }else if (shape.shapeType == AWPCollisionShapeType.CYLINDER_SHAPE) {
+ var cylinder:AWPCylinderShape = shape as AWPCylinderShape;
+ drawCylinder(cylinder.radius, cylinder.height / 2, transform, color);
+ }else if (shape.shapeType == AWPCollisionShapeType.STATIC_PLANE) {
+ var staticPlaneShape:AWPStaticPlaneShape = shape as AWPStaticPlaneShape;
+ drawPlane(staticPlaneShape.normal, staticPlaneShape.constant, transform, color);
+ }else if (shape.shapeType == AWPCollisionShapeType.CONVEX_HULL_SHAPE) {
+ var convex:AWPConvexHullShape = shape as AWPConvexHullShape;
+ drawTriangles(convex.geometry, convex.localScaling, transform, color);
+ }else if (shape.shapeType == AWPCollisionShapeType.TRIANGLE_MESH_SHAPE) {
+ var triangleMesh:AWPBvhTriangleMeshShape = shape as AWPBvhTriangleMeshShape;
+ drawTriangles(triangleMesh.geometry, triangleMesh.localScaling, transform, color);
+ }else if (shape.shapeType == AWPCollisionShapeType.HEIGHT_FIELD_TERRAIN) {
+ //var terrain:AWPHeightfieldTerrainShape = shape as AWPHeightfieldTerrainShape;
+ //drawTriangles(terrain.geometry, terrain.localScaling, transform, color);
+ }
+ }
+
+ private function debugDrawConstraint(constraint:AWPTypedConstraint):void {
+ var drawFrames:Boolean = ((m_debugMode & AWPDebugDraw.DBG_DrawConstraints) != 0);
+ var drawLimits:Boolean = ((m_debugMode & AWPDebugDraw.DBG_DrawConstraintLimits) != 0);
+ if (constraint.constraintType == AWPTypedConstraintType.POINT2POINT_CONSTRAINT_TYPE) {
+ var p2pC:AWPPoint2PointConstraint = constraint as AWPPoint2PointConstraint;
+ var tr:AWPTransform = new AWPTransform();
+ var pivot:Vector3D = p2pC.pivotInA.clone();
+ pivot = p2pC.rigidBodyA.transform.transformVector(pivot);
+ tr.position = pivot;
+ if (drawFrames) drawTransform(tr, 200);
+ if (p2pC.rigidBodyB) {
+ pivot = p2pC.pivotInB.clone();
+ pivot = p2pC.rigidBodyB.transform.transformVector(pivot);
+ tr.position = pivot;
+ if (drawFrames) drawTransform(tr, 200);
+ }
+ }else if (constraint.constraintType == AWPTypedConstraintType.HINGE_CONSTRAINT_TYPE) {
+ var pHinge:AWPHingeConstraint = constraint as AWPHingeConstraint;
+ var pos:Vector3D = pHinge.rigidBodyA.worldTransform.position;
+ var rot:Matrix3D = pHinge.rigidBodyA.worldTransform.rotationWithMatrix;
+ var from:Vector3D = rot.transformVector(pHinge.pivotInA);
+ from = from.add(pos);
+ var to:Vector3D = rot.transformVector(pHinge.axisInA);
+ to.scaleBy(200);
+ to = from.add(to);
+ if (drawFrames) drawLine(from,to,0xff0000);
+ if (pHinge.rigidBodyB) {
+ pos = pHinge.rigidBodyB.worldTransform.position;
+ rot = pHinge.rigidBodyB.worldTransform.rotationWithMatrix;
+ from = rot.transformVector(pHinge.pivotInB);
+ from = from.add(pos);
+ to = rot.transformVector(pHinge.axisInB);
+ to.scaleBy(200);
+ to = from.add(to);
+ if (drawFrames) drawLine(from,to,0xff0000);
+ }
+
+ var minAng:Number = pHinge.limit.low;
+ var maxAng:Number = pHinge.limit.high;
+ if (minAng != maxAng) {
+ var drawSect:Boolean = true;
+ if(minAng > maxAng) {
+ minAng = 0;
+ maxAng = 2 * Math.PI;
+ drawSect = false;
+ }
+ if (drawLimits) {
+ var normal:Vector3D = to.subtract(from);
+ normal.normalize();
+ var axis:Vector3D = normal.crossProduct(new Vector3D(0, 0, 1));
+ if (axis.length > -0.01 && axis.length < 0.01) {
+ axis = normal.crossProduct(new Vector3D(0, -1, 0));
+ }
+ axis.normalize();
+ to = rot.transformVector(axis);
+ to.scaleBy(200);
+ to = from.add(to);
+ drawLine(from,to,0x00ff00);
+ drawArc(from, normal, axis, 200, 200, minAng, maxAng, 0xffff00, drawSect);
+ }
+ }
+ }else if (constraint.constraintType == AWPTypedConstraintType.CONETWIST_CONSTRAINT_TYPE) {
+ var pCT:AWPConeTwistConstraint = constraint as AWPConeTwistConstraint;
+ var trA:AWPTransform = pCT.rbAFrame.clone();
+ trA.appendTransform(pCT.rigidBodyA.worldTransform);
+ if (drawFrames) drawTransform(trA, 200);
+ if (pCT.rigidBodyB) {
+ var trB:AWPTransform = pCT.rbBFrame.clone();
+ trB.appendTransform(pCT.rigidBodyB.worldTransform);
+ if (drawFrames) drawTransform(trB, 200);
+ }
+ if (drawLimits) {
+ rot = pCT.rigidBodyA.worldTransform.rotationWithMatrix;
+ normal = rot.transformVector(pCT.rbAFrame.axisZ);
+ axis = rot.transformVector(pCT.rbAFrame.axisY);
+ minAng = -pCT.swingSpan1;
+ maxAng = pCT.swingSpan1;
+ drawArc(trA.position, normal, axis, 200, 200, minAng, maxAng, 0xffff00, true);
+
+ normal = rot.transformVector(pCT.rbAFrame.axisX);
+ axis = rot.transformVector(pCT.rbAFrame.axisY);
+ minAng = -pCT.twistSpan;
+ maxAng = pCT.twistSpan;
+ drawArc(trA.position, normal, axis, 200, 200, minAng, maxAng, 0xffff00, true);
+
+ normal = rot.transformVector(pCT.rbAFrame.axisY);
+ axis = rot.transformVector(pCT.rbAFrame.axisX);
+ minAng = -pCT.swingSpan2;
+ maxAng = pCT.swingSpan2;
+ drawArc(trA.position, normal, axis, 200, 200, minAng, maxAng, 0xffff00, true);
+ }
+ }else if (constraint.constraintType == AWPTypedConstraintType.D6_CONSTRAINT_TYPE) {
+ var p6DOF:AWPGeneric6DofConstraint = constraint as AWPGeneric6DofConstraint;
+ trA = p6DOF.rbAFrame.clone();
+ trA.appendTransform(p6DOF.rigidBodyA.worldTransform);
+ if (drawFrames) drawTransform(trA, 200);
+ if (p6DOF.rigidBodyB) {
+ trB = p6DOF.rbBFrame.clone();
+ trB.appendTransform(p6DOF.rigidBodyB.worldTransform);
+ if (drawFrames) drawTransform(trB, 200);
+ }
+ if (drawLimits) {
+ rot = p6DOF.rigidBodyA.worldTransform.rotationWithMatrix;
+ normal = rot.transformVector(p6DOF.rbAFrame.axisX);
+ axis = rot.transformVector(p6DOF.rbAFrame.axisY);
+ minAng = p6DOF.getRotationalLimitMotor(0).loLimit;
+ maxAng = p6DOF.getRotationalLimitMotor(0).hiLimit;
+ drawArc(trA.position, normal, axis, 200, 200, minAng, maxAng, 0xffff00, true);
+
+ rot = p6DOF.rigidBodyA.worldTransform.rotationWithMatrix;
+ normal = rot.transformVector(p6DOF.rbAFrame.axisY);
+ axis = rot.transformVector(p6DOF.rbAFrame.axisX);
+ minAng = p6DOF.getRotationalLimitMotor(1).loLimit;
+ maxAng = p6DOF.getRotationalLimitMotor(1).hiLimit;
+ drawArc(trA.position, normal, axis, 200, 200, minAng, maxAng, 0xffff00, true);
+
+ rot = p6DOF.rigidBodyA.worldTransform.rotationWithMatrix;
+ normal = rot.transformVector(p6DOF.rbAFrame.axisZ);
+ axis = rot.transformVector(p6DOF.rbAFrame.axisY);
+ minAng = p6DOF.getRotationalLimitMotor(2).loLimit;
+ maxAng = p6DOF.getRotationalLimitMotor(2).hiLimit;
+ drawArc(trA.position, normal, axis, 200, 200, minAng, maxAng, 0xffff00, true);
+
+ var bbMin:Vector3D = p6DOF.getTranslationalLimitMotor().lowerLimit;
+ var bbMax:Vector3D = p6DOF.getTranslationalLimitMotor().upperLimit;
+ drawBox(bbMin, bbMax, trA, 0xffff00);
+ }
+ }
+ }
+
+ public function debugDrawWorld():void {
+ if (m_debugMode & AWPDebugDraw.DBG_NoDebug) return;
+
+ var dir:Vector3D = _view.camera.forwardVector.clone();
+ dir.scaleBy(100);
+ _segmentSet.position = _view.camera.position.add(dir);
+ _segmentSet.removeAllSegments();
+
+ var color:uint;
+ for each (var obj:AWPCollisionObject in _physicsWorld.collisionObjects) {
+ if (m_debugMode & AWPDebugDraw.DBG_DrawCollisionShapes)
+ {
+ switch(obj.activationState)
+ {
+ case AWPCollisionObject.ACTIVE_TAG:
+ color = 0xffffff; break;
+ case AWPCollisionObject.ISLAND_SLEEPING:
+ color = 0x00ff00; break;
+ case AWPCollisionObject.WANTS_DEACTIVATION:
+ color = 0x00ffff; break;
+ case AWPCollisionObject.DISABLE_DEACTIVATION:
+ color = 0xff0000; break;
+ case AWPCollisionObject.DISABLE_SIMULATION:
+ color = 0xffff00; break;
+ default:
+ color = 0xff0000;
+ }
+ debugDrawObject(obj.worldTransform, obj.shape, color);
+ }
+ if (m_debugMode & AWPDebugDraw.DBG_DrawRay)