Search code examples
javascriptxml3d

XML3D: generateRay


I'm implementing draggable object in XML3D and i need a help with xml3d.generateRay function, as an argument it takes two numbers, as I understand correctly those are x,y coordinates of point in projection space that ray passes through. But are those coordinates in reference to the window element (left-top corner of the browser window) or to the xml upper-left corner?

Second question: how can I get hit point from getElementByRay

Specification says differently for different versions - and since there is no spec for 4.9 I ask.


Solution

  • The coordinates are given in window space, so relative to the top left corner of the window.

    You can get the hit point and hit normal from getElementByRay by passing two XML3DVec3 objects into the function, eg:

    var hitPoint = new XML3DVec3();
    var hitNormal = new XML3DVec3();
    xml3dElement.getElementByRay(ray, hitPoint, hitNormal);
    

    The function will fill the vectors with the hit point and normal in world space.