Jump to content
  • Advertisement
Sign in to follow this  
Ey-Lord

Mouse coordinate, gluUnproject() ect ..

This topic is 4737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys ! I've got a small pb : i'm building a tiny app . in wich there is only ONE quad z = 0 ; -3 < x < -4 ; -3.5 < y < 3.5 ; for his coordinates . my camera is set up as : gluLookAt(0,0,10,0,0,0,0,1,0); She is not moving at all . My goal is simply to detect where ( in x,y ) is my mouse ON the quad . I tried a couple of things with gluUnprject() and gluProject() ... i cant get the result i want :/ Some strange things : gluUnProject(xmouse, ymouse, 0,matrixview,proj,vp,&xWorldMouse, &yWorldMouse, &zWorldMouse); -> gives me value for (x,y) around ( -1 / 1 ) ; in my screen , valu should be ranged in (-5 / 5 ) gluProject(3,3,0,matrixview,proj,vp,&Mx, &My, &Mz); -> gives me a z of 0.99091 ... dunno where it comes from . i'm kinda lost here ...

Share this post


Link to post
Share on other sites
Advertisement
Hi,
try this way :
1)when the mouse over draw the whole scene with solid color like your quad make it red and make sure you disable lighting , texture .... etc.
2)use glReadPixel() and use the mouse coord to get the pixel that the mouse on it .
3)check the color if it's red this mean you are on the quad.
i hope you get the way "check the red book for more information"
bye,

Share this post


Link to post
Share on other sites
yeah i read about that method ; but that will only tell me tahti am over the qaud ; not the (x,y) pos ON the quad :)
thx anyway

Share this post


Link to post
Share on other sites
Z = 1 give wierd results too .
anyway pb solved, i found an ugly way to this but at least its works :





int xmouse = cInputManager::GetInstance().mouseX ;
int ymouse = cInputManager::GetInstance().mouseY ;

GLdouble matrixview[16] ;
GLdouble proj[16] ;

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

glGetDoublev ( GL_MODELVIEW_MATRIX, matrixview );
glGetDoublev ( GL_PROJECTION_MATRIX, proj );

GLdouble xWorldMouse ;
GLdouble yWorldMouse ;
GLdouble zWorldMouse ;

gluUnProject(xmouse,768 - ymouse, 0.990991,matrixview,proj,vp,&xWorldMouse, &yWorldMouse, &zWorldMouse);

if ( xWorldMouse >= -3 && xWorldMouse <= 4 && yWorldMouse >= -3.5 && yWorldMouse <= 3.5 )
{
int xquad = 0 ;
int yquad = 0 ;
if ( xWorldMouse > 0 )
{
xquad = 512 * ( xWorldMouse / 7 ) + ( 3 * 512 / 7 ) ;
}
else xquad = 512 * ( xWorldMouse/ 7 ) + ( 3 * 512 / 7 ) ;

if ( yWorldMouse > 0 )
{
yquad = 512 * ( yWorldMouse / 7 ) + ( 512 / 2 ) ;
}
else yquad = 512 * ( yWorldMouse/ 7 ) + ( 512 / 2 ) ;
}


I found the "0.990991" for z, while messing with gluproject() .
To found the coord in my quad i just do some easy math conversion ( 7 is the size in GL unit of my quad )

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!