Adam's Lair Forum

game development and casual madness
It is currently 2018/05/23, 09:13

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Vector Graphics
PostPosted: 2018/01/24, 04:21 
Newbie
Newbie

Joined: 2018/01/23, 04:09
Posts: 4
Location: New Zealand
Role: Hobbyist
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.

_________________
I am certain to be wrong. I will try to make this less true as a function of time.


Top
 Profile  
 
 Post subject: Re: Vector Graphics
PostPosted: 2018/01/24, 08:33 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 860
Location: Italy
Role: Hobbyist
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
Code:
public class MyComponent : Component, ICmpRenderer
{
   [DontSerialize]
   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
      c.DrawLine(...)
      c.DrawCircle(...);
   }
}


Good luck :D

_________________
Come on Duality's Discord channel. We have cookies! :mrgreen:


Top
 Profile  
 
 Post subject: Re: Vector Graphics
PostPosted: 2018/01/24, 09:21 
Newbie
Newbie

Joined: 2018/01/23, 04:09
Posts: 4
Location: New Zealand
Role: Hobbyist
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

_________________
I am certain to be wrong. I will try to make this less true as a function of time.


Top
 Profile  
 
 Post subject: Re: Vector Graphics
PostPosted: 2018/01/25, 03:39 
Newbie
Newbie

Joined: 2018/01/23, 04:09
Posts: 4
Location: New Zealand
Role: Hobbyist
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:
END

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.

Code:
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:

Code:
     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.

_________________
I am certain to be wrong. I will try to make this less true as a function of time.


Top
 Profile  
 
 Post subject: Re: Vector Graphics
PostPosted: 2018/01/25, 10:07 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 860
Location: Italy
Role: Hobbyist
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: )

_________________
Come on Duality's Discord channel. We have cookies! :mrgreen:


Top
 Profile  
 
 Post subject: Re: Vector Graphics
PostPosted: 2018/01/25, 20:47 
Member
Member

Joined: 2016/08/03, 22:07
Posts: 52
Location: Florida
Role: Hobbyist
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.


Top
 Profile  
 
 Post subject: Re: Vector Graphics
PostPosted: 2018/01/26, 03:42 
Newbie
Newbie

Joined: 2018/01/23, 04:09
Posts: 4
Location: New Zealand
Role: Hobbyist
Thanks a bunch, guys. Great link and explanations here!

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

_________________
I am certain to be wrong. I will try to make this less true as a function of time.


Top
 Profile  
 
 Post subject: Re: Vector Graphics
PostPosted: 2018/01/26, 18:18 
Member
Member

Joined: 2016/08/03, 22:07
Posts: 52
Location: Florida
Role: Hobbyist
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group