Finding a light's location relative to an object

Working on shadow rendering via shadow volumes. But part of the code needs to find the position of a light in object cordinents. Here is a list of the data I have.

The Transforation Matrix for the Object
The location of the light in World Cor.

I need the location of the light relative to the model. What I have been doing is extracting the 3, 7, and 11th elements from the matrix (which are the transformation section) and subtracting them from the light’s position. However, this method fails to take into account the scale, shear, rotation elemets.

Any Ideas?

Yeah, the light in object space Lo can be found by multiplying the light in world space Lw by the inverse of the model matrix

Lo = M^-1 * Lw

Right, I kindof knew that, but could someone supply an OpenGL example? How do I get the inverse of a matrix without knowing the starting values inverse when I build the matrix. Or will this work?

for (x = 0; x < 16; x++){
matrix[x] * -1;


An algorithm for a matrix inverse can be found here

Why do you need the light position in object space? Maybe there’s a way to accomplish what you’re attempting without such a matrix - just a thought.