Message-ID: From: Shawn Hargreaves To: djgpp AT delorie DOT com Subject: Re: Mouse in 3D environment Date: Tue, 24 Mar 1998 09:19:47 -0000 MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk Theuzifan writes: > Did you have any idea on how to implement a mouse in a 3D > environment? I mean, I have a 3D world, I have a mouse, and I > want to know at what 3d object I've clicked... what should I do? This is exactly the same process as drawing raytraced graphics. You need to convert your 2d mouse position into a 3d ray (the exact centre of the screen produces a ray from the camera in the direction you are looking, clicking a bit to the left produces a ray facing slightly left of the camera direction, etc). Then just project this ray through the 3d world until it hits something, and you have found your object. The comp.graphics.algorithms FAQ is a good reference for the math involved with this, and the Graphics Gems files may also be useful (if I remember right they also contain some examples of trackball input functions for doing 3d rotation with a mouse). Shawn Hargreaves.