Advertisement

gluSphere() REALLY strange effect!?!

Started by August 30, 2001 09:12 PM
3 comments, last by Viscous-Flow 23 years, 5 months ago
Ok... I am drawing a few spheres USING THE gluSphere() that rotate around a central yellow sphere (much like the sun; the "sun" is a positional light as well in the middle of the scene). I am simulatiung a solar system much like ours except that all the planets aren''t in the same plane like ours (with the exception of Pluto). Basically, all the planets fly around the "sun" in all sorts of directions. Where the strange thing occurs is when two or more planets "collide" with each other. I don''t want to create an explosion effect or have them bounce back etc. I just want the planets to "fly" through each other. Anyways, what happens is that the colliding planets all "converge" and they look like a cell going backwards through the stages of mitosis (I think that gives a good description if you remember a basic biology class) The balls continue to rotate until they all make one sphere of multiple colors then they all "pop" out on the other side of the ball it "collided" with. What I "think" should happen is that the sphere that was drawn the last would cover the other spheres. Is that a correct assumption? What do you think the problem is... Any help would be GrEaTlY appreciated. THANK YOU!
I think I may have found the problem...The spheres are all on the SAME z-axis. It does work properly if the z-axis is changed, but I don''t really want them all to have different z-axis depths. Any ideas?

THANKS!
Advertisement
Here is the relevant source code:

The render function:
//  Render the scenevoid GLMain::Render(){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	//  Clear the screen	glLoadIdentity();									//  Reset the origin back to the center	//  Move back 15 units into the screen	glTranslatef(0.0f, 0.0f, -15.0f);	//  Set the position of the sun ball light 15 units into the screen	glLightfv(GL_LIGHT1, GL_POSITION, sunBallPosition);	glPushMatrix();		//  Move to where the sun ball would be		glTranslatef(sunBallPosition[0], 					 sunBallPosition[1], 					 sunBallPosition[2]);		glColor3f(1.0f, 1.0f, 0.0f);	//  Yellow		//  Draw the sphere		gluSphere(sphereQuadric, 0.5f, 30, 30);	glPopMatrix();	//  Draw the opaque planet	glPushMatrix();		//  Rotate the sphere on the y-axis		glRotatef(-angle, 1.0f, 0.0f, 0.0f);		//  Move 6 units on the positive z-axis from the origin		glTranslatef(0.0f, 0.0f, -6.0f);		glColor4f(0.2f, 1.0f, 0.2f, 1.0f);	//  Semi-green		//  Draw the sphere		gluSphere(sphereQuadric, 1.0f, 30, 30);	glPopMatrix();	//  Draw the opaque planet	glPushMatrix();		//  Rotate the sphere on the x-axis and z-axis		glRotatef(angle, 1.0f, 1.0f, 0.0f);		//  Move 6 units on the negative z-axis from the origin and 3 units on the positive x-axis		glTranslatef(0.0f, 0.0f, -6.0f);		glColor4f(0.2f, 0.2f, 1.0f, 1.0f);	//  Semi-blue		//  Draw the sphere		gluSphere(sphereQuadric, 1.0f, 30, 30);	glPopMatrix();	//  Draw the opaque planet	glPushMatrix();		//  Rotate the sphere on the x-axis and z-axis		glRotatef(-angle, 1.0f, 1.0f, 0.0f);		//  Move 6 units on the negative z-axis from the origin and 3 units on the negative x-axis		glTranslatef(0.0f, 0.0f, -6.0f);		glColor4f(1.0f, 0.2f, 1.0f, 1.0f);	//  Semi-purple		//  Draw the sphere		gluSphere(sphereQuadric, 1.0f, 30, 30);	glPopMatrix();	//  Enable blending	glEnable(GL_BLEND);	//  Enable read-only depth buffer	glDepthMask(GL_FALSE);	//  Set the blend function to what we use for transparency	glBlendFunc(GL_SRC_ALPHA, GL_ONE);	//  Draw the partially transparent planet	glPushMatrix();		//  Rotate the sphere on the y-axis		glRotatef(angle, 0.0f, 1.0f, 0.0f);		//  Move 6 units on the positive z-axis from the origin		glTranslatef(0.0f, 0.0f, 6.0f);		glColor4f(1.0f, 0.2f, 0.2f, 0.95f);	//  Semi-red		//  Draw the sphere		gluSphere(sphereQuadric, 1.0f, 30, 30);	glPopMatrix();	//  Enable read-only depth buffer	glDepthMask(GL_TRUE);	//  Disable blending	glDisable(GL_BLEND);}


The Init function that sets the states for OGL machine The lighting variables are defined in another function but you get the idea:

//  Reset the matrix mode	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	//  Set what states that are needed to be enabled here	glEnable(GL_CULL_FACE);			//  Enable face culling that tells OpenGL not to calculate the inside of polygons	glEnable(GL_DEPTH_TEST);		//  Enable hidden surface removal	glCullFace(GL_BACK);			//  Only draw the front side of the polygon	glFrontFace(GL_CCW);			//	Polygons that are draw counter-clockwise are on the outside	glEnable(GL_POLYGON_SMOOTH);	//  Enable antialiasing	glShadeModel(GL_SMOOTH);		//  Enable smooth shading	//  Lighting	//  Enable lighting	glEnable(GL_LIGHTING);	//  Set properties for global light (GL_LIGHT0)	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);	//  Set properties for sun ball light (GL_LIGHT1)	glLightfv(GL_LIGHT1, GL_DIFFUSE, sunBallDiffuse);	glLightfv(GL_LIGHT1, GL_SPECULAR, sunBallSpecular);	glLightfv(GL_LIGHT1, GL_POSITION, sunBallPosition);		//  Set diffuse material light intensities for objects - only for front polygons	glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiffuse);	//  Enable the lights	glEnable(GL_LIGHT0);	//  Global light	glEnable(GL_LIGHT1);	//  Sun ball light	//  Enable color tracking	glEnable(GL_COLOR_MATERIAL);	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);	//  Do it only for the front of the polygons and for ambient and diffuse light	//  Clear background to black	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);


Maybe it is the blending function or the z-depths for the opaque "planets". THANKS!
Sorry, but I noticed the spacing between lines was missing making it somewhat hard to read. Anyway, I would appreciate the help.

Edited by - Viscous-Flow on August 30, 2001 11:14:42 PM
If I''m understanding your problem right, simply turn of the depth test glDisable(GL_DEPTH_TEST) int the init function. Your problem is that all planets are on the same place, and because they all have the same radius, would be exactly on the same position. If you would have a perfect sphere, that wouldn''t be a problem, but because your spheres are built from trinangles you get these funny effects.

Hope it helps
Ben

This topic is closed to new replies.

Advertisement