View Full Version : Mouse click position?
03-10-2003, 10:52 AM
I've got a 3D scene with a heighmap.
The camera shows the heightmap from the top like a ISO-perspective. It's free turnable and you can zoom a little bit in.
If the user clicks on a position on the screen I like to calculate the X and Y position on the heightmap where the user clicked on - How is that possible?
03-10-2003, 11:35 PM
Read the Z-buffer value at (X, Y), then use gluUnproject() with (X, Y, Z).
03-11-2003, 05:02 AM
Well, here's my code:
glReadPixels(Cursor.X, Cursor.Y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winz);
GLdouble objx, objy, objz;
gluUnProject((GLdouble)Cursor.X, (GLdouble)Cursor.Y, winz, (GLdouble *)modelMatrix, (GLdouble *)projMatrix, viewport, &objx, &objy, &objz);
GLdouble tx = objx; //Just to test
float x = tx;
float y = objy / 10000.0;
float z = objz / 10000.0;
SetWindowText(g_window->hWnd, (FloatToStr(float(x)) + " - " + FloatToStr(float(y)) + " - " + FloatToStr(z)).c_str());
but if I run it and try it there comes an error in line "GLdouble tx = objx"
German error: "GleitkommaŁberlauf"
English should be something like "OVERFLOW"
03-11-2003, 05:34 AM
You can't typecast the matrices to GLdouble* like that. Instead, declare them as GLdouble, and use glGetDoublev() to retrieve them.
03-11-2003, 06:21 AM
Thx - It works =D
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.