Adam's Lair Forum

Vector Graphics
Page 1 of 1

Author:  Conundrum [ 2018/01/24, 04:21 ]
Post subject:  Vector Graphics

Hi, I'm new here.

Which of the draw functions is used for drawing lines point to point? I am not familiar with some of the jargon terms in the .Drawing documentation.

Am I correct in assuming a vertex is equivalent to a point in 3d space that will not render without an array of three or more organized perpendicular to the camera object? If so, how would I draw a line between two points?

God, these are dumb questions, but I'm stumped when I look at the current documentation.

I'm just wanting to draw simple geometric shapes using vector graphics (sprites will be unsuitable due to scaling issues). I want to achieve this by handing duality vector matrices. (This is not trivial given my current experience.)

Also, thank you for your patience.

Author:  SirePi [ 2018/01/24, 08:33 ]
Post subject:  Re: Vector Graphics

Hi there, and welcome :mrgreen:

The answer to your question could vary greatly, depending on the amount of things you want to draw and the performances you need.

For starters, your custom Components will have to implement ICmpRenderer and provide their own drawing methods.
Second, you might want to try drawing with Canvas, which is a utility (?) object that lets you draw directly with basic primitives, such as Lines, Circles, Points, etc.. without worrying about vertices and such (there is also a DrawVertices method, but let's ignore it for now); Canvas is not the best way to do it, peformance-wise, but it's by far the easiest (and it will take you up to some hundreds or thousands of objects on screen before you can notice a performance difference with other drawing methods).

Something like this should put you in the right direction
public class MyComponent : Component, ICmpRenderer
   private CanvasBuffer _canvasBuffer; // use a CanvasBuffer for less memory and GC impact
   void ICmpRenderer.Draw(IDrawDevice device)
      if (_canvasBuffer == null)
         _canvasBuffer = new CanvasBuffer();

      Canvas canvas = new Canvas(device, _canvasBuffer);
      ... // your drawing code here

Good luck :D

Author:  Conundrum [ 2018/01/24, 09:21 ]
Post subject:  Re: Vector Graphics

Thank you, SirePi.

The Canvas object seems perfect for my purposes (and current understanding). I really appreciate the sample code you've offered.

I'll see how much I can do with this method. :D

Author:  Conundrum [ 2018/01/25, 03:39 ]
Post subject:  Re: Vector Graphics

EDIT: Is there somewhere that offers a rundown on the render pipeline in this framework? Because I have some questions.

Why do I need a "bound radius"? What does it do? Where should I set it? When? How?

What am I supposed to do with the IsVisible method?

Obviously these questions are granular and the answers will vary depending on "What I want to do with them." I would rather read what it is and what it is for somewhere and not bother present company with an endless array of simple questions. The docs may suit someone who is familiar with common rendering conventions, but they are opaque to me.

Ignore the following I have solved the errors in a non-functional manner:

I'm having difficulty understanding the appropriate management of the ICmpRenderer interface. While the code SirePi has offered supplies the ICmpRenderer.Draw method, the other members are not implementable in any obvious sense (I am likely making a set of incorrect assumptions).

I've tried several approaches to solving the problem without luck. I understand that I need to define both the .IsVisible and .BoundRadius members. But I don't know how to address them correctly. (I've not dealt with interfaces before, though I have a basic understanding that they are similar to a class or... Something.) The syntax I have tried isn't solving the problem.

public class MyClass : Component, ICmpRenderer
       MyClass.BoundRadius = ///some float/single

I must be misunderstanding the C# syntax here. Do I need to use a method to implement this interface? I've tried a few times to do this something like:

     void ICmpRenderer.BoundRadius()
     { ///I can't figure out what would be here.}
    float ICmpRenderer.BoundRadius = ///some float;

I am clueless what I ought to be doing here. The docs don't describe the function of Bound.Radius, but it is required for... something. More or less irrelevant until I can get the code in a state that can be run.

Any suggestions or direct answers would be appreciated.

Author:  SirePi [ 2018/01/25, 10:07 ]
Post subject:  Re: Vector Graphics

I'll try to answer as best as I can, but unfortunately I can't give you an exact rundown, as I mostly program by instinct as well :D

Conundrum wrote:
Why do I need a "bound radius"? What does it do? Where should I set it? When? How?

The BoundRadius is used by the engine to get a rough estimate of how much space your ICmpRenderer is going to take on screen, in order to decide if it actually should be drawn or now (if it appears to be completely out of screen, it won't be drawn)

Conundrum wrote:
What am I supposed to do with the IsVisible method?

IsVisible is used to determine if your ICmpRenderer is actually visible in the current drawing pass; by default there are 30 VisibilityGroups on both Scene and Overlay space. You should return true or false based on the visibility condition you want to implement (for example, if you were to always return true you would get your component drawn twice, once on Scene and once in Overlay).
To better understand this, you should probably take a peek at the Renderer.cs class in the source code.

If you still need help, just ask (see you are on discord as well, just ping @Adam for emergencies and tell him I sent you :mrgreen: )

Author:  RollerJesus [ 2018/01/25, 20:47 ]
Post subject:  Re: Vector Graphics

This link is super helpful in understanding the rendering pipeline.

Regarding bound radius, what SirePi said is accurate but it also seems to be used to draw the circle around the object when in the editor. When I've calculated them, I figured out a bounding box of my component, then calculated the hypotenuse of the bounding box so the circle completely encapsulates my component.

For IsVisible, I believe this is a supplement to the culling (set by the view plane distance) done by the camera (I believe) so you can override and force it to be visible or not.

Author:  Conundrum [ 2018/01/26, 03:42 ]
Post subject:  Re: Vector Graphics

Thanks a bunch, guys. Great link and explanations here!

Let's see what I can do with it...

Author:  RollerJesus [ 2018/01/26, 18:18 ]
Post subject:  Re: Vector Graphics

Post back when you can - I'm also interested in vector graphics for both debugging (which I think it pretty good already) but also in combination with shaders for actual game content.

Page 1 of 1 All times are UTC + 1 hour [ DST ]
Powered by phpBB® Forum Software © phpBB Group