delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/24/05:18:25

Message-ID: <D1FB30BBA491D1118E6D006097BCAE391AAA72@Probe-nt-2a.Probe.co.uk>
From: Shawn Hargreaves <ShawnH AT Probe DOT co DOT uk>
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

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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019