Hi,
I'm using the FreePascal compiler (http://www.freepascal.org/). I have a tile based landscape with objects and now I want to know at wich tile/object the user clicks. First I use gluUnProject to get the 3D coordinates and then, I use a tree to know on wich tile/object the user clicks. But the gluUnProject function has strange output.
This is the code:
Code: //************************************************************************************************ //Get the tile wich is selected //************************************************************************************************ function GetOGLPos(X, Y: Integer): T3D_Point; var viewport: TViewPortArray; modelview: T16dArray; projection: T16dArray; winZ: Single; resPoint: T3D_Point; begin glGetDoublev(GL_MODELVIEW_MATRIX, @modelview ); glGetDoublev(GL_PROJECTION_MATRIX, @projection ); glGetIntegerv(GL_VIEWPORT, @viewport ); // In Delphi A Y Value Of 0 Returns An Unknown Value // I Discovered This While I Was Testing A Crosshair if(Y = 0) then Y := 1; glReadPixels(X,-Y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,@winZ); gluUnProject(X,viewport[4]-Y,winZ,modelview,projection,viewport,@resPoint[0],@resPoint[1],@resPoint[2]); writeLn(floatToStr(resPoint[0]) + ' , ' + floatToStr(resPoint[1]) + ' , ' + floatToStr(resPoint[2])); Result := resPoint; end;
I got results like 0.01268 for x, 1085,36 for y and -0,099 for z. All my tiles are 1x1 and the result doesn't change to much. The y-value (1085,36) is much too high.
Does somebody knows what the problem is?
|