orxDisplay_Draw*

edited January 2015 in Help request
Hi, next to my post about handling input events, my final objective is to draw Bézier curves, thus, the use of orxDisplay_DrawLine/Circle (from my point of view).

I get my coordinates (thanks to the previous topic) and I can display them when created through orxObject_CreateFromConfig(). I prefer not to store orxOBJECTs, but only the orxVECTORs related to my clicked coordinates to use them with the orxDisplay_Draw* functions.
My problem is that, having my orxVECTOR array and looping on it with orxDisplay_DrawCircle, nothing happen in my windows.

Are there pre-requisites or some initialization steps before using the orxDisplay_Draw* functions ?

Comments

  • edited January 2015
    If I understood what you said correctly, you are using the mouse position as input. If that is the case, did you convert the clicked position to a world position with orxRender_GetWorldPosition?
  • edited January 2015
    Yes, I did.
    It was a problem at first, but, I found topics on this matter and the correction helped me to display my points through orxOBJECTs.
  • edited January 2015
    saverio, I'm also interested in using the drawing functions at some point. There are currently no examples for drawing lines, circles and beziers in the wiki or forum.

    Would you mind sharing a few examples when you get it going? I notice that the drawing must be done every frame, so it would be nice to see which loop routine you put the redraw into.
  • edited January 2015
    Hi Saverio,

    all the orxDisplay_* API expects coordinates in screen space. If you're using world space coordinates with it, it's unlikely to work!
    Now if you don't want to do the conversion yourself, you can create a dummy orxOBJECT that lives in the world.

    Now, that brings me to Sausage's question. :)

    You can then listen for the orxRENDER_EVENT_OBJECT_START event, when you receive it, all the info you'll need to display this object on screen will be in the payload. You can use those information and add your local bezier values to it to finally draw lines/circles where you want. Here's a very simple example that only uses position of an object and will display a yellow circle underneath.
    Here's the event handler:
    orxSTATUS orxFASTCALL EventHandler(const orxEVENT *_pstEvent)
    {
      if((_pstEvent->eType == orxEVENT_TYPE_RENDER)
      && (_pstEvent->eID == orxRENDER_EVENT_OBJECT_START))
      {
        orxRENDER_EVENT_PAYLOAD *pstPayload;
        orxVECTOR vPos;
    
        pstPayload = (orxRENDER_EVENT_PAYLOAD *)_pstEvent->pstPayload;
        orxVector_Set(&vPos, pstPayload->stObject.pstTransform->fDstX, pstPayload->stObject.pstTransform->fDstY, orxFLOAT_0);
        orxDisplay_DrawCircle(&vPos, 50, orx2RGBA(255, 255, 0, 255), orxTRUE);
      }
    
      return orxSTATUS_SUCCESS;
    }
    

    PS: You need the latest from the source repository for this to compile. I recently renamed the payload, it used to be called orxRENDER_EVENT_OBJECT_PAYLOAD instead and had the pstTransform field directly (not ->stObject.pstTransform).
  • edited January 2015
    Sausage, as a side note, if you want a quick&dirty example of bezier, here's a patch you can apply on the hg repo that contains a quick test I made last year when adding bezier support.

    To try it, start orx (bounce) and press 'T'. https://forum.orx-project.org/uploads/legacy/fbfiles/files/bezier.zip
  • edited January 2015
    Ahh.... that makes total sense now, thank you. I've previously wanted to add debug rectangles around objects and touch zones without using ShowDebug = true (which shows on everything).

    I'll make a routine and post here if anyone is interested.
  • edited January 2015
    iarwain wrote:
    Sausage, as a side note, if you want a quick&dirty example of bezier, here's a patch you can apply on the hg repo that contains a quick test I made last year when adding bezier support.

    To try it, start orx (bounce) and press 'T'. https://forum.orx-project.org/uploads/legacy/fbfiles/files/bezier.zip

    Thanks Iarwain, I'll check this out. I've also had some success creating bezier waves for aliens. Routine is still underway and will publish if anyone wants it. But hadn't tried drawing beziers.
  • edited January 2015
    Thanks to all of you, the example was helpful : my problem was my alpha channel value :pinch:.
    As I get my coordinates with orxMouse_GetPosition(), I'm already in screen space, so no need for conversion.

    I don't mind publishing my code (I have to finish it first ;)). Right now, as my program is doing nothing else than that, I'm calling the orxDisplay_Draw* functions in the update callback of the main clock.
  • edited January 2015
    Oh, I misread, sorry, thought you were using the same coordinates than when displaying it with orxOBJECTs!
    Glad you got it working! :)
  • edited February 2015
    Hi there, Beziers, the return !!

    The first draft is finished. It's very basic : you make a polyline and the Beziers curve is drawn accordingly. The source is fair enough for a tutorial, but needs some work to be used in a bigger project.
    Now, as sausage wanted examples, here is the source. https://forum.orx-project.org/uploads/legacy/fbfiles/files/beziers_curve.zip
  • edited February 2015
    Thanks Saverio.

    If you want to be able to edit the wiki directly, all you need is to register there and let me know so I can give you write access.
  • edited March 2015
    ok, fine with me
Sign In or Register to comment.