Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Sincostan90's avatar
Sincostan90
Honored Guest
10 years ago

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

  • Anonymous's avatar
    Anonymous
    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.
  • viewportWidth / 2, viewportHeight / 2
    works well (stupid me).

    Thank you