Permalink
Browse files

Cleanup!

  • Loading branch information...
1 parent 33db3a5 commit fbae4631e97e5d9bf00dc46741f0646a1ffab671 @ringodotnl ringodotnl committed Aug 21, 2011
Showing with 2,563 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. BIN lib/AwayPhysics.swc
  3. +39 −0 src/awayphysics/AWPBase.as
  4. +228 −0 src/awayphysics/collision/dispatch/AWPCollisionObject.as
  5. +14 −0 src/awayphysics/collision/dispatch/AWPGhostObject.as
  6. +39 −0 src/awayphysics/collision/dispatch/AWPManifoldPoint.as
  7. +10 −0 src/awayphysics/collision/shapes/AWPBoxShape.as
  8. +41 −0 src/awayphysics/collision/shapes/AWPBvhTriangleMeshShape.as
  9. +10 −0 src/awayphysics/collision/shapes/AWPCapsuleShape.as
  10. +36 −0 src/awayphysics/collision/shapes/AWPCompoundShape.as
  11. +10 −0 src/awayphysics/collision/shapes/AWPConeShape.as
  12. +10 −0 src/awayphysics/collision/shapes/AWPCylinderShape.as
  13. +28 −0 src/awayphysics/collision/shapes/AWPHeightfieldTerrainShape.as
  14. +11 −0 src/awayphysics/collision/shapes/AWPShape.as
  15. +10 −0 src/awayphysics/collision/shapes/AWPSphereShape.as
  16. +15 −0 src/awayphysics/collision/shapes/AWPStaticPlaneShape.as
  17. +14 −0 src/awayphysics/data/AWPCollisionFilterGroups.as
  18. +12 −0 src/awayphysics/data/AWPCollisionFlags.as
  19. +218 −0 src/awayphysics/dynamics/AWPDynamicsWorld.as
  20. +230 −0 src/awayphysics/dynamics/AWPRigidBody.as
  21. +183 −0 src/awayphysics/dynamics/character/AWPKinematicCharacterController.as
  22. +82 −0 src/awayphysics/dynamics/constraintsolver/AWPAngularLimit.as
  23. +132 −0 src/awayphysics/dynamics/constraintsolver/AWPConeTwistConstraint.as
  24. +78 −0 src/awayphysics/dynamics/constraintsolver/AWPGeneric6DofConstraint.as
  25. +77 −0 src/awayphysics/dynamics/constraintsolver/AWPHingeConstraint.as
  26. +21 −0 src/awayphysics/dynamics/constraintsolver/AWPPoint2PointConstraint.as
  27. +147 −0 src/awayphysics/dynamics/constraintsolver/AWPRotationalLimitMotor.as
  28. +165 −0 src/awayphysics/dynamics/constraintsolver/AWPTranslationalLimitMotor.as
  29. +23 −0 src/awayphysics/dynamics/constraintsolver/AWPTypedConstraint.as
  30. +55 −0 src/awayphysics/dynamics/vehicle/AWPRaycastInfo.as
  31. +84 −0 src/awayphysics/dynamics/vehicle/AWPRaycastVehicle.as
  32. +22 −0 src/awayphysics/dynamics/vehicle/AWPVehicleTuning.as
  33. +226 −0 src/awayphysics/dynamics/vehicle/AWPWheelInfo.as
  34. +22 −0 src/awayphysics/events/AWPCollisionEvent.as
  35. +32 −0 src/awayphysics/math/AWPMatrix3x3.as
  36. +18 −0 src/awayphysics/math/AWPTransform.as
  37. +58 −0 src/awayphysics/math/AWPVector3.as
  38. +21 −0 src/awayphysics/plugin/IMesh3D.as
  39. +23 −0 src/awayphysics/plugin/ITerrain.as
  40. +53 −0 src/awayphysics/plugin/away3d/Away3DMesh.as
  41. +62 −0 src/awayphysics/plugin/away3d/Away3DTerrain.as
