sos

I have some trouble in OpenGL these days .
I hope that you can help me ,thank you sincerely!
My question: Now I draw a object by the function -glBegin(GL_QUADS); And after some process by light , the object was appeared in the screen. But I want to select a polygon by the mouse in the screen , I don’t know how to get original coordinate of the whole polygon area ,is there any function in
OpengGL, if there isn’t ,and How to finish it?
thank you

Orient, you gotta do it the other way round. You’ve to calculate the direction vector into which your mouse points . When you have got this vector you can also do many prechecks then with DistanceLinePoint, if you give your models’ boundingboxes a center and radius value, so that you at the end only still have some less polygons remaining which you need to test with RayTriIntersect.

Unfortunately can’t paste any code here… although, wait… ok, here some old Delphi code, shouldn’t be a big deal for you to translate it to C++:

Procedure CalcMouseVec;
Var PX,PY,PZ,ZX,ZY,ZZ : Single;
CosG,CosN,SinG,
SinN : Single;
gangle,nangle : single;
VPMidX,VPMidY : Single;

 Begin
   gangle:=-OglW.DriverV.observerv.Gier/180*pi;
   nangle:=-OglW.DriverV.observerv.Nick/180*pi;

   CosG:=cos(gangle);SinG:=sin(gangle);
   CosN:=cos(nangle);SinN:=sin(nangle);

   VPMidX:=OglW.DriverV.display_rect.width/2;
   VPMidY:=OglW.DriverV.display_rect.Height/2;
   //Calculate unrotated mousevector
   PX:=OglW.DriverV.perspectivev.FrLeft/VPMidX*-(actmx-VPMidX);
   PY:=OglW.DriverV.perspectivev.FrTop/VPMidY*-(actmy-VPMidY);
   PZ:=-OglW.DriverV.perspectivev.Near_Clipping;
   //rotate by nick angle
   zx:=px;
   zz:=CosN*pz+SinN*py;
   zy:=-SinN*pz+CosN*py;
   //rotate by gier angle
   MouseVec.x:=CosG*zx+SinG*zz;
   MouseVec.y:=zy;
   MouseVec.z:=-SinG*zx+CosG*zz;
 End;

Ok, for this you need to have following values:
-your frustum edges
-your mouse x and mouse y
-your actual nick and gier
Result:
MouseVec (Vector pointing from your eye position to where your mouse points at)

If you don’t know how to calculate your frustum… so still use gluPerspective instead, please replace it through following as the frustum values will later be needed to calculate your mouse vector:

mfFrTop    = mfClipNear*(float)tan((mfAugYAngle/2.f)*(pi/180.f));
mfFrRight  = mfFrTop*(mfAugXAngle/mfAugYAngle);
mfFrBottom = -mfFrTop;
mfFrLeft   = -mfFrRight;
glFrustum(mfFrLeft,mfFrRight,mfFrBottom,mfFrTop,mfClipNear,mfClipFar);		

Hope this helps,

   BlackJack

[This message has been edited by BlackJack (edited 07-17-2002).]