Vector drawing with floating point coordinates & a zoomable canvas lazarus / 39-Graphics ---------------------------------------------------------------------- trayres · 2015-07-13 20:52 I apologize if this question is overly broad, but I'm trying to piece together what I need and I'm hoping the discussion will help foment ideas to help nail down how to go about this. I'm trying to implement something like a schematic capture system - so I know I need a translation between the world and viewport coordinates and I need a transform matrix to do pan/zoom - the way I had done it before (by scaling up the bitmap on the canvas) wasn't good. So I need to take one of 5 graphics primitives (polygon, rectangle, circle, arc, and text) that is composed of a set of points, compose a class that holds a ragged array of these types that describes what is on the schematic page with methods to set and get collections of items based on if they're within the viewport or not, and then redraw the viewport with all the segments that are contained within the viewport (using something like a Cohen-Southerland algorithm for the polygons and rectangles, and something else to determine clipping for the other items). This will allow me to pan/zoom arbitrarily and will prevent scaling issues. I also have to be able to resize the viewport when the user resizes the form, rather than scaling the bitmap that's within it (otherwise that'd be goofy behavior). So I'm starting to work on this - does anyone have thoughts or input? Am I on the right track, or am I crackers? Thanks all! ---------------------------------------------------------------------- zamtmn · 2015-07-13 21:29 I am also trying to do something like vector editor: http://forum.lazarus.freepascal.org/index.php/topic,16665.0.html also see fpvectorial: http://forum.lazarus.freepascal.org/index.php/board,54.0.html ---------------------------------------------------------------------- taazz · 2015-07-13 21:53 I wouldn't use fpvectorial my self it gives me the filling of a half though solution but it has good functionality build in, any way, there is aggpas that is a renderer written in pascal with sub pixel accuracy and everything, as far as I understand it should be able to support everything you just described easily. ---------------------------------------------------------------------- zamtmn · 2015-07-13 22:37 >>as far as I understand it should be able to support everything you just described easily. easily and beautifully, but unfortunately very slow and not leaving hope for at least some piece hardware acceleration. Generally it is not a rasterizer problem, it is necessary to do so that he could be anything - standart canvas, OpenGL context or aggcanvas. ---------------------------------------------------------------------- Graeme · 2015-07-13 23:11 Take a look at AggPas [https://github.com/graemeg/fpGUI/tree/master/sr c/corelib/render/software]. From what you describe, AggPas already supports a lot of what you need. vector based graphics, floating point coordinates, transform and rotate, viewports, zoom & rotate, sub-pixel accuracy drawing etc. It should be easy to implement what you need with AggPas. Some AggPas docs:   https://github.com/graemeg/fpGUI/tree/master/docs/aggpas ---------------------------------------------------------------------- jmpessoa · 2015-07-13 23:20 You can try: https://github.com/jmpessoa/tfpnoguigraphicsbridge                            + https://github.com/jmpessoa/tfpdxfbridge [real (and floating) world coordinate,  viewport, "dxf" export format, ... ] ---------------------------------------------------------------------- Signal · 2015-07-14 00:06 Would cairo work for you? http://cairographics.org/ There is a cairo wrapper included in https://code.google.com/p/luipack/ ---------------------------------------------------------------------- zamtmn · 2015-07-14 08:26 Quote from: trayres on July 13, 2015, 10:52:12 pmSo I'm starting to work on this - does anyone have thoughts or input? Am I on the right track, or am I crackers? For entirely the right way will be better at once lay spatial indexs and primitives lod (level of detail) features ---------------------------------------------------------------------- circular · 2015-07-14 17:46 With BGRABitmap, you've got Canvas2d property, where you can set a transformation matrix before rendering. Also there is the TBGRAPath object that can contain a shape, and also you can define a transformation. So for example, each object could have its path object, and you could then draw it on Canvas2d. To have a surface on the screen, you can use TBGRAVirtualScreen component. In the OnRedraw event, you can draw the current position by setting the matrix and drawing the shapes. ---------------------------------------------------------------------- trayres · 2015-07-15 05:48 Hi everyone! There are a lot of options and it's taking me some time to digest them all; these are all great references and I thank everyone for their input! I'm looking at OpenGL, but I don't see (any?) modern references to OpenGL for Delphi/Lazarus (everything is for C++), and OpenGL looks very complicated. The Cairo wrapper in luipack looks great - I'll have to check it out more. Sorry it is taking so long to formulate a response, I'm trying to check out each thing in turn.  [Edit]For TCairoPaintBox, is it not normally a part of the standard LCL? I'd like something that was part of the standard LCL because I worry about the component becoming unsupported by the mainline developers. ---------------------------------------------------------------------- trayres · 2015-07-16 20:38 So it looks like I'll be forced to do all the drawing myself - I'm not really sophisticated enough to do OpenGL, so that's out. I need to implement a series of algorithms for transforms of matrices - is there a library that provides this already? Like a Lazarus Math or Lazmath or something that might be useful? Then I need to get the pixel count of the monitor, find the extent of the window, take the user's current schematic size, determine what items are in the window (including those partially occluded) and draw those bits that are not occluded. That's what I've worked out so far; this is so much fun! [EDIT] I bought "Pascal Plus Data Structures" by Nell Dale and Susan C. Lilly - there is some good material in there that will even go into the matrix math I need. I'll post updates as it goes along. ---------------------------------------------------------------------- User137 · 2015-07-20 05:04 I can guide you with OpenGL if that's needed, referring to my nxPascal game engine. https://github.com/Zaflis/nxpascal/blob/master/src/nxGL.pas#L1312 Code: [Select]  glGetIntegerv(GL_VIEWPORT, @pdetails^.viewPort);   glGetDoublev(GL_PROJECTION_MATRIX, @pdetails^.projM);   glGetDoublev(GL_MODELVIEW_MATRIX, @pdetails^.modelM);OpenGL has sets of glGet... and glSet... functions. Those lines work both ways if you want to set matrices. But nxPascal has ready functions you can use to easier set window size and scaling. Quotepixel count of the monitorScreen.Width and Height. Quotefind the extent of the windowForm1.Width and .Height Quotealgorithms for transforms of matricesYeah there are many functions for matrices: https://github.com/Zaflis/nxpascal/blob/master/src/nxMath3D.pas#L843 Lastly, to draw a single triangle with OpenGL you can do it with: Code: [Select]glBegin(GL_TRIANGLE); glVertex3f(10, 0, 0); // top glVertex3f(0, 20, 0); // bottom left glVertex3f(20, 20, 0); // bottom right glEnd; ---------------------------------------------------------------------- zamtmn · 2015-07-20 07:39 trayres You offered a lot of options. I think it would be better to join one of them and not to duplicate work. Although Yes, it's fun))