PDA

View Full Version : Finding a light's location relative to an object



tbc++
05-28-2004, 08:44 AM
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?

plasmonster
05-28-2004, 09:22 AM
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

tbc++
05-28-2004, 12:22 PM
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;
}

tbc++

plasmonster
05-28-2004, 01:20 PM
An algorithm for a matrix inverse can be found here
http://skal.planet-d.net/demo/matrixfaq.htm#Q24

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.