Hi Tom,
On 18 April 2014 15:27, Jolley, Thomas P <[email protected]> wrote:
> Hi Robert,
>
> I think Tianlan may be correct about the getScale function. Here's why:
>
> The osg Matrix class was written as row major ordering (layout in memory is
> column major so it works with OpenGl).
OSG Matrix is row major and is stored in memory as row major, OpenGL
is by convention column major these days but it actually stored as row
major.
If you look at the matrix in row major order with the rotation matrix
separated from the scaling it will look something like this
>
> Sx { r00, r01, r02, 0 }
> Sy { r10, r11, r12, 0 }
> Sz { r20, r21, r22, 0 }
> 1 { x, y, z, 1 }
A scale matrix is:
{ Sx 0 0 0 }
{ 0 Sy 0 0 }
{ 0 0 Sz 0 }
{ 0 0 0 1 }
To scale a vertex you do:
v' = v * S;
The v'.x = v.x * S(0,0) + v.y*S(1,0) + v.z*S(2,0)+1*S(3,0);
v'.y = v.x * S(0,1) + v.y*S(1,1) + v.z*S(2,1)+1*S(3,1);
v'.z = v.x * S(0,2) + v.y*S(1,2) + v.z*S(2,2)+1*S(3,2);
With the assumption that v.w = 1.0;
The current implementation looks at the length of v'.x for scale.x etc.
>
> This assumes the 3x3 rotation matrix, r, is properly normalized and no skew.
>
> To get the X scale, Sx, value you need to get the length of the top row from
> the matrix. The current getScale function gets the length of the left column
> (of the rotation matrix only). The getScale function also swaps rows and
> columns when getting the Y and Z scale. To me, it looks like the getScale
> function improperly transposes the 3x3 rotation matrix.
It's not improperly transposed, it just works in the v' coordinate
frame rather than the original v coordinate frame.
There are two position interpretations which is the problem, both are valid.
Given there are two different ways one can interpret a scale, and what
you want will depend upon on the context it leaves us with a
condundrum. In the context of decompose it has an explicit matrix
decomposition order so is not open to mis-interpretation, however, as
it has a fixed decomposition order it might not be ideal for all types
of usage.
When there are two possible interpretation I'd be inclined on deprecating it.
Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org