[gameprogrammer] Re: OpenGL and mouse click location

On Wed, 2005-04-06 at 18:20 +0200, iso8859-1 wrote:
> Hi everybody,
> 
> I'm trying to write a tile-based game in OpenGL/SDL. The camera looks
> directly down on the map (no isometric view, just top-down). The
> scrolling is realised via translating the map and zooming is realised by
> changing the angle in gluPerspective. So the map remains at a fixed
> z-coordinate (10 in my case).
> The tiles are textured quads using pngs as textures.
> 
> My question is: How do I determine which tile the user clicked on? Even
> an algorithm without the zoom and scrolling would be perfect since the
> rest is easy.

To draw on the screen you had to construct a matrix that transforms
object space to screen space. IIRC, the inverse of that matrix should
transform screen space into object space. So, transform the point you
get from the mouse into object space and then look up which tile covers
that point. Or, since getting the inverse can be a PITA and you need
just one matrix multiply for each point, you can transform your object
coordinates into screen space and do the comparison there.

You could also read up on OpenGL "picking" and use that mechanism to do
the job. Picking provides a way to associate a tag with a primitive and
to test to see if the primitive passes through a small rectangle on the
screen. OpenGL will give you back the tag of every primitive that passes
through the picking rectangle.

                Bob Pendleton

> 
> Best regards, Tobias
> 
> P.S.: I'm sorry if it's a double post, but I had some problems with my mail 
> program.

That's ok, it wouldn't have been a double post if I read the list before
I checked for errors on the list. :-)

                Bob Pendleton


> 
> 
> 
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> 
> 
> 
-- 
+--------------------------------------+
+ Bob Pendleton: writer and programmer +
+ email: Bob@xxxxxxxxxxxxx             +
+ web: www.GameProgrammer.com          +
+ www.Wise2Food.com                    +
+ nutrient info on 6,000+ common foods +
+--------------------------------------+



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: