Terminator Posted July 14, 2016 Share Posted July 14, 2016 Hello, I am using a code to define a VR camera, so when I rotate my phone the camera move, however I want to disable the default movement and change it based on a formula different than the normal one 1st, here is the code: //camera cameraPosition = new BABYLON.Vector3(0, .5, -1.8); var camera = new BABYLON.VRDeviceOrientationFreeCamera ("camera", cameraPosition, scene); and I was able to get the device rotation angles using these: window.addEventListener("deviceorientation", onDeviceMovement, false); function onDeviceMovement(event){ console.log("Device movement (alpha,beta,gamma): " + event.alpha + ", " + event.beta + ", " + event.gamma ); }; so assuming that I have the alpha, beta, gamma, how can I disable the current movement, and replace the rotation angles of the camera based on a formula that includes alpha,beta and gamma? Quote Link to comment Share on other sites More sharing options...
chicagobob123 Posted July 14, 2016 Share Posted July 14, 2016 WOW that would be awesome. What device is this you are using? Please say Gear VR I think the camera has an input which I think you can dispose camera.input.dispose But I am not at all an expert just started using a gamepad with to control VR movement. If you have this working it would be fantastic. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 14, 2016 Share Posted July 14, 2016 Hey, @chicagobob123 is right. Thanks to the new input system, you can just remove the current input like this: http://www.babylonjs-playground.com/#5W4LY Then you can either implement your own input or just handle the inputs the way you do it right now Quote Link to comment Share on other sites More sharing options...
Terminator Posted July 15, 2016 Author Share Posted July 15, 2016 For some reason this code didn’t work: camera.inputs.removeByType("FreeCameraVRDeviceOrientationInput") however I was able to remove all inputs using this (which solved the input problem for me): camera.inputs.clear(); Now my problem is with camera rotation, I was just experimenting how to rotate the camera when I am in the VR Camera mode (in order to link the rotation to the device rotation angles in the next step) but it didn’t work (though the rotation code works with Free Camera). This playground tries to rotate the VR camera in each frame (but it doesn't work!): http://www.babylonjs-playground.com/#18VZJM#0 This playground is the exact same code as the above but the camera is Free Camera (and the rotation works!): http://www.babylonjs-playground.com/#18VZJM#1 so any idea why/how to make the rotation code works with VR camera? Quote Link to comment Share on other sites More sharing options...
chicagobob123 Posted July 15, 2016 Share Posted July 15, 2016 This is a mystery. One I have to figure out. I tried. The WebVRFreeCamera and it did not seem to work either. With out without clearing the input. There has to be something different but I just dont see it yet. Will look at it after I get done with some other code. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 15, 2016 Share Posted July 15, 2016 This is because VR camera are not using rotation but rotationQuaternion (To be aligned with what the browser provides) chicagobob123 1 Quote Link to comment Share on other sites More sharing options...
chicagobob123 Posted July 15, 2016 Share Posted July 15, 2016 So for your example to rotate the X you can do this //Before rendering each frame scene.registerBeforeRender(function () { var e = new BABYLON.Vector3(camera.rotation.x,0,0); camera.rotation.x += 0.01; camera.rotationQuaternion = BABYLON.Quaternion.RotationYawPitchRoll(e.y, e.x, e.z); }); Seems to work here. Here is a playground example http://www.babylonjs-playground.com/#18VZJM#25 Quote Link to comment Share on other sites More sharing options...
chicagobob123 Posted July 15, 2016 Share Posted July 15, 2016 Thanks Deltakosh that was exactly it. In my GearVR with a bluetooth came controler I was able to get rotation and movement. Kinda nuts. Performance.. Well it was awful. The 3D items seem to move smooth but the camera movements were very rough.This could be because of the bluetooth input. Thats why I hope Terminator can tap into the great Samsung along with the buttons on the side for forward, back, up and down. Quote Link to comment Share on other sites More sharing options...
Terminator Posted July 18, 2016 Author Share Posted July 18, 2016 it is an important step that you were able to make the rotation work , I am lately learning about the Quaternion rotation in order to understand it better, btw I am actually using Google cardboard, and the plan is to use the head rotation in order to rotate the camera, but I am also using ultrasonic sensors in order to detect the player movement (left/right), so I am not using any controllers but rather the player movement in real life will be reflected in the game.. I am still experimenting with that, so for now, I have no idea how smooth this is going to be, but I have finished a good part so far. Quote Link to comment Share on other sites More sharing options...
chicagobob123 Posted July 18, 2016 Share Posted July 18, 2016 I was hoping for a Samsung Gear VR interface but have no idea about how to glue it together. Far as understanding, have a partial on the math but rely on the a Euler conversion 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.