Heteroclinic.net logo

www.heteroclinic.net

Two-pass 3D Object and Mouse Collision Detection
20130731
Introductio

TwoPass3DObjectAndMouseCollisionDetection.pdf

In computer graphics, the 3D models are projected to the 2D canvas pane of a GUI for real visualization. A mouse click event can get the point position in the 2D canvas pane. If we want to get the real 3D model's particular position projected to the 2D pixel coordinate, probably we have to un-project the 2D point. At least, it will involve depth test. Accurate computation may also involve ray-tracing, scene graph, octree, 3D sorting etc. We try to simplify the burden by taking a different approach.


How it works

TwoPass3DObjectAndMouseCollisionDetection-pass-1.jpg

TwoPass3DObjectAndMouseCollisionDetection-pass-2.jpg


First, we draw the colorful virtual world.

Second pass, each object is draw in bacground rendering. In Fig.(\ref{2ndpass}), they may look like the same. But each of them is drawn with a unique mono-chrome color. We click the 2D pane, get a pixel position, the pixel position gives a unique color in format like [0,15,243,255], a 4 byte RGBA color. The color is mapped to a unique object ID.



Discussion
This article is not peer reviewed. If you find some errors or you want to give some comments, please contact the author.