Advertisement

problem with normals

Started by February 02, 2004 01:57 PM
29 comments, last by ioda100 21 years, 1 month ago
i tried to draw a 3D figure and to redraw it on the other face to have a 360° D object but the normals of the first face seem to be replace by these from the face behind. for 2nd face, i do only *(-1) to the z coordonate of each vertex and normal. here is an image of what happen : http://membres.lycos.fr/ioda100/3D/normals.jpg here is the code : http://membres.lycos.fr/ioda100/3D/normal%20code.txt thx in advance for your help
so is the pic of both faces? & the big gray area is where 1 face is supposed to be... & instead its just gray?
Advertisement
Is z depth or height? If it is depth, the 2nd face is probably drawn behind (instead of in front of) the camera.
there is the first face (the big picture) and behind it, the second face (we look at it normally with a 180 rotation) (the second face is 2 times smaller to see what the problem is)


normally we can''t see the second face when we see the first because it is supposed to be behind but i don''t know why it''s not the case
z is depth but i think the second face is behind

i will look a this later, i have to go now

thx for your response
i will repost when i will have verifid this
no i think all is drawn in front of the camera but one party of the 1st face has a problem (with normals???)

here are some more picture to illustrate the problem

http://membres.lycos.fr/ioda100/3D/2emeface.JPG
and
http://membres.lycos.fr/ioda100/3D/profil.JPG

in 2emeface.JPG (obtain by a 180° rotation of the initial scene) we see that the second face all is ok

in profil.JPG (obtain by a little rotation of the initial scene) we see in the upper left corner the connexion between the 2 figures and that all is drawn

What is the problem plz? the second face is the simetry of the first (i take -z coordonate of each vertex and -z coordonate of the normal)
Advertisement
why in the world would you want to take the negative Z of the vertices or the normals? what effect are you lookin for?
also, do you have ambient light enabled? Do you have front & back facing polygons enabled for the light or just front facing?
I think it''s this:

I think you have only one light that''s between the nearest face and the camera. If so, the problematic face is faced away from that light so it isn''t lighted at all, so only ambient lighting will occur. Try adding one light on the other side of the faces or just don''t invert the normal z. The second will be incorrect if you want to do everything realistic as that face will be shadowed normally by the other if that other face is between the light and the ''problem face''.

If you get what i mean.
First, thx for your responses.

I tried to add a lignt behind the second face but it doesn''t work. When i don''t do -z, the second face is drawn in the same direction then the first but still behind the first.

For Anonymous Poster : i''m not looking for a special effect, in the beginning i had only 1 face to draw, now i try 360° 3D so i try first to do a symetry object with something i had already.

you say : "Do you have front & back facing polygons enabled for the light or just front facing?" How to do this? Can it be my problem?

Here are all my settings used for opengl :

in the display function :
glClear(GL_COLOR_BUFFER_BIT);
glLightfv ( GL_LIGHT0,GL_POSITION,light_pos );

in the init function :
GLfloat ambient_light[] = {0.3, 0.3, 0.45, 1.0};
GLfloat source_light[] = {0.6, 0.5, 0.5, 1.0};
GLfloat light_pos[] = {7.0, 0.0, 0.0, 1.0};

glEnable ( GL_LIGHTING );
glLightModelfv ( GL_LIGHT_MODEL_AMBIENT,ambient_light );
glLightfv ( GL_LIGHT0,GL_DIFFUSE,source_light );
glLightfv ( GL_LIGHT0,GL_POSITION,light_pos );
glEnable ( GL_LIGHT0 );

// Enable material properties for lighting
glEnable ( GL_COLOR_MATERIAL );
glColorMaterial ( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );

glClearColor ( 1.0, 1.0, 1.0, 0.5 );

i don''t think i have something else to configure the ligths... in my prog.
I think I see what you are trying to do now... you have the front half of a face or statue & you want to take another half just like it... invert it & attach it to the original half so you''ll have a "thin" but 3D model. First of all, this is a rather expensive way to get a simple object, I hope there isn''t much going on your scene. As far as initializing... be sure you enable depth_testing as well. It appears that your 2nd half is always drawn on top of the 1st half, no matter what. in fact... the more I look at those pictures... the more I think you don''t have depth testing enabled. Do this:
glEnable(GL_DEPTH_TEST);   //NECESSARYglDepthFunc(GL_LEQUAL);    //good to specify 


The default for the type of polygons you draw is front & back, but to be sure:

glEnable( GL_CULL_FACE ); //enable front & back facing polysglFrontFace( GL_CCW ); 


that second line tells openGL that a polygon''s front side is towards you if you specify it''s vertices in a counter clock-wise order (in case you wanna use front facing only).
Whatsoever you do, do it heartily as to the Lord, and not unto men.

This topic is closed to new replies.

Advertisement