Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup!

  • Loading branch information...
commit fbae4631e97e5d9bf00dc46741f0646a1ffab671 1 parent 33db3a5
@ringodotnl ringodotnl authored
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
4 .gitignore
@@ -0,0 +1,4 @@
+/bin
+/.settings
+/.project
+/away3d_core_fp11
View
BIN  lib/AwayPhysics.swc
Binary file not shown
View
39 src/awayphysics/AWPBase.as
@@ -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;
+ }
+}
View
228 src/awayphysics/collision/dispatch/AWPCollisionObject.as
@@ -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);
+ }
+ }
+}
View
14 src/awayphysics/collision/dispatch/AWPGhostObject.as
@@ -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);
+ }
+ }
+}
View
39 src/awayphysics/collision/dispatch/AWPManifoldPoint.as
@@ -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;
+ }
+ }
+}
View
10 src/awayphysics/collision/shapes/AWPBoxShape.as
@@ -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);
+ }
+ }
+}
View
41 src/awayphysics/collision/shapes/AWPBvhTriangleMeshShape.as
@@ -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);
+ }
+ }
+}
View
10 src/awayphysics/collision/shapes/AWPCapsuleShape.as
@@ -0,0 +1,10 @@
+package awayphysics.collision.shapes
+{
+ public class AWPCapsuleShape extends AWPShape
+ {
+ public function AWPCapsuleShape(radius : Number = 50, height : Number = 100)
+ {
+ pointer = bullet.createCapsuleShapeMethod(radius / _scaling, height / _scaling);
+ }
+ }
+}
View
36 src/awayphysics/collision/shapes/AWPCompoundShape.as
@@ -0,0 +1,36 @@
+package awayphysics.collision.shapes
+{
+ import flash.geom.Matrix3D;
+ import flash.geom.Vector3D;
+
+ public class AWPCompoundShape extends AWPShape
+ {
+ private var m_children : Vector.<AWPShape>;
+
+ public function AWPCompoundShape()
+ {
+ pointer = bullet.createCompoundShapeMethod();
+
+ m_children = new Vector.<AWPShape>();
+ }
+
+ public function addChildShape(child : AWPShape, localPos : Vector3D, localRot : Matrix3D) : void
+ {
+ var rotArr : Vector.<Number> = localRot.rawData;
+ bullet.addCompoundChildMethod(pointer, child.pointer, localPos.x / _scaling, localPos.y / _scaling, localPos.z / _scaling, rotArr[0], rotArr[4], rotArr[8], rotArr[1], rotArr[5], rotArr[9], rotArr[2], rotArr[6], rotArr[10]);
+
+ m_children.push(child);
+ }
+
+ public function removeChildShapeByIndex(childShapeindex : int) : void
+ {
+ bullet.removeCompoundChildMethod(pointer, childShapeindex);
+
+ m_children.splice(childShapeindex, 1);
+ }
+
+ public function get children() : Vector.<AWPShape> {
+ return m_children;
+ }
+ }
+}
View
10 src/awayphysics/collision/shapes/AWPConeShape.as
@@ -0,0 +1,10 @@
+package awayphysics.collision.shapes
+{
+ public class AWPConeShape extends AWPShape
+ {
+ public function AWPConeShape(radius : Number = 50, height : Number = 100)
+ {
+ pointer = bullet.createConeShapeMethod(radius / _scaling, height / _scaling);
+ }
+ }
+}
View
10 src/awayphysics/collision/shapes/AWPCylinderShape.as
@@ -0,0 +1,10 @@
+package awayphysics.collision.shapes
+{
+ public class AWPCylinderShape extends AWPShape
+ {
+ public function AWPCylinderShape(radius : Number = 50, height : Number = 100)
+ {
+ pointer = bullet.createCylinderShapeMethod(radius * 2 / _scaling, height / _scaling, radius * 2 / _scaling);
+ }
+ }
+}
View
28 src/awayphysics/collision/shapes/AWPHeightfieldTerrainShape.as
@@ -0,0 +1,28 @@
+package awayphysics.collision.shapes
+{
+ import awayphysics.plugin.ITerrain;
+
+ public class AWPHeightfieldTerrainShape extends AWPShape
+ {
+ private var dataPtr : uint;
+
+ public function AWPHeightfieldTerrainShape(terrain : ITerrain)
+ {
+ var dataLen : int = terrain.sw * terrain.sh;
+ dataPtr = bullet.createHeightmapDataBufferMethod(dataLen);
+
+ var data : Vector.<Number> = terrain.heights;
+ alchemyMemory.position = dataPtr;
+ for (var i : int = 0; i < dataLen; i++ ) {
+ alchemyMemory.writeFloat(data[i] / _scaling);
+ }
+
+ pointer = bullet.createTerrainShapeMethod(dataPtr, terrain.sw, terrain.sh, terrain.lw / _scaling, terrain.lh / _scaling, 1, -terrain.maxHeight / _scaling, terrain.maxHeight / _scaling, 1);
+ }
+
+ public function deleteHeightfieldTerrainShapeBuffer() : void
+ {
+ bullet.removeHeightmapDataBufferMethod(dataPtr);
+ }
+ }
+}
View
11 src/awayphysics/collision/shapes/AWPShape.as
@@ -0,0 +1,11 @@
+package awayphysics.collision.shapes
+{
+ import awayphysics.AWPBase;
+
+ public class AWPShape extends AWPBase
+ {
+ public function AWPShape()
+ {
+ }
+ }
+}
View
10 src/awayphysics/collision/shapes/AWPSphereShape.as
@@ -0,0 +1,10 @@
+package awayphysics.collision.shapes
+{
+ public class AWPSphereShape extends AWPShape
+ {
+ public function AWPSphereShape(radius : Number = 50)
+ {
+ pointer = bullet.createSphereShapeMethod(radius / _scaling);
+ }
+ }
+}
View
15 src/awayphysics/collision/shapes/AWPStaticPlaneShape.as
@@ -0,0 +1,15 @@
+package awayphysics.collision.shapes
+{
+ import flash.geom.Vector3D;
+
+ public class AWPStaticPlaneShape extends AWPShape
+ {
+ public function AWPStaticPlaneShape(normal : Vector3D = null, constant : Number = 0)
+ {
+ if (!normal) {
+ normal = new Vector3D(0, 1, 0);
+ }
+ pointer = bullet.createStaticPlaneShapeMethod(normal.x, normal.y, normal.z, constant / _scaling);
+ }
+ }
+}
View
14 src/awayphysics/data/AWPCollisionFilterGroups.as
@@ -0,0 +1,14 @@
+package awayphysics.data
+{
+ public class AWPCollisionFilterGroups
+ {
+ public static var DefaultFilter : int = 1;
+ public static var StaticFilter : int = 2;
+ public static var KinematicFilter : int = 4;
+ public static var DebrisFilter : int = 8;
+ public static var SensorTrigger : int = 16;
+ public static var CharacterFilter : int = 32;
+ public static var AllFilter : int = -1;
+ // all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
+ }
+}
View
12 src/awayphysics/data/AWPCollisionFlags.as
@@ -0,0 +1,12 @@
+package awayphysics.data
+{
+ public class AWPCollisionFlags
+ {
+ public static var CF_STATIC_OBJECT : int = 1;
+ public static var CF_KINEMATIC_OBJECT : int = 2;
+ public static var CF_NO_CONTACT_RESPONSE : int = 4;
+ public static var CF_CUSTOM_MATERIAL_CALLBACK : int = 8;
+ public static var CF_CHARACTER_OBJECT : int = 16;
+ public static var CF_DISABLE_VISUALIZE_OBJECT : int = 32;
+ }
+}
View
218 src/awayphysics/dynamics/AWPDynamicsWorld.as
@@ -0,0 +1,218 @@
+package awayphysics.dynamics
+{
+ import awayphysics.AWPBase;
+ import awayphysics.data.AWPCollisionFlags;
+ import awayphysics.dynamics.character.AWPKinematicCharacterController;
+ import awayphysics.dynamics.constraintsolver.AWPTypedConstraint;
+ import awayphysics.dynamics.vehicle.AWPRaycastVehicle;
+ import awayphysics.math.AWPVector3;
+ import flash.geom.Vector3D;
+
+
+ public class AWPDynamicsWorld extends AWPBase
+ {
+ private static var currentDynamicsWorld : AWPDynamicsWorld;
+ private var m_gravity : AWPVector3;
+ private var m_rigidBodies : Vector.<AWPRigidBody>;
+ private var m_nonStaticRigidBodies : Vector.<AWPRigidBody>;
+ private var m_vehicles : Vector.<AWPRaycastVehicle>;
+ private var m_characters : Vector.<AWPKinematicCharacterController>;
+
+ public static function getInstance() : AWPDynamicsWorld
+ {
+ if (!currentDynamicsWorld) {
+ trace("version: BulletFlash v0.62 alpha (16-8-2011)");
+ currentDynamicsWorld = new AWPDynamicsWorld();
+ }
+ return currentDynamicsWorld;
+ }
+
+ public function AWPDynamicsWorld()
+ {
+ AWPBase.initialize();
+
+ m_rigidBodies = new Vector.<AWPRigidBody>();
+ m_nonStaticRigidBodies = new Vector.<AWPRigidBody>();
+ m_vehicles = new Vector.<AWPRaycastVehicle>();
+ m_characters = new Vector.<AWPKinematicCharacterController>();
+ }
+
+ // init the physics world with btDbvtBroadphase
+ // refer to http://bulletphysics.org/mediawiki-1.5.8/index.php/Broadphase
+ public function initWithDbvtBroadphase() : void
+ {
+ pointer = bullet.createDiscreteDynamicsWorldWithDbvtMethod();
+ m_gravity = new AWPVector3(pointer + 224);
+ this.gravity = new Vector3D(0, -10, 0);
+ }
+
+ // init the physics world with btAxisSweep3
+ // refer to http://bulletphysics.org/mediawiki-1.5.8/index.php/Broadphase
+ public function initWithAxisSweep3(worldAabbMin : Vector3D, worldAabbMax : Vector3D) : void
+ {
+ pointer = bullet.createDiscreteDynamicsWorldWithAxisSweep3Method(worldAabbMin.x / _scaling, worldAabbMin.y / _scaling, worldAabbMin.z / _scaling, worldAabbMax.x / _scaling, worldAabbMax.y / _scaling, worldAabbMax.z / _scaling);
+ m_gravity = new AWPVector3(pointer + 224);
+ this.gravity = new Vector3D(0, -10, 0);
+ }
+
+ // add a rigidbody to physics world
+ public function addRigidBody(body : AWPRigidBody) : void
+ {
+ bullet.addBodyMethod(body.pointer);
+
+ if (body.collisionFlags != AWPCollisionFlags.CF_STATIC_OBJECT) {
+ if (m_nonStaticRigidBodies.indexOf(body) < 0) {
+ m_nonStaticRigidBodies.push(body);
+ }
+ }
+ if (m_rigidBodies.indexOf(body) < 0) {
+ m_rigidBodies.push(body);
+ }
+ }
+
+ // add a rigidbody to physics world with group and mask
+ // refer to: http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Filtering
+ public function addRigidBodyWithGroup(body : AWPRigidBody, group : int, mask : int) : void
+ {
+ bullet.addBodyWithGroupMethod(body.pointer, group, mask);
+
+ if (body.collisionFlags != AWPCollisionFlags.CF_STATIC_OBJECT) {
+ if (m_nonStaticRigidBodies.indexOf(body) < 0) {
+ m_nonStaticRigidBodies.push(body);
+ }
+ }
+ if (m_rigidBodies.indexOf(body) < 0) {
+ m_rigidBodies.push(body);
+ }
+ }
+
+ // remove a rigidbody from physics world
+ public function removeRigidBody(body : AWPRigidBody) : void
+ {
+ bullet.removeBodyMethod(body.pointer);
+
+ if (m_nonStaticRigidBodies.indexOf(body) >= 0) {
+ m_nonStaticRigidBodies.splice(m_nonStaticRigidBodies.indexOf(body), 1);
+ }
+ if (m_rigidBodies.indexOf(body) >= 0) {
+ m_rigidBodies.splice(m_rigidBodies.indexOf(body), 1);
+ }
+ }
+
+ public function addConstraint(constraint : AWPTypedConstraint, disableCollisionsBetweenLinkedBodies : Boolean = false) : void
+ {
+ bullet.addConstraintMethod(constraint.pointer, disableCollisionsBetweenLinkedBodies ? 1 : 0);
+ }
+
+ public function removeConstraint(constraint : AWPTypedConstraint) : void
+ {
+ bullet.removeConstraintMethod(constraint.pointer);
+ }
+
+ public function addVehicle(vehicle : AWPRaycastVehicle) : void
+ {
+ bullet.addVehicleMethod(vehicle.pointer);
+
+ if (m_vehicles.indexOf(vehicle) < 0) {
+ m_vehicles.push(vehicle);
+ }
+ }
+
+ public function removeVehicle(vehicle : AWPRaycastVehicle) : void
+ {
+ bullet.removeVehicleMethod(vehicle.pointer);
+
+ if (m_vehicles.indexOf(vehicle) >= 0) {
+ m_vehicles.splice(m_vehicles.indexOf(vehicle), 1);
+ }
+ }
+
+ public function addCharacter(character : AWPKinematicCharacterController, group : int = 32, mask : int = -1) : void
+ {
+ bullet.addCharacterMethod(character.pointer, group, mask);
+
+ if (m_characters.indexOf(character) < 0) {
+ m_characters.push(character);
+ }
+ }
+
+ public function removeCharacter(character : AWPKinematicCharacterController) : void
+ {
+ bullet.removeCharacterMethod(character.pointer);
+
+ if (m_characters.indexOf(character) >= 0) {
+ m_characters.splice(m_characters.indexOf(character), 1);
+ }
+ }
+
+ // get the gravity of physics world
+ public function get gravity() : Vector3D {
+ return m_gravity.v3d;
+ }
+
+ // set the gravity of physics world
+ public function set gravity(g : Vector3D) : void {
+ m_gravity.v3d = g;
+ for each (var body:AWPRigidBody in m_nonStaticRigidBodies) {
+ body.gravity = g;
+ }
+ }
+
+ // get all rigidbodies
+ public function get rigidBodies() : Vector.<AWPRigidBody> {
+ return m_rigidBodies;
+ }
+
+ // get all non static rigidbodies
+ public function get nonStaticRigidBodies() : Vector.<AWPRigidBody> {
+ return m_nonStaticRigidBodies;
+ }
+
+ public function get vehicles() : Vector.<AWPRaycastVehicle> {
+ return m_vehicles;
+ }
+
+ public function get characters() : Vector.<AWPKinematicCharacterController> {
+ return m_characters;
+ }
+
+ // set physics world scaling
+ // refer to http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Scaling_The_World
+ public function set scaling(v : Number) : void {
+ _scaling = v;
+ }
+
+ // get physics world scaling
+ public function get scaling() : Number {
+ return _scaling;
+ }
+
+ // get/set if implement object collision callback
+ public function get collisionCallbackOn() : Boolean {
+ return memUser._mru8(pointer + 247) == 1;
+ }
+
+ public function set collisionCallbackOn(v : Boolean) : void {
+ memUser._mw8(pointer + 247, v ? 1 : 0);
+ }
+
+ // set time step and simulate the physics world
+ // refer to: http://bulletphysics.org/mediawiki-1.5.8/index.php/Stepping_the_World
+ public function step(timeStep : Number, maxSubSteps : int = 1, fixedTimeStep : Number = 1.0 / 60) : void
+ {
+ bullet.stepMethod(timeStep, maxSubSteps, fixedTimeStep);
+
+ for each (var body:AWPRigidBody in m_nonStaticRigidBodies) {
+ body.updateTransform();
+ }
+
+ for each (var vehicle:AWPRaycastVehicle in m_vehicles) {
+ vehicle.updateWheelsTransform();
+ }
+
+ for each (var character:AWPKinematicCharacterController in m_characters) {
+ character.updateTransform();
+ }
+ }
+ }
+}
View
230 src/awayphysics/dynamics/AWPRigidBody.as
@@ -0,0 +1,230 @@
+package awayphysics.dynamics
+{
+ import awayphysics.collision.dispatch.AWPCollisionObject;
+ import awayphysics.collision.shapes.AWPShape;
+ import awayphysics.data.AWPCollisionFlags;
+ import awayphysics.math.AWPMatrix3x3;
+ import awayphysics.math.AWPVector3;
+ import awayphysics.plugin.IMesh3D;
+
+ import flash.geom.Matrix3D;
+ import flash.geom.Vector3D;
+
+ public class AWPRigidBody extends AWPCollisionObject
+ {
+ private var m_invInertiaTensorWorld : AWPMatrix3x3;
+ private var m_linearVelocity : AWPVector3;
+ private var m_angularVelocity : AWPVector3;
+ private var m_linearFactor : AWPVector3;
+ private var m_gravity : AWPVector3;
+ private var m_gravity_acceleration : AWPVector3;
+ private var m_invInertiaLocal : AWPVector3;
+ private var m_totalForce : AWPVector3;
+ private var m_totalTorque : AWPVector3;
+
+ // rigidbody is static if mass is zero, otherwise is dynamic
+ public function AWPRigidBody(shape : AWPShape, skin : IMesh3D = null, mass : Number = 0)
+ {
+ pointer = bullet.createBodyMethod(this, shape.pointer, mass);
+ super(pointer, shape, skin);
+
+ m_invInertiaTensorWorld = new AWPMatrix3x3(pointer + 256);
+ m_linearVelocity = new AWPVector3(pointer + 304);
+ m_angularVelocity = new AWPVector3(pointer + 320);
+ m_linearFactor = new AWPVector3(pointer + 340);
+ m_gravity = new AWPVector3(pointer + 356);
+ m_gravity_acceleration = new AWPVector3(pointer + 372);
+ m_invInertiaLocal = new AWPVector3(pointer + 388);
+ m_totalForce = new AWPVector3(pointer + 404);
+ m_totalTorque = new AWPVector3(pointer + 420);
+ }
+
+ override public function set position(pos : Vector3D) : void {
+ super.position = pos;
+ if (this.collisionFlags == AWPCollisionFlags.CF_STATIC_OBJECT) {
+ updateTransform();
+ }
+ }
+
+ override public function set rotation(rot : Matrix3D) : void {
+ super.rotation = rot;
+ if (this.collisionFlags == AWPCollisionFlags.CF_STATIC_OBJECT) {
+ updateTransform();
+ }
+ }
+
+ override public function setWorldTransform(pos : Vector3D, rot : Matrix3D) : void
+ {
+ super.setWorldTransform(pos, rot);
+ if (this.collisionFlags == AWPCollisionFlags.CF_STATIC_OBJECT) {
+ updateTransform();
+ }
+ }
+
+ // add a center force to the rigidbody
+ public function applyCentralForce(force : Vector3D) : void
+ {
+ var vec : Vector3D = force.clone();
+ m_totalForce.v3d = vec.add(m_totalForce.v3d);
+ activate();
+ }
+
+ // add torque to the rigidbody
+ public function applyTorque(torque : Vector3D) : void
+ {
+ var vec : Vector3D = torque.clone();
+ vec.scaleBy(1 / _scaling);
+ m_totalTorque.v3d = vec.add(m_totalTorque.v3d);
+ activate();
+ }
+
+ // add a force to the rigidbody
+ public function applyForce(force : Vector3D, rel_pos : Vector3D) : void
+ {
+ applyCentralForce(force);
+ applyTorque(rel_pos.crossProduct(force));
+ }
+
+ // add a center impulse to the rigidbody
+ public function applyCentralImpulse(impulse : Vector3D) : void
+ {
+ var vec : Vector3D = impulse.clone();
+ vec.scaleBy(1 / _scaling);
+ vec.scaleBy(inverseMass);
+ m_linearVelocity.v3d = vec.add(m_linearVelocity.v3d);
+ activate();
+ }
+
+ // add a torque impulse to the rigidbody
+ public function applyTorqueImpulse(torque : Vector3D) : void
+ {
+ var tor : Vector3D = torque.clone();
+ tor.scaleBy(1 / _scaling);
+ var vec : Vector3D = new Vector3D(m_invInertiaTensorWorld.col1.v3d.dotProduct(tor), m_invInertiaTensorWorld.col2.v3d.dotProduct(tor), m_invInertiaTensorWorld.col3.v3d.dotProduct(tor));
+ m_angularVelocity.v3d = vec.add(m_angularVelocity.v3d);
+ activate();
+ }
+
+ // add a impulse to the rigidbody
+ public function applyImpulse(impulse : Vector3D, rel_pos : Vector3D) : void
+ {
+ if (inverseMass != 0) {
+ applyCentralImpulse(impulse);
+ applyTorqueImpulse(rel_pos.crossProduct(impulse));
+ }
+ }
+
+ // clear all force and torque to zero
+ public function clearForces() : void
+ {
+ m_totalForce.v3d = new Vector3D();
+ m_totalTorque.v3d = new Vector3D();
+ }
+
+ // set the gravity of this rigidbody
+ public function set gravity(acceleration : Vector3D) : void {
+ if (inverseMass != 0) {
+ acceleration.scaleBy(1 / inverseMass);
+ m_gravity.v3d = acceleration;
+ activate();
+ }
+ m_gravity_acceleration.v3d = acceleration;
+ }
+
+ public function get invInertiaTensorWorld() : Matrix3D {
+ return m_invInertiaTensorWorld.m3d;
+ }
+
+ public function get linearVelocity() : Vector3D {
+ return m_linearVelocity.sv3d;
+ }
+
+ public function set linearVelocity(v : Vector3D) : void {
+ m_linearVelocity.sv3d = v;
+ }
+
+ public function get angularVelocity() : Vector3D {
+ return m_angularVelocity.v3d;
+ }
+
+ public function set angularVelocity(v : Vector3D) : void {
+ m_angularVelocity.v3d = v;
+ }
+
+ public function get linearFactor() : Vector3D {
+ return m_linearFactor.v3d;
+ }
+
+ public function get gravity() : Vector3D {
+ return m_gravity.v3d;
+ }
+
+ public function get gravityAcceleration() : Vector3D {
+ return m_gravity_acceleration.v3d;
+ }
+
+ public function get invInertiaLocal() : Vector3D {
+ return m_invInertiaLocal.v3d;
+ }
+
+ public function get totalForce() : Vector3D {
+ return m_totalForce.v3d;
+ }
+
+ public function get totalTorque() : Vector3D {
+ return m_totalTorque.sv3d;
+ }
+
+ public function get mass() : Number {
+ return 1 / inverseMass;
+ }
+
+ public function get inverseMass() : Number {
+ return memUser._mrf(pointer + 336);
+ }
+
+ public function set inverseMass(v : Number) : void {
+ memUser._mwf(pointer + 336, v);
+ }
+
+ public function get linearDamping() : Number {
+ return memUser._mrf(pointer + 436);
+ }
+
+ public function set linearDamping(v : Number) : void {
+ memUser._mwf(pointer + 436, v);
+ }
+
+ public function get angularDamping() : Number {
+ return memUser._mrf(pointer + 440);
+ }
+
+ public function set angularDamping(v : Number) : void {
+ memUser._mwf(pointer + 440, v);
+ }
+
+ public function get linearSleepingThreshold() : Number {
+ return memUser._mrf(pointer + 464) * _scaling;
+ }
+
+ public function set linearSleepingThreshold(v : Number) : void {
+ memUser._mwf(pointer + 464, v / _scaling);
+ }
+
+ public function get angularSleepingThreshold() : Number {
+ return memUser._mrf(pointer + 468);
+ }
+
+ public function set angularSleepingThreshold(v : Number) : void {
+ memUser._mwf(pointer + 468, v);
+ }
+
+ public function get rigidbodyFlags() : int {
+ return memUser._mr32(pointer + 496);
+ }
+
+ public function set rigidbodyFlags(v : int) : void {
+ memUser._mw32(pointer + 496, v);
+ }
+ }
+}
View
183 src/awayphysics/dynamics/character/AWPKinematicCharacterController.as
@@ -0,0 +1,183 @@
+package awayphysics.dynamics.character
+{
+ import awayphysics.AWPBase;
+ import awayphysics.collision.dispatch.AWPGhostObject;
+ import awayphysics.collision.shapes.AWPShape;
+ import awayphysics.math.AWPVector3;
+
+ import flash.geom.Vector3D;
+
+ public class AWPKinematicCharacterController extends AWPBase
+ {
+ private var m_shape : AWPShape;
+ private var m_ghostObject : AWPGhostObject;
+ private var m_walkDirection : AWPVector3;
+ private var m_normalizedDirection : AWPVector3;
+
+ public function AWPKinematicCharacterController(ghostObject : AWPGhostObject, shape : AWPShape, stepHeight : Number)
+ {
+ m_ghostObject = ghostObject;
+ m_shape = shape;
+
+ pointer = bullet.createCharacterMethod(ghostObject.pointer, shape.pointer, stepHeight, 1);
+
+ m_walkDirection = new AWPVector3(pointer + 60);
+ m_normalizedDirection = new AWPVector3(pointer + 76);
+ }
+
+ public function get ghostObject() : AWPGhostObject {
+ return m_ghostObject;
+ }
+
+ public function get shape() : AWPShape {
+ return m_shape;
+ }
+
+ public function updateTransform() : void
+ {
+ m_ghostObject.updateTransform();
+ }
+
+ public function setWalkDirection(walkDirection : Vector3D) : void
+ {
+ useWalkDirection = true;
+ m_walkDirection.sv3d = walkDirection;
+ var vec : Vector3D = walkDirection.clone();
+ vec.normalize();
+ m_normalizedDirection.v3d = vec;
+ }
+
+ public function setVelocityForTimeInterval(velocity : Vector3D, timeInterval : Number) : void
+ {
+ useWalkDirection = false;
+ m_walkDirection.sv3d = velocity;
+ var vec : Vector3D = velocity.clone();
+ vec.normalize();
+ m_normalizedDirection.v3d = vec;
+ velocityTimeInterval = timeInterval;
+ }
+
+ public function warp(origin : Vector3D) : void
+ {
+ m_ghostObject.position = origin;
+ }
+
+ public function onGround() : Boolean
+ {
+ return (verticalVelocity == 0 && verticalOffset == 0);
+ }
+
+ public function canJump() : Boolean
+ {
+ return onGround();
+ }
+
+ public function jump() : void
+ {
+ if (!canJump())
+ return;
+
+ verticalVelocity = jumpSpeed;
+ wasJumping = true;
+ }
+
+ public function setMaxSlope(slopeRadians : Number) : void
+ {
+ maxSlopeRadians = slopeRadians;
+ maxSlopeCosine = Math.cos(slopeRadians);
+ }
+
+ public function getMaxSlope() : Number
+ {
+ return maxSlopeRadians;
+ }
+
+ public function get fallSpeed() : Number {
+ return memUser._mrf(pointer + 24) * _scaling;
+ }
+
+ public function set fallSpeed(v : Number) : void {
+ memUser._mwf(pointer + 24, v / _scaling);
+ }
+
+ public function get jumpSpeed() : Number {
+ return memUser._mrf(pointer + 28) * _scaling;
+ }
+
+ public function set jumpSpeed(v : Number) : void {
+ memUser._mwf(pointer + 28, v / _scaling);
+ }
+
+ public function get maxJumpHeight() : Number {
+ return memUser._mrf(pointer + 32) * _scaling;
+ }
+
+ public function set maxJumpHeight(v : Number) : void {
+ memUser._mwf(pointer + 32, v / _scaling);
+ }
+
+ public function get gravity() : Number {
+ return memUser._mrf(pointer + 44) * _scaling;
+ }
+
+ public function set gravity(v : Number) : void {
+ memUser._mwf(pointer + 44, v / _scaling);
+ }
+
+ private function get wasJumping() : Boolean {
+ return memUser._mru8(pointer + 169) == 1;
+ }
+
+ private function set wasJumping(v : Boolean) : void {
+ memUser._mw8(pointer + 169, v ? 1 : 0);
+ }
+
+ private function get useWalkDirection() : Boolean {
+ return memUser._mru8(pointer + 171) == 1;
+ }
+
+ private function set useWalkDirection(v : Boolean) : void {
+ memUser._mw8(pointer + 171, v ? 1 : 0);
+ }
+
+ private function get velocityTimeInterval() : Number {
+ return memUser._mrf(pointer + 172);
+ }
+
+ private function set velocityTimeInterval(v : Number) : void {
+ memUser._mwf(pointer + 172, v);
+ }
+
+ private function get verticalVelocity() : Number {
+ return memUser._mrf(pointer + 16);
+ }
+
+ private function set verticalVelocity(v : Number) : void {
+ memUser._mwf(pointer + 16, v);
+ }
+
+ private function get verticalOffset() : Number {
+ return memUser._mrf(pointer + 20);
+ }
+
+ private function set verticalOffset(v : Number) : void {
+ memUser._mwf(pointer + 20, v);
+ }
+
+ private function get maxSlopeRadians() : Number {
+ return memUser._mrf(pointer + 36);
+ }
+
+ private function set maxSlopeRadians(v : Number) : void {
+ memUser._mwf(pointer + 36, v);
+ }
+
+ private function get maxSlopeCosine() : Number {
+ return memUser._mrf(pointer + 40);
+ }
+
+ private function set maxSlopeCosine(v : Number) : void {
+ memUser._mwf(pointer + 40, v);
+ }
+ }
+}
View
82 src/awayphysics/dynamics/constraintsolver/AWPAngularLimit.as
@@ -0,0 +1,82 @@
+package awayphysics.dynamics.constraintsolver
+{
+ import awayphysics.AWPBase;
+
+ public class AWPAngularLimit extends AWPBase
+ {
+ public function AWPAngularLimit(ptr : uint)
+ {
+ pointer = ptr;
+ }
+
+ public function setLimit(low : Number, high : Number, _softness : Number = 0.9, _biasFactor : Number = 0.3, _relaxationFactor : Number = 1.0) : void
+ {
+ halfRange = (high - low) / 2;
+ center = normalizeAngle(low + halfRange);
+ softness = _softness;
+ biasFactor = _biasFactor;
+ relaxationFactor = _relaxationFactor;
+ }
+
+ public function get center() : Number {
+ return memUser._mrf(pointer + 0);
+ }
+
+ public function set center(v : Number) : void {
+ memUser._mwf(pointer + 0, v);
+ }
+
+ public function get halfRange() : Number {
+ return memUser._mrf(pointer + 4);
+ }
+
+ public function set halfRange(v : Number) : void {
+ memUser._mwf(pointer + 4, v);
+ }
+
+ public function get softness() : Number {
+ return memUser._mrf(pointer + 8);
+ }
+
+ public function set softness(v : Number) : void {
+ memUser._mwf(pointer + 8, v);
+ }
+
+ public function get biasFactor() : Number {
+ return memUser._mrf(pointer + 12);
+ }
+
+ public function set biasFactor(v : Number) : void {
+ memUser._mwf(pointer + 12, v);
+ }
+
+ public function get relaxationFactor() : Number {
+ return memUser._mrf(pointer + 16);
+ }
+
+ public function set relaxationFactor(v : Number) : void {
+ memUser._mwf(pointer + 16, v);
+ }
+
+ public function get correction() : Number {
+ return memUser._mrf(pointer + 20);
+ }
+
+ public function get sign() : Number {
+ return memUser._mrf(pointer + 24);
+ }
+
+ private function normalizeAngle(angleInRadians : Number) : Number
+ {
+ var pi2 : Number = 2 * Math.PI;
+ var result : Number = angleInRadians % pi2;
+ if (result < -Math.PI) {
+ return result + pi2;
+ } else if (result > Math.PI) {
+ return result - pi2;
+ } else {
+ return result;
+ }
+ }
+ }
+}
View
132 src/awayphysics/dynamics/constraintsolver/AWPConeTwistConstraint.as
@@ -0,0 +1,132 @@
+package awayphysics.dynamics.constraintsolver
+{
+ import awayphysics.dynamics.AWPRigidBody;
+
+ import flash.geom.Matrix3D;
+ import flash.geom.Vector3D;
+
+ public class AWPConeTwistConstraint extends AWPTypedConstraint
+ {
+ public function AWPConeTwistConstraint(rbA : AWPRigidBody, pivotInA : Vector3D, rotationInA : Matrix3D, rbB : AWPRigidBody = null, pivotInB : Vector3D = null, rotationInB : Matrix3D = null)
+ {
+ m_rbA = rbA;
+ m_rbB = rbB;
+
+ var posInA : Vector3D = pivotInA.clone();
+ posInA.scaleBy(1 / _scaling);
+ var rotArrInA : Vector.<Number> = rotationInA.rawData;
+ if (rbB) {
+ var posInB : Vector3D = pivotInB.clone();
+ posInB.scaleBy(1 / _scaling);
+ var rotArrInB : Vector.<Number> = rotationInB.rawData;
+ pointer = bullet.createConeTwistConstraintMethod2(rbA.pointer, posInA, new Vector3D(rotArrInA[0], rotArrInA[4], rotArrInA[8]), new Vector3D(rotArrInA[1], rotArrInA[5], rotArrInA[9]), new Vector3D(rotArrInA[2], rotArrInA[6], rotArrInA[10]), rbB.pointer, posInB, new Vector3D(rotArrInB[0], rotArrInB[4], rotArrInB[8]), new Vector3D(rotArrInB[1], rotArrInB[5], rotArrInB[9]), new Vector3D(rotArrInB[2], rotArrInB[6], rotArrInB[10]));
+ } else {
+ pointer = bullet.createConeTwistConstraintMethod1(rbA.pointer, posInA.x, posInA.y, posInA.z, rotArrInA[0], rotArrInA[4], rotArrInA[8], rotArrInA[1], rotArrInA[5], rotArrInA[9], rotArrInA[2], rotArrInA[6], rotArrInA[10]);
+ }
+ }
+
+ public function setLimit(_swingSpan1 : Number, _swingSpan2 : Number, _twistSpan : Number, _softness : Number = 1, _biasFactor : Number = 0.3, _relaxationFactor : Number = 1) : void
+ {
+ swingSpan1 = _swingSpan1;
+ swingSpan2 = _swingSpan2;
+ twistSpan = _twistSpan;
+
+ limitSoftness = _softness;
+ biasFactor = _biasFactor;
+ relaxationFactor = _relaxationFactor;
+ }
+
+ /*
+ public function setMaxMotorImpulse(_maxMotorImpulse:Number):void {
+ maxMotorImpulse = _maxMotorImpulse;
+ bNormalizedMotorStrength = false;
+ }
+
+ public function setMaxMotorImpulseNormalized(_maxMotorImpulse:Number):void {
+ maxMotorImpulse = _maxMotorImpulse;
+ bNormalizedMotorStrength = true;
+ }
+ */
+ public function get limitSoftness() : Number {
+ return memUser._mrf(pointer + 416);
+ }
+
+ public function set limitSoftness(v : Number) : void {
+ memUser._mwf(pointer + 416, v);
+ }
+
+ public function get biasFactor() : Number {
+ return memUser._mrf(pointer + 420);
+ }
+
+ public function set biasFactor(v : Number) : void {
+ memUser._mwf(pointer + 420, v);
+ }
+
+ public function get relaxationFactor() : Number {
+ return memUser._mrf(pointer + 424);
+ }
+
+ public function set relaxationFactor(v : Number) : void {
+ memUser._mwf(pointer + 424, v);
+ }
+
+ public function get damping() : Number {
+ return memUser._mrf(pointer + 428);
+ }
+
+ public function set damping(v : Number) : void {
+ memUser._mwf(pointer + 428, v);
+ }
+
+ public function get swingSpan1() : Number {
+ return memUser._mrf(pointer + 432);
+ }
+
+ public function set swingSpan1(v : Number) : void {
+ memUser._mwf(pointer + 432, v);
+ }
+
+ public function get swingSpan2() : Number {
+ return memUser._mrf(pointer + 436);
+ }
+
+ public function set swingSpan2(v : Number) : void {
+ memUser._mwf(pointer + 436, v);
+ }
+
+ public function get twistSpan() : Number {
+ return memUser._mrf(pointer + 440);
+ }
+
+ public function set twistSpan(v : Number) : void {
+ memUser._mwf(pointer + 440, v);
+ }
+
+ public function get fixThresh() : Number {
+ return memUser._mrf(pointer + 444);
+ }
+
+ public function set fixThresh(v : Number) : void {
+ memUser._mwf(pointer + 444, v);
+ }
+
+ public function get twistAngle() : Number {
+ return memUser._mrf(pointer + 500);
+ }
+
+ public function get angularOnly() : Boolean {
+ return memUser._mru8(pointer + 512) == 1;
+ }
+
+ public function set angularOnly(v : Boolean) : void {
+ memUser._mw8(pointer + 512, v ? 1 : 0);
+ }
+ /*public function get enableMotor():Boolean { return memUser._mru8(pointer + 540) == 1; }
+ public function set enableMotor(v:Boolean):void { memUser._mw8(pointer + 540, v ? 1 : 0); }
+ public function get bNormalizedMotorStrength():Boolean { return memUser._mru8(pointer + 541) == 1; }
+ public function set bNormalizedMotorStrength(v:Boolean):void { memUser._mw8(pointer + 541, v ? 1 : 0); }
+ public function get maxMotorImpulse():Number { return memUser._mrf(pointer + 560); }
+ public function set maxMotorImpulse(v:Number):void { memUser._mwf(pointer + 560, v); }*/
+ }
+}
View
78 src/awayphysics/dynamics/constraintsolver/AWPGeneric6DofConstraint.as
@@ -0,0 +1,78 @@
+package awayphysics.dynamics.constraintsolver
+{
+ import awayphysics.dynamics.AWPRigidBody;
+
+ import flash.geom.Matrix3D;
+ import flash.geom.Vector3D;
+
+ public class AWPGeneric6DofConstraint extends AWPTypedConstraint
+ {
+ private var m_linearLimits : AWPTranslationalLimitMotor;
+ private var m_angularLimits : Vector.<AWPRotationalLimitMotor>;
+
+ public function AWPGeneric6DofConstraint(rbA : AWPRigidBody, pivotInA : Vector3D, rotationInA : Matrix3D, rbB : AWPRigidBody = null, pivotInB : Vector3D = null, rotationInB : Matrix3D = null, useLinearReferenceFrameA : Boolean = false)
+ {
+ m_rbA = rbA;
+ m_rbB = rbB;
+
+ var posInA : Vector3D = pivotInA.clone();
+ posInA.scaleBy(1 / _scaling);
+ var rotArrInA : Vector.<Number> = rotationInA.rawData;
+ if (rbB) {
+ var posInB : Vector3D = pivotInB.clone();
+ posInB.scaleBy(1 / _scaling);
+ var rotArrInB : Vector.<Number> = rotationInB.rawData;
+ pointer = bullet.createGeneric6DofConstraintMethod2(rbA.pointer, posInA, new Vector3D(rotArrInA[0], rotArrInA[4], rotArrInA[8]), new Vector3D(rotArrInA[1], rotArrInA[5], rotArrInA[9]), new Vector3D(rotArrInA[2], rotArrInA[6], rotArrInA[10]), rbB.pointer, posInB, new Vector3D(rotArrInB[0], rotArrInB[4], rotArrInB[8]), new Vector3D(rotArrInB[1], rotArrInB[5], rotArrInB[9]), new Vector3D(rotArrInB[2], rotArrInB[6], rotArrInB[10]), useLinearReferenceFrameA ? 1 : 0);
+ } else {
+ pointer = bullet.createGeneric6DofConstraintMethod1(rbA.pointer, posInA.x, posInA.y, posInA.z, rotArrInA[0], rotArrInA[4], rotArrInA[8], rotArrInA[1], rotArrInA[5], rotArrInA[9], rotArrInA[2], rotArrInA[6], rotArrInA[10], useLinearReferenceFrameA ? 1 : 0);
+ }
+
+ m_linearLimits = new AWPTranslationalLimitMotor(pointer + 668);
+
+ m_angularLimits = new Vector.<AWPRotationalLimitMotor>(3, true);
+ m_angularLimits[0] = new AWPRotationalLimitMotor(pointer + 856);
+ m_angularLimits[1] = new AWPRotationalLimitMotor(pointer + 920);
+ m_angularLimits[2] = new AWPRotationalLimitMotor(pointer + 984);
+ }
+
+ public function getTranslationalLimitMotor() : AWPTranslationalLimitMotor
+ {
+ return m_linearLimits;
+ }
+
+ public function getRotationalLimitMotor(index : int) : AWPRotationalLimitMotor
+ {
+ if (index > 2) return null;
+ else return m_angularLimits[index];
+ }
+
+ public function setLinearLimit(low : Vector3D, high : Vector3D) : void
+ {
+ m_linearLimits.lowerLimit = low;
+ m_linearLimits.upperLimit = high;
+ }
+
+ public function setAngularLimit(low : Vector3D, high : Vector3D) : void
+ {
+ m_angularLimits[0].loLimit = normalizeAngle(low.x);
+ m_angularLimits[0].hiLimit = normalizeAngle(high.x);
+ m_angularLimits[1].loLimit = normalizeAngle(low.y);
+ m_angularLimits[1].hiLimit = normalizeAngle(high.y);
+ m_angularLimits[2].loLimit = normalizeAngle(low.z);
+ m_angularLimits[2].hiLimit = normalizeAngle(high.z);
+ }
+
+ private function normalizeAngle(angleInRadians : Number) : Number
+ {
+ var pi2 : Number = 2 * Math.PI;
+ var result : Number = angleInRadians % pi2;
+ if (result < -Math.PI) {
+ return result + pi2;
+ } else if (result > Math.PI) {
+ return result - pi2;
+ } else {
+ return result;
+ }
+ }
+ }
+}
View
77 src/awayphysics/dynamics/constraintsolver/AWPHingeConstraint.as
@@ -0,0 +1,77 @@
+package awayphysics.dynamics.constraintsolver
+{
+ import awayphysics.dynamics.AWPRigidBody;
+
+ import flash.geom.Vector3D;
+
+ public class AWPHingeConstraint extends AWPTypedConstraint
+ {
+ private var m_limit : AWPAngularLimit;
+
+ public function AWPHingeConstraint(rbA : AWPRigidBody, pivotInA : Vector3D, axisInA : Vector3D, rbB : AWPRigidBody = null, pivotInB : Vector3D = null, axisInB : Vector3D = null, useReferenceFrameA : Boolean = false)
+ {
+ m_rbA = rbA;
+ m_rbB = rbB;
+
+ if (rbB) {
+ pointer = bullet.createHingeConstraintMethod2(rbA.pointer, rbB.pointer, pivotInA.x / _scaling, pivotInA.y / _scaling, pivotInA.z / _scaling, pivotInB.x / _scaling, pivotInB.y / _scaling, pivotInB.z / _scaling, axisInA.x, axisInA.y, axisInA.z, axisInB.x, axisInB.y, axisInB.z, useReferenceFrameA ? 1 : 0);
+ } else {
+ pointer = bullet.createHingeConstraintMethod1(rbA.pointer, pivotInA.x / _scaling, pivotInA.y / _scaling, pivotInA.z / _scaling, axisInA.x, axisInA.y, axisInA.z, useReferenceFrameA ? 1 : 0);
+ }
+
+ m_limit = new AWPAngularLimit(pointer + 676);
+ }
+
+ public function setLimit(low : Number, high : Number, _softness : Number = 0.9, _biasFactor : Number = 0.3, _relaxationFactor : Number = 1.0) : void
+ {
+ m_limit.setLimit(low, high, _softness, _biasFactor, _relaxationFactor);
+ }
+
+ public function setAngularMotor(_enableMotor : Boolean, _targetVelocity : Number, _maxMotorImpulse : Number) : void
+ {
+ enableAngularMotor = _enableMotor;
+ motorTargetVelocity = _targetVelocity;
+ maxMotorImpulse = _maxMotorImpulse;
+ }
+
+ public function get motorTargetVelocity() : Number {
+ return memUser._mrf(pointer + 668) * _scaling;
+ }
+
+ public function set motorTargetVelocity(v : Number) : void {
+ memUser._mwf(pointer + 668, v / _scaling);
+ }
+
+ public function get maxMotorImpulse() : Number {
+ return memUser._mrf(pointer + 672) * _scaling;
+ }
+
+ public function set maxMotorImpulse(v : Number) : void {
+ memUser._mwf(pointer + 672, v / _scaling);
+ }
+
+ public function get angularOnly() : Boolean {
+ return memUser._mru8(pointer + 724) == 1;
+ }
+
+ public function set angularOnly(v : Boolean) : void {
+ memUser._mw8(pointer + 724, v ? 1 : 0);
+ }
+
+ public function get enableAngularMotor() : Boolean {
+ return memUser._mru8(pointer + 725) == 1;
+ }
+
+ public function set enableAngularMotor(v : Boolean) : void {
+ memUser._mw8(pointer + 725, v ? 1 : 0);
+ }
+
+ public function get useOffsetForConstraintFrame() : Boolean {
+ return memUser._mru8(pointer + 727) == 1;
+ }
+
+ public function set useOffsetForConstraintFrame(v : Boolean) : void {
+ memUser._mw8(pointer + 727, v ? 1 : 0);
+ }
+ }
+}
View
21 src/awayphysics/dynamics/constraintsolver/AWPPoint2PointConstraint.as
@@ -0,0 +1,21 @@
+package awayphysics.dynamics.constraintsolver
+{
+ import awayphysics.dynamics.AWPRigidBody;
+
+ import flash.geom.Vector3D;
+
+ public class AWPPoint2PointConstraint extends AWPTypedConstraint
+ {
+ public function AWPPoint2PointConstraint(rbA : AWPRigidBody, pivotInA : Vector3D, rbB : AWPRigidBody = null, pivotInB : Vector3D = null)
+ {
+ m_rbA = rbA;
+ m_rbB = rbB;
+
+ if (rbB) {
+ pointer = bullet.createP2PConstraintMethod2(rbA.pointer, rbB.pointer, pivotInA.x / _scaling, pivotInA.y / _scaling, pivotInA.z / _scaling, pivotInB.x / _scaling, pivotInB.y / _scaling, pivotInB.z / _scaling);
+ } else {
+ pointer = bullet.createP2PConstraintMethod1(rbA.pointer, pivotInA.x / _scaling, pivotInA.y / _scaling, pivotInA.z / _scaling);
+ }
+ }
+ }
+}
View
147 src/awayphysics/dynamics/constraintsolver/AWPRotationalLimitMotor.as
@@ -0,0 +1,147 @@
+package awayphysics.dynamics.constraintsolver
+{
+ import awayphysics.AWPBase;
+
+ public class AWPRotationalLimitMotor extends AWPBase
+ {
+ public function AWPRotationalLimitMotor(ptr : uint)
+ {
+ pointer = ptr;
+ }
+
+ public function isLimited() : Boolean
+ {
+ if (loLimit > hiLimit) return false;
+
+ return true;
+ }
+
+ public function get loLimit() : Number {
+ return memUser._mrf(pointer + 0);
+ }
+
+ public function set loLimit(v : Number) : void {
+ memUser._mwf(pointer + 0, v);
+ }
+
+ public function get hiLimit() : Number {
+ return memUser._mrf(pointer + 4);
+ }
+
+ public function set hiLimit(v : Number) : void {
+ memUser._mwf(pointer + 4, v);
+ }
+
+ public function get targetVelocity() : Number {
+ return memUser._mrf(pointer + 8);
+ }
+
+ public function set targetVelocity(v : Number) : void {
+ memUser._mwf(pointer + 8, v);
+ }
+
+ public function get maxMotorForce() : Number {
+ return memUser._mrf(pointer + 12);
+ }
+
+ public function set maxMotorForce(v : Number) : void {
+ memUser._mwf(pointer + 12, v);
+ }
+
+ public function get maxLimitForce() : Number {
+ return memUser._mrf(pointer + 16);
+ }
+
+ public function set maxLimitForce(v : Number) : void {
+ memUser._mwf(pointer + 16, v);
+ }
+
+ public function get damping() : Number {
+ return memUser._mrf(pointer + 20);
+ }
+
+ public function set damping(v : Number) : void {
+ memUser._mwf(pointer + 20, v);
+ }
+
+ public function get limitSoftness() : Number {
+ return memUser._mrf(pointer + 24);
+ }
+
+ public function set limitSoftness(v : Number) : void {
+ memUser._mwf(pointer + 24, v);
+ }
+
+ public function get normalCFM() : Number {
+ return memUser._mrf(pointer + 28);
+ }
+
+ public function set normalCFM(v : Number) : void {
+ memUser._mwf(pointer + 28, v);
+ }
+
+ public function get stopERP() : Number {
+ return memUser._mrf(pointer + 32);
+ }
+
+ public function set stopERP(v : Number) : void {
+ memUser._mwf(pointer + 32, v);
+ }
+
+ public function get stopCFM() : Number {
+ return memUser._mrf(pointer + 36);
+ }
+
+ public function set stopCFM(v : Number) : void {
+ memUser._mwf(pointer + 36, v);
+ }
+
+ public function get bounce() : Number {
+ return memUser._mrf(pointer + 40);
+ }
+
+ public function set bounce(v : Number) : void {
+ memUser._mwf(pointer + 40, v);
+ }
+
+ public function get enableMotor() : Boolean {
+ return memUser._mru8(pointer + 44) == 1;
+ }
+
+ public function set enableMotor(v : Boolean) : void {
+ memUser._mw8(pointer + 44, v ? 1 : 0);
+ }
+
+ public function get currentLimitError() : Number {
+ return memUser._mrf(pointer + 48);
+ }
+
+ public function set currentLimitError(v : Number) : void {
+ memUser._mwf(pointer + 48, v);
+ }
+
+ public function get currentPosition() : Number {
+ return memUser._mrf(pointer + 52);
+ }
+
+ public function set currentPosition(v : Number) : void {
+ memUser._mwf(pointer + 52, v);
+ }
+
+ public function get currentLimit() : int {
+ return memUser._mr32(pointer + 56);
+ }
+
+ public function set currentLimit(v : int) : void {
+ memUser._mw32(pointer + 56, v);
+ }
+
+ public function get accumulatedImpulse() : Number {
+ return memUser._mrf(pointer + 60);
+ }
+
+ public function set accumulatedImpulse(v : Number) : void {
+ memUser._mwf(pointer + 60, v);
+ }
+ }
+}
View
165 src/awayphysics/dynamics/constraintsolver/AWPTranslationalLimitMotor.as
@@ -0,0 +1,165 @@
+package awayphysics.dynamics.constraintsolver
+{
+ import awayphysics.AWPBase;
+ import awayphysics.math.AWPVector3;
+
+ import flash.geom.Vector3D;
+
+ public class AWPTranslationalLimitMotor extends AWPBase
+ {
+ private var m_lowerLimit : AWPVector3;
+ private var m_upperLimit : AWPVector3;
+ private var m_accumulatedImpulse : AWPVector3;
+ private var m_normalCFM : AWPVector3;
+ private var m_stopERP : AWPVector3;
+ private var m_stopCFM : AWPVector3;
+ private var m_targetVelocity : AWPVector3;
+ private var m_maxMotorForce : AWPVector3;
+ private var m_currentLimitError : AWPVector3;
+ private var m_currentLinearDiff : AWPVector3;
+
+ public function AWPTranslationalLimitMotor(ptr : uint)
+ {
+ pointer = ptr;
+
+ m_lowerLimit = new AWPVector3(ptr + 0);
+ m_upperLimit = new AWPVector3(ptr + 16);
+ m_accumulatedImpulse = new AWPVector3(ptr + 32);
+ m_normalCFM = new AWPVector3(ptr + 60);
+ m_stopERP = new AWPVector3(ptr + 76);
+ m_stopCFM = new AWPVector3(ptr + 92);
+ m_targetVelocity = new AWPVector3(ptr + 112);
+ m_maxMotorForce = new AWPVector3(ptr + 128);
+ m_currentLimitError = new AWPVector3(ptr + 144);
+ m_currentLinearDiff = new AWPVector3(ptr + 160);
+ }
+
+ public function get lowerLimit() : Vector3D {
+ return m_lowerLimit.sv3d;
+ }
+
+ public function set lowerLimit(v : Vector3D) : void {
+ m_lowerLimit.sv3d = v;
+ }
+
+ public function get upperLimit() : Vector3D {
+ return m_upperLimit.sv3d;
+ }
+
+ public function set upperLimit(v : Vector3D) : void {
+ m_upperLimit.sv3d = v;
+ }
+
+ public function get accumulatedImpulse() : Vector3D {
+ return m_accumulatedImpulse.sv3d;
+ }
+
+ public function set accumulatedImpulse(v : Vector3D) : void {
+ m_accumulatedImpulse.sv3d = v;
+ }
+
+ public function get normalCFM() : Vector3D {
+ return m_normalCFM.v3d;
+ }
+
+ public function set normalCFM(v : Vector3D) : void {
+ m_normalCFM.v3d = v;
+ }
+
+ public function get stopERP() : Vector3D {
+ return m_stopERP.v3d;
+ }
+
+ public function set stopERP(v : Vector3D) : void {
+ m_stopERP.v3d = v;
+ }
+
+ public function get stopCFM() : Vector3D {
+ return m_stopCFM.v3d;
+ }
+
+ public function set stopCFM(v : Vector3D) : void {
+ m_stopCFM.v3d = v;
+ }
+
+ public function get targetVelocity() : Vector3D {
+ return m_targetVelocity.sv3d;
+ }
+
+ public function set targetVelocity(v : Vector3D) : void {
+ m_targetVelocity.sv3d = v;
+ }
+
+ public function get maxMotorForce() : Vector3D {
+ return m_maxMotorForce.v3d;
+ }
+
+ public function set maxMotorForce(v : Vector3D) : void {
+ m_maxMotorForce.v3d = v;
+ }
+
+ public function get currentLimitError() : Vector3D {
+ return m_currentLimitError.v3d;
+ }
+
+ public function set currentLimitError(v : Vector3D) : void {
+ m_currentLimitError.v3d = v;
+ }
+
+ public function get currentLinearDiff() : Vector3D {
+ return m_currentLinearDiff.v3d;
+ }
+
+ public function set currentLinearDiff(v : Vector3D) : void {
+ m_currentLinearDiff.v3d = v;
+ }
+
+ public function get limitSoftness() : Number {
+ return memUser._mrf(pointer + 48);
+ }
+
+ public function set limitSoftness(v : Number) : void {
+ memUser._mwf(pointer + 48, v);
+ }
+
+ public function get damping() : Number {
+ return memUser._mrf(pointer + 52);
+ }
+
+ public function set damping(v : Number) : void {
+ memUser._mwf(pointer + 52, v);
+ }
+
+ public function get restitution() : Number {
+ return memUser._mrf(pointer + 56);
+ }
+
+ public function set restitution(v : Number) : void {
+ memUser._mwf(pointer + 56, v);
+ }
+
+ public function get enableMotorX() : Boolean {
+ return memUser._mru8(pointer + 108) == 1;
+ }
+
+ public function set enableMotorX(v : Boolean) : void {
+ memUser._mw8(pointer + 108, v ? 1 : 0);
+ }
+
+ public function get enableMotorY() : Boolean {
+ return memUser._mru8(pointer + 109) == 1;
+ }
+
+ public function set enableMotorY(v : Boolean) : void {
+ memUser._mw8(pointer + 109, v ? 1 : 0);
+ }
+
+ public function get enableMotorZ() : Boolean {
+ return memUser._mru8(pointer + 110) == 1;
+ }
+
+ public function set enableMotorZ(v : Boolean) : void {
+ memUser._mw8(pointer + 110, v ? 1 : 0);
+ }
+ }
+}
View
23 src/awayphysics/dynamics/constraintsolver/AWPTypedConstraint.as
@@ -0,0 +1,23 @@
+package awayphysics.dynamics.constraintsolver
+{
+ import awayphysics.AWPBase;
+ import awayphysics.dynamics.AWPRigidBody;
+
+ public class AWPTypedConstraint extends AWPBase
+ {
+ protected var m_rbA : AWPRigidBody;
+ protected var m_rbB : AWPRigidBody;
+
+ public function AWPTypedConstraint()
+ {
+ }
+
+ public function get rigidBodyA() : AWPRigidBody {
+ return m_rbA;
+ }
+
+ public function get rigidBodyB() : AWPRigidBody {
+ return m_rbB;
+ }
+ }
+}
View
55 src/awayphysics/dynamics/vehicle/AWPRaycastInfo.as
@@ -0,0 +1,55 @@
+package awayphysics.dynamics.vehicle
+{
+ import awayphysics.AWPBase;
+ import awayphysics.math.AWPVector3;
+
+ import flash.geom.Vector3D;
+
+ public class AWPRaycastInfo extends AWPBase
+ {
+ private var m_contactNormalWS : AWPVector3;
+ private var m_contactPointWS : AWPVector3;
+ private var m_hardPointWS : AWPVector3;
+ private var m_wheelDirectionWS : AWPVector3;
+ private var m_wheelAxleWS : AWPVector3;
+
+ public function AWPRaycastInfo(ptr : uint)
+ {
+ pointer = ptr;
+
+ m_contactNormalWS = new AWPVector3(ptr + 0);
+ m_contactPointWS = new AWPVector3(ptr + 16);
+ m_hardPointWS = new AWPVector3(ptr + 36);
+ m_wheelDirectionWS = new AWPVector3(ptr + 52);
+ m_wheelAxleWS = new AWPVector3(ptr + 68);
+ }
+
+ public function get contactNormalWS() : Vector3D {
+ return m_contactNormalWS.v3d;
+ }
+
+ public function get contactPointWS() : Vector3D {
+ return m_contactPointWS.sv3d;
+ }
+
+ public function get hardPointWS() : Vector3D {
+ return m_hardPointWS.sv3d;
+ }
+
+ public function get wheelDirectionWS() : Vector3D {
+ return m_wheelDirectionWS.v3d;
+ }
+
+ public function get wheelAxleWS() : Vector3D {
+ return m_wheelAxleWS.v3d;
+ }
+
+ public function get suspensionLength() : Number {
+ return memUser._mrf(pointer + 32) * _scaling;
+ }
+
+ public function get isInContact() : Boolean {
+ return memUser._mru8(pointer + 84) == 1;
+ }
+ }
+}
View
84 src/awayphysics/dynamics/vehicle/AWPRaycastVehicle.as
@@ -0,0 +1,84 @@
+package awayphysics.dynamics.vehicle
+{
+ import awayphysics.AWPBase;
+ import awayphysics.dynamics.AWPRigidBody;
+ import awayphysics.plugin.IMesh3D;
+
+ import flash.geom.Vector3D;
+
+ // create the raycast vehicle
+ // refer to https://docs.google.com/document/edit?id=18edpOwtGgCwNyvakS78jxMajCuezotCU_0iezcwiFQc
+ public class AWPRaycastVehicle extends AWPBase
+ {
+ private var m_chassisBody : AWPRigidBody;
+ private var m_wheelInfo : Vector.<AWPWheelInfo>;
+
+ public function AWPRaycastVehicle(tuning : AWPVehicleTuning, chassis : AWPRigidBody)
+ {
+ pointer = bullet.createVehicleMethod(tuning, chassis.pointer);
+
+ m_chassisBody = chassis;
+ m_wheelInfo = new Vector.<AWPWheelInfo>();
+ }
+
+ public function getRigidBody() : AWPRigidBody
+ {
+ return m_chassisBody;
+ }
+
+ public function getNumWheels() : int
+ {
+ return m_wheelInfo.length;
+ }
+
+ public function getWheelInfo(index : int) : AWPWheelInfo
+ {
+ if (index < m_wheelInfo.length) {
+ return m_wheelInfo[index];
+ }
+ return null;
+ }
+
+ public function addWheel(_skin : IMesh3D, connectionPointCS0 : Vector3D, wheelDirectionCS0 : Vector3D, wheelAxleCS : Vector3D, suspensionRestLength : Number, wheelRadius : Number, tuning : AWPVehicleTuning, isFrontWheel : Boolean) : void
+ {
+ var wp : uint = bullet.addVehicleWheelMethod(pointer, connectionPointCS0.x / _scaling, connectionPointCS0.y / _scaling, connectionPointCS0.z / _scaling, wheelDirectionCS0.x, wheelDirectionCS0.y, wheelDirectionCS0.z, wheelAxleCS.x, wheelAxleCS.y, wheelAxleCS.z, suspensionRestLength / _scaling, wheelRadius / _scaling, tuning, (isFrontWheel) ? 1 : 0);
+
+ if (m_wheelInfo.length > 0) {
+ var num : int = 0;
+ for (var i : int = m_wheelInfo.length - 1; i >= 0; i-- ) {
+ num += 1;
+ m_wheelInfo[i] = new AWPWheelInfo(wp - 284 * num, m_wheelInfo[i].skin);
+ }
+ }
+
+ m_wheelInfo.push(new AWPWheelInfo(wp, _skin));
+ }
+
+ public function applyEngineForce(force : Number, wheelIndex : int) : void
+ {
+ m_wheelInfo[wheelIndex].engineForce = force;
+ }
+
+ public function setBrake(brake : Number, wheelIndex : int) : void
+ {
+ m_wheelInfo[wheelIndex].brake = brake;
+ }
+
+ public function setSteeringValue(steering : Number, wheelIndex : int) : void
+ {
+ m_wheelInfo[wheelIndex].steering = steering;
+ }
+
+ public function getSteeringValue(wheelIndex : int) : Number
+ {
+ return m_wheelInfo[wheelIndex].steering;
+ }
+
+ public function updateWheelsTransform() : void
+ {
+ for each (var wheel:AWPWheelInfo in m_wheelInfo) {
+ wheel.updateTransform();
+ }
+ }
+ }
+}
View
22 src/awayphysics/dynamics/vehicle/AWPVehicleTuning.as
@@ -0,0 +1,22 @@
+package awayphysics.dynamics.vehicle
+{
+ public class AWPVehicleTuning
+ {
+ public var suspensionStiffness : Number;
+ public var suspensionCompression : Number;
+ public var suspensionDamping : Number;
+ public var maxSuspensionTravelCm : Number;
+ public var frictionSlip : Number;
+ public var maxSuspensionForce : Number;
+
+ public function AWPVehicleTuning()
+ {
+ suspensionStiffness = 5.88;
+ suspensionCompression = 0.83;
+ suspensionDamping = 0.88;
+ maxSuspensionTravelCm = 500;
+ frictionSlip = 10.5;
+ maxSuspensionForce = 6000;
+ }
+ }
+}
View
226 src/awayphysics/dynamics/vehicle/AWPWheelInfo.as
@@ -0,0 +1,226 @@
+package awayphysics.dynamics.vehicle
+{
+ import awayphysics.AWPBase;
+ import awayphysics.math.AWPTransform;
+ import awayphysics.math.AWPVector3;
+ import awayphysics.plugin.IMesh3D;
+
+ import flash.geom.Matrix3D;
+ import flash.geom.Vector3D;
+
+ // defining suspension and wheel parameters
+ // refer to https://docs.google.com/document/edit?id=18edpOwtGgCwNyvakS78jxMajCuezotCU_0iezcwiFQc
+ public class AWPWheelInfo extends AWPBase
+ {
+ private var m_skin : IMesh3D;
+ private var m_raycastInfo : AWPRaycastInfo;
+ private var m_worldTransform : AWPTransform;
+ private var m_chassisConnectionPointCS : AWPVector3;
+ private var m_wheelDirectionCS : AWPVector3;
+ private var m_wheelAxleCS : AWPVector3;
+
+ public function AWPWheelInfo(ptr : uint, _skin : IMesh3D = null)
+ {
+ pointer = ptr;
+ m_skin = _skin;
+
+ m_raycastInfo = new AWPRaycastInfo(ptr);
+ m_worldTransform = new AWPTransform(ptr + 92);
+ m_chassisConnectionPointCS = new AWPVector3(ptr + 156);
+ m_wheelDirectionCS = new AWPVector3(ptr + 172);
+ m_wheelAxleCS = new AWPVector3(ptr + 188);
+ }
+
+ public function get skin() : IMesh3D {
+ return m_skin;
+ }
+
+ public function get raycastInfo() : AWPRaycastInfo {
+ return m_raycastInfo;
+ }
+
+ public function set worldPosition(pos : Vector3D) : void {
+ m_worldTransform.position.sv3d = pos;
+ }
+
+ public function get worldPosition() : Vector3D {
+ return m_worldTransform.position.sv3d;
+ }
+
+ public function set worldRotation(rot : Matrix3D) : void {
+ m_worldTransform.rotation.m3d = rot;
+ }
+
+ public function get worldRotation() : Matrix3D {
+ return m_worldTransform.rotation.m3d;
+ }
+
+ public function updateTransform() : void
+ {
+ var pos : Vector3D = this.worldPosition;
+ var rot : Vector.<Number> = this.worldRotation.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 get chassisConnectionPointCS() : Vector3D {
+ return m_chassisConnectionPointCS.sv3d;
+ }
+
+ public function set chassisConnectionPointCS(v : Vector3D) : void {
+ m_chassisConnectionPointCS.sv3d = v;
+ }
+
+ public function get wheelDirectionCS() : Vector3D {
+ return m_wheelDirectionCS.v3d;
+ }