Sfoglia il codice sorgente

better version of forward ray

Raanan Weber 5 anni fa
parent
commit
2eb051a937
1 ha cambiato i file con 8 aggiunte e 6 eliminazioni
  1. 8 6
      src/XR/webXRInputSource.ts

+ 8 - 6
src/XR/webXRInputSource.ts

@@ -37,7 +37,6 @@ export interface IWebXRControllerOptions {
  * Represents an XR controller
  */
 export class WebXRInputSource {
-    private _tmpQuaternion = new Quaternion();
     private _tmpVector = new Vector3();
     private _uniqueId: string;
 
@@ -94,6 +93,8 @@ export class WebXRInputSource {
             this.grip.rotationQuaternion = new Quaternion();
         }
 
+        this._tmpVector.set(0, 0, (this._scene.useRightHandedSystem ? -1.0 : 1.0));
+
         // for now only load motion controllers if gamepad object available
         if (this.inputSource.gamepad) {
             WebXRMotionControllerManager.GetMotionControllerWithXRInput(inputSource, _scene, this._options.forceControllerProfile).then((motionController) => {
@@ -149,12 +150,13 @@ export class WebXRInputSource {
      */
     public getWorldPointerRayToRef(result: Ray, gripIfAvailable: boolean = false) {
         const object = gripIfAvailable && this.grip ? this.grip : this.pointer;
-        let worldMatrix = object.computeWorldMatrix();
-        worldMatrix.decompose(undefined, this._tmpQuaternion, undefined);
-        this._tmpVector.set(0, 0, (this._scene.useRightHandedSystem ? -1.0 : 1.0));
-        this._tmpVector.rotateByQuaternionToRef(this._tmpQuaternion, this._tmpVector);
+        Vector3.TransformNormalToRef(
+            this._tmpVector,
+            object.getWorldMatrix(),
+            result.direction
+        );
+        result.direction.normalize();
         result.origin.copyFrom(object.absolutePosition);
-        result.direction.copyFrom(this._tmpVector);
         result.length = 1000;
     }