View Full Version : problem with lighting

Hello guys,

I have a small tunnel(cylinder). The light has uniform effect(seems like 2D lighting). No shades nothing. I'm not sure whether i have to specify normals. If i have to, then how to specify a normal for a hollow cylinder.

Extra infos:

Cylinder parallel to z-axis. light positioned inside the cylinder,1/4th distance from one end of the tunnel..

lighting - code

GLfloat pos0[] = {0.0,0.0,0.5,1.0};

GLfloat dif0[] = {0.99,0.99,0.99,1.0};

GLfloat ambi0[]= {0.5,0.5,0.5,1.0};

glLightfv(GL_LIGHT0,GL_AMBIENT,ambi0);

glLightfv(GL_LIGHT0,GL_DIFFUSE,dif0);

glLightfv(GL_LIGHT0,GL_POSITION,pos0);

glEnable(GL_LIGHT0);

glEnable(GL_LIGHTING);

glEnable(GL_COLOR_MATERIAL);

could you guys tell me what's wrong?

Many thanks in advance

pl

Halcyon

12-09-2002, 09:01 PM

Hey there pl,

Yeah you're gonna need to apply normals to the surfaces so it OpenGL knows how to shade the surface. You also need to set up the material for the surface. That way it knows HOW the surface will react to a certain light hitting it. I'm not totally sure how to calculate the normals for the cylinder, but i can tell you that there will be more than one. Since the surface direction is always changing, there will be one for every polygon. Hope i was of some use! I'm sure someone way smarter than me will know what to do in terms of calculations. Good luck!

- Halcyon

satan

12-10-2002, 01:20 AM

I think you want smooth shading for your tunnel so you will need one surface normal for every vertex. But you only need to calculate the normals for a circle and distribute them along your cylinder. Imaginig you have the vertices for a circle (here named v[i]) on the xy plane with the origin as its center. As all v are vectors pointing in the same direction as the corresponding vertexnormal you just have to normalize them and have the normals for a cylinder (vn[i]=v[i]/length of v[i] - with vn the vertexnormals). Since you want them to point inside and not outside the normal for a given vertex v[i] is not vn[i] but -vn[i].

hih

satan,

the only known quantity is centre of the circle. can you tell me how to calculate the normal using that?

satan

12-11-2002, 02:18 AM

Originally posted by pl:

satan,

the only known quantity is centre of the circle. can you tell me how to calculate the normal using that?

No, there is no way to do this.

You can't even draw it when you only know the centre, you at least need the radius, too.

And in my last post I already told you what to do. Now let's try it with some code (in pascal) but I think you should be able to understand it:

// radius

r:=50;

// number of vertices

n:=16;

// alpha scaling factor

s:=2*pi/n;

// calculating circle on xy plane z=0

for i:=0 to n-1 do begin

alpha:=s*i;

CirclePoint[i].x:=r*sin(alpha);

CirclePoint[i].y:=r*cos(alpha);

CirclePoint[i].z:=0;

end;

CirclePoint[n]:=CirclePoint[0];

// calculating normals pointing inside

for i:=0 to n-1 do begin

CircleNormal[i].x:=-CirclePoint[i].x;

CircleNormal[i].y:=-CirclePoint[i].y;

CircleNormal[i].z:=0;

CircleNormal[i].Normalize;

end;

CircleNormal[n]:=CircleNormal[0];

Btw normals are vectors therefor it makes no difference to the normals where your centre of the circle is. And remember the centre of the circle is just an offset applied to all verticies calculated in the above code.

If this does not help you i think you should try to learn your vector math.

satan,

I'm really sorry. It took a while to understand your answer. Thanks

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.