# Base-transform-matrix using only one vector?

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

## 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 on other sites

...
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 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.

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 10
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013152
×