Sign in to follow this  

Spot light direction

This topic is 4355 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
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
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

This topic is 4355 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this