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.

I multiply a matrix with a position vector to get a new position, however, now I need to change my matrix from y-up coordinate space to z-up. Changing only the matrix won't work: how to apply the change to the vector (change position vector from y-up to z-up)?

share|improve this question
    
Maybe rotating along X and if needed, setting Y as -Y? –  Gustavo Maciel May 2 '12 at 9:19
    
In the title you wrote Z to Y, then in the question you wrote Y to Z. So which is it? –  David Gouveia May 2 '12 at 10:17
    
Fixed. isn't the solution similar though? –  ippk May 2 '12 at 10:23
    
@ippk It's similar enough. I've tried explaining the general case. Should be easy to adapt to your specific needs. –  David Gouveia May 2 '12 at 10:25
add comment

1 Answer

You need to be more clear about the coordinate systems you're converting from and to (for instance, when Y is up, in which direction does Z point, etc). But either way it's simple to derive your matrix. I'll just do an example using this assumption:

   Y                 Z / Y 
   |__ X      =>     |/__ X
  /              
 Z   

(1. Y Up)           (2. Z Up)            

Think what happens to each axis on the left side, when it's converted to the right side:

  • X in (2) is the same as X in (1)
  • Y in (2) is the same as -Z in (1)
  • Z in (2) is the same as Y in (1)

One idea is to encode the changes above in a simple matrix, such as the one below. It should be easy to understand the correlation between the matrix and the description above, but I've also added the multiplication so you can see the way in which it modifies the result.

[ 1  0  0 ]   [ x ]   [  x  ]
[ 0  0 -1 ] * [ y ] = [ -z  ]
[ 0  1  0 ]   [ z ]   [  y  ]

This is actually just a 90 degrees rotation matrix. You could concatenate this matrix at the end of your previous transformation, so that the conversion is done automatically as part of the matrix multiplication.

Or, alternatively you can just do it manually at the end like:

float y = position.Y;
position.Y = -position.Z;
position.Z = y;
share|improve this answer
    
A bit confused about in which way this is actually converting, but it's a matter of swapping the -1 and the 1 on the matrix if it's the other way around. –  David Gouveia May 2 '12 at 10:42
1  
Or if wished, dont inverse Z at all, depending on the coordinate system –  Gustavo Maciel May 2 '12 at 11:03
    
@Gustavo-Gtoknu Exactly. Just draw both of your coordinate systems, and then see what changes from one to the other. –  David Gouveia May 2 '12 at 11:12
add comment

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.