Jump to content
  • Advertisement
Sign in to follow this  
Ultraseamus

building matrices

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

In 3D space I am trying to build a right-handed viewing transformation given: eye --> The position in world space of the camera. at --> The position in world space of the target. up --> The camera's up direction. //all vectors. this is what i am trying right now: gfxVector3 v; v = (eye - at); v /= (v.Length()); gfxVector3 up; gfxMatrix4 temp; up.x = 0; up.y = 0; up.z = 1; gfxVector3 m; m = (up (dot) v) * v; gfxVector3 u; u = v(cross)m; gfxVector3 w; w = up - m; u.Normalize(); v.Normalize(); w.Normalize(); temp = gfxMatrix4(u.x,u.y,u.z,((-u) * eye), v.x,v.y,v.z,(-(v) * eye), w.x,w.y,w.z,(-(w) * eye), 0,0,0,1); , and a right-handed projection transformation given: VertFOV --> Camera's vertical FOV. Measured in angles. mAspect --> The ratio (width / height); determines horizontal FOV. mDistNear --> Distance from the eye to the near clip plane. mDistFar --> Distance from the eye to the far clip plane. and for this i am trying: gfxMatrix4 temp; mVertFOV *= (PI / 180.0f); temp = gfxMatrix4((tan(2/VertFOV))/mAspect,0,0,0, 0,(mDistFar+mDistNear)/(mDistFar-mDistNear),0,(-2*(mDistFar*mDistNear))/(mDistFar-mDistNear), 0,0,tan(2/VertFOV),0, 0,1,0,0); I am not sure if either of these attempts are right or wrong if someone could check my process and confirm, or tell me where i am going wrong. Sorry if this is hard to read, i can clean it up a bit, or answer any questions.

Share this post


Link to post
Share on other sites
Advertisement
Just looking at the 'look at' code, I noticed this:
m = (up (dot) v) * v;

gfxVector3 u;
u = v(cross)m;
'm' and 'v' are parallel, which means that u will always be zero-length; I'm guessing this is not what you want.

A 'look at' matrix is usually calculated very straightforwardly with a few cross products, whereas you seem to be making it a bit more complicated. You might check the DX online documentation, as they give the formulation for both RH and LH lookat matrices (using row vectors though; you'll have to transpose).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!