calculate rotation values



  • On 13/12/2014 at 12:26, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   16 
    Platform:    Mac  ;  
    Language(s) :     C++  ;

    ---------
    hey

    i try  to calculate a rotation from a object and get the opposite to an other object

    sourceMagnet = the source object  
    targetMagnet = the object witch should be on the opposite side of sourceM
    selected object is a parent of targetMag witch take the rotation

    I can`t find my error - have one a tip please :)

                    Vector rotTarget = MatrixToHPB(targetMagnet->GetMg(), ROTATIONORDER_HPB);
                    Vector rotSource = MatrixToHPB(sourceMagnet->GetMg(), ROTATIONORDER_HPB);
                    Vector rotdif = rotSource-rotTarget;
                    
                    if (rotdif.x > 0){
                        rotdif -= Vector(Rad(180.0),0,0);
                    }else{
                        rotdif += Vector(Rad(180.0),0,0);
                    }
                    selectedObject->SetRotationOrder(ROTATIONORDER_HPB);
                   	selectedObject->SetAbsRot(selectedObject->GetAbsRot()-rotdif);
    


  • On 14/12/2014 at 11:33, xxxxxxxx wrote:

    Give this a try and see if it does what you want.

        BaseObject *master = doc->SearchObject("master");  
      Matrix masterMtx = master->GetMg();  
      BaseObject *slave = doc->SearchObject("slave");  
      Matrix slaveMtx = slave->GetMg();  
      
      //Get the three axis vectors for the two objects  
      Vector m1 = masterMtx.v1;  
      Vector m2 = masterMtx.v2;  
      Vector m3 = masterMtx.v3;  
      Vector s1 = slaveMtx.v1;  
      Vector s2 = slaveMtx.v2;  
      Vector s3 = slaveMtx.v3;  
      
      //A switch the user can use to make the object rotate either in the same direction, or the opposite direction of the master object  
      Bool rotDir = FALSE;  
      
      //If any of the axis vectors don't match up..Then the child(slave) is rotated differently than the parent(master)  
      if(m1 != s1 || m2 != s2 || m3 != s3)  
      {  
          if(rotDir) masterMtx = !masterMtx;     //Invert the masterMtx so we rotate the target in reverse  
      
          slaveMtx.v1 = Vector(masterMtx.v1);  
          slaveMtx.v2 = Vector(masterMtx.v2);   //Set the slave axis to the same as the parent's axis vectors  
          slaveMtx.v3 = Vector(masterMtx.v3);  
          slave->SetMg(slaveMtx);  
          slave->Message(MSG_UPDATE);  
      
          if(rotDir) masterMtx = !masterMtx;    //Restore the masterMtx back where it was originally  
      }  
      else return FALSE;
    

    -ScottA



  • On 14/12/2014 at 15:55, xxxxxxxx wrote:

    get en error here

    if(rotDir) masterMtx = !masterMtx;
    Invalid argument type 'Matrix' (aka 'Matrix64') to unary expression

    and 
    I need to set the parent of slave with the new values - so i need to get them to the parent



  • On 14/12/2014 at 16:37, xxxxxxxx wrote:

    In R16, ! operator is an equality operator.  For inversion,  you need to use the ~ operator instead.

    ETA: Maxon needs to stratify, solidify, and establish their API fundamentals once and for all.  These are changed almost on a version by version basis.  Do they realize the sheer waste of time required to update and maintain code for these radical changes and legacy support?!



  • On 15/12/2014 at 01:44, xxxxxxxx wrote:

    Hi Robert,

    while I empathize your anger about changes in the SDK, I need to ask for your understanding.

    The C4D developers don't change the API for fun. Quite the contrary is true, they do as much as they can to keep it as compatible as possible. Yet it is a thin line, as on the other hand external developers complain about inconsistencies in the API and claim further development. And finally internal development may cause the need for changes in the API as well and I'm pretty sure, we all want Cinema 4D to develop further.

    Believe me, none of the changes is taken lightly, instead quite long and lively internal discussions forego such changes.

    All I can do is to beg your pardon for any inconveniences caused.



  • On 15/12/2014 at 06:46, xxxxxxxx wrote:

    Hi Robert,

    Thanks for you reply

    i try it with 
    masterMtx = ~masterMtx;

    but the result is not invers

    Thanks



  • On 15/12/2014 at 07:09, xxxxxxxx wrote:

    It`s maybe a wrong understanding - I Like to mirror the slave object to master - same position but flipped.



  • On 15/12/2014 at 07:29, xxxxxxxx wrote:

    In the code I posted. The slave should rotate with the master.
    But if you change this variable: rotDir = true;
    Then the slave should rotate in the opposite direction of the master (mirrored).

    FYI:
    Just in case you're wondering. The reason I did not use -= and SetAbsRot() in my code is because that will make the object rotate every time the code is executed. And this will cause the object to keep spinning repeatedly every time the code is executed. Like a propeller.

    -ScottA



  • On 15/12/2014 at 07:35, xxxxxxxx wrote:

    hey ScottA,

    thanks for you help

    i use this code and the object is not mirrored -

    Matrix masterMtx = targetMagnet->GetMg();
                    Matrix slaveMtx = sourceMagnet->GetMg();
                    
                    //Get the three axis vectors for the two objects
                    Vector m1 = masterMtx.v1;
                    Vector m2 = masterMtx.v2;
                    Vector m3 = masterMtx.v3;
                    Vector s1 = slaveMtx.v1;
                    Vector s2 = slaveMtx.v2;
                    Vector s3 = slaveMtx.v3;
                    
                    //A switch the user can use to make the object rotate either in the same direction, or the opposite direction of the master object
                    
                    //If any of the axis vectors don't match up..Then the child(slave) is rotated differently than the parent(master)
                    if(m1 != s1 || m2 != s2 || m3 != s3)
                    {
                        GePrint(String::VectorToString(Vector(masterMtx.v1))+" "+String::VectorToString(Vector(masterMtx.v2))+" "+String::VectorToString(Vector(masterMtx.v3)));
                        masterMtx = ~masterMtx; //Invert the masterMtx so we rotate the target in reverse
                        GePrint(String::VectorToString(Vector(masterMtx.v1))+" "+String::VectorToString(Vector(masterMtx.v2))+" "+String::VectorToString(Vector(masterMtx.v3)));
                        slaveMtx.v1 = Vector(masterMtx.v1);
                        slaveMtx.v2 = Vector(masterMtx.v2);   //Set the slave axis to the same as the parent's axis vectors
                        slaveMtx.v3 = Vector(masterMtx.v3);
    

    the result of the prints are 
    (0;1;0) (1;0;0) (0;0;-1)
    (0;1;0) (1;0;0) (0;0;-1)



  • On 15/12/2014 at 08:41, xxxxxxxx wrote:

    It works fine in R13.
    They must have made some very drastic matrix changes in the R16 SDK.

    I will try to figure out the R16 version when I get chance.

    -ScottA



  • On 15/12/2014 at 08:47, xxxxxxxx wrote:

    beside from the mirror of the Slave - I stuck on the transform from a parent object.  I like to move the parent object - that the child(slave) match the master.

                        BaseObject *mother = sourceMagnet->GetUp();
                        if (mother){
                            GePrint(mother->GetName());
                            Vector DifabsPos = sourceMagnet->GetAbsPos();
                            slaveMtx = slaveMtx + MatrixMove(DifabsPos);
                            mother->SetMg(slaveMtx);
                            mother->Message(MSG_UPDATE);
                            EventAdd();
    

    Many Thanks



  • On 15/12/2014 at 09:34, xxxxxxxx wrote:

    I tried the code I posted in R16. And it works using ~ to invert the matrix.
    I'm not sure why it's not working for you?

    -ScottA



  • On 15/12/2014 at 09:38, xxxxxxxx wrote:

    For unterständig - i should see the invert by printing the vectors ?



  • On 11/03/2015 at 12:11, xxxxxxxx wrote:

    I'm wondering if this is solved?


Log in to reply