Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

After some rotations and to from quaternion conversions I get negative scale from Matrix 4x4, is it possible? I need that scale to draw sprite on screen so I get sprite flipped, how to deal with this problem should I just handle negative scale in sprite drawing method.

if MatrixHasNegativeScale then invert scale, draw sprite with inverted scale after m4.initWithHeadPitchRoll(0, 0, 180); I already get negative scale. or something wrong with matrix class?

Edit I create transformation matrix(rotation + scale + translate) rotation around Oz by 180 and when I extract scale from it, it has negative value is it normal?

share|improve this question
    
By scale are you referring to element m44 of the matrix? –  Pieter Geerkens Apr 25 '13 at 21:51
    
By scale I refer to m00 m11 m22, m4 is variable of matrix 4x4 –  bobenko Apr 25 '13 at 21:57
    
Mathematicians usually start at m11, CIS types at m00. If the determinant of the non-translational portion of the matrix is negative, that means the sprite is being reflected. It sounds like you are referring to that when you say m00 m11 m22, but of course that only applies if the off-diagonal elements (of the non-translational portion) of the matrix are all 0. –  Pieter Geerkens Apr 25 '13 at 22:06
    
Let's go over your exact commands, what language and libraries do you use? What series of commands do you use to create the matrix? What command(s) do you use to extract the scale? If you could provide intermediate data dumps of example data between the individual commands that might also help. –  eBusiness Apr 26 '13 at 21:29

1 Answer 1

up vote 4 down vote accepted

If your matrix and quaternion classes are functioning properly, then a sequence of rotations should not ever give you a reflection (inverting or flipping a sprite). You should not just sweep the problem under the rug by writing code to flip something if it comes out with a reflection; you should try to figure out the actual problem.

That being said, based on the comments, it's not clear to me that you actually have a reflection showing up. Negative components in a matrix show up naturally as a result of rotations. For example a 2D rotation matrix for a 180-degree rotation is

[ -1  0 ]
[  0 -1 ]

The presence of negative values in the matrix - even along the main diagonal - doesn't mean anything by itself. You have to look at the determinant of the matrix to see whether it's orientation-preserving (positive) or orientation-reversing (negative), and in this case the determinant is +1, so this is a perfectly legit rotation matrix, with no reflection.

share|improve this answer
    
That matrix could be described as a scale of -1. Note that a similar scale -1 3D matrix has a determinant of -1, and thus will mirror the object. –  eBusiness Apr 25 '13 at 23:38
    
@eBusiness Yep. Conversely, a 180-degree rotation about any axis in 3D could be described as a scale of -1 along the axes perpendicular to the rotation axis, but has a determinant of +1. –  Nathan Reed Apr 26 '13 at 0:04
    
So what should I do? if rotation of 180degree gives me negative scale? should I modify scale given to renderer based on matrix determinant? something like if determinant > 0 scale < 0 then negate scale –  bobenko Apr 26 '13 at 9:23
1  
@bobenko No, a 180 rotation in 3D does not give negative scale. But what exactly are you trying to do? Your question is not very clear on that. –  eBusiness Apr 26 '13 at 11:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.