EddyVerbruggen / nativescript-ar

Augmented Reality NativeScript plugin
https://www.nativescript.org/blog/preview-of-augmented-reality-in-nativescript
MIT License
118 stars 36 forks source link

Quaternion issue (android) #45

Closed nickolanack closed 5 years ago

nickolanack commented 5 years ago

I'm pretty sure that rotateBy method for android is not using quaternions correctly should be:

rotateBy(by: ARRotation): void {
    const currentRotation = this.android.getLocalRotation().eulerAngles();
    this.android.setLocalRotation(
      new (<any>com.google.ar.sceneform).math.Quaternion(
        new (<any>com.google.ar.sceneform).math.Vector3(
          currentRotation.x + by.x,
          currentRotation.y + by.y,
          currentRotation.z + by.z
        )
      )
    );
  }
nickolanack commented 5 years ago

I'm not 100% percent sure, but will test and if I'm correct I'll PR

nickolanack commented 5 years ago

my solution is wrong... this.android.getLocalRotation().eulerAngles() does not do what I thought. But I still think that the original method is not correct

nickolanack commented 5 years ago

updated android rotateBy method

rotateBy(by: ARRotation): void {
    const currentRotation = this.android.getLocalRotation();
    const rotateBy=new (<any>com.google.ar.sceneform).math.Quaternion(
        new (<any>com.google.ar.sceneform).math.Vector3(
          by.x,
          by.y,
          by.z
        )
      );
    this.android.setLocalRotation((<any>com.google.ar.sceneform).math.Quaternion.multiply(currentRotation, rotateBy) );
  }