# Thread: My lighting is way off

1. LightRelPos = LightAbsolutePos - ObjectAbsolutePos
LightPosInObjectSpace = ObjectRotation * LightRelPos

dot(LightPosInObjectSpace, normal)

2. Originally Posted by hlewin
LightRelPos = LightAbsolutePos - ObjectAbsolutePos
LightPosInObjectSpace = ObjectRotation * LightRelPos

dot(LightPosInObjectSpace, normal)
They're spheres. Can they really be rotated?

3. 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:

4. 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.

5. Originally Posted by Nowhere-01
you clearly don't know what you're doing.
Well, duh. I did ask for tutorials in the first post, so I'll check that one out. Thanks.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•