PDA

View Full Version : moving a light



gfp91
04-23-2012, 05: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);
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

BionicBytes
04-24-2012, 01: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:
light_Position.x=tVector3.x;
light_Position.y=tVector3.y;
light_Position.z=tVector3.z;

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.