View
@@ -0,0 +1,4 @@
+/bin
+/.settings
+/.project
+/away3d_core_fp11
View
Binary file not shown.
@@ -0,0 +1,39 @@
+package awayphysics
+{
+ import cmodule.AwayPhysics.*;
+
+ import flash.utils.ByteArray;
+
+ public class AWPBase
+ {
+ protected static var loader : CLibInit;
+ protected static var bullet : Object;
+ protected static var memUser : MemUser;
+ protected static var alchemyMemory : ByteArray;
+ private static var initialized : Boolean = false;
+
+ /**
+ * Initialize the Alchemy Memory and get the pointer of the buffer
+ */
+ public static function initialize() : void
+ {
+ if (initialized) {
+ return;
+ }
+ initialized = true;
+
+ loader = new CLibInit();
+ bullet = loader.init();
+
+ memUser = new MemUser();
+
+ var ns : Namespace = new Namespace("cmodule.AwayPhysics");
+ alchemyMemory = (ns::gstate).ds;
+ }
+
+ // 1 visual units equal to 0.01 bullet meters by default
+ // refer to http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Scaling_The_World
+ protected static var _scaling : Number = 100;
+ public var pointer : uint;
+ }
+}
@@ -0,0 +1,228 @@
+package awayphysics.collision.dispatch
+{
+ import awayphysics.AWPBase;
+ import awayphysics.collision.shapes.AWPShape;
+ import awayphysics.data.AWPCollisionFlags;
+ import awayphysics.events.AWPCollisionEvent;
+ import awayphysics.math.AWPTransform;
+ import awayphysics.math.AWPVector3;
+ import awayphysics.plugin.IMesh3D;
+
+ 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 var ACTIVE_TAG : int = 1;
+ public static var ISLAND_SLEEPING : int = 2;
+ public static var WANTS_DEACTIVATION : int = 3;
+ public static var DISABLE_DEACTIVATION : int = 4;
+ public static var DISABLE_SIMULATION : int = 5;
+ private var m_shape : AWPShape;
+ private var m_skin : IMesh3D;
+ private var m_worldTransform : AWPTransform;
+ private var m_anisotropicFriction : AWPVector3;
+ private var dispatcher : EventDispatcher;
+
+ public function AWPCollisionObject(ptr : uint, shape : AWPShape, skin : IMesh3D)
+ {
+ m_shape = shape;
+ m_skin = skin;
+
+ pointer = ptr;
+
+ m_worldTransform = new AWPTransform(ptr + 4);
+ m_anisotropicFriction = new AWPVector3(ptr + 164);
+
+ dispatcher = new EventDispatcher(this);
+ }
+
+ public function get shape() : AWPShape {
+ return m_shape;
+ }
+
+ public function get skin() : IMesh3D {
+ return m_skin;
+ }
+
+ // update the transform of skin mesh
+ public function updateTransform() : void
+ {
+ var pos : Vector3D = this.position;
+ var rot : Vector.<Number> = this.rotation.rawData;
+
+ var tr : Matrix3D = new Matrix3D(Vector.<Number>([rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8], rot[9], rot[10], rot[11], pos.x, pos.y, pos.z, 1]));
+
+ if (m_skin) {
+ m_skin.transform = tr;
+ }
+ }
+
+ public function set position(pos : Vector3D) : void {
+ m_worldTransform.position.sv3d = pos;
+ }
+
+ public function get position() : Vector3D {
+ return m_worldTransform.position.sv3d;
+ }
+
+ public function set rotation(rot : Matrix3D) : void {
+ m_worldTransform.rotation.m3d = rot;
+ }
+
+ public function get rotation() : Matrix3D {
+ return m_worldTransform.rotation.m3d;
+ }
+
+ public function setWorldTransform(pos : Vector3D, rot : Matrix3D) : void
+ {
+ m_worldTransform.position.sv3d = pos;
+ m_worldTransform.rotation.m3d = rot;
+ }
+
+ public function get worldTransform() : Matrix3D {
+ return null;
+ }
+
+ 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 memUser._mrf(pointer + 224);
+ }
+
+ public function set friction(v : Number) : void {
+ memUser._mwf(pointer + 224, v);
+ }
+
+ public function get restitution() : Number {
+ return memUser._mrf(pointer + 228);
+ }
+
+ public function set restitution(v : Number) : void {
+ memUser._mwf(pointer + 228, v);
+ }
+
+ public function get hasAnisotropicFriction() : int {
+ return memUser._mr32(pointer + 180);
+ }
+
+ public function set hasAnisotropicFriction(v : int) : void {
+ memUser._mw32(pointer + 180, v);
+ }
+
+ public function get contactProcessingThreshold() : Number {
+ return memUser._mrf(pointer + 184);
+ }
+
+ public function set contactProcessingThreshold(v : Number) : void {
+ memUser._mwf(pointer + 184, v);
+ }
+
+ public function get collisionFlags() : int {
+ return memUser._mr32(pointer + 204);
+ }
+
+ public function set collisionFlags(v : int) : void {
+ memUser._mw32(pointer + 204, v);
+ }
+
+ public function get islandTag() : int {
+ return memUser._mr32(pointer + 208);
+ }
+
+ public function set islandTag(v : int) : void {
+ memUser._mw32(pointer + 208, v);
+ }
+
+ public function get companionId() : int {
+ return memUser._mr32(pointer + 212);
+ }
+
+ public function set companionId(v : int) : void {
+ memUser._mw32(pointer + 212, v);
+ }
+
+ public function get deactivationTime() : Number {
+ return memUser._mrf(pointer + 220);
+ }
+
+ public function set deactivationTime(v : Number) : void {
+ memUser._mwf(pointer + 220, v);
+ }
+
+ public function get activationState() : int {
+ return memUser._mr32(pointer + 216);
+ }
+
+ public function set activationState(newState : int) : void {
+ if (activationState != AWPCollisionObject.DISABLE_DEACTIVATION && activationState != AWPCollisionObject.DISABLE_SIMULATION) {
+ memUser._mw32(pointer + 216, newState);
+ }
+ }
+
+ public function forceActivationState(newState : int) : void
+ {
+ memUser._mw32(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);
+ }
+
+ 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, body : AWPCollisionObject) : void
+ {
+ var pt : AWPManifoldPoint = new AWPManifoldPoint(mpt);
+ var event : AWPCollisionEvent = new AWPCollisionEvent(AWPCollisionEvent.COLLISION_ADDED);
+ event.manifoldPoint = pt;
+ event.collisionObject = body;
+
+ this.dispatchEvent(event);
+ }
+ }
+}
@@ -0,0 +1,14 @@
+package awayphysics.collision.dispatch
+{
+ import awayphysics.collision.shapes.AWPShape;
+ import awayphysics.plugin.IMesh3D;
+
+ public class AWPGhostObject extends AWPCollisionObject
+ {
+ public function AWPGhostObject(shape : AWPShape, skin : IMesh3D = null)
+ {
+ pointer = bullet.createGhostObjectMethod(this, shape.pointer);
+ super(pointer, shape, skin);
+ }
+ }
+}
@@ -0,0 +1,39 @@
+package awayphysics.collision.dispatch
+{
+ 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);
+ }
+
+ public function get localPointA() : Vector3D {
+ return m_localPointA.sv3d;
+ }
+
+ public function get localPointB() : Vector3D {
+ return m_localPointB.sv3d;
+ }
+
+ public function get normalWorldOnB() : Vector3D {
+ return m_normalWorldOnB.v3d;
+ }
+
+ public function get appliedImpulse() : Number {
+ return memUser._mrf(pointer + 112) * _scaling;
+ }
+ }
+}
@@ -0,0 +1,10 @@
+package awayphysics.collision.shapes
+{
+ public class AWPBoxShape extends AWPShape
+ {
+ public function AWPBoxShape(width : Number = 100, height : Number = 100, depth : Number = 100)
+ {
+ pointer = bullet.createBoxShapeMethod(width / _scaling, height / _scaling, depth / _scaling);
+ }
+ }
+}
@@ -0,0 +1,41 @@
+package awayphysics.collision.shapes
+{
+ import awayphysics.plugin.IMesh3D;
+
+ public class AWPBvhTriangleMeshShape extends AWPShape
+ {
+ private var indexDataPtr : uint;
+ private var vertexDataPtr : uint;
+
+ public function AWPBvhTriangleMeshShape(mesh : IMesh3D, useQuantizedAabbCompression : Boolean = true)
+ {
+ var indexData : Vector.<uint> = mesh.indices;
+ var indexDataLen : int = indexData.length;
+ indexDataPtr = bullet.createTriangleIndexDataBufferMethod(indexDataLen);
+
+ alchemyMemory.position = indexDataPtr;
+ for (var i : int = 0; i < indexDataLen; i++ ) {
+ alchemyMemory.writeInt(indexData[i]);
+ }
+
+ var vertexData : Vector.<Number> = mesh.vertices;
+ var vertexDataLen : int = vertexData.length;
+ vertexDataPtr = bullet.createTriangleVertexDataBufferMethod(vertexDataLen);
+
+ alchemyMemory.position = vertexDataPtr;
+ for (i = 0; i < vertexDataLen; i++ ) {
+ alchemyMemory.writeFloat(vertexData[i] / _scaling);
+ }
+
+ var triangleIndexVertexArrayPtr : uint = bullet.createTriangleIndexVertexArrayMethod(int(indexDataLen / 3), indexDataPtr, int(vertexDataLen / 3), vertexDataPtr);
+
+ pointer = bullet.createBvhTriangleMeshShapeMethod(triangleIndexVertexArrayPtr, useQuantizedAabbCompression ? 1 : 0, 1);
+ }
+
+ public function deleteBvhTriangleMeshShapeBuffer() : void
+ {
+ bullet.removeTriangleIndexDataBufferMethod(indexDataPtr);
+ bullet.removeTriangleVertexDataBufferMethod(vertexDataPtr);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit fbae463

Please sign in to comment.