Author Topic: About Darwinbots3  (Read 6056 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7704
    • View Profile
Re: About Darwinbots3
« Reply #15 on: April 06, 2015, 05:16:17 PM »
Actually transferring only changes in general is something Blacklight could use.  For the native DirectX visualizer it gets tricky because after a certain point just grabbing all the scene data and redrawing it is preferable because you can do a memcpy from the sim data to the DirectX buffers instead of hopping around updating things, but having the option and doing the perf comparison probably isn't a bad idea.

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: About Darwinbots3
« Reply #16 on: April 08, 2015, 04:18:02 PM »
For the actual drawable objects all I need is the DrawPrimitive and AffineMatrix(from EnqueueDrawable), correct?
In affineMatrix I see 6 Scalars or 3 Vectors. How to draw a circle or rectangle from it? I tried to extract it from it's being used in the DX version, but that didn't make it more clear for me.

Basically a ellipse got the following tags in svg. How would it match with the objects going in?
cx x-pos
cy y-pos
rx x-size
ry y-size
size

A rectangle
width
height
x x-pos
y y-pos

A polygon
A list of points
Oh my god, who the hell cares.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7704
    • View Profile
Re: About Darwinbots3
« Reply #17 on: April 08, 2015, 05:09:13 PM »
For the actual drawable objects all I need is the DrawPrimitive and AffineMatrix(from EnqueueDrawable), correct?

Looking through the code I think the easiest thing to do is subclass Blacklight.Core.WindowHandle.  There's a few abstracts to implement.  Among them is an overload of EnqueueDrawable that takes in the primitive and transform.  The transform it gives you includes all the baking from different levels of the hierarchy.  Blacklight.SharpDX9 isn't all that readable (interfacing with GPUs just seems to breed ugly code) but it should give you an idea about how the WindowHandle is set up there.  You'd also want to subclass Blacklight.Core.IModule.  Note that it gets passed in a raw win32 pointer to a window, which is how DirectX works.  That's mostly moot for what you're trying to do.  I'm not sure exactly the best way to approach this, but it's mostly an architectural question so we can probably ignore it right now.

If you're trying to send the draw commands to a browser over http, say, your WindowHandle might just bake the drawables in to XML and put it somewhere (memory or disk) for a http server to serve.  And the way it's set up right now is very much based on how DirectX/OpenGL group similar commands in to "draw calls".  Most of that is just overhead if you're working with SVG.  So feel free to bend the code to work in a way that makes sense for SVG and we can try and figure out a better way later.  But I'd still consider working through the WindowHandle interface if it's even a little reasonable, as it's doing all the work around keeping things consistent for you.

Quote
In affineMatrix I see 6 Scalars or 3 Vectors. How to draw a circle or rectangle from it? I tried to extract it from it's being used in the DX version, but that didn't make it more clear for me.

It's an Affine transformation matrix.  There's an implicit row at the bottom with [0 0 1].  Position vectors are assumed to have an implicit 1 at the end [x y 1] and direction vectors are assumed to have an implicit 0 at the end (x y 0).  The rules are a bit weird but it means you can combine two transformations (translations + orientations) using just matrix math.

SVG has this capability built in I believe.  Which is obviously very nice for us :)  See TransformAttribute.

Quote
Basically a ellipse got the following tags in svg. How would it match with the objects going in?
cx x-pos
cy y-pos
rx x-size
ry y-size
size

If your browser works correctly I think you can just draw it as a circle and the skewing/stretching will happen as part of the affine transformation.  That said I had some difficulty getting that working when I played with it last (again, different browsers are better about this than others).

Otherwise you can extract out the ellipse from the transformed circle.  I have to do this for the shader code for SharpDX9.  Basically you can take a singular value decomposition of the 2x2 matrix (that is, drop the third column from the affine transform) to turn it in to rotation * scale * rotation.  Since circles are radially symmetrical you can drop the last rotation.  The scale gives you the x/y scale of the circle, which turns it in to an ellipse.  Then the rotation puts it in the right orientation.

