O'Reilly logo

WebGL Game Development by Sumeet Arora

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Learning the basics of picking

All 3D platforms have a very basic problem to solve: what is under the mouse? This problem in the 3D world is referred to as picking. It is not simple and straightforward and involves nontrivial mathematics and some complex algorithms, but it is solvable once you understand the core concept. To solve the problem, there are two approaches in picking, based on an object color and ray casting.

Picking based on an object's color

Each object in the scene is assigned a unique diffuse color, and then the complete scene is rendered in an offscreen framebuffer. When the user clicks on the scene, we get the color from the texture in a framebuffer of the corresponding click coordinate. Then, we iterate through the list of objects ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required