OT: Calculate Up Vector



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

    On 02/04/2007 at 12:10, xxxxxxxx wrote:

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

    ---------
    Hi Guys,
    I'm using the Target node within Xpresso to have objects look at a specific object. The problem I'm running into is gimbal lock, which is to be expected. I have looked on numerous math and game developer sites to try and find a way to calculate an Up Vector for this target expression node. The COFFEE code is as follows:

        
        
          
         var mobj = Object->GetMg();  
         var tobj = Target->GetMg();  
           
         var p1 = mobj->GetV0();  
         var p2 = tobj->GetV0();
        
        
        
        
         var m = new(Matrix);
        
        
        
        
         m->SetV0(p1);   
         m->SetV3(vnorm(p2 - p1));   
         m->SetV2(vnorm(vcross(p2-p1, vector(0,1,0))));   
         m->SetV1(vnorm(vcross(p2-p1, vector(0,0,1))));   
            
         Rotation=m->GetHPB();
        
        
        
        
         var orot=mobj->GetHPB();  
          Rotation.z=orot.z;  
        
    

    So, does anyone here know how to calculate the up vector for this expression? Or even able to provide some links for calculating an up vector? As always any help is much appreciated.
    Josh



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

    On 02/04/2007 at 17:16, xxxxxxxx wrote:

    this should work

    main()
    {
         var mobj = Object->GetMg();
         var tobj = Target->GetMg();
         var upobj = UpVector->GetMg();
         
         var p1 = mobj->GetV0();
         var p2 = tobj->GetV0();
         var p3 = upobj->GetV0();

    var m = new(Matrix);

    m->SetV0(p1);
         m->SetV1(vnorm(vcross(p2-p1, p3-p1)));
         m->SetV3(vnorm(p2 - p1));
         m->SetV2(vnorm(vcross(p2-p1, m->GetV1())));
              
         Rotation=m->GetHPB();
    }

    cheers,
    Matthias



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

    On 02/04/2007 at 17:41, xxxxxxxx wrote:

    I'll try this out tomorrow, but thanks for the quick response.

    Josh



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

    On 12/08/2007 at 04:55, xxxxxxxx wrote:

    I used this code, too. But what disturbs me is, that the Y axis of the object is always pointing away from the UpVector object. It would be more intuitive to use if the Y axis would point towards the UpVector object.

    How can I turn this around?

    Thanks in advance & best regards,
    Frank



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

    On 12/08/2007 at 12:38, xxxxxxxx wrote:

    Ah, OK, I already found out.

    Instead of:

    m->SetV1(vnorm(vcross(p2-p1, p3-p1)));
    

    it has to be

    m->SetV1(vnorm(vcross(p2-p1, p1-p3)));
    

    Then the Y axis is pointing towards the UpVector object.


Log in to reply