• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Vector2.Transform

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Vector2.Transform

    I'm converting some NT7 code to NT8. I'm rendering a polygon on the chart. I define the shape with an array of vector2:

    Code:
                         SharpDX.Vector2[] pointsUpArrow = new SharpDX.Vector2[] {
                            new SharpDX.Vector2 {X=0,Y=0 },
                            new SharpDX.Vector2 {X=8,Y=10},
                            new SharpDX.Vector2 {X=-7,Y=10},
                            new SharpDX.Vector2 {X=0,Y=0}
                         };
    ( In NT7 / GDI this was an array of Point objects )

    I need to move this to the current bar and in some cases rotate it so that it's upside down.
    In GDI this was easy:
    graphics.TranslateTransform( x,y ) would move to the x,y coordinate of the bar ( given x and y )
    graphics.RotateTransform(180) would invert the drawing.

    In DirectX I've been searching the web for hours trying to find and example of how to do this and I can't figure it out. Do you have an example that?
    Example that:
    1. Defines a simple polygon ( a triangle would be fine )
    2. Draws them on each bar
    3. Sometimes inverts them so they're pointing down.

    I believe that the use of SharpDX.Vector2.Transform is what's required but I haven't found an example of how to use this method to achieve it.

    Thank you.

    #2
    Originally posted by Brillo View Post
    I'm converting some NT7 code to NT8. I'm rendering a polygon on the chart. I define the shape with an array of vector2:

    Code:
                         SharpDX.Vector2[] pointsUpArrow = new SharpDX.Vector2[] {
                            new SharpDX.Vector2 {X=0,Y=0 },
                            new SharpDX.Vector2 {X=8,Y=10},
                            new SharpDX.Vector2 {X=-7,Y=10},
                            new SharpDX.Vector2 {X=0,Y=0}
                         };
    ( In NT7 / GDI this was an array of Point objects )

    I need to move this to the current bar and in some cases rotate it so that it's upside down.
    In GDI this was easy:
    graphics.TranslateTransform( x,y ) would move to the x,y coordinate of the bar ( given x and y )
    graphics.RotateTransform(180) would invert the drawing.

    In DirectX I've been searching the web for hours trying to find and example of how to do this and I can't figure it out. Do you have an example that?
    Example that:
    1. Defines a simple polygon ( a triangle would be fine )
    2. Draws them on each bar
    3. Sometimes inverts them so they're pointing down.

    I believe that the use of SharpDX.Vector2.Transform is what's required but I haven't found an example of how to use this method to achieve it.

    Thank you.
    Take a look at the DrawingTools\ChartMarkers

    There is a TriangleBase class we use to render small triangles as chart markers.

    I believe Transform Matrix logic is essentially what you are after.

    Code:
    // the geometry is created with 0,0 as point origin, and pointing UP by default.
    // so translate & rotate as needed
    SharpDX.Matrix3x2 transformMatrix;
    
    if (IsUpTriangle)
        transformMatrix = SharpDX.Matrix3x2.Translation(endVector);
    else
        transformMatrix = SharpDX.Matrix3x2.Rotation(MathHelper.DegreesToRadians(180), SharpDX.Vector2.Zero) * SharpDX.Matrix3x2.Translation(endVector);
    Then you just set the RenderTarget.Transform to the calculated transformMatrix

    You can read more about this concept from the Direct2D API docs: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    Specific information on rotating an object can be found here:

    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    Note that documentation is for the unmanaged API, but SharpDX wrapper namespaces have similar calls as C#/.NET objects
    MatthewNinjaTrader Product Management

    Comment


      #3
      ChartMarker

      I see that the ChartMarker class has some useful support for rendering.

      Instead of rolling all my own Direct2d1 code in my OnRender of my indy I'm thinking of leveraging the ChartMarker class instead. I see that it has it's own OnRender and it's own OnStateChange.

      I've derived my own type of triangle drawing class from this class and provided a way for my indy to specify the existence of each instance, it's location and orientation on the chart.

      My questions are:
      Is this usage supported?
      How should my indy instantiate my ChartMarker instances?
      Can my indy do so in OnBarUpdate or OnMarketData events to add markers to the chart?

      Comment


        #4
        While we do not yet have documentation on a more advanced topic as you are trying to do, it's entirely possible and something we're happy to support and help with.

        All of the info is exposed in the drawing tools class. If you want to make a custom drawing tool which inherits behavior from a default object, that is a great approach extending existing functionality.

        As far as calling this drawing tool object like you do a normal drawing do in an indicators OnBarUpdate() or OnMarketData() method, you simply need to extend the partial Draw class and provide your own method to return the custom object which you can call from the indicator.

        I've attached an example of an indicator which implements both a custom drawing tool derived from the ChartMarkers class, and defines it's own Draw..() method. Then from the indicator class, you can see how to call it.
        Attached Files
        Last edited by NinjaTrader_Matthew; 11-08-2016, 05:03 PM.
        MatthewNinjaTrader Product Management

        Comment


          #5
          I should also mention, the example I provided will work as a manual drawing tool as well, since we derived all base behavior from the chart markers. If you do not want users to access your object from the charts menu for manual drawing, you can set the "DisplayOnChartsMenus" to false during your custom OnStateChange() set defaults.

          http://ninjatrader.com/support/helpG...hartsmenus.htm
          MatthewNinjaTrader Product Management

          Comment


            #6
            Thank you Mathew. Very helpful.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by digibob, 12-13-2019, 10:01 PM
            4 responses
            14 views
            0 likes
            Last Post bltdavid  
            Started by TraderJim618, Today, 11:24 AM
            0 responses
            1 view
            0 likes
            Last Post TraderJim618  
            Started by NT-Roland, Today, 10:03 AM
            1 response
            7 views
            0 likes
            Last Post Lancer
            by Lancer
             
            Started by TraderJim618, 12-07-2019, 01:20 PM
            2 responses
            10 views
            0 likes
            Last Post TraderJim618  
            Started by kevinfloresz, Today, 09:46 AM
            0 responses
            11 views
            0 likes
            Last Post kevinfloresz  
            Working...
            X