Help! I have possible precision errors in a simple OpenGL scene

  • Follow


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 );
}

//////////////////////////////////////////////////////////////
0
Reply mrmpb 7/10/2003 11:03:18 PM

fungus wrote:
 
> 
> 10000/0.001 is 10000000, a big number - much too
> big to expect a sphere of radius 1 to draw
> perfectly. Try adjusting these numbers, especially
> the 0.001.

Yep, tried .1 and it works fine now. Thank you!
0
Reply mrmpb 7/11/2003 6:09:27 AM


MPB wrote:

> fungus wrote:
>  
> 
>>10000/0.001 is 10000000, a big number - much too
>>big to expect a sphere of radius 1 to draw
>>perfectly. Try adjusting these numbers, especially
>>the 0.001.
> 
> 
> Yep, tried .1 and it works fine now. Thank you!

FYI, in a real application 'near' would be slightly smaller than the collision 
distance. For example, in a FPS where the collision distance is 5, you might use 
a near of 4.5.

-- 
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com

0
Reply Phil 7/11/2003 4:09:43 PM

2 Replies
288 Views

(page loaded in 0.047 seconds)

Similiar Articles:













7/22/2012 6:46:38 PM


Reply: