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


First, we draw the colorful virtual world.

TwoPass3DObjectAndMouseCollisionDetection-pass-2.jpg


Second pass, each object is draw in back ground 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.

Project Friends Torus Demo1.1 I
Simple GLCamera

20130731

How to:
Download FriendsTorusDemo1.1.zip
md5sum: d58aed75e537b09f0d4bcce779076e8e

Project Friends Torus Demo1.1 II
GLMovingObject

20130731

How to:
Download FriendsTorusDemo1.1.zip
md5sum: d58aed75e537b09f0d4bcce779076e8e

Friends Torus 31 Days Development Log
20130701-20130731

Log 20130701-20130731.