LightRelPos = LightAbsolutePos - ObjectAbsolutePos
LightPosInObjectSpace = ObjectRotation * LightRelPos
dot(LightPosInObjectSpace, normal)
Printable View
LightRelPos = LightAbsolutePos - ObjectAbsolutePos
LightPosInObjectSpace = ObjectRotation * LightRelPos
dot(LightPosInObjectSpace, normal)
there's GLM library for vector\matrix math, that has syntax based GLSL: http://glm.g-truc.net/
generating viewMatrix in GLM can be done with glm::LookAt function, or using a set of manual transformations:
Code :
glm::mat4 viewMatrix = glm::rotate(glm::mat4(1.0), -cameraRotation.x, glm::vec3(1, 0, 0)); viewMatrix = glm::rotate(viewMatrix, -cameraRotation.y, glm::vec3(0, 1, 0)); viewMatrix = glm::rotate(viewMatrix, -cameraRotation.z, glm::vec3(0, 0, 1)); viewMatrix = glm::translate(viewMatrix, -cameraPosition);
note, that rotation in this case goes before translation.
but you better off starting with http://www.opengl-tutorial.org/begin...al-3-matrices/
and reading some other literature on matrix transformations and spaces. because you clearly don't know what you're doing.
also, you can use this image as reference for transformation spaces:
http://www.paulsprojects.net/tutorials/smt/spaces.jpg
Rotation applies to more vertex-attributes(meaning normals for this). And in practice, when approximating a sphere with triangles, one may see quite a difference in the shape depending on the viewpoint.
But: believe it or not, what I write above is wrong: You just apply the Rotation to the object - not to the lights relative Position.
That is what you might be doing if multiplying the normal with gl_NormalMatrix - depending on how you use the ModelViewMatrix.