Jump to content
  • Advertisement
Sign in to follow this  
painofangels

Base-transform-matrix using only one vector?

This topic is 2753 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 recently found a snippet of (GLSL) code in a CG-paper I was studying:


mat3 baseTransform( vec3 v3Normal )
{
vec3 up = vec3( 0.01, 0.99, 0.0 );
vec3 tangent = normalize( cross( up, v3Normal ) );
vec3 cotangent = normalize( cross( v3Normal, tangent ) );

return mat3( tangent, cotangent, v3Normal );
}



This function builds a rotation matrix to change coordinate-bases by taking one vector as the z-axis of the new coordinate basis.
What I wonder about is the "liberal" use of the up-vector. Normally, you'd have to rely on having two vectors of the desired coordinate base defined and these two can be used to construct the remaining one. Or you'd at least ensure that the "helper" vector you use to construct the first orthonormal vector lies on one of the planes of the coordinate base together with the first orthogonal vector (like its the case with the "user-up" vector used in View-matrix construction" ). but this above method seems pretty "optimistic" to me. And it also should fail whenever v3Normal = up...
Am I missing something? Is this a valid approach to change coordinate-bases?

Share this post


Link to post
Share on other sites
Advertisement

...
Am I missing something? Is this a valid approach to change coordinate-bases?

It may at least be valid in the domain it is written for. In the general case, however, I'd second you that it is risky to use.

Share this post


Link to post
Share on other sites
It's the classic "LookAt" routine for building a camera to world transform. It does become unstable when the view vector nearly coincides with the up vector, so it's usually protected by a pitch limit.

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.

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!