Jump to content
  • Advertisement


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


Nedd help with Seting View Matrix

This topic is 6787 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, i looked in the directx SDK D3Dim Doc''s (page 123) and i found that function witch setting view matrix: HRESULT D3DUtil_SetViewMatrix( D3DMATRIX& mat, D3DVECTOR& vFrom, D3DVECTOR& vAt, D3DVECTOR& vWorldUp ) { // Get the z basis vector, which points straight ahead. This is the // difference from the eyepoint to the lookat point. D3DVECTOR vView = vAt - vFrom; FLOAT fLength = Magnitude( vView ); if( fLength < 1e-6f ) return E_INVALIDARG; // Normalize the z basis vector vView /= fLength; // Get the dot product, and calculate the projection of the z basis // vector onto the up vector. The projection is the y basis vector. FLOAT fDotProduct = DotProduct( vWorldUp, vView ); D3DVECTOR vUp = vWorldUp - fDotProduct * vView; // If this vector has near-zero length because the input specified a // bogus up vector, let''s try a default up vector if( 1e-6f > ( fLength = Magnitude( vUp ) ) ) { vUp = D3DVECTOR( 0.0f, 1.0f, 0.0f ) - vView.y * vView; // If we still have near-zero length, resort to a different axis. if( 1e-6f > ( fLength = Magnitude( vUp ) ) ) { vUp = D3DVECTOR( 0.0f, 0.0f, 1.0f ) - vView.z * vView; if( 1e-6f > ( fLength = Magnitude( vUp ) ) ) return E_INVALIDARG; } } // Normalize the y basis vector vUp /= fLength; // The x basis vector is found simply with the cross product of the y // and z basis vectors D3DVECTOR vRight = CrossProduct( vUp, vView ); // Start building the matrix. The first three rows contains the basis // vectors used to rotate the view to point at the lookat point D3DUtil_SetIdentityMatrix( mat ); mat._11 = vRight.x; mat._12 = vUp.x; mat._13 = vView.x; mat._21 = vRight.y; mat._22 = vUp.y; mat._23 = vView.y; mat._31 = vRight.z; mat._32 = vUp.z; mat._33 = vView.z; // Do the translation values (rotations are still about the eyepoint) mat._41 = - DotProduct( vFrom, vRight ); mat._42 = - DotProduct( vFrom, vUp ); mat._43 = - DotProduct( vFrom, vView ); return S_OK; } there is something i dont understand , what the "1e-6f" means? and what the Magnitude, CrossProduct, and DotProduct functions doing?

Share this post

Link to post
Share on other sites
Magnitude computes the length of the vector

Length = sqrt(x*x + y*y + z*z)

CrossProduct computes a vector that is orthogonal to both input vector. The length of the new vector is the area of the parallellogram that the two vector comprise.

CrossProduct.x = A.y*B.z - A.z*B.y
CrossProduct.y = A.z*B.x - A.x*B.z
CrossProduct.z = A.x*B.y - A.y*B.z

DotProduct multiplies the elements of the vectors pairwise and sums the product

DotProduct = A.x*B.x + A.y*B.y + A.z*B.z

1e-6f means 10-6 and it is used to make sure that the length isn't too small. If the length is too small then the floating point operations will give you unexpected results because of the low accuracy of floating point values.


Edited by - WitchLord on 4/15/00 10:52:00 AM

Share this post

Link to post
Share on other sites

  • 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!