Jump to content
  • Advertisement


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


Lights ?

This topic is 5699 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
You have to set the light position every frame...

And if you want it to be dark where there is no light, you have to set the ambient light to a lower value.

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)...


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


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

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 .


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))

bool canmove(float xdir, float ydir, float zdir)
CVector3 poly[];

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

//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;
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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!