View Full Version : gluProject and y coords...

Lamer

02-12-2005, 01:07 AM

Hi.

Plzm explain me one thing. So

I have world coord (0,0). And this code give me result (320,63)

double modelMatrix[16]; double projMatrix[16]; int viewport[4];

double objx; double objy; double objz;

float x_; float y_; float z_;

glGetIntegerv(GL_VIEWPORT, viewport);

glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);

glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);

gluProject(vx, vy, 0, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

x_ = float(objx);

y_ = float(objy);

z_ = float(objz);

How to make so, that I got (320,240), e.g. the centre?

mikael_aronsson

02-13-2005, 01:23 AM

It all depends on how you setup your projection/modelview matrix, if you use orthographic projection you can map the world coordinates (almost) anyway you want, have a look at the FAQ on this website it explains most of the details of how to do it.

Your example does not include how you setup the projection/modelview matrix so it is impossible to answer why you get the coordinates you say.

Mikael

Lamer

02-13-2005, 01:41 PM

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);

mikael_aronsson

02-13-2005, 10:59 PM

Hi !

So wx and wy is 0 ?, if you have not modified the modelview matrix, that might be the problem, the "camera" is at 0,0,0 and you try to project the point at 0,0,0, this is also outside the near clipping plane, so if you try to move the "camera" away from the origin a little it might work better, use glTranslate(0,0,z)

As you are using perspective mode you always have to be careful with the Z value, you do get a perfect 320,240 match at the origin until you move the "camera", then it will no longer work.

Mikael

Mikael

Lamer

02-14-2005, 04:36 AM

ok, i have add a LoadIdentity before and in 0,0 I got 320,240. I use Z=0 in gluProject.

But than I have very big numbers.

For example:

vx= 0 x_=320

vy= -15 y_=9047

and

vx= 7,6 x_=-4086 (why minus?)

vy= 0,1001 y_=234.2

I tried to change z to 1,0,-1,0.1, but nothing good.

Lamer

02-17-2005, 10:42 AM

plz, help anybody...

I semd to you small CPP project with problem...

My ICQ: 149448686

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.