First I have to thank tonyo_au for his help with implementing my shaders. My next goal is to add headlights to my little car, but it’s giving me some issues…
I’ve got sphere’s implemented on the front of the car and when I try to have them give off light they act really weird.
First off I have to set the vec4 to have a last entry of “1” or I get no light effect at all. According to Angel’s book I need to set the point source to zero to get a light, exact opposite of what I’m seeing…
Second, although it moves with the car, the light ALWAYS points towards the rear of the scene (see attached jpeg file)… I can drive around and turn, but it is always pointing “back” as opposed to the direction the car is facing… The entire code base is attached in a zip file, but here is what I’m trying to work on:
//Now the headlights (re-introduce material properties to modify them)
mvstack.push(mv);
//Left headlight
mv = mv*Translate(2.0, 2.1, 5.0)*Scale(0.5, 0.5, 0.1);
glUniformMatrix4fv(model_view, 1, GL_TRUE, mv);
glVertexAttrib4f(vAmbientDiffuseColor, 1.0, 1.0, 1.0, 0.0);
glVertexAttrib4fv(vSpecularColor, vec4(1.0f,1.0f,1.0f,1.0f));
glVertexAttrib1f(vSpecularExponent, 150.0);
glUniform4fv(light_position, 1, mv * vec4(0, -10, 90, 1));
glUniform4fv(light_color, 1, vec4(1,1,1,1));
glUniform4fv(ambient_light, 1, vec4(1, 1, 1, 2));
glDrawArrays(GL_TRIANGLES, 0, 1140);
mv = mvstack.pop(); //restore back to the car transform
mvstack.push(mv);
//Right headlight
mv = mv*Translate(-2.0, 2.1, 5.0)*Scale(0.5, 0.5, 0.1);
glUniformMatrix4fv(model_view, 1, GL_TRUE, mv);
glVertexAttrib4f(vAmbientDiffuseColor, 1.0, 1.0, 1.0, 0.0);
glDrawArrays(GL_TRIANGLES, 0, 1140);
mv = mvstack.pop(); //restore back to the car transform
Attached is a picture of running this code and the behavior of the headlights. FYI it’s the “light_position” vec4 uniform that I’m modifying…
Can anybody give me some help on these lights? Am I way off base here?
Thanks in advance,
–Pete