# Spot light direction

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone, I am making a spot light using cube map. And it works perfectly for map. This spot light I control by position and light direction. But for physic objects (objects that can rotate, and move) spot light direction isn't correct. This is how I calculate light position for models: // I get invert model matrix (by model transformation matrix) invMat = invertMatrix(model->transformation); // then I transform light position by that inverted matrix transformPosition(model_light->pos, light->pos, invMat); and now I have light position that is correct for model. And ir works fine with omni light... But how to tranform light direction? (It is not correct if I tranform it by inverted matrix). Thank you for your help.

##### Share on other sites
Probably I should transfor light direction vector by model matrix like this:

void transformDir(GLfloat *out, GLfloat *in, float m[4][4])
{
out[0] = in[0] * m[0][0] + in[1] * m[1][0] + in[2] * m[2][0];
out[1] = in[0] * m[0][1] + in[1] * m[1][1] + in[2] * m[2][1];
out[2] = in[0] * m[0][2] + in[1] * m[1][2] + in[2] * m[2][2];
}
// where in - light vector, m - model matrix, out - transformated light vector

Is this correct? :)

##### Share on other sites
Assuming that the linear transform portion of 'm' is a rotation only, that (or its transpose, depending on your convention) looks correct.

##### Share on other sites
Quote:
 Original post by jykAssuming that the linear transform portion of 'm' is a rotation only, that (or its transpose, depending on your convention) looks correct.

But if this m matrix is transformation, which is made like this:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(translation[0], translation[1], translation[2]);
glRotatef(RigidBodyAngle, RigidRotAxis[0], RigidRotAxis[1], RigidRotAxis[2]);
glScalef(scaling[0], scaling[1], scaling[2]);
glGetFloatv(GL_MODELVIEW_MATRIX, transformation); // model tranformation mat
glPopMatrix();

can I then transform light direction?

I am still stuck with this, the cube map still rotates incomprehensible on physics models... I'am only need to get correct light direction :|

[Edited by - Daver on January 13, 2006 2:07:05 PM]

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 104
• 11
• ### Forum Statistics

• Total Topics
632977
• Total Posts
3009679
• ### Who's Online (See full list)

There are no registered users currently online

×