Book Image

WebGL HOTSHOT

By : Mitch Williams
Book Image

WebGL HOTSHOT

By: Mitch Williams

Overview of this book

Table of Contents (17 chapters)
WebGL HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Selecting locations from a rotated texture map and perspective correction


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.

The California state flag rotated to show how clicking on individual regions needs to adjusted for rotations

Engage thrusters

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...