Skip to main content
New Participant
May 6, 2015

Object Picking in WebVR based application

Hey guys,

I am developing an web-application that uses WebVR (DK1) to achieve vr ability in browsers. I would like to pick objects by my line-of-sight (looking at them). Traditional object picking via ray casting is already implemented, but I don't know which values are necessary for x and y, in the past it was the mouse:


Vector3f origin = unproject(x, y, 0, viewportWidth, viewportHeight, modelView);
Vector3f direction = unproject(x, y, 1, viewportWidth, viewportHeight, modelView).sub(origin);
Ray ray = new Ray(origin, direction);
// process intersections

    3 replies

    May 7, 2015
    I can't tell what, if any, WebGL library you're using but I'm guessing you'd want the origin to be the position of the camera and the direction to be the camera's quaternion/euler vector. If that doesn't work, you could try using 0.5, 0.5 or viewportWidth / 2, viewportHeight / 2 in place of x, y.
    May 7, 2015
    Also, if you're interested, the Three.js WebGL library already has support for WebVR and there are boilerplate projects for it that help you get started and libraries that provide features like object picking and reticles.
    New Participant
    May 7, 2015
    viewportWidth / 2, viewportHeight / 2
    works well (stupid me).

    Thank you