View Full Version : moving a light

04-23-2012, 06:55 PM
Hi i need help with moving a light.
at the start of the program i define the floats.

GLfloat Light_Ambient[] = {0.7f, 0.7f, 0.7f, 255.0f};
GLfloat Light_Diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat Light_Position[]= {0.0f, 1.0f, 3.5f, 1.0f};

but later on in the program while the scene is running i wanted to move the light to the players position

glLightfv(GL_LIGHT1, GL_AMBIENT, Light_Ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, Light_Diffuse);
glLightfv(GL_LIGHT1, GL_POSITION, Light_Position);
light_Position[]={tVector3.x,tVector3.y,tVector3.z, 1.0f};

but i get the following errors
1>i:\year 2\graphics programming\mloader\main.cpp(318) : error C2059: syntax error : ']'
1>i:\year 2\graphics programming\mloader\main.cpp(318) : error C2143: syntax error : missing ';' before '{'
1>i:\year 2\graphics programming\mloader\main.cpp(318) : error C2143: syntax error : missing ';' before '}'

Thanks GFP91

04-24-2012, 02:00 AM
This looks like a C++ type issue, where you don't quite understand what your doing. I don't program in C++ myself, but I can see what you have done, so forgive me if I don't use the correct terms here.
Initially, you used the following:

GLfloat Light_Position[]= {0.0f, 1.0f, 3.5f, 1.0f};
which is to declare a variable array of type GLFloat which has a fixed length of 4. At the same time, C++ allows you to assign some initial values, so internally it's using a constructor to assign those.
Now, later on

light_Position[]={tVector3.x,tVector3.y,tVector3.z, 1.0f};

you have attempted to do the exact same thing - which is not allowed. You can't call a constructor twice on the same variable. So instead of that you just need to call one of the operators which could be as simple as:

There is more than likely another wasy to do the above in a single line, but as I said I'll leave that to someone else.