Virtually any 3D computer-graphics application needs to provide mechanisms for the user to interact with the scene. For instance, in a game, you may want to point at your target and perform an action upon it. Or in a CAD system, you may want to be able to select an object in your scene and modify its properties. In this chapter, we’ll learn the basics of implementing these kinds of interactions in WebGL.
To start, we should point out that we can select objects by casting a ray (vector) from the camera position (also known as the eye position) into the scene and calculate the objects that lie along its path. This is known as ray-casting and involves detecting intersections between the ray and object surfaces in the scene.
Ray-casting is the use of ray–surface intersection tests to solve a variety of problems in computer graphics and computational...