Re: [Algorithms] Correct Way to transform direction vector
Brought to you by:
vexxed72
|
From: Jim O. <j.o...@in...> - 2000-10-31 23:49:53
|
Shouldn't this also work:
Vector3 dirWorld3 = /* three component direction vector of the ray in world
space */
Vector4 dirWorld4 = { dir3.x, dir3.y, dir3.z, 0 }
Vector4 dirLocal4 = dirWorld4 * worldToLocal;
(Where worldToLocal is the inverse of the localToWorld matrix, or of
localToWorld is orthogonal, the transpose of localToWorld, since it will be
equal to the inverse in that case).
The idea being that since you are transforming a direction vector and not a
point, it should not be affected by any translations that might be present
in the localToWorld matrix.
Performance wise, you are probably better of grabbing the 3x3 orientation
(and scale) submatrix and using that with the 3 component version of the
direction vector.
Jim Offerman
Innovade
The Atlantis Project
http://www.theatlantisproject.com
|