Fixed camera to 3DoF (rotation only)

Hi, my question this. When moving the camera via phone or headset, it is 6DoF and the camera’s position can change along with its rotation. I’d like to restrict to just rotation (so fixed position) like with 3DoF. How would I do this? emitting “Recenter” updates both position and rotation of the camera, but I read in the documentation you can set the target position and rotation. This is what I tried.

const FixedCamera = {
  schema: {
    x: { type: 'number', default: 0 },
    y: { type: 'number', default: 1.6 }, // Default camera height
    z: { type: 'number', default: 0 },
    updateInterval: { type: 'number', default: 500 } // Time in milliseconds
  },
  init() {
    this.scene = this.el.sceneEl
    this.tick = AFRAME.utils.throttleTick(this.tick, this.data.updateInterval, this)

    this.el.sceneEl.addEventListener('realityready', () => {
      this.recenterCamera();
    })
  },
  recenterCamera() {
    let currentRotation = this.el.object3D.rotation; // This is already a THREE.Euler object
    let facingQuaternion = new THREE.Quaternion();
    facingQuaternion.setFromEuler(currentRotation); // Convert Euler to Quaternion directly
    
    console.log(facingQuaternion.w, facingQuaternion.x, facingQuaternion.y, facingQuaternion.z)
    this.scene.emit('recenter', {
      origin: { x: this.data.x, y: this.data.y, z: this.data.z },
      facing: {
        w: facingQuaternion.w,
        x: facingQuaternion.x,
        y: facingQuaternion.y,
        z: facingQuaternion.z
      }
    });
  },
  tick() {
    this.recenterCamera()
  }
}

export { FixedCamera };

Attached to the a-camera. It doesn’t seem to be working, and the rotation is always updating to the same rotation instead of what the camera’s current rotation is.

I think you’re looking for the disableWorldTracking parameter on xrweb:

xrweb="disableWorldTracking: true"
1 Like

@Austin_Donnelly - @Evan’s suggestion will work on Android (since gyro is enabled by default), but for iOS you’ll probably need to request gyro permissions explicitly (if disableWorldTracking is set to true then our engine doesn’t request gyro for you). You shouldn’t need any of your custom code from your original post.

Simply add a pipeline module that sets gyro as a dependency, for example

XR8.addCameraPipelineModule({
  name: 'request-gyro',
  requiredPermissions: () => ([XR8.XrPermissions.permissions().DEVICE_ORIENTATION]),
})
2 Likes

Thanks for that extra tip actually, it was just what I needed after I initially got it working on Android.

So, this is what worked for me.

XR8.addCameraPipelineModule({
        name: 'request-gyro',
        requiredPermissions: () => ([XR8.XrPermissions.permissions().DEVICE_ORIENTATION]),
      })

Adding this helped with iOS when I wanted to set disableWorldTracking to true.

Next, I realized that just setting the attribute or value of disableWorldTracking to true on an existing xrweb component doesn’t actually change it. You either have to remove xrweb altogether and then add it again with this attribute or just add xrweb manually in a component instead.

For my goal, I wanted to essentially remove world tracking for mobile devices only, so I did this in one of my components.

const FixedCamera = {
  init() {
    this.scene = this.el.sceneEl

    this.scene.setAttribute('xrweb', this.isMobileDevice() ? 'disableWorldTracking: true' : '')
    
    this.el.sceneEl.addEventListener('realityready', () => {
      console.log("REALITY READY")      
      this.recenterCamera()
    })
  },
  recenterCamera() {
    this.scene.emit('recenter')
  },
  isMobileDevice() {
    return AFRAME.utils.device.isMobile()
  }
}

export { FixedCamera }

So far, it seems to work well, even with VR HMDs.

1 Like

@Austin_Donnelly Glad to hear you have things working. You are correct that you can’t modify disableWorldTracking at runtime, so you’ll have to remove and add/re-add xrweb to change things.

We do this in some of our other sample projects:

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.