HoloLite Posted October 31, 2017 Share Posted October 31, 2017 (edited) 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 October 31, 2017 by HoloLite added more details Quote Link to comment Share on other sites More sharing options...
HoloLite Posted October 31, 2017 Author Share Posted October 31, 2017 Looks like the following does the trick camera.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(-x, 0, 0); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 31, 2017 Share Posted October 31, 2017 Ping @davrous and @RaananW And the answer is definitely yes (just set camera.rotationQuaternion and call camera.resetPose() Quote Link to comment Share on other sites More sharing options...
HoloLite Posted October 31, 2017 Author Share Posted October 31, 2017 I don't see the resetPose() method in camera. Did you mean the camera.resetToCurrentRotation() ? For the first time I am getting the real vr sickness after mucking around with headset rotation directly. Hehe, this has to be done carefully I guess Quote Link to comment Share on other sites More sharing options...
brianzinn Posted November 1, 2017 Share Posted November 1, 2017 Yes, resetToCurrentRotation() - it calls resetPose(), but on _vrDevice: https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/VR/babylon.webVRCamera.ts#L252 Quote Link to comment Share on other sites More sharing options...
HoloLite Posted November 1, 2017 Author Share Posted November 1, 2017 @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(); Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 1, 2017 Share Posted November 1, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.