By: Gene Gorokhovsky (geneg102)
- 2008-10-30 15:48 |
||
In case of Math.PI turn, if we find the largest diagonal element, only corresponding axis dimension needs to be calculated using square root, the rest can be done from the off-center elements. If, by convention, we pick the the sign of the the elements calculated from square root as positive, rest come out automatically, simplifying logic and speeding up code. This also eliminates need for checks for negative square root checks (since any normalization jitter affects only diagonal elements close to -1, and such element cannot possibly be the largest.) The whole PI branch becomes if (m.m00 >= m.m11) { if (m.m00 >= m.m22) { //00 is max diag x = Math.sqrt(0.5 * (m.m00+1)); y = m.m01 * 0.5 / x; z = m.m02 * 0.5 / x; } else { //22 is max z = Math.sqrt(0.5 * (m.m22+1)); x = m.m02 * 0.5 / z; y = m.m12 * 0.5 / z; } } else { if (m.m11 >= m.m22) { //11 is max diag y = Math.sqrt(0.5 * (m.m11+1)); x = m.m01 * 0.5 / y; z = m.m12 * 0.5 / y; } else { //22 is max z = Math.sqrt(0.5 * (m.m22+1)); x = m.m02 * 0.5 / z; y = m.m12 * 0.5 / z; } }
back to matrix to axis-angle page |