See Main.fx and MatrixDecomposition.fx and search for SVD.

...

For polygons, it's a little conceptually tricky.  Basically polygons in Blacklight are drawn with some uniform thickness border.  To make drawing this easier, polygons are decomposed into a collection of monotone polygons, each of which has exactly one of the original edges of the original polygon.  These are the BorderPolygons.  When you draw them, you want one half of them to be the interior color and the other half to be the exterior color, based on the distance of the pixel from the border.  Or just ignore it entirely (probably reasonable for now).  Either way they store a triangular decomposition, so you can draw them as triangles.

If you think it'd be better to spit out the raw polygon points, we'll need to rearchitect things in Blacklight.Core/Drawables/Polygon, as right now the Polygon builds the BorderPolygons which build the BorderTriangles, and all the intermediaries are discarded.
« Last Edit: April 08, 2015, 06:04:20 PM by Numsgil »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7704
    • View Profile
Re: About Darwinbots3
« Reply #18 on: April 08, 2015, 06:06:31 PM »
Looking/thinking about it more maybe going through WindowHandle is overkill and you can just write something to take in a Scene and spit out the XML/SVG.  I'm pretty sure SVG can handle nested transforms, which is most of the reason WindowHandle can't just take the raw primitives in.  Is there an equivalent in SVG to Collages and Cels and the like?

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: About Darwinbots3
« Reply #19 on: April 09, 2015, 03:12:36 AM »
Oh my god, who the hell cares.

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: About Darwinbots3
« Reply #20 on: April 09, 2015, 04:46:08 PM »
Silly issue. The svg I generate is upside down mirrored when I compare it with the dx9 version. I'm likely switching some parameters around, but I don't know which ones.

With the w3c link.
W3C says: matrix(<a> <b> <c> <d> <e> <f>)
I'm using : matrix(M00,M10,M01,M11,M02,M12)

edit: added dx9.png
« Last Edit: April 09, 2015, 04:49:17 PM by Peter »
Oh my god, who the hell cares.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7704
    • View Profile
Re: About Darwinbots3
« Reply #21 on: April 09, 2015, 04:50:41 PM »
Do you know what "quadrant" SVG draws in?  That is, which corner of the screen is the origin in?  Or is it in the middle?  GPUs draw in the 4th quadrant, so the origin is the top left of the screen and increasing values of y go down (increasing values of x go to the right).  That's either how Blacklight works or I switched it to use the 1st quadrant so the origin is in the bottom left.  I don't remember which.

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: About Darwinbots3
« Reply #22 on: April 09, 2015, 04:56:08 PM »
I don't have a clue, google search seem to point to top left.

Numbering goes up down and to the right anyway. Top left are the lowest coordinates.
« Last Edit: April 09, 2015, 04:58:48 PM by Peter »
Oh my god, who the hell cares.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7704
    • View Profile
Re: About Darwinbots3
« Reply #23 on: April 09, 2015, 06:44:58 PM »
My math might be screwy in Blacklight, I'm not sure.

I'm guessing you're not going through the camera/viewport classes at all?  You might take a look at how they do their transformations.  eg: viewport.cs.  Basically a viewport is a mapping between the rectangle on the screen measured in pixels and some generic "clip space", which is normalized.  Camera handles the mapping between world and viewport.

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: About Darwinbots3
« Reply #24 on: April 11, 2015, 01:24:00 PM »
I did a scale(1,-1) on all objects and that seemed to put it back into perspective, didn't (yet) find where to extract it the proper transformation from. :x

Is there some kind of unique identifier for the objects? As to be able to 'follow' movements for objects, know that this rectangle drawn is the same as the rectangle in a previous frame, but at a different location/angle.
Oh my god, who the hell cares.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7704
    • View Profile
Re: About Darwinbots3
« Reply #25 on: April 11, 2015, 02:53:53 PM »
There's nothing right now.  I thought about it a couple times but I could never decide if it was a good idea to add.  For DirectX you're not necessarily better off updating existing things over just pushing an entire new array, and usually you're more interested in updating a spatial section of the scene that the user can see than updating entities 2, 4, 7, and 9, say.

