Global pos to local pos wrt another obj



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 22/09/2007 at 20:36, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R8.2-R10 
    Platform:   Windows  ; Mac  ;  Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    This is baffling me at the moment. I have a null object elsewhere in a document and want to convert its global position so that it is a local position with respect to another object in a hierarchy (local to that object's parent system). Not sure how to do this - and I can't just parent the null object to get a proper local position using GetPos().

    Maybe an inverse global matrix?

    lpos = null->GetMg().off * !obj->GetMg();



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 23/09/2007 at 15:31, xxxxxxxx wrote:

    I was correct. To put other objects into a local system of another, that was correct. :)



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/09/2007 at 00:25, xxxxxxxx wrote:

    Hello kuroyume0161,

    can you please describe your way a little more in detail? I have the same problem but my problem is that I have right-hand-side coordinate-systems and have to transform them into left-hand-side ones.
    Would be nice if you describe your way in detail.

    Thanks in advance

    guckmalda



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 24/09/2007 at 08:02, xxxxxxxx wrote:

    That was it. I should clarify that this puts the other object into the coordinate system of the object not the object parent system (so that the object coordinates can be considered PSR (0,0,0)(1,1,1)(0,0,0)). These were the results being sought.

    So basically, you have a null object at the root (parent system in the World or Global) and another object, say reference, in a hierarchy. To put the null object's position in the reference system, take its global position and multiply it by the inverse of the reference global matrix:

    Vector localpos = null->GetMg().off * !reference->GetMg();
    

    As for converting right to left handed coordinate systems, use a similarity transform matrix:

    // - Apply similarity transform (z-trans and z row-column are negated except for overlap (v3.z))  
    Matrix sm;  
    sm.v1.z *=     -1.0f;  
    sm.v2.z *=     -1.0f;  
    sm.v3.x *=     -1.0f;  
    sm.v3.y *=     -1.0f;  
    sm.off.z *=     -1.0f;
    

    Pre-multiply this to the matrix to be converted from right to left:

    Matrix rtol = rhm * sm;
    

    Hope that helps. :)



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/07/2009 at 15:12, xxxxxxxx wrote:

    Thanks for the link here Robert. I'm a but confused by the matrix sm. What matrix is this? Looking at your code snippet I presume sm must come from somewhere as the z column is being multiplied by -1.

    It's late, so perhaps it's just not sinking in, but if you can offer any clarity, then that would be great!

    Cheers
    H



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 14/07/2009 at 23:16, xxxxxxxx wrote:

    Normally I apply this to an existing right-handed matrix to make it left-handed (C4D).

    If this is for changing handedness of vectors, it may be sufficient to simply negate the z values of the vectors which will literally change the handedness in one go.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/07/2009 at 09:36, xxxxxxxx wrote:

    So in your code, Matrix sm is declared and this is presumably identity. You then multiply a number of its components by -1. Thisks what's confusing me, surely Skme of the componets you are multiplying by -1 are always zero, or does sm represent a matrix I wish to convert? In which case what is the rhm matrix?

    Thanks for you help with this, just struggling to understand fully!!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 15/07/2009 at 18:45, xxxxxxxx wrote:

    That was just an example. Matrix sm would be some prepared matrix. For instance, here's my support method to convert Poser (right-hand) to Cinema 4D (left-hand) matrices:

    > // Apply Similarity matrix to Mat Spheres R-H/RowMajor matrix (matSphereRaw) \> //\*---------------------------------------------------------------------------\* \> void ConvertPoserMatrix(BaseContainer\* jbc, Matrix mat, const LONG& id) \> //\*---------------------------------------------------------------------------\* \> { \>      // - Apply similarity transform (z-trans and z row-column are negated except for overlap (v3.z)) \>      mat.v1.z \*=          -1.0f; \>      mat.v2.z \*=          -1.0f; \>      mat.v3.x \*=          -1.0f; \>      mat.v3.y \*=          -1.0f; \>      mat.off.z \*=     -1.0f; \>      jbc->SetMatrix(id,     mat); \> }

    'rhm' is of course a right-handed matrix to be converted (formatted to C4D matrix - transposed if necessary).

    Applied twice, this would change the Poser matrix back to right-handed. So, if you have a C4D matrix and want it to be right-handed, this would achieve it. After that, if you are exporting the matrix, you'll need to consider row-vector vs. column-vector.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 16/07/2009 at 00:40, xxxxxxxx wrote:

    Thanks Robert; you're a star. All working fine. Naturaly had to flip my z verts and normals and the winding order, but that was the easy bit!

    Appreciate your taking the time and glad you trod the path before me and figured it out! I don't envy you that pain! Thanks for sharing!

    I found it odd that there wasn't more info on this process on the web tbh!

    Cheers
    H


Log in to reply