The next challenge is clicking on a specific region of a texture map when the camera or mesh is rotated. The number of vertical and horizontal pixels will not be the same and nor will they be located in the same place. The texture coordinates will need to be precise and rotated. Using the California flag, shown in the following screenshot, the distance of the star from the left edge is smaller once the flag is rotated. In addition, the letters are equally spaced above but not when the flag is rotated.
As before, we generate a ray into the 3D scene based on the mouse click with one of the ray's endpoints beginning at the camera that sits at the origin at (0, 0, 0). If the ray intersects the mesh's bounding box, we then call getElementIntersection()
, which is a revision from the previous example...