# Converting WindowCoordinates(x,y) to 3d Coordinates?

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?

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).]

What specifically don’t you understand?

General algo: Check out the function gluUnproject.

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?

gluUnProject is exactly it, thank you.

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.

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);

Originally posted by escozooz:
[b]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 );[/b]

: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
[/shocked]

Yeah I am smart. Thanks I got it running fine now.