moving light source
i have just start my first OpenGl but have some problems on lightsource.
1) Can the lightsource moving around but not static? pls tell me the method.(of course best will sample code)
2) how to define a circular motion path? (the xyz coordinate is difficult to me)
pls me give some help ASAP, thx a lot!
To move the lightsource simply call:
glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
each frame, and update the LightPos variable (wich in this case would be a float[4] array x,y,z and something else
Here's a quick example to roate the light around orgin.
or something like that..
return 1;
Edited by - panic on May 2, 2001 7:14:25 PM
glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
each frame, and update the LightPos variable (wich in this case would be a float[4] array x,y,z and something else
Here's a quick example to roate the light around orgin.
#include <math.h> // for sinf and cosffloat rot;float raduis = 5.0f;void display(void) {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();// If your'e doing any global translations, do it hereGLfloat LightPos[] = { -cosf(rot) * radius, 0.0f, sinf(rot) * radius, 1.0f};glLightfv(GL_LIGHT0, GL_POSITION, LightPos);// Draw your stuffrot += 0.05f;glutSwapBuffers(); // or glSwapBuffers(hDC); if not using glut}
or something like that..
return 1;
Edited by - panic on May 2, 2001 7:14:25 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement