Jump to content

rotate VR camera


Terminator
 Share

Recommended Posts

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?

 

Link to comment
Share on other sites

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. 

 

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. 

 

Link to comment
Share on other sites

it is an important step that you were able to make the rotation work B), 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.

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...