Drawing 2D lines or Rectangles


#1

Hello,
I am trying to create a new plugin which I want to be able to draw rectangles on the active viewport. It looks like it could be possible to do it by calculating the positions of lines and drawing them. However if possible I would like to see if their is an easier way of doing it.

I noticed in the rhinocommon gitlab project that their is a commented out definition for draw2dline and Draw2dRectangle, which seem like they would be exactly what I am looking for. So does anyone have any suggestions, or idea if/when those 2 functions would be usable?

edit: I forgot to say this, I am using C# and am trying to do this in a display conduit (which seemed the logical place)


(Steve Baer) #2

Do you want to draw these lines in “screen space” (window coordinates)?


#3

Yes, I have found a way that would possible to do it by drawing to a bitmap then drawing that bitmap onto the scene which will work if need be, if their is an easier/better way of doing it then that would be awesome.


(Steve Baer) #4

I’ll try to make a convenient function for this on the DisplayPileline class in the future, but for now you should be able to get the transform of screen to world from the viewport. Something like the following.

var transform = e.Viewport.GetTransform(CoordinateSystem.Screen, CoordinateSystem.World);
// convert screen points to world.
screen_point1.Transform(transform);
screen_point2.Transform(transform);
e.Display.PushDepthTesting();
e.Display.PushDepthWriting();
e.Display.EnableDepthTesting(false);
e.Display.EnableDepthWriting(false);
e.Display.DrawLine(screen_point1, screen_point2, Color.Red);
e.Display.PopDepthWriting();
e.Display.PopDepthTesting();

#5

Awesome, that looks like it will work exactly how we wanted it and a convenience function would be amazing.

Grant