PDA

View Full Version : Converting WindowCoordinates(x,y) to 3d Coordinates?



escozooz
03-09-2002, 06:38 AM
I was reading through the drag and drop tutorial posted earlier but I didn't understand the key concept of converting window x,y coordinates into world coordinate (x, y, z )

Is there some general algo that does this?

hatemagnet
03-09-2002, 06:03 PM
Hi esco.

I haven't read the tutorial you are refering to, but if I understand you right, basically you are refering to defining a mapping from space onto a plane. You can learn about this in an introductory linear algebra book. It will be in a section called something like 'Linear Transformations".

Going from space into the plane is similar. for example,

if you have the point (1,1,1) in space, it's just (1,1,0) in the xy-plane. It will be in the same chapter.

[This message has been edited by hatemagnet (edited 03-09-2002).]

Jambolo
03-10-2002, 10:03 AM
What specifically don't you understand?

General algo: Check out the function gluUnproject.

escozooz
03-10-2002, 10:03 AM
Specifically I want to click somewhere on the screen ( return x, y ) and have an object move there in 3d space. ( given only x, y from mouse)

Similar to when you move characters in warcraft/starcraft?

Is that still linear transformations?

escozooz
03-10-2002, 10:34 AM
gluUnProject is exactly it, thank you.

escozooz
03-10-2002, 11:01 AM
Whats wrong with these calls? I need these matricies for gluUnProject;

GLdouble model[32];
glGet(GL_MODELVIEW_MATRIX, model );

GLdouble proj[32];
glGet( GL_PROJECTION_MATRIX, proj );

GLint viewportCoords[4] = {0};
glGetIntegerv(GL_VIEWPORT, viewportCoords);

Errors:
------------------
Warning : implicit 'int' is no longer supported in C++
main.cpp line 46 glGet(GL_MODELVIEW_MATRIX, model );

Error : declaration syntax error
main.cpp line 46 0x0BA6

x3 for each call.

Furrage
03-11-2002, 05:55 AM
The model view and projection matrix are 16 units each. They are called with glGetDoublev. Your viewport should be initialised with 4 values, but in this case it is not necessary. Hence your code should look something like this...

GLdouble model[16];
glGetDoublev(GL_MODELVIEW_MATRIX, model );

GLdouble proj[16];
glGetDoublev(GL_PROJECTION_MATRIX, proj );

GLint viewportCoords[4];
glGetIntegerv(GL_VIEWPORT, viewportCoords);

zeckensack
03-11-2002, 06:29 AM
Originally posted by escozooz:
Whats wrong with these calls?
GLint viewportCoords[4] = {0};
glGetIntegerv(GL_VIEWPORT, viewportCoords);

Errors:
------------------
Warning : implicit 'int' is no longer supported in C++
main.cpp line 46 glGet(GL_MODELVIEW_MATRIX, model );
:eek:
That obviously means that you put the glGet() calls outside of your code. The compiler understands that as a declaration. Put them into your functions, man http://www.opengl.org/discussion_boards/ubb/biggrin.gif
[/shocked]

escozooz
03-11-2002, 03:22 PM
Yeah I am smart. Thanks I got it running fine now.