Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Use Inkscape to make Box2d world

Author
Message
Ranietz
AGK Gold Backer
21
Years of Service
User Offline
Joined: 2nd Sep 2004
Location: Norway
Posted: 6th Jul 2011 00:43 Edited at: 6th Jul 2011 01:10
Hi

I'm writing a program so I can draw shapes in Inkscape and import the svg file into DBPro and use the data to make a Box2d world.

So far I can draw rectangles, circles and straight paths (no bezier curves). Closed paths with 8 or less nodes will be turned into a polygon. I use two layers in Inkscape called "LayerStatic" and "LayerDynamic". The rest of the layers will be ignored.

Here's the code. It's not too well commented and I'm sure there are some bugs in there.



I've also attached a svg file for you to try out. Hopefully someone will find this useful.

Feel free to comment, modify and expand the code.

Additional info:
-The svg file must be saved as an Inkscape svg file. I don't know how well it handles other types of svg files.
-In Inkscape preferences -> SVG Output: uncheck "Allow relative coordinates" and "Force repeat commands"
-Rectangles, circles and paths can be moved, duplicated and resized but not rotated.
-Nodes can be added and removed from a path. Just make sure you make the path straight afterwards by making the nodes into corners.
-Ungroup all objects before you save the file.
-You don't have to snap the nodes to a grid set to pixels but I find it's easier to work that way.
-Box2d and Matrix1 plugins required.
Wilf
Valued Member
20
Years of Service
User Offline
Joined: 1st Jun 2006
Location: Gone to Unity.
Posted: 6th Jul 2011 10:56
Awesome, I'll check this out tonight.
Bencito
14
Years of Service
User Offline
Joined: 15th Oct 2011
Location:
Posted: 16th Oct 2011 01:03
I wrote a script which supports affine transformations and quadratic benzier curves if you're interested http://www.deluge.co/?q=node/2

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 16th Oct 2011 02:46 Edited at: 16th Oct 2011 02:49
@Bencito - http://gmt.soest.hawaii.edu/gmt/README.TRIANGLE

There's also a download for the algorithm around the web which I'm using myself. It's hard to find the algorithm now on google for the algorithm called "triangle", but it is very very handy...

EDIT I love the site though. Very thorough...

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-10 16:57:46
Your offset time is: 2026-07-10 16:57:46