# calculating look direction from rotation

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

## Recommended Posts

Hey guys, i was wondering how to calculate the look direction vector from a rotation x, y, z vales i have. i have looked to this thread http://www.gamedev.net/community/forums/topic.asp?topic_id=352932 and i am having problems. I understand that i should be using Spherical-to-Cartesian conversion as the member stated, but its not working with me. NVector3 vDiff = NVector3(view.x, view.y, view.z); float XRot = atan2(-vDiff.y, sqrt(vDiff.x*vDiff.x + vDiff.z*vDiff.z)); float YRot = atan2(vDiff.x, vDiff.z); float sx = sinf(XRot); float cx = cosf(XRot); float sy = sinf(YRot); float cy = cosf(YRot); float x = sy*cx; float y = -sx; float z = cy*cx; view.x = x; view.y = y; view.z = z; is there anything im doing wrong? But im wondering where does the rotation x y z values come in here? btw im using Direct3D. thanks [Edited by - ramy on October 2, 2007 4:26:24 PM]

##### Share on other sites
If you are using left-handed coordinate system this works fine, otherwhise you probably have to multiply focusLength with -1.
                Vector3 lookAt = new Vector3(0, 0, this.focusLength);                                                lookAt.TransformCoordinate(Matrix.RotationYawPitchRoll(this.rotation.Y, this.rotation.X, 0));                lookAt += this.location;                return lookAt;

##### Share on other sites
what is the focus length?

actually im implementing as what i wrote in the post, and its not working, maybe its my custom rotation control i implemented :S not sure how to check

[Edited by - ramy on October 2, 2007 4:24:51 PM]

##### Share on other sites
Focuslength can be any positive number if your game doesn't have any depth of field-effect.

##### Share on other sites
yup, thanks a million. it worked out for me. plus my visuals were miss leading, so its all ok now =D

thanks Chimaira

[Edited by - ramy on October 2, 2007 4:18:31 PM]

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 10
• 12
• 17
• ### Forum Statistics

• Total Topics
632909
• Total Posts
3009171
• ### Who's Online (See full list)

There are no registered users currently online

×