Jump to content

How to rotate the WebVRFreeCamera


HoloLite
 Share

Recommended Posts

Hello,

I am trying to rotate or change the orientation of the web vr camera programmatically. I am using the WinMR controllers.

The base codes are from the sponza/mansion teleportation where we can change the camera position. I wonder if it's possible to change the camera orientation using thumbstick as well (like teleportation in the cliff house).

Setting the camera's rotation (x, y, z) does not seem to make any impact.

There has to be a way right ? Please help. Thanks

Edited by HoloLite
added more details
Link to comment
Share on other sites

@brianzinn thanks for the tips!

I ended up having to do the following codes. Not sure if this is the most efficient one, but it seems all lines are needed to make it actually works.

  var y = camera.rotation.y + xVal/30;
  camera.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(-y, 0, 0);
  camera.rotation.y = y;
  camera.resetToCurrentRotation();
Link to comment
Share on other sites

I think there is a form of confusion regarding what resetPose does :)

resetPose will take the current rotation in the y axis (using quaternions, but it is better to understand it this way) and resets it on the device level. Meaning, the device's y is being reset. In Babylon nothing changes. So - if the user looks 90 gedrees to the right and resets its pose, the internal pose of the device itself (not babylon's rotation) will be 90 degrees to the left. So that looking 90 degrees to the right will be 0 degrees.

If you want to create a default pose to start with, there are two options to do that - you can either set the camera's rotationQuaternion (the came, not its children or anything else). This will set a rotation offset that will always be added to the camera. The other way is rotating your entire scene the other way. The 2nd option is of course a bit far-fetched, if you haven't prepared for it. I like the 2nd option as it keeps the camera's rotation at 0,0,0,1, which I personally like :) To do that you will need to set a parent object for the entire scene (not including the camera) and rotate it. But the 1st option (rotationQuaternion) should be working.

If you want to share a scene where it is not working (or not working as expected), let me know.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...