And you'd probably want to have the unique identifier you're using encode the hierarchy of scene->cel->collage->collage->collage->...->entity in some way.  At the simplest we could encode it in a string so each scene, cel, collage and entity had a unique name and the final entity's pedigree name would be like "scene1.background.tree47.branch12.leaf6.triangle39" or something like that.

Maybe the hierarchy only goes down to the first collage.  The collages are supposed to represent things that basically don't move relative to each other, so assuming anything downwards from the collage has the same relative transform it had the frame before is probably fair.

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: About Darwinbots3
« Reply #26 on: April 12, 2015, 11:06:50 AM »
Updating existing things seems necessary. I'm animating the slipstream testbed a few seconds and I'm up to a few MB. :wacko:
Normally it doesn't do any updates between cycles, does it?

Also, svg doesn't seem to want to take affine matrix into animations. Is there a method to calculate the angle/scaling I'm overlooking?
Oh my god, who the hell cares.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7704
    • View Profile
Re: About Darwinbots3
« Reply #27 on: April 12, 2015, 04:56:26 PM »
Updating existing things seems necessary. I'm animating the slipstream testbed a few seconds and I'm up to a few MB. :wacko:
Normally it doesn't do any updates between cycles, does it?

It resends everything every time the viewport gets invalidated.  I don't remember if there's a timer that forces it to draw at 60 FPS but certainly everytime you drag the display or zoom in/out it redraws.

Quote
Also, svg doesn't seem to want to take affine matrix into animations. Is there a method to calculate the angle/scaling I'm overlooking?

Isn't there an <animatetransform> tag?

If you have to you can extract the scale, rotation, skew and translation from an affine transformation, you'll need to SVD decompose the first two columns like I was mentioning before.  The translation is just the last column, though, so that part's easy :)

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: About Darwinbots3
« Reply #28 on: April 13, 2015, 04:42:09 AM »
Updating existing things seems necessary. I'm animating the slipstream testbed a few seconds and I'm up to a few MB. :wacko:
Normally it doesn't do any updates between cycles, does it?

It resends everything every time the viewport gets invalidated.  I don't remember if there's a timer that forces it to draw at 60 FPS but certainly everytime you drag the display or zoom in/out it redraws.
It would send the same basic drawings then? Just to be certain. There isn't something that calculates what's between 2 frames and draws that. It just draws the situation of a frame. If 60FPS is on, it may draw exactly the same multiple times.

I'm asking because SVG does intermediates itself. I don't think intermediate calculating happens currently, I just want to make sure.

Also, svg doesn't seem to want to take affine matrix into animations. Is there a method to calculate the angle/scaling I'm overlooking?

Isn't there an <animatetransform> tag?

If you have to you can extract the scale, rotation, skew and translation from an affine transformation, you'll need to SVD decompose the first two columns like I was mentioning before.  The translation is just the last column, though, so that part's easy :)
<animatetransform> doesn't want a affine matrix, but scale, rotation, translation and skew. :(

I'll take a good look at the .fx files you linked. I already had the translation, that was the one where I was quite confident I was going to implement it correct.
« Last Edit: April 13, 2015, 04:45:49 AM by Peter »
Oh my god, who the hell cares.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7704
    • View Profile
Re: About Darwinbots3
« Reply #29 on: April 13, 2015, 12:21:20 PM »
Updating existing things seems necessary. I'm animating the slipstream testbed a few seconds and I'm up to a few MB. :wacko:
Normally it doesn't do any updates between cycles, does it?

It resends everything every time the viewport gets invalidated.  I don't remember if there's a timer that forces it to draw at 60 FPS but certainly everytime you drag the display or zoom in/out it redraws.
It would send the same basic drawings then? Just to be certain. There isn't something that calculates what's between 2 frames and draws that. It just draws the situation of a frame. If 60FPS is on, it may draw exactly the same multiple times.

It sends the same thing, yeah.  If it's humming along at 60 FPS it just sends through the current transform of everything 60 times a second, changed or not.