Coordinates from Local to Global in COFFEE?



  • On 12/09/2016 at 09:12, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R12 
    Platform:   Windows  ;   
    Language(s) :   C.O.F.F.E.E  ;

    ---------
    Hi

    I want to lock a null to a single point of a polygon object, with its axis aligned to point's normal. To do this, I've got an Xpresso COFFEE node into which I'm feeding the point normal from a point node. I'm using the 'VectorToHPB' command inside the COFFEE node to do the orientation and it works as expected if the polygon object isn't rotated. However, the normal information is in local coordinates and when I rotate the polygon object, the null's position remains locked to the point but its orientation stays the same as before the rotation. I believe I need the global rotation coordinates of the normal in order to orient the locked object correctly. Could someone please tell me how I can go about converting the normal's coordinates from local to global? Also, Is there a way to get the point normal inside COFFEE without it having to be fed from a point node?

    Thanks in advance



  • On 13/09/2016 at 12:02, xxxxxxxx wrote:

    Hi,

    I guess you are stuck with R12, right? Otherwise I'd recommend to use Python instead of COFFEE, which by now is way more powerful.

    So lets stay in COFFEE:
    You usually use the Matrix (in this case the global matrix) of an object for such calculations/transformations. You can retrieve global or local matrix from a BaseObject using GetMg(), GetMgn() or GetMl(), GetMln().
    There's also a quite useful page on Using matrices in the COFFEE documentation, which should help to learn some background on the topic.

    In your case it should be enough to feed the global matrix of your polygon object into the COFFEE node and use GetMulV() to multiply it with the normal vector. The result is then fed into VectorToHPB().

    But this won't be sufficient, if the polygon object (or one of its parents) is non-uniformly scaled.
    Articles like this or this explain the problems you are running into in such a case. I'll leave it to you or the community to figure out the math...



  • On 13/09/2016 at 17:30, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Hi,

    I guess you are stuck with R12, right? Otherwise I'd recommend to use Python instead of COFFEE, which by now is way more powerful.

    So lets stay in COFFEE:
    You usually use the Matrix (in this case the global matrix) of an object for such calculations/transformations. You can retrieve global or local matrix from a BaseObject using GetMg(), GetMgn() or GetMl(), GetMln().
    There's also a quite useful page on Using matrices in the COFFEE documentation, which should help to learn some background on the topic.

    In your case it should be enough to feed the global matrix of your polygon object into the COFFEE node and use GetMulV() to multiply it with the normal vector. The result is then fed into VectorToHPB().

    But this won't be sufficient, if the polygon object (or one of its parents) is non-uniformly scaled.
    Articles like this or this explain the problems you are running into in such a case. I'll leave it to you or the community to figure out the math...

    Hi Andreas

    Thank you so much for your help. I appreciate it tremendously. I was beginning to worry that I'd be stuck at this point but your solution works perfectly.

    I've read through the Using Matrices section, dozens of times and just as I think I've got it handled, I realize that I'm still confused. I think, however, my problem is more related to understanding why certain calculations are done with the matrix to get to a certain result.

    I'm making this little setup for cluster joints and my character's mesh will never be non-uniformly scaled so luckily that isn't really a problem for me.

    Thank you, again.


Log in to reply