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.

If I have an object space described by transformation matrix that should be applied to object to transform it to world space, what I have to do to transform point (world space) to that object space.

I guess it's more of a math question, but I believe gamedevs are more familiar with terminology.

share|improve this question

2 Answers 2

up vote 7 down vote accepted

If you have a matrix that transforms from object to world space, the inverse of that matrix will transform a world space value to object space.

share|improve this answer
    
Could you elaborate on the details of that transform matrix? Or point me to somewhere that explains it? I'm trying to solve a similar problem. –  Justin Nov 7 '12 at 19:47
    
It isn't that simple. You cannot easily invert a 4x4 matrix with rotate scale and translate components. –  bobobobo Jan 7 '13 at 21:24
1  
Well, it's just math. But it's a lot of math, and it's not trivial or intuitive math. Most math libraries will supply a matrix inversion function for you. If so, you just call that. If you're writing your own math routines, my 4x4 matrix invert function is here, in the function named "vsMatrix4x4::InverseGeneral()". Feel free to use/adapt. –  Trevor Powell Jan 7 '13 at 21:46

You need to keep around the components of how you built your world matrix to begin with.

Say your world matrix is for a spinning coin. So, it has rotate, scale, then translate in that order.

Let's assume you're using row-major matrices. You'd form your forward transformation matrix as:

matrix = rotate(30,60,90) * Scale(5) * Translate ( 5, 0, 0 )

Form the backwards (inverse) transformation as just the opposite operations, in the opposite order.

inv_matrix = Translate( -5, 0, 0 ) * Scale( 1.0/5.0 ) * TRANSPOSE( rotate(30,60,90) ) 

So note a few things:

  • inverse of rotation matrix ("unrotate") is just its transpose. (this is a special property of rotation matrices only and doesn't apply to other matrix types)
  • inverse of scale matrix (unscale) is 1/scale
  • inverse of translation matrix is applying -translate
share|improve this answer

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.