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

    ObjectData::Draw

    Cinema 4D SDK
    c++ r21
    2
    3
    493
    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.
    • A
      AiMiDi
      last edited by

      I want to draw the object 2d on the screen (the front, always displayed), but my code will have problems, how can I modify it.
      Now it looks like there is a problem with the drawing order? My object should be drawn last.
      b01488c5-325e-4d41-b26a-cd1d89952eae-image.png

      class Obj : public ObjectData
      {
      public:
      	DRAWRESULT Draw(BaseObject* op, DRAWPASS drawpass, BaseDraw* bd, BaseDrawHelp* bh);
      	static NodeData* Alloc() { return NewObjClear(Obj); }
      };
      
      
      DRAWRESULT Obj::Draw(BaseObject* op, DRAWPASS drawpass, BaseDraw* bd, BaseDrawHelp* bh) {
      	if (drawpass != DRAWPASS::OBJECT)
      		return DRAWRESULT::SKIP;
      
      	if (op == nullptr || bd == nullptr || bh == nullptr)
      		return DRAWRESULT::FAILURE;
      
      	const Vector& screenSpacePos = bd->WS(op->GetMg().off);
      	// set color
      	bd->SetPen(Vector(255,86,137)/255);
      	// draw circle
      	bd->DrawCircle2D(screenSpacePos.x, screenSpacePos.y, 15);
      	// draw handle
      	bd->DrawHandle2D(screenSpacePos, DRAWHANDLE::BIG);
      	if (bd->TestBreak())
      		return DRAWRESULT::OK;
      
      	return DRAWRESULT::OK;
      }
      

      Thank,
      AiMiDi

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hi @AiMiDi,

        thank you for reaching out to us. We are not 100% certain what you mean with:

        Now it looks like there is a problem with the drawing order?

        , but I would assume you want the handle to be drawn in front of the cube-like geometry and not behind it? This is caused by drawing into the draw-pass DRAWPASS::OBJECT. Changing the drawing space to a screen projection while in the Object draw pass will not bring the drawn content in front of everything else, as this just means using another coordinate system and nothing else (as done in your code with const Vector& screenSpacePos = bd->WS(op->GetMg().off);).

        You probably want to draw into the draw-pass HANDLES, as this is the draw pass into which one is meant to draw handles. Relevant in this context might also be the DRAWPASS enum and this older blog post of ours[URL-REMOVED].

        I hope this helps, if anything remains unclear, please do not hesitate to ask.

        Cheers,
        Ferdinand


        [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • A
          AiMiDi
          last edited by

          Thanks for your answer, it solved my problem.

          Thank,
          AiMiDi

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