2D diagram

Started by
1 comment, last by Wyrframe 14 years, 3 months ago
I'm not developing a game, but I haven't been able to get a satisfactory answer elsewhere and I figure this is where the graphics experts are. I need to display a large number (thousands or tens of thousands) of points in 2D space with lines connecting pairs of points. The user needs to be able to zoom (preferably "infinitely"), with the points behaving dimensionlessly and the lines behaving one-dimensionally (i.e. zooming in, the ellipses representing points get farther apart but don't get bigger, and the lines get longer but not thicker). The user also needs to be able to scroll. I tried doing this in GDI+ (iterating through a linked list of ellipses, drawing one at a time) but it was way too slow. You'd have to wait for several seconds for all the points to reload after clicking a scroll button. Drawing to bitmaps first, then displaying a bitmap solves the laggy scrolling problem but makes zooming tedious and only allows a fixed number of zoom levels. I'm guessing OpenGL or DirectX is needed. Can someone point me towards the right API and techniques? How are these problems solved in CAD or GIS applications? Are there any relevant books? The next thing I'm planning to try is OpenGL with Qt, if anyone can comment on that. Thanks a lot for your help.
Advertisement

(thousands or tens of thousands) is n't a big number for 3D rendering, but OpenGL doesnot support 2D rendering originally. If you are sticked to OGL, you can try to extend any of the open src 3D engines. It would take several thousands of lines.

With Win Vista/7, maybe You can try the Direct2D. I just read a little of that. It's easy to use and should be of high performance.
---Mellow Yuemellow.yue@gmail.com
You need to re-think things just a bit. You need two things to do this efficiently; a spatial partitioning system, and a view-oriented rendering system instead of a world-oriented one.

First look up "quadtree". You want to put your points and lines into the quadtree, and when you render an area from the tree you want to query the tree for all points and lines that intersect with the view rectangle. This is very fast because of how a quadtree works; you only draw those lines and points that are going to be visible (more or less).

Second, once you have that information, you know the exact screen-space dimensions you want your points and lines to have, so just render them that way. Don't think of them being of a certain size in world-space; this is in fact probably exactly what you're doing right now, you just haven't noticed that zooming to any scale except 1:1 will produce separate view, screen, and world spaces, where you currently seem to be thinking in only world space.


Edit: Oh, and also; linked lists are generally for data sets that need frequent add/remove operations at arbitrary locations, but get fully iterated or searched only infrequently. Try using vectors or other dynamic-sizing array replacements.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

This topic is closed to new replies.

Advertisement