Browse Source

Final integration of Raanan excellent work

David Catuhe 10 years ago
parent
commit
82a2ba6937

+ 7 - 18
Babylon/Cameras/babylon.freeCamera.js

@@ -25,10 +25,8 @@ var BABYLON;
             this._oldPosition = BABYLON.Vector3.Zero();
             this._diffPosition = BABYLON.Vector3.Zero();
             this._newPosition = BABYLON.Vector3.Zero();
-            this._newPositionBuffer = BABYLON.Vector3.Zero();
             this._onCollisionPositionChange = function (collisionId, newPosition, collidedMesh) {
                 if (collidedMesh === void 0) { collidedMesh = null; }
-                var fromGravity = collisionId !== _this.uniqueId;
                 //TODO move this to the collision coordinator!
                 if (_this.getScene().workerCollisions)
                     newPosition.multiplyInPlace(_this._collider.radius);
@@ -42,10 +40,6 @@ var BABYLON;
                             _this.onCollide(collidedMesh);
                         }
                     }
-                    //check if it is the gravity inspection
-                    if (fromGravity) {
-                        _this._needMoveForGravity = (BABYLON.Vector3.DistanceSquared(oldPosition, _this.position) != 0);
-                    }
                 };
                 updatePosition(newPosition);
             };
@@ -166,22 +160,21 @@ var BABYLON;
                 this._reset();
             }
         };
-        FreeCamera.prototype._collideWithWorld = function (velocity, gravityInspection) {
-            if (gravityInspection === void 0) { gravityInspection = false; }
+        FreeCamera.prototype._collideWithWorld = function (velocity) {
             var globalPosition;
             if (this.parent) {
-                globalPosition = BABYLON.Vector3.TransformCoordinates(gravityInspection ? this._newPositionBuffer : this.position, this.parent.getWorldMatrix());
+                globalPosition = BABYLON.Vector3.TransformCoordinates(this.position, this.parent.getWorldMatrix());
             }
             else {
                 globalPosition = this.position;
             }
             globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPosition);
             this._collider.radius = this.ellipsoid;
-            //in case we are using web workers, add gravity to the velocity to prevent the dual-collision checking
-            if (this.getScene().workerCollisions) {
+            //add gravity to the velocity to prevent the dual-collision checking
+            if (this.applyGravity) {
                 velocity.addInPlace(this.getScene().gravity);
             }
-            this.getScene().collisionCoordinator.getNewPosition(this._oldPosition, velocity, this._collider, 3, null, this._onCollisionPositionChange, gravityInspection ? this.uniqueId + 100000 : this.uniqueId);
+            this.getScene().collisionCoordinator.getNewPosition(this._oldPosition, velocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);
         };
         FreeCamera.prototype._checkInputs = function () {
             if (!this._localDirection) {
@@ -213,10 +206,7 @@ var BABYLON;
         };
         FreeCamera.prototype._updatePosition = function () {
             if (this.checkCollisions && this.getScene().collisionsEnabled) {
-                this._collideWithWorld(this.cameraDirection, false);
-                if (this.applyGravity && !this.getScene().workerCollisions) {
-                    this._collideWithWorld(this.getScene().gravity, true);
-                }
+                this._collideWithWorld(this.cameraDirection);
             }
             else {
                 this.position.addInPlace(this.cameraDirection);
@@ -230,5 +220,4 @@ var BABYLON;
     })(BABYLON.TargetCamera);
     BABYLON.FreeCamera = FreeCamera;
 })(BABYLON || (BABYLON = {}));
-
-//# sourceMappingURL=../Cameras/babylon.freeCamera.js.map
+//# sourceMappingURL=babylon.freeCamera.js.map

+ 10 - 20
Babylon/Cameras/babylon.freeCamera.ts

@@ -16,7 +16,6 @@
         private _oldPosition = BABYLON.Vector3.Zero();
         private _diffPosition = BABYLON.Vector3.Zero();
         private _newPosition = BABYLON.Vector3.Zero();
-        private _newPositionBuffer = BABYLON.Vector3.Zero();
         private _attachedElement: HTMLElement;
         private _localDirection: Vector3;
         private _transformedDirection: Vector3;
@@ -178,11 +177,11 @@
             }
         }
 
-        public _collideWithWorld(velocity: Vector3, gravityInspection: boolean = false): void {
+        public _collideWithWorld(velocity: Vector3): void {
             var globalPosition: Vector3;
 
             if (this.parent) {
-                globalPosition = BABYLON.Vector3.TransformCoordinates(gravityInspection ? this._newPositionBuffer : this.position, this.parent.getWorldMatrix());
+                globalPosition = BABYLON.Vector3.TransformCoordinates(this.position, this.parent.getWorldMatrix());
             } else {
                 globalPosition = this.position;
             }
@@ -190,18 +189,16 @@
             globalPosition.subtractFromFloatsToRef(0, this.ellipsoid.y, 0, this._oldPosition);
             this._collider.radius = this.ellipsoid;
 
-            //in case we are using web workers, add gravity to the velocity to prevent the dual-collision checking
-            if (this.getScene().workerCollisions) {
+            //add gravity to the velocity to prevent the dual-collision checking
+            if (this.applyGravity) {
                 velocity.addInPlace(this.getScene().gravity);
             }
 
-            this.getScene().collisionCoordinator.getNewPosition(this._oldPosition, velocity, this._collider, 3, null, this._onCollisionPositionChange, gravityInspection ? this.uniqueId + 100000 : this.uniqueId);
-            
+            this.getScene().collisionCoordinator.getNewPosition(this._oldPosition, velocity, this._collider, 3, null, this._onCollisionPositionChange, this.uniqueId);
+
         }
 
         private _onCollisionPositionChange = (collisionId: number, newPosition: Vector3, collidedMesh: AbstractMesh = null) => {
-            var fromGravity: boolean = collisionId !== this.uniqueId;
-
             //TODO move this to the collision coordinator!
             if (this.getScene().workerCollisions)
                 newPosition.multiplyInPlace(this._collider.radius);
@@ -218,15 +215,11 @@
                         this.onCollide(collidedMesh);
                     }
                 }
-                //check if it is the gravity inspection
-                if (fromGravity) {
-                    this._needMoveForGravity = (BABYLON.Vector3.DistanceSquared(oldPosition, this.position) != 0);
-                }
-            }    
-            
+            }
+
             updatePosition(newPosition);
         }
-        
+
         public _checkInputs(): void {
             if (!this._localDirection) {
                 this._localDirection = BABYLON.Vector3.Zero();
@@ -260,10 +253,7 @@
 
         public _updatePosition(): void {
             if (this.checkCollisions && this.getScene().collisionsEnabled) {
-                this._collideWithWorld(this.cameraDirection, false);
-                if (this.applyGravity && !this.getScene().workerCollisions) {
-                    this._collideWithWorld(this.getScene().gravity, true);
-                }
+                this._collideWithWorld(this.cameraDirection);
             } else {
                 this.position.addInPlace(this.cameraDirection);
             }

File diff suppressed because it is too large
+ 24 - 25
babylon.2.1-beta.debug.js


File diff suppressed because it is too large
+ 17 - 17
babylon.2.1-beta.js


File diff suppressed because it is too large
+ 26 - 0
babylon.2.1-beta.noworker.js