Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    HPB>>XYZ conversion and atan2

    SDK Help
    0
    1
    176
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

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

      On 10/11/2004 at 13:31, xxxxxxxx wrote:

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

      ---------
      Hi
      Just wanted to post this somewhere since it needed me much time to implement this stuff on my own, but it seems to work now. There are lot's of angle configurations if you want to export to another coordinate system (XYZ YZX XZY...). Hope this is usefull for someone - likely to someone who want to write an exporter in COFFEE like I did.

      If you need another rotation combination, go to http://magic-software.com/ , they offer a paper on converting euler angles. Quite usefull other stuff, too.

      The following code returns a XYZ rotation vector in degrees (not HPB!) for a right handed coordinate system - if you need it lefthanded you can try to negate the X angle (should work). The passed parameter has to be a normalized local matrix.

        
      // Atan2 conversion similiar to the java/C implementation  
      // a quick implementation - don't know if it's bugfree  
      atan2(x,y) {  
           var value = 0;  
           if (y==0) {  
                if (x<0) return -PI05;  
                else return PI05;  
           }  
           value = atan(x/y);  
           if (y<0) {  
                if (x>0) value +=PI;  
                else value -= PI;  
           }  
           return value;  
      }  
      // converts a rotation by a matrix (has to be a normalized local matrix) to XYZ rotation   
      // instead of HPB, which is required for some export formats  
      convertRotation(matrix) {  
           var v1 = matrix->GetV1();  
           var v2 = matrix->GetV2();  
           var v3 = matrix->GetV3();  
           var thetaY = asin(v1.z),thetaX=0,thetaZ=0;  
           if (thetaY<PI05) {  
                if (thetaY>-PI05) {  
                     thetaX = atan2(-v2.z,v3.z);  
                     thetaZ = atan2(-v1.y,v1.x);  
                } else {  
                     thetaX = -atan2(v2.y,v2.x);  
                     thetaZ = 0;  
                }  
           } else {  
                thetaX = atan2(v2.x,v2.y);  
                thetaZ = 0;  
           }  
           return vector(-thetaX,thetaY,thetaZ)*180/PI;  
      }  
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post