c++ - openGL lighting rotates with camera -


i'm trying build simple uni coursework , i've tried light it, lights seem rotate camera, totally annoying...

i've pasted code below using pastebin (so doesn't stretch page), here's little explanation too:

i added lights in display::init (using poollight class). camera set in display::resize. it's placed above 'pool table' @ (0, 0, 80), looking down (0, 0, -1), x axis being forward/up (1, 0, 0).

this simple movement , rotation of camera adjusts lights too, not geometry (or perhaps adjusts geometry, , not lights, i'm not sure).

i have read of other answers here concerning same issue, don't understand well. i'm hoping can explain me in simpler terms, or maybe spot obvious i've accidentally excluded.

anyway, here code:

main display class

poollight class:

#include "poollight.h" #include "glut/glut.h" #include "gl/gl.h" #include "gl/glu.h"  poollight::poollight(glenum lightnumber, glenum lighttype, float red, float green, float blue, bool distant, float posx, float posy, float posz) {     this->lightnumber = lightnumber;     this->lighttype = lighttype;      color[0] = red; color[1] = green; color[2] = blue; color[3] = 1;     position[0] = posx; position[1] = posy; position[2] = posz; position[3] = (int) (!distant);     gllightfv(lightnumber, lighttype, color);     gllightfv(lightnumber, gl_position, position);      enabled(true); }   poollight::~poollight(void) { }  void poollight::setspotlight(float angle, float attenuation, float dirx, float diry, float dirz) {     gllightf(lightnumber, gl_spot_exponent, angle);     gllightf(lightnumber, gl_constant_attenuation, attenuation);     gllightf(lightnumber, gl_linear_attenuation, 0.0f);     gllightf(lightnumber, gl_quadratic_attenuation, 0.0f);     spotdirection[0] = dirx; spotdirection[1] = diry; spotdirection[2] = dirz;     gllightfv(lightnumber, gl_spot_direction, spotdirection);     gllightf(lightnumber, gl_spot_cutoff, 60); }  void poollight::enabled(bool enabled) {     if (enabled) glenable(lightnumber);     else gldisable(lightnumber); } 

after changing camera position, call gllightfv(lightnumber, gl_position, position) again world-coordinates of light. draw scene.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -