Grrr, I am trying to do ‘proper’ seection as opposed to the OpenGL selection i have been using. I am using the following code to select a vertex in the scene. the problem is that i have 4 views all snaped to different positions (front,left,side etc) and i get odd lengths back when i am selecting from a view that is snaped to a camera angle other than z is into the screen and y is up.
can anyone suggest what is happening?
code:
int iViewport[4];
double dModelViewMatrix[16];
double dProjectionMatrix[16];
double d1x,d1y,d1z,d2x,d2y,d2z;
m_cGLRC.Begin();
glGetDoublev(GL_MODELVIEW_MATRIX,dModelViewMatrix);
glGetDoublev(GL_PROJECTION_MATRIX,dProjectionMatrix);
glGetIntegerv(GL_VIEWPORT,iViewport);
int iY = iViewport[3] - point.y;
gluUnProject(point.x,iY,0.0,dModelViewMatrix,dProjectionMatrix,iViewport,&d1x,&d1y,&d1z);
gluUnProject(point.x,iY,1.0,dModelViewMatrix,dProjectionMatrix,iViewport,&d2x,&d2y,&d2z);
m_cGLRC.End();
C3DPoint cScale;
pDoc->m_cModel.GetScale(cScale);
for(int i=0; i<pDoc->m_cModel.m_cPoints.GetSize(); i++)
{
CSTAPoint *pPoint = pDoc->m_cModel.m_cPoints.GetAt(i);
float ox = pPoint->pt[0] * cScale.pt[0];
float oy = pPoint->pt[1] * cScale.pt[1];
float oz = pPoint->pt[2] * cScale.pt[2];
float r = (oz - d1z) / (d2z - d1z);
float px = d1x + r * (d2x - d1x);
float py = d1y + r * (d2y - d1y);
float pz = oz;
TRACE("POINT %f,%f,%f
MOUSE %f,%f,%f
",ox,oy,oz,px,py,pz);
C3DVector v1(ox,oy,oz);
C3DVector v2(px,py,pz);
C3DVector vDist = C3DTools::Vector(v1,v2);
float fLen = C3DTools::Magnitude(vDist);
TRACE("LEN: %f
", fLen);
if(fLen < 0.01)
{
pDoc->SelectGeometry(pPoint,false);
}
}