Jump to content
  • Advertisement
Sign in to follow this  
Daver

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by jyk
Assuming 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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!