瀏覽代碼

Fix Camera Position

sevan 8 年之前
父節點
當前提交
0661d92791
共有 2 個文件被更改,包括 22 次插入5 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 21 5
      src/Cameras/Holographic/babylon.holographicCamera.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -4,6 +4,7 @@
  - New Unity 5 Editor Toolkit. Complete pipeline integration [Doc](TODO) - ([MackeyK24](https://github.com/MackeyK24))
  - New DebugLayer. [Doc](TODO) - ([temechon](https://github.com/temechon))
  - New `VideoTexture.CreateFromWebCam` to generate video texture using WebRTC. [Demo](https://www.babylonjs-playground.com#1R77YT#2) - (Sebastien Vandenberghe)(https://github.com/sebavanmicrosoft) / ([deltakosh](https://github.com/deltakosh))
+ - New `HolographicCamera` to support rendering on Windows Holographic. - ([sebavan](https://github.com/sebavan))
 
 ### Updates
  - `Effect.getVertexShaderSource()` and `Effect.getFragmentShaderSource()` now returns the effective shader code (including evaluation of #define) ([deltakosh](https://github.com/deltakosh))

+ 21 - 5
src/Cameras/Holographic/babylon.holographicCamera.ts

@@ -1,4 +1,10 @@
-module BABYLON {
+interface Window { 
+    holographicViewMatrix: boolean;
+    getViewMatrix(): Float32Array;
+    getCameraPositionVector(): Float32Array;
+} 
+
+module BABYLON {
     export class HolographicCamera extends Camera {
         
         private _identityProjection: Matrix;
@@ -33,8 +39,11 @@
 
             var self = this;
             this._onBeforeRenderObserver = scene.onBeforeRenderObservable.add(function (scene) {
-                self._holographicViewMatrix.m = (<any>window).getViewMatrix();
+                self._holographicViewMatrix.m = window.getViewMatrix();
                 self.setViewMatrix(self._holographicViewMatrix);
+
+                var position = window.getCameraPositionVector();
+                self.position.copyFromFloats(-position[0], position[1], -position[2]);
             })
             this._onBeforeCameraRenderObserver = scene.onBeforeCameraRenderObservable.add(function() {
                 if (scene.frustumPlanes) {
@@ -63,9 +72,16 @@
 
         public setViewMatrix(view: Matrix) : void {
             this._holographicViewMatrix = view;
-            this.position.x = view.m[12];
-            this.position.y = view.m[13];
-            this.position.z = -view.m[14];
+
+            view.m[0] = -view.m[0];
+            view.m[1] = -view.m[1];
+            view.m[2] = -view.m[2];
+            view.m[3] = -view.m[3];
+
+            view.m[8] = -view.m[8];
+            view.m[9] = -view.m[9];
+            view.m[10] = -view.m[10];
+            view.m[11] = -view.m[11];
         };
         
         public _initCache(): void { };