I am drawing a simple scene of a sphere of radius 1 and a plane
of 10000 x 10000.
The sphere at (9000, 1, -9000) looks embedded in the plane
although it shouldn't, and rotating the camera causes all kinds of
flickering.
However if the sphere is placed at (90, 1, -90) the scene looks fine.
Can anyone explain this? Thanks!
Here is the C++ code:
//////////////////////////////////////////////////////////////
HDC m_hdc;
GLUquadricObj* m_quadricObj = NULL;
int m_width = 800;
int m_height = 600;
....
void drawScene()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// set up the viewport and projection matrix
glViewport( 0, 0, m_width, m_height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective(
60, // FOV angle
(double)m_width / (double)m_height, // aspect ratio
.001, // near
10000 ); // far
const double ballX = 9000;
const double ballY = 1;
const double ballZ = -9000;
// rotate the camera
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
static double cameraAngle = 0;
cameraAngle += .001;
glRotated( cameraAngle, 0, 1, 0 );
glTranslated( -ballX, -(ballY + 1), -(ballZ + 10) );
// draw a red plane
glBegin( GL_QUADS );
glColor3ub( 200, 100, 100 );
glVertex3d( 0, 0, 0 );
glVertex3d( 10000, 0, 0 );
glVertex3d( 10000, 0, -10000 );
glVertex3d( 0, 0, -10000 );
glEnd();
// draw a green ball
glTranslated( ballX, ballY, ballZ );
glColor3ub( 100, 200, 100 );
gluSphere( m_quadricObj, 1, 10, 10 );
SwapBuffers( m_hdc );
}
//////////////////////////////////////////////////////////////
|