I have been facing a problem regarding selecting the space in negative z direction with glulookat function. my code works fine for selecting a space providing two digonal points in the workspace if either one has positive z value but if both of the z value is negative the code fails.
void COpenGLBaseView::Select(float x1,float y1, float z1,float x2,float y2,float z2)
{
if(x1 > x2)
{
Swap(x1,x2);
}
if(y1 > y2)
{
Swap(y1,y2);
}
if(z1 > z2)
{
Swap(z1,z2);
}
GLint hits, view[4];
glSelectBuffer(m_BucketSize, m_aBucket);
glGetIntegerv(GL_VIEWPORT, view);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(m_cx * 0.5, m_cy * 0.5,m_cx, m_cy, view);
glOrtho(x1,x2,y1,y2,z1,z2);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(z1<0 && z2<0)
{
gluLookAt(0.0,0.0,-(z1+z2), 0.0 , 0.0 ,-(z1+z2),0.0,1.0,z1);
}
else
{
gluLookAt(0.0,0.0,z1+z2, 0.0 , 0.0 ,z1,0.0,1.0,0.0);
}
m_pContour->RenderSelection();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
hits = glRenderMode(GL_RENDER);
glMatrixMode(GL_MODELVIEW);
int SelectedNum = hits;
if(SelectedNum > 0)
{
for(int i = 0;i < SelectedNum; ++i)
{
m_SelectedParticles.push_back(m_aBucket[i * 4 + 3]);
if(TM_SELECT_REGION_DIRECT)
{
m_SelectedParticlesToSeeParticleFlow.insert(m_aBucket[i * 4 + 3]);
}
}
}
if(TM_SELECT_REGION_DIRECT)
{
m_SelectedParticles.clear();
set<int>::iterator it;
for(it= m_SelectedParticlesToSeeParticleFlow.begin(); it!= m_SelectedParticlesToSeeParticleFlow.end(); it++)
{
m_SelectedParticles.push_back(*it);
}
}
glLoadIdentity();
SetupViewingTransform();
Invalidate(false);
}
bool COpenGLBaseView::CompareFramewithTrackValue(int trackValue,bool checkStepForward)
{
if(checkStepForward)
{
if(trackValue<frameNumber)
{
return true;
}
}
else
{
if(trackValue>initialframeNumber)
{
return true;
}
}
return false;
}
could any one please help.