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);`    
`   glEnable(GL_LIGHT1);`    
 `  glEnable(GL_LIGHTING);`
    `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

Well, when you get some errors like this:

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 '}'

you have missplaced in your program one of the following requirements form the errors: "]" or the ";".

When you initially declare your array, this is ok:
GLfloat Light_Position[]= {0.0f, 1.0f, 3.5f, 1.0f};
That will create an array and initialise it with the specified values at declaration.

But later in your program where you do this:
light_Position[]={tVector3.x,tVector3.y,tVector3.z, 1.0f};
Depending on which version of the C++ standard you are using:
Because the array has already been declared/initialised and/or because you are using the square brackets, this line is erroneous.

To fix the problem:
If you're using the new C++0x standard, then simply removing the square brackets should work:
light_Position={tVector3.x,tVector3.y,tVector3.z, 1.0f};
The C++0x standard (or whatever it's called this week! Heh heh) allows you to use extended initialiser lists like this.

Otherwise, if you are using the old C++ standard, then you should assign new values to each item in the array separately. e.g.
light_Position[0]=tVector3.x;
light_Position[1]=tVector3.y;
And so on!

<nevermind>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.