Просмотр исходного кода

Getter for body velocity

and one nasty bug fix. or one nasty bug fixed. depends how you look at
it.
Raanan Weber 10 лет назад
Родитель
Сommit
1394665501

+ 11 - 0
src/Physics/Plugins/babylon.cannonJSPlugin.ts

@@ -435,6 +435,17 @@
         public setAngularVelocity(impostor: PhysicsImpostor, velocity: Vector3) {
             impostor.physicsBody.angularVelocity.copy(velocity);
         }
+        
+        public getLinearVelocity(impostor: PhysicsImpostor): Vector3 {
+            var v = impostor.physicsBody.velocity;
+            if (!v) return null;
+            return new Vector3(v.x, v.y, v.z)
+        }
+        public getAngularVelocity(impostor: PhysicsImpostor): Vector3 {
+            var v = impostor.physicsBody.angularVelocity;
+            if (!v) return null;
+            return new Vector3(v.x, v.y, v.z)
+        }
 
         public setBodyMass(impostor: PhysicsImpostor, mass: number) {
             impostor.physicsBody.mass = mass;

+ 12 - 2
src/Physics/Plugins/babylon.oimoJSPlugin.ts

@@ -324,6 +324,16 @@ module BABYLON {
             impostor.physicsBody.angularVelocity.init(velocity.x, velocity.y, velocity.z);
         }
 
+        public getLinearVelocity(impostor: PhysicsImpostor): Vector3 {
+            var v = impostor.physicsBody.linearVelocity;
+            if (!v) return null;
+            return new Vector3(v.x, v.y, v.z)
+        }
+        public getAngularVelocity(impostor: PhysicsImpostor): Vector3 {
+            var v = impostor.physicsBody.angularVelocity;
+            if (!v) return null;
+            return new Vector3(v.x, v.y, v.z)
+        }
 
         public setBodyMass(impostor: PhysicsImpostor, mass: number) {
             var staticBody: boolean = mass === 0;
@@ -349,14 +359,14 @@ module BABYLON {
         }
 
         public setMotor(joint: IMotorEnabledJoint, force?: number, maxForce?: number, motorIndex?: number) {
-            var motor = motorIndex ? joint.physicsJoint.rotationalLimitMotor2 : joint.physicsJoint.rotationalLimitMotor2 || joint.physicsJoint.limitMotor;
+            var motor = motorIndex ? joint.physicsJoint.rotationalLimitMotor2 : joint.physicsJoint.rotationalLimitMotor1 || joint.physicsJoint.limitMotor;
             if (motor) {
                 motor.setMotor(force, maxForce);
             }
         }
 
         public setLimit(joint: IMotorEnabledJoint, upperLimit: number, lowerLimit?: number, motorIndex?: number) {
-            var motor = motorIndex ? joint.physicsJoint.rotationalLimitMotor2 : joint.physicsJoint.rotationalLimitMotor2 || joint.physicsJoint.limitMotor;
+            var motor = motorIndex ? joint.physicsJoint.rotationalLimitMotor2 : joint.physicsJoint.rotationalLimitMotor1 || joint.physicsJoint.limitMotor;
             if (motor) {
                 motor.setLimit(upperLimit, lowerLimit || -upperLimit);
             }

+ 2 - 0
src/Physics/babylon.physicsEngine.ts

@@ -181,6 +181,8 @@
         setPhysicsBodyTransformation(impostor: PhysicsImpostor, newPosition: Vector3, newRotation: Quaternion);
         setLinearVelocity(impostor: PhysicsImpostor, velocity: Vector3);
         setAngularVelocity(impostor: PhysicsImpostor, velocity: Vector3);
+        getLinearVelocity(impostor: PhysicsImpostor) : Vector3;
+        getAngularVelocity(impostor: PhysicsImpostor) : Vector3;
         setBodyMass(impostor: PhysicsImpostor, mass: number);
         sleepBody(impostor: PhysicsImpostor);
         wakeUpBody(impostor: PhysicsImpostor);

+ 8 - 0
src/Physics/babylon.physicsImpostor.ts

@@ -146,6 +146,10 @@ module BABYLON {
             }
             this._physicsEngine.getPhysicsPlugin().setBodyMass(this, mass);
         }
+        
+        public getLinearVelocity() : Vector3 {
+            return this._physicsEngine.getPhysicsPlugin().getLinearVelocity(this);    
+        }
 
         /**
          * Set the body's linear velocity.
@@ -154,6 +158,10 @@ module BABYLON {
             this._physicsEngine.getPhysicsPlugin().setLinearVelocity(this, velocity);
         }
         
+        public getAngularVelocity() : Vector3 {
+             return this._physicsEngine.getPhysicsPlugin().getAngularVelocity(this);    
+        }
+        
         /**
          * Set the body's linear velocity.
          */