Basically I am trying to create a radar which has a 2D shape showing where the object is in 3D coordinates. a bit like here http://www.4gamer.net/patch/demo/freelancer.jpg, with the red triangles.
Now it works fine until I turn my camera about 180 Degrees where I am not facing the object anymore where the 2D shape will appear even though the object is behind the camera, in the same position.
The video below will show what I mean (Quality is not good but its the green square shape , that will appear with the big space ship[supposed to happen] and when I turn it will appear again[not supposed to happen]) -
The code I am using is here below for gluProject:
glPushMatrix();
double modelview[16];
double proj[16];
int viewport[4];
double winx, winy, winz;
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
glGetDoublev(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, viewport);
if(gluProject(m_enemyPos.x, m_enemyPos.y, m_enemyPos.z, modelview, proj, viewport, &winx, &winy, &winz) == GL_TRUE)
{
if(winx > WINDOW_WIDTH)
winx = WINDOW_WIDTH - 10;
if(winx <0)
winx = 0;
if(winy > WINDOW_HEIGHT)
winy = WINDOW_HEIGHT;
if(winy < 0)
winy = 0;
screenTest.SetPosition(winx, winy);
screenTest.Render();
}
glPopMatrix();
"screenTest" is the little square that is being rendered to show where the object is.
In this specific project I am using my own camera functions - so manipulating my own matrices . I thought this would be a problem and tried the same thing in another project where I am using gluLookAt - and suprise surprise , it is the same problem.
So I am not really sure how to fix this or what I am doing wrong, so any help is appreciated.
Thanks
Romesh