jdurrant

Can't get camera.getTarget() to work with WebVR Camera (HTC Vive)

Recommended Posts

I've used camera.getTarget() to advance a character forward, as described here: 

It's worked well with a FreeCamera, but I can't get it to work with the WebVR camera. camera.getTarget().subtract(camera.position) always returns the same vector regardless of what I'm looking at through the VR headset.

It was a bit tricky to demonstrate in the playground, but I managed: https://www.babylonjs-playground.com/#7DYN70#11

That demo starts with a FreeCamera attached to the canvas. Open up the JavaScript console, and you'll see that it's logging the camera.getTarget().subtract(camera.position) vector every second. If you move the camera looking direction with your mouse, you'll see that the "looking vector" changes in the console.

Now the same code, but with a WebVR camera (HTC Vive): https://www.babylonjs-playground.com/#7DYN70#10

In the console, the "looking vector" is always the same, regardless of what I'm seeing in the HTC Vive headset.

As always, thanks for your help!

Share this post


Link to post
Share on other sites

VR! One of my favorite topics.

So... the WebVR camera is actually a simple parent camera with two "eyes" - left and right. Just like your eyes, those two cameras have a different "direction". This direction trick can be done on webVRCamera.leftCamera or webVRCamera.rightCamera (both are free cameras).

You need to decide which eye to use. 

Hope this helps!

Share this post


Link to post
Share on other sites

Yo! :) 

an interesting suggestion. I remember that when I implemented that I had a reason not to do that, but I honestly can't think of it right now. Let me make some calculations ;)

If you want to PR this suggestion to the WebVR camera, be my guest! I will comment on the PR itself.

Share this post


Link to post
Share on other sites

In general I think it had something to do with depth and focus. The eyes never really look straight, but the two cameras are practically parallel. But, again, I can't remember. I just know that I tried, and eventually always used the left eye.

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.