Archived

This topic is now archived and is closed to further replies.

Directional Light From Camera

This topic is 5010 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, Im having a little trouble with matrices. I have set up a view matrix that I am spinning around using the mouse. However, What I want to do is set up a directional light pointing towards where I am facing (the view). so I have a D3DXMATRIX member variable representing the current view matrix. I use this in the SetTransform(..) so I know the matrix is getting changed ok. Once I change the view, what I need to know is how to obtain the vector facing the direction of the view. Imagine you are a camera on the end of a torch, I need to find the direction vector required to set the directional light. i.e. 0.0f 1.0f 0.0f if my cam is pointing along the y axis. Is there an easy way to obtain this vector, I dont know too much about Dot Products, or cross products, are these the key to what I am looking for? Hope you can help [edited by - MatthewEva on March 30, 2004 8:19:29 AM]

Share this post


Link to post
Share on other sites
You can get the camera''s view vector directly from the view matrix:

direction.x = view._13;
direction.y = view._23;
direction.z = view._33;

In general, you can get a bunch of info from the view matrix:

right.x = view._11;
right.y = view._21;
right.z = view._31;
up.x = view._12;
up.y = view._22;
up.z = view._32;
direction.x = view._13;
direction.y = view._23;
direction.z = view._33;

Hope this helps,
neneboricua

Share this post


Link to post
Share on other sites