My little sandbox app

Almost there. Just gotta do some tweaking, and currently I'm having some trouble where whenever I run the debug build, no small triangles ever get created. I'm certain that most of them are large enough to not cause any assertions.

In any case, here's a teaser:

Image

I notice no lag with collisions at first but after the meshes get pretty complicated my method runs pretty slow. There is a LOT of room for optimization.

I am pretty surprised that this scene in the screenshot runs at 30 frames per second, it's got to have about 1000 objects...
That motion blur looks awesome, too bad it runs at 4 fps on my laptop =) Im not even going to comment on the subdivision and breaking since its way out of my league.
I'm guessing that you're on some type of intel integrated graphics. the way I did the motion blur, it simply draws the entire scene as many times as there are blur samples, so if you set it to 8 samples, you can fully expect the framerate to decrease eight-fold.

Useful and very neat looking if you're running some serious graphics hardware but a faster method will be necessary for the majority of computers. the effect does help when physics starts running slow and choppy, but since a slow cpu is likely to also be paired with a slow GPU, there's no point in me relying on the heavily fillrate-expensive motion blur to help make it look better, as chances are it'd make things even slower...

A thanks to kdmiller3 who first did the motionblur in this fashion and showed me how it was done. 😁

I'm curious as to how the integrated (intel etc) video cards handle non-blurred effects. Could you run v0.23 and see if it runs well? Pretty sure I don't have it enabled there.
the laptops video chipset is this, 2gig ram, 1.86ghz centrino. Havent tried it with v0.23. But i tried it on another random computer (P4 2.4ghz, some old matrox card i believe), the blurred version ran at sub 1 fps! =) And v0.23 ran smooth as silk, but theres no framerate counter.
The engine should run fine with the basics (no multisampling no blur) on ancient hardware (pre P4 and any random 64+mb videocard). I have no idea how something like a TNT2 or ATi Rage will handle it, but really, if you have one of those, just toss it out the window. 😆
Hi DC443

I wasn't very interested by convex objects since I saw your sandbox.
This is really awesome how good the decomposition is processing !

Breaking object is also very neat and inspire a lot 🙂

Unfortunately I'm using a wrapped version of Box2d with BlitzMax so I probably won't be able to add specific functions and methods of your Delaunay decomposition tool.

  • In older post you had in mind to add saving/loading "decomposed" objects to your sandbox.
    Using your sandbox as a convex editor would be very useful until the official Box2d 2.5 "Convex decomposition" routine.
    A customisable Grid with snapping would be a nice addition too.
    What's your plan about that "editor" ?
  • Would it be possible to reorganise your code as a clean Add-on to Box2d so we could easily extend the API of all Box2d ports ? A bit like what we can see in the Contrib SVN about ewjordan ConvexDecomposition.
    I don't have currently a global view of your Delaunay Decomposition to know every essential functions (like "convexDecomp").

Thanks for any help on this 🙂
I'm not sure how to make a patch to add the functionality, but I can probably provide some code to add on to ewjordan's b2polygon and b2triangle code, that will perform my convex decomposition method... However i can't say that it would be my main priority because I have to put as much of my motivation into working on game design as I can otherwise my project will begin to stagnate.

All of the code that does it is on my sourceforge SVN, i believe the SVN source at the moment reflects the v0.25 build that I have uploaded there. Basically what you are looking at are the convexDecomp(b2vec2* vertices, num_verts, shapedef, bodydef) function, which will rely on the code in DelaunayTriangulation, which is a rip from some Code by Paul Bourke I pulled from his site. Aside from the Delaunay Triangulator, I use ewjordan's b2Polygon and b2Triangle "toolkit" a lot, but you'll notice that the version of it that I have in my source is not his latest bit of code on the box2d svn (it differs by minor details -- it should not be hard to get it to fit but I cannot guarantee anything).

I am reluctant to call this a good solution because it is quite inferior to a real Constrained Delaunay Triangulation algorithm because currently I perform a regular DT and then slice up any triangles lying in the way of an edge. This can add quite a bit of overhead and cause lots of unnecessary slowdown on certain (ugly looking) shapes. However for any shapes in which all of the edges are included in the triangulation, it's about as good as I can do because I have no idea how to improve the "polygonizeTriangles()" method which takes triangles and merges them into convex polygons. It is currently somewhat slow and not optimal but I have not made and will not make any attepts to figure out how it functions. 😆
Quote:
In older post you had in mind to add saving/loading "decomposed" objects to your sandbox.
Using your sandbox as a convex editor would be very useful until the official Box2d 2.5 "Convex decomposition" routine.
A customisable Grid with snapping would be a nice addition too.
What's your plan about that "editor" ?


I'm actually not sure exactly what I had in mind but it's useful to save decomposed objects by storing their decomposed state so it does not have to be recalculated. It would just be a two-dimensional array (I would almost certainly just use a std::vector<std::vector< b2Vec2 > > for something like this) and a simple loop to put that data into a box2d body. This seems to me like something that the game designer has to take care of himself.

If you are talking about retrieving a convex decomposition of a shape that you want to export and use in your own program, etc, i'm surprised that there arent other, better tools out there that'll crank out a decomposition, since what I have here is just a quick-and-dirty, as fast as possible method. Put a couple printlines into the code?

Im pretty certain that my grid is in there and is adjustable, use the plus and minus numpad keys.

The editor was just something I threw together to draw polygons with. It would eventually merge into whatever my level editor would become although I am not sure if my game will have a need for (or even freely allow) lots of free-form concave shapes. I really have no plans to make some elaborate interface for the polygon drawing. The error checking is a little complex though, however this is partly because of the way I made holes and the main shape separate (which really only served to complicate things.. since it relaly doesnt matter which particular shape is the red one). In any case you are free to steal that code... Its in tool.h...
Thanks for the fast answer 🙂

I didn't think about looking after creation tool for convex decomposition but it's a good idea.

It's not a priority for me, so I will probably wait a bit and finish my current project too.
Making shapes by hand for stuff that's not dynamic is probably a good idea because you've got more control. For example if you wanted an X-shape you'd use two rectangles that cross, thats 2 shapes, but a convex decomposition will make at least 3 rectangles. Although for the first case, using SetMassFromShapes() will double-count the cross-over area for setting the mass and inertia, but that's not a big deal.

Original thread: https://box2d.org/forum/viewtopic.php?t=975