• Create Account

### #Actualhaegarr

Posted 30 April 2012 - 12:40 AM

You apply each particular transformation one-by-one. That is horribly inefficient and not the way to go. Instead compute an overall transformation by composing all the particular transformations, and apply that thing as a whole. Mathematically spoken, you compute (using column vectors here)
v' = T2 * ( R2 * ( T1 * ( R1 * v ) ) )
for all vertices v, assuming 2 transformations in your list, where the usual way would look like
v' = ( T2 * R2 * T1 * R1 ) * v = M * v with M := T2 * R2 * T1 * R1
instead. The inefficiency becomes more and more relevant the more transformations you have and the more vertices you transform, of course.

Now, when looking at your given problem, you want to transform from global to local space. In other words, you want to compute v from v' when still using the above naming scheme. Hence you require to apply the inverse transformation, because
M-1 * v' = M-1 * ( M * v ) = v

When using a composed transformation then inverting it is all you have to do. However, for the sake of clarity and perhaps you insist of using the particular transformations, the effect of inversion is
M-1 = ( T2 * R2 * T1 * R1 )-1 = R1-1 * T1-1 * R2-1 * T2-1
so that not only each each transformation is inverted but also the order is reversed. Do you have considered this?

Now let us assuming that M is the the local-to-global transformation of your model. You can transform the model into global space using M on the model's vertices, followed by doing the hit test in global space. This would be inefficient, so you want to go the other way: Transform the ray into model's local space and apply the hit test therein. Hence you have to do
r1' = M-1 * r1
r2' = M-1 * r2
onto the both points r1 and r2 defining the ray, and do the hit test with r1' and r2'.

### #1haegarr

Posted 29 April 2012 - 03:43 AM

You apply each particular transformation one-by-one. That is horribly inefficient and not the way to go. Instead compute an overall transformation by composing all the particular transformations, and apply that thing as a whole. Mathematically spoken, you compute (using column vectors here)
v' = T2 * ( R2 * ( T1 * ( R1 * v ) ) )
for all vertices v, assuming 2 transformations in your list, where the usual way would look like

v' = ( T2 * R2 * T1 * R1 ) * v = M * v with M := T2 * R2 * T1 * R1
instead. The inefficiency becomes more and more relevant the more transformations you have and the more vertices you transform, of course.

Now, when looking at your given problem, you want to transform from global to local space. In other words, you want to compute v from v' when still using the above naming scheme. Hence you require to apply the inverse transformation, because
M-1 * v' = M-1 * ( M * v ) = v

When using a composed transformation then inverting it is all you have to do. However, for the sake of clarity and perhaps you insist of using the particular transformations, the effect of inversion is
M-1 = ( T2 * R2 * T1 * R1 )-1 = R1-1 * T1-1 * R2-1 * T2-1
so that not only each each transformation is inverted but also the order is reversed. Do you have considered this?

Now let us assuming that M is the the local-to-global transformation of your model. You can transform the model into global space using M on the model's vertices, followed by doing the hit test in global space. This would be inefficient, so you want to go the other way: Transform the ray into model's local space and apply the hit test therein. Hence you have to do
r1' = M-1 * r1

r2' = M-1 * r2
onto the both points r1 and r2 defining the ray, and do the hit test with r1' and r2'.

PARTNERS