
Please help me !!! Lighting problem...
Hi everyone !
I have a project to do in opengl and i encounter some very big problems with lighting.
We have to realize a representation of the solar system. I''ve almost done some things, such as planet creation and rotation, and i have also put some light. In fact the light comes from the sun, which is the center of my solar system (original, isn''t it ??? :D)
But, as planets are rotating around the sun, when they come in front of it, they should be really dark. And my problem is that they remain lightened. What should i do ? I have almost disabled general ambient light and ambient light which comes from my sun.
Please help me, and if you can, send me answers by mail
duran065@etudiant.univ-nancy2.fr
Thanks !
Adrien D.

I''m not sure what you mean by "come in front of it [the sun]". Do you mean that the side facing away from the sun is lit like the side facing towards the sun? The most likely cause of just about any lighting problem is the normals. Do you have normals defined for your models?
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
How to Ask Questions the Smart Way.
It''s exactly what you mean ! The two faces are lightened the same way. Can you explain me how to use those normals ?
If you want, you can leave me your mail, and i can send you my source code.
Thx a lot.
Adrien D.
If you want, you can leave me your mail, and i can send you my source code.
Thx a lot.
Adrien D.
The normals are part of each vertex of the model. Just like you have vertex position and texture information, you define a normal for each vertex which is how OpenGL computes lighting. What are you using to generate your models, a modeling tool such as 3D Studio Max, using already made models, procedurally creating the models in code? Most 3d modeling tools will give you the option to export vertex normals. It sounds like you are generating the models procedurally. In that case you can calculate the face normals by taking the cross product of two of the edges of each face. Then to find the vertex normals, you need to loop through each vertex and average all of the face normals that share this vertex. I hope that makes since.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
How to Ask Questions the Smart Way.
Holy cow, don't do that just to get the normals. If you are drawing your planets (spheres) manually (ie: computing each vertex & making quads/triangles) then do something like the code at the bottom of this reply.
If you are just making a GL quadric, then I think there is a command flag that generates smooth normals for that quadric. Try this...
//your quad pointer
GLUquadricObj *quadratic;
//this sets it up
quadratic=gluNewQuadric();
//this next line is for lighting & textures:
gluQuadricNormals(quadratic, GLU_SMOOTH);
//only for textures:
gluQuadricTexture(quadratic, GL_TRUE);
//creates your planet
gluSphere(quadratic,planet_radius,32,32);
This is an example of manually generating your sphere:
//X,Y,Z are vertice locations. Nx,Ny,Nz are normal vectors.
//you can also think of X,Y,Z as vectors
//(from the sphere's center to that vertex)
R = Sphere_Radius;
for( theta=0.0 ; theta<=360.0 ; theta+=increment )
{
Rtheta = PI*theta/180.0f;
glRotatef(0.99f*increment,0.0f,1.0f,0.0f);
glBegin(GL_QUADS);
for( phi=0.0f; phi<180.0f ; phi+=increment)
{
Rphi = PI*phi/180.0f;
//compute the normals
nX1 = GLfloat(sin(Rphi));
nY1 = GLfloat(cos(Rphi));
nX2 = GLfloat(sin(Rphi+Rten));
nY2 = GLfloat(cos(Rphi+Rten));
nZ3 = GLfloat(sin(Rfive*sin(Rphi)));
nX3 = nX1*GLfloat(cos(Rfive*sin(Rphi)));
nY3 = nY1*GLfloat(cos(Rfive*sin(Rphi)));
nZ4 = GLfloat(sin(Rfive*sin(Rphi+Rten)));
nX4 = nX2*GLfloat(cos(Rfive*sin(Rphi+Rten)));
nY4 = nY2*GLfloat(cos(Rfive*sin(Rphi+Rten)));
//the actual coordinates are just Radius * Normals
X1 = R*nX1;
Y1 = R*nY1;
X2 = R*nX2;
Y2 = R*nY2;
Z3 = R*nZ3;
X3 = R*nX3;
Y3 = R*nY3;
Z4 = R*nZ4;
X4 = R*nX4;
Y4 = R*nY4;
//plot vertexes with normals
glNormal3f( nX1, nY1, nZ1);
glVertex3f(X1,Y1,Z1);
glNormal3f( nX2, nY2, nZ2);
glVertex3f(X2,Y2,Z2);
glNormal3f( nX4, nY4, nZ4);
glVertex3f(X4,Y4,Z4);
glNormal3f( nX3, nY3, nZ3);
glVertex3f(X3,Y3,Z3);
}
glEnd();
}
[edited by - Luke Miklos on November 13, 2003 8:05:12 PM]
If you are just making a GL quadric, then I think there is a command flag that generates smooth normals for that quadric. Try this...
//your quad pointer
GLUquadricObj *quadratic;
//this sets it up
quadratic=gluNewQuadric();
//this next line is for lighting & textures:
gluQuadricNormals(quadratic, GLU_SMOOTH);
//only for textures:
gluQuadricTexture(quadratic, GL_TRUE);
//creates your planet
gluSphere(quadratic,planet_radius,32,32);
This is an example of manually generating your sphere:
//X,Y,Z are vertice locations. Nx,Ny,Nz are normal vectors.
//you can also think of X,Y,Z as vectors
//(from the sphere's center to that vertex)
R = Sphere_Radius;
for( theta=0.0 ; theta<=360.0 ; theta+=increment )
{
Rtheta = PI*theta/180.0f;
glRotatef(0.99f*increment,0.0f,1.0f,0.0f);
glBegin(GL_QUADS);
for( phi=0.0f; phi<180.0f ; phi+=increment)
{
Rphi = PI*phi/180.0f;
//compute the normals
nX1 = GLfloat(sin(Rphi));
nY1 = GLfloat(cos(Rphi));
nX2 = GLfloat(sin(Rphi+Rten));
nY2 = GLfloat(cos(Rphi+Rten));
nZ3 = GLfloat(sin(Rfive*sin(Rphi)));
nX3 = nX1*GLfloat(cos(Rfive*sin(Rphi)));
nY3 = nY1*GLfloat(cos(Rfive*sin(Rphi)));
nZ4 = GLfloat(sin(Rfive*sin(Rphi+Rten)));
nX4 = nX2*GLfloat(cos(Rfive*sin(Rphi+Rten)));
nY4 = nY2*GLfloat(cos(Rfive*sin(Rphi+Rten)));
//the actual coordinates are just Radius * Normals
X1 = R*nX1;
Y1 = R*nY1;
X2 = R*nX2;
Y2 = R*nY2;
Z3 = R*nZ3;
X3 = R*nX3;
Y3 = R*nY3;
Z4 = R*nZ4;
X4 = R*nX4;
Y4 = R*nY4;
//plot vertexes with normals
glNormal3f( nX1, nY1, nZ1);
glVertex3f(X1,Y1,Z1);
glNormal3f( nX2, nY2, nZ2);
glVertex3f(X2,Y2,Z2);
glNormal3f( nX4, nY4, nZ4);
glVertex3f(X4,Y4,Z4);
glNormal3f( nX3, nY3, nZ3);
glVertex3f(X3,Y3,Z3);
}
glEnd();
}
[edited by - Luke Miklos on November 13, 2003 8:05:12 PM]
Whatsoever you do, do it heartily as to the Lord, and not unto men.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement