Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    How to Handle Handles

    SDK Help
    0
    3
    375
    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

      On 21/02/2013 at 09:05, xxxxxxxx wrote:

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

      ---------
      Hello all, 
      I've been experimenting with the Rounded Tube example plugin and I've been trying to figure out how handles work and I think I have a basic understanding of them now.  I'm getting stuck thought trying to make a handle that can move on the X and Z axis independently of each other.  I swapped the rounded tube out with a plane and I want to control the height and width with a handle in the corner.  Which I can do, but it always moves the same on both axises.

      I think it has to do with changing something on these two lines in GetHandle(), but I'm not to sure what I need to change.

        
      info.direction = Vector(1.0, 0.0, 0.0);  
      info.type = HANDLECONSTRAINTTYPE_LINEAR;  
      

      Any hints would be useful.  Thanks!

      Dan

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 21/02/2013 at 13:17, xxxxxxxx wrote:

        Here are the Handle methods that I use in one of my plugins.  Not that the UNFURL_UNFURL_AMOUNT goes from 0.0 to 1.0 (0% to 100%).

        // ObjectData.Draw  
        //*---------------------------------------------------------------------------*  
        DRAWRESULT UnfurlObj::Draw(BaseObject* op, DRAWPASS drawpass, BaseDraw* bd, BaseDrawHelp* bh)  
        //*---------------------------------------------------------------------------*  
        {  
          if (!(op && bd && bh))                return DRAWRESULT_DRAWN;  
          
          if (drawpass == DRAWPASS_HANDLES)  
          {  
              LONG        hitid = op->GetHighlightHandle(bd);  
              HandleInfo    info;  
          
              bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));  
              bd->SetMatrix_Matrix(op, bh->GetMg());  
              GetHandle(op, 0L, info);  
              if (hitid == 0L)    bd->SetPen(GetViewColor(VIEWCOLOR_SELECTION_PREVIEW));  
              else                bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));  
              bd->DrawHandle(info.position, DRAWHANDLE_BIG, 0L);  
          
              GetHandle(op, 1L, info);  
              bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));  
              bd->DrawLine(info.position, Vector(0.0), 0L);  
              bd->SetMatrix_Matrix(NULL, Matrix());  
              if (hit == 0L)    bd->SetPen(GetViewColor(VIEWCOLOR_SELECTION_PREVIEW));  
              else            bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));  
              bd->DrawHandle(GetHandle(op, 0L),DRAWHANDLE_BIG,0L);  
              // Line from center to Handle  
              bd->SetPen(GetViewColor(VIEWCOLOR_ACTIVEPOINT));  
              bd->DrawLine(GetHandle(op, 1L),m.off,0L);  
          }  
          return SUPER::Draw(op, drawpass, bd, bh);  
        }  
        // ObjectData.GetHandle  
        //*---------------------------------------------------------------------------*  
        void UnfurlObj::GetHandle(BaseObject* op, LONG i, HandleInfo& info)  
        //*---------------------------------------------------------------------------*  
        {  
          BaseContainer* data =    op->GetDataInstance();  
          if (!data)                return;  
          
          info.position.x =        data->GetReal(UNFURL_UNFURL_AMOUNT)*125.0;  
          info.direction.x =        1.0;  
          info.type =                HANDLECONSTRAINTTYPE_LINEAR;  
        }  
        // ObjectData.DetectHandle  
        //*---------------------------------------------------------------------------*  
        LONG UnfurlObj::DetectHandle(BaseObject* op, BaseDraw* bd, LONG x, LONG y, QUALIFIER qualifier)  
        //*---------------------------------------------------------------------------*  
        {  
          HandleInfo    info;  
          GetHandle(op, 0L, info);  
          return (bd->PointInRange(info.position*op->GetMg(),x,y))?0L:NOTOK;  
        }  
        // ObjectData.MoveHandle  
        //*---------------------------------------------------------------------------*  
        Bool UnfurlObj::MoveHandle(BaseObject* op, BaseObject* undo, const Vector& mouse_pos, LONG hit_id, QUALIFIER qualifier, BaseDraw* bd)  
        //*---------------------------------------------------------------------------*  
        {  
          BaseContainer*    dst =    op->GetDataInstance();  
          if (!dst)                return TRUE;  
          HandleInfo        info;  
          Real            val =    mouse_pos.x;  
          GetHandle(op, hit_id, info);  
          
          if (bd)  
          {  
              Matrix mg =        op->GetUpMg() * undo->GetMl();  
              Vector pos =    bd->ProjectPointOnLine(info.position * mg, info.direction ^ mg, mouse_pos.x, mouse_pos.y);  
              val =            (pos * !mg) * info.direction;  
          }  
          
          if (hit_id != 0L)        return TRUE;  
          dst->SetReal(UNFURL_UNFURL_AMOUNT,FCut01(val*0.008));  
          return TRUE;  
        }  
        
        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 06/03/2013 at 10:45, xxxxxxxx wrote:

          Thanks a ton Robert, I got distracted by some other projects, cause for the every late response.

          Dan

          1 Reply Last reply Reply Quote 0
          • First post
            Last post