Hello there
I have array of points that I draw in OpenGL (code below):
procedure Draw();
begin
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glClearColor(255,255,255,0);
glLoadIdentity; //biezaca macierz = I
gluLookAt(0,0,KameraZ, 0,0,0,0,1,0);
glRotatef(Theta, 1.0, 0.0, 0.0);
glRotatef(Phi, 0.0, 1.0, 0.0);
glTranslated(MoveX,MoveY,0);
glPointSize(2);
glBegin(GL_POINTS);
for I := 0 to High(Stars) - 1 do //stars is my array of array of points
for j := 0 to High(stars[i]) - 1 do
begin
glColor3ub(stars[i,j].R,stars[i,j].g, stars[i,j].b);
glVertex3i(stars[i,j].x,stars[i,j].y, stars[i,j].distance);
end;
glEnd;
SwapBuffers(wglGetCurrentDC);
end;
In my application onMouseMove event set KameraZ (zoom), Theta & Phi (rotate angle) and MoveX, MoveY (move left/right & up/down).
Now … when user hold shift and click on scene I like to find point under clicked coords (mouse coords converted to opengl coords). After find first one (in this coords can be lot of points but I need only one neares camera look) i like to compare and find this point in my array by X, Y and Distans. I have to do that because point in array (stars) has more informations (OpenGL only show location of this point). I try to do that with such code:
procedure MouseClick(const X, Y: Integer);
type
T3D_Point = array [1..3] of Double;
var
i, j: Integer;
pt: T3D_Point;
function GetOGLPos(X, Y: Integer): T3D_Point;
var
viewport: array [1..4] of Integer;
modelview: array [1..16] of Double;
projection: array [1..16] of Double;
winZ: Single;
begin
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );
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,
Result[1], Result[2], Result[3]);
end;
begin
pt := GetOGLPos(X,Y);
for I := 0 to High(stars) do
for j := 0 to High(stars[i]) do
if (CompareValue(stars[i,j].x, pt[1], 2) = EqualsValue) and
(CompareValue(stars[i,j].y, pt[2], 2) = EqualsValue) then
begin
sbar.Panels[0].Text := 'Line:'+IntToStr(i)+',Point:'+IntToStr(j)+
',R:'+FloatToStr(Round(stars[i,j].R))+
',G:'+FloatToStr(Round(stars[i,j].G))+
',B:'+FloatToStr(Round(stars[i,j].B));
Break;
end;
end;
procedure pPaintMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (ssShift in Shift) and (Button = mbLeft) then
MouseClick(x,y);
end;
but even if KameraZ = 100 and Theta, Phi, MoveX and MoveY is set to 0 sbar.Panels[0].Text is empty. Why?