Xr base experience camera default override?

Do I need to “default override” something in the xr camera to change its values?

when I do xr.baseExperience.camera.rotation.y (or _y) = 1.5;

it’s values are unchanged when I log the console.

Same thing for other values like the upvector, etc.

I’m basically trying to press my side paddle and turn the ground into the sky and vice versa when I click the other paddle (so I can look up and see the ground).

Some starter advice would be cool… Happy to dive into the docs but need some advice about what to look at.

ah ha, I can log in the console and change the position, but I can’t change the rotation, which makes me thing that the rotation is being set by the position of the head; I guess I still want the head to be able to do all sorts of stuff, but I just want the side triggers to flip the world upside down (I’m playing around in the camera component looking for how to do this). I wonder if you have to temporarily disable taking in the player’s position of their head, flip the world, then re-enable head tracking.

The WebXR camera has its rotationQuaternion set, so setting .rotation will do nothing. You will need to set the quaternion if you want to rotate the camera.

I would recommend checking the transportation rotation code (Babylon.js/WebXRControllerTeleportation.ts at master · BabylonJS/Babylon.js · GitHub) to understand how to do it correctly.

1 Like

OK, you got it, thank you; will dig in.

Alright

                    //rotation
      motionController
        .getComponent("xr-standard-squeeze")
        .onButtonStateChangedObservable.add(component => {
          if (component.changes.pressed) {
            if (component.pressed) {
              xr.baseExperience.camera.rotationQuaternion.z = xr.baseExperience.camera.rotationQuaternion.z - 0.1;
            }
          }
        });

This starts twirling me around the space, which is a good start. I’ve never worked with Quaternions before. Is this the part of the docs I should be looking at: Rotation Conventions | Babylon.js Documentation ? I’m trying to flip the floor/ground no matter where I’m looking (in my headset).

I notice that if look in the right direction (west, e.g., or z, who knows) then I can rotate correctly, but if I look in any other direction, I start spiraling off into space. So, trying to learn more about this.

Wondering if there is some way to “bypass” the complexity of quaternions and just get the result of a flip. Maybe .toEulerAngles is the way? (but then have to learn about Euler angles…). Maybe this is what I should be looking at, bc it looks like you can supply a rotation to world space: Rotation Quaternions | Babylon.js Documentation

I am playing with this now: mesh.rotationQuaternion = new BABYLON.Quaternion.RotationAxis(axis, angle); from this guide: BabylonJS Guide

this “usually” flips me (puts the ground in the sky):

     motionController
            .getComponent("xr-standard-squeeze")
            .onButtonStateChangedObservable.add(component => {
              if (component.changes.pressed) {
                if (component.pressed) {
                  //xr.baseExperience.camera.rotationQuaternion.z = xr.baseExperience.camera.rotationQuaternion.z + 0.1;
                  xr.baseExperience.camera.rotationQuaternion = new BABYLON.Quaternion.RotationAxis(new BABYLON.Vector3(1,0,0), 3.14159);
                }
              }
            });

this “sort of” resets me (puts the ground below my feet):

   motionController
                .getComponent("xr-standard-squeeze")
                .onButtonStateChangedObservable.add(component => {
                  if (component.changes.pressed) {
                    if (component.pressed) {
                      //xr.baseExperience.camera.rotationQuaternion.z = xr.baseExperience.camera.rotationQuaternion.z - 0.1;
                      xr.baseExperience.camera.rotationQuaternion.x = 0;
                      xr.baseExperience.camera.rotationQuaternion.y = 0;
                      xr.baseExperience.camera.rotationQuaternion.z = -0;
                      xr.baseExperience.camera.rotationQuaternion.w = -1;
                    }
                  }
                });

I think this is still “gaze dependent” and I have to figure out how to make it gaze independent.