Archived

This topic is now archived and is closed to further replies.

ProfEich

Lights ?

Recommended Posts

Hi! I made a heightmap and put a texture on it. Now I like to get a light like a "sun". My first step was to activate the light. Well done! But if I move my camera the light moves, too. Also if I set GL_POSITION for the light. And there isn''t really a shadow behind the mountains. Is there maybe a simple tutorial. The octree example on gametutorials has the problem with the camera moving.

Share this post


Link to post
Share on other sites
unfortunatly, the default ambient levels are not 0. so set the defautl ambient level for the light it'self, but also don't forget to set:

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ... );

the default for the above is 0.2, which is annoying.


for your lighting, when you set the lights poisiotn, it is multiplied through the modelview matrix (well, the inverse to be precise), so it is effectivly treated like a vertex... So if you were to set your light before you set your camera, it would be just like drawing a vertex before setting the camera, ie, it would always be the same.... so you should set the light after setting your camera. And since it's a 'sun', make sure you set the w component of it's position to 0, this indicates an infinite light, which is considerably faster (the position effectivly becomes the lights direction)...

ie:

float lightDir[]={0.2,0.3,0.4,0};

glLightfv(GL_LIGHT0,GL_POSITION,lightDir);
...

note that the last value is zero, thats the w component.

| - Project-X - my mega project.. close... - | - adDeath - | - email me - |

[edited by - RipTorn on May 5, 2003 1:22:19 AM]

Share this post


Link to post
Share on other sites
Hello,

I''ve made a collision function witch returns me the normal vector of the plane that "camera" just went into! (escuse my english) OK, now i want to make my camera slide along the wall. How can I do that? I know that I must get the camera velocity vector and compute new one based on wall normal vector or somesort.
And another (short) question: How can I generate lightmap texture coords. for a more complex geometry given the lights positions!
Thanks .


YO!

Share this post


Link to post
Share on other sites
here''s my extremely lazy answer.. use 3dmath.h (its found with a few of the tutorials on this site specifically the ones on plane-sphere collision and others around there). 3dmath.h is the best header I found that takes care of all the pesky math involved in detecting whether your camera hits a wall. Here is some code thats pseudocode-ish of how you would use 3dmath.h to detect whether your camera hits a wall (represented by a simple quad).

CVector3 CAMERA(0, 0, 0); //takes three values: x, y, z

void move()
{
if(canmove(1.0f, 0.0f, 0.0f))
CAMERA.x+=1.0f;
}

bool canmove(float xdir, float ydir, float zdir)
{
CVector3 poly[];
poly[0].x=0.0f;
poly[0].y=0.0f;
poly[0].z=0.0f;
poly[1].x=1.0f;
poly[1].y=0.0f;
poly[1].z=0.0f;
poly[2].x=1.0f;
poly[2].y=1.0f;
poly[2].z=0.0f;
poly[3].x=0.0f;
poly[3].y=1.0f;
poly[3].z=0.0f;

CVector3 camera; //replace camera.x, camera.y and camera.z with
//the location of the camera, you could pass the positions to
//the function or make the camera position global
camera.x=CAMERA.x+xdir;
camera.y=CAMERA.y+ydir;
camera.z=CAMERA.z+zdir;

//SpherePolygonCollision(polygons, line, numverticesOfWall,
//RadiusOfSphereAroundCamera) will be the function you use to
//detect whether the camera hits a wall.. false means it doesn''t
//hit true means it hits.

if(SpherePolygonCollision(poly, camera, 4, 1.0f))
return false;
else
return true;
}




My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.

Share this post


Link to post
Share on other sites