Original Post
I have been able to use selection while drawing basic primitives
but when I try it with my class that loads an MD2 file no matter
how big or where on the screen the model is drawn it always says the mouse cursor is on top. I project the 3D Model so it can be drawn inside a 2D box and whenever I use this method is when stuff doesn''t work. Here''s the code that calculates the projection.
void LoadMD2::Draw2D(int X,int Y,int Width,int Height,float D)
{
float XDist,YDist,XRatio,YRatio;
Vectors3f Top,Bottom,Left,Right,Pos;
glPushMatrix();
glLoadIdentity();
//=================
// D is Depth
// MouseToOpenGL converts 2D coords to 3D
Top=MS.MouseToOpenGL(X+(Width/2),Y+Height,D);
Bottom=MS.MouseToOpenGL(X+(Width/2),Y,D);
Left=MS.MouseToOpenGL(X,Y+(Height/2),D);
Right=MS.MouseToOpenGL(X+Width,Y+(Height/2),D);
Pos=MS.MouseToOpenGL(X+(Width/2),Y+(Height/2),D);
XDist=Left.Distance(Right); // Width of bounding area in 3D space
YDist=Top.Distance(Bottom); // Height of bounding area
XRatio=XDist/Model.ModelDimensions.X; // calculate how much
YRatio=YDist/Model.ModelDimensions.Y; // to scale model to fit
// choose lowest scale val so we keep scale proportional
if(YRatio < XRatio)
XRatio=YRatio;
//=====================
glTranslatef(Pos.X,Pos.Y,Pos.Z);
glScalef(XRatio,XRatio,XRatio);
Draw(); // draw Model
glPopMatrix();
}