Light probs... again...

I don’t think I understand the opengl-light-model correctly.

[ul][li] How can I set the radius of the light[*] How can I set the stuph to light up[/ul][/li]I’ve got the basics working however, somehow I cant figure out the above. The normals get calculated like :

float Ax, Ay, Az;
float Bx, By, Bz;
float Cx, Cy, Cz;
float l;
for(long i=0;iLevelWidth;i++)
for(long j=0;jLevelHeight;j++)
{
Ax = x1;
Ay = y1;
Az = z1;
Bx = x2 - x1;
By = y2 - y1;
Bz = z2 - z1;
Cx=AyBz - ByAz;
Cy=AzBx - BzAx;
Cz=AxBy - BxAy;
l = (float)sqrt(CxCx + CyCy + Cz*Cz);
this->Normals[i+j*this->LevelWidth].x += Cx / l;
this->Normals[i+j*this->LevelWidth].y += Cy / l;
this->Normals[i+j*this->LevelWidth].z += Cy / l;
}

Help – Divide

[This message has been edited by Divide Overflow (edited 11-22-2000).]

[ul][li] How can I set the radius of the light[/ul][/li]

It works so …

Attenuation_factor=1/(kc+kld+kqd*d)
d = distance between the light’s position and the vertex
kc = GL_CONSTANT_ATTENUATION
kl = GL_LINEAR_ATTENUATION
kq = GL_QUADRATIC_ATTENUATION

Example:
pa=(x,y,z,1)
glLightf(GL_LIGHT0, GL_POSITION, pa):
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 2.0);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 1.0);
glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.5);

Let say we have a full intensity Blue (255) - result will be 255*AttenuationFactor.


For more info go from http://www.opengl.org
-> Coding
-> OpenGL Programming Guide Version 1.0
-> Chapter 5 Lighting

it’s a very good guide!

Thanx for your help.

Found the bug, turned out to be a bug in my normal-interpolation-routine (I really love that word )

Another question…

Say I got these 2 lights setup like this :

Light1->Position.x = 0;
Light1->Position.y = 0;
Light1->Position.z = 0;
Light1->Ambient.a = 1.0f;
Light1->Ambient.r = 0.3f;
Light1->Ambient.g = 0.3f;
Light1->Ambient.b = 0.3f;
Light1->Diffuse.a = 1.0f;
Light1->Diffuse.r = 0.0f;
Light1->Diffuse.g = 0.0f;
Light1->Diffuse.b = 0.0f;
Light1->Specular.a = 1.0f;
Light1->Specular.r = 0.3f;
Light1->Specular.g = 0.3f;
Light1->Specular.b = 0.3f;

Light2->Position.x = 0;
Light2->Position.y = 0;
Light2->Position.z = 0;
Light2->Ambient.a = 1.0f;
Light2->Ambient.r = 1.0f;
Light2->Ambient.g = 0.0f;
Light2->Ambient.b = 0.0f;
Light2->Diffuse.a = 1.0f;
Light2->Diffuse.r = 1.0f;
Light2->Diffuse.g = 0.0f;
Light2->Diffuse.b = 0.0f;
Light2->Specular.a = 1.0f;
Light2->Specular.r = 1.0f;
Light2->Specular.g = 0.0f;
Light2->Specular.b = 0.0f;

Shouldn’t they be both visible and not just light 1 ?

Are you sure it’s only the first light that is visible? They are both placed at the same position, so it might look like that it’s only one light.

And another thing, did you enable the second light at all?

Well, it might be that the ‘sun’ light “overwrites” the red light, but I’m sure its enabled. If I glDisable() the first light the 2nd light becomes visible.

[This message has been edited by Divide Overflow (edited 11-24-2000).]

Okay, forget the above posts.
I just want an example of a lightball that floats over a floor… (so basically a light which moves above a polygon )

Thanx !

[This message has been edited by Divide Overflow (edited 11-30-2000).]