Code center > Darwinbots3

About Darwinbots3

<< < (4/10) > >>

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

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

Numsgil:

--- Quote from: Peter on April 08, 2015, 04:18:02 PM ---For the actual drawable objects all I need is the DrawPrimitive and AffineMatrix(from EnqueueDrawable), correct?

--- End quote ---

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.

--- End quote ---

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

--- End quote ---

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.

Numsgil:
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?

Peter:
I think the g element gets close. https://developer.mozilla.org/en-US/docs/Web/SVG/Element/g

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version