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.

Program Announcements / Box2D Wrapper V2.0.0 - 2D Physics engine with CCD

Author
Message
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th Mar 2008 21:58 Edited at: 29th Jun 2010 17:13
EDIT:
Box2D v2.1.2 released!

---------
~~ OLD ~~
---------

See latest post for details.

UPDATED 14 APRIL 09
After a week of hard work, I've finally (I think) finished wrapping v2.0.0 of Box2D for DBP It has a total of ~400 functions, (as large as Dark Physics!)

edit:
I have now fixed a few bugs which Xlaydos pointed out

Here is a very simple test program to show how it works:


As you can see, there are a number of different ways you can create bodies. If you don't need to set much information about them, the simplest way to create a dynamic box is this:


That will firstly create a dynamic body at location (0,0) with an angle of 0. Then it will add a box shape to that body with a width of 1, a height of 1, a density of 1, a friction of 0.5, and a restitution of 1. Finally, it will recalculate the mass of the body. You must do this whenever you finish adding/removing shapes on a body!

Here is a NEW wiki for the plugin! The help files redirect to files on the wiki, so you can now edit and view pages from within the IDE

Before adding a new page documenting a command, please look at some existing pages to see how they are laid out, both for functions, and commands.

The plugin uses these units:
Distance: Meters
Angles: Radians
Forces: Newtons (kg.m/s²)
Mass: Kilograms
Density: kg/m²
Time: Seconds
Torque: Newton Meters (N.m)
Speed: m/s
Acceleration: m/s²

NeX the Fairly Fast Ferret
14
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 16th Mar 2008 23:13 Edited at: 16th Mar 2008 23:18
Does it still have unit conversion? Most, if not all of the commands have changed names. I'm having to go through my entire 5,000 line engine, correcting it bit by bit.


I fail at life. No, really.
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th Mar 2008 23:30
Sorry v2 of the engine has changed so much that I had to completely rewrite it all. Also, these names are more regular than the others... It doesn't currently have unit conversion, mainly because people were using pixel units, which although scaled down to meters, meant that things such as forces, etc. were too huge to be accurately represented by floats.

NeX the Fairly Fast Ferret
14
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 16th Mar 2008 23:32 Edited at: 16th Mar 2008 23:34
Are the angles still in radians? I think I might just stick to the old one - CCD is certainly tempting, but not enough to make me want to relearn the physics engine and spend maybe a week recoding.


I fail at life. No, really.
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 16th Mar 2008 23:40
What if I add an option to use change the units?

It can't be that difficult to swap over...

NeX the Fairly Fast Ferret
14
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 16th Mar 2008 23:46 Edited at: 16th Mar 2008 23:47
It is when you were using all of the shortcut functions that no longer exist. I wasn't messing around with templates, etc. This newer version looks to be quite neat, though. Thanks for making this fantastic DLL, and its ancestry.


I fail at life. No, really.
Darth Vader
14
Years of Service
User Offline
Joined: 10th May 2005
Location: Adelaide SA, I am the only DB user here!
Posted: 17th Mar 2008 01:41
How well can this do car physics? Or is that dependant on the programmer?


Freddix
AGK Developer
16
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 17th Mar 2008 10:08
Hi,

Happy to see the new release of your plugin
The only problem is that it come with no samples ...
Only the DLL and the KEYWORD.

Will you make a package containing samples ?

Regards,
Fred
Odyssey-Creators.

Gandalf said: "All we have to decide is what to do with the time that is given to us"
Odyssey-Creators - X-Quad Editor - 3DMapEditor
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 17th Mar 2008 18:41 Edited at: 17th Mar 2008 18:42
I hope to add this to the wiki
Here is what I have so far.

Nack
16
Years of Service
User Offline
Joined: 29th Jul 2003
Location:
Posted: 21st Mar 2008 03:29 Edited at: 21st Mar 2008 03:33
hey Diggsey
Great plugin! Congratz on the wrapper! Inspirational haha
I am currently wrapping this too to another language =D

I want to ask you a question thoughhh...
I presume this is you ^^
http://www.box2d.org/forum/viewtopic.php?f=4&t=27

What did you end up doing to fix your first problem?? the LNK2019 thingy...

Nack


Nream is DONE! 3D Adventure Maker
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Mar 2008 11:54
If you have Box2D in the same solution, just go into the project dependencies for you project, and set it to depend upon the Box2 project.

If they are not in the same solution, add box2d.lib to the linker input (project properties -> linker -> input) for release mode, and box2d_d.lib for debug mode. Make sure the additional library directories contains the 'Box2D\Library' folder, and the additional include directories contains the 'Box2D\Include' folder

Nack
16
Years of Service
User Offline
Joined: 29th Jul 2003
Location:
Posted: 21st Mar 2008 18:06 Edited at: 21st Mar 2008 18:09
oh thanks a bunch! it works!
I was looking at your wrapper and testing some stuff.....matching it with the "hello box2D" one. Is it just me, or is the box moving upwards? for the gravity....is -10 equal to downward force? or upward force? I cant seem to find the answer in the wiki or manual.....they just say, its ....gravity. lol

I keep thinking its moving upwards cus the output position Y starts from 4 and decrease to -1. so the coord in the screen would be 4 and move upwards to -1. is it just me?


Nream is DONE! 3D Adventure Maker
Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 21st Mar 2008 21:49
Nack, in box2d downwards is positive
Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 21st Mar 2008 23:51
Nice to see box2d v2.0 out so soon diggsey It's looking great so far thanks a lot.

I'm having trouble getting to grips with the new commands in particular the "b2CreateRevoluteJointTemplate" command. It asks for 2 local coordinates (x and y), but shouldn't you just need 1? I tried varying values but couldn't get it to work.

Thanks
BMacZero
13
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ N_America/ USA/ CA/ South
Posted: 22nd Mar 2008 02:41 Edited at: 22nd Mar 2008 02:53
How did I miss this?!?!

Edit: Oh you have a wiki now I see. Fancy

Now I can go restart Los Mineros. Yay!

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 30th Mar 2008 19:55 Edited at: 30th Mar 2008 19:55
@Nack + Xlaydos
Box2D does not dictate which way is up or down, you (or darkbasic) does that. It just happens that in most things, including darkbasic, the point 0,0 is in the top left, and the y position increases as you go down. If gravity is positive, the objects' y positions will increase and the object will go down on the screen, if it's negative they will decrease. You could if you wanted draw things so that positive y is up (in 3d this is true by default).

Dark Developer
12
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Mindspace
Posted: 3rd Apr 2008 19:46 Edited at: 3rd Apr 2008 19:46
This stuff seems to be very cool, but... to tell the truth, I really need some tutorial how to use it.
Dark Developer
12
Years of Service
User Offline
Joined: 31st Aug 2006
Location: Mindspace
Posted: 4th Apr 2008 19:22
I got an error while using b2SetBodyPosition command, it says that this command is not exists...
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 5th Apr 2008 13:43
I've tested it a number of times and it works fine for me

NeX the Fairly Fast Ferret
14
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 6th Apr 2008 00:57
Could this be used for a top down GTA clone, I wonder? Disabling gravity and making large air resistance might just work.


I fail at life. No, really.
Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 20th Apr 2008 14:16
How do you cycle through the contacts in V2.0?

I was using this code before:


Thanks
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Apr 2008 22:08 Edited at: 20th Apr 2008 22:09
@Xlaydos
Due to the addition of continuous collision detection, it means that contacts can be created and destroyed within the same time-step. That means that some contacts will never exist outside of it, and will not be detected with similar code to that. To fix this, Box2D now uses callbacks. They are functions that are called at the exact time when a contact is created, persists, or is destroyed.

You can use 'b2SetContactListener' along with IanM's function pointer plugin to assign a 'listener' function.
Now that you pointed it out, I have noticed that the listener is called with a ContactPoint, not a contact, and currently there are no functions to retrieve data from it. I will release an update to fix this, but until then, if you can't wait, you can use IanM's peek/poke functions.

Your callback function will be called with these parameters:
function MyContactListener(ContactPoint as integer, status as integer)

Status can be -1,0, or 1, meaning remove, persist, and create respectively.

ContactPoint contains a pointer to memory containing information about the contact. Until I release the update, you can use these bits of code to get the data:


peek integer(ContactPoint,0) `Returns the first shape involved in the collision.

peek integer(ContactPoint,4) `Returns the second shape involved in the collision.

peek float(ContactPoint,8) `Returns the x contact position in world coordinates.

peek float(ContactPoint,12) `Returns the y contact position in world coordinates.

peek float(ContactPoint,16) `Returns the x contact normal (a vector containing the direction of collision).

peek float(ContactPoint,20) `Returns the y contact normal (a vector containing the direction of collision).

peek float(ContactPoint,24) `Returns the separation (It's negative when the shapes are overlapping).

peek float(ContactPoint,28) `Normal force (the force Box2D applies in the direction of the contact normal to push apart the shapes).

peek float(ContactPoint,32) `Tangent force (the force Box2D applies at right angles to the contact normal to simulate friction).


The fix will be soon

Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 20th Apr 2008 22:24
Thanks for the quick reply, i'll have a play around with those commands

Thanks a lot
TyroN
11
Years of Service
User Offline
Joined: 3rd Apr 2008
Location: Canada
Posted: 20th Apr 2008 23:18
hey can i use this with Dark GDK ?
Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 20th Apr 2008 23:32 Edited at: 20th Apr 2008 23:38
Hmm i'm having a few problems, my program is crashing when a contact occurs upon exiting the contactlistener function. (Maybe it needs to return a value?)

Here is some example code: (modded your example)



I assume you mean + instead of , in the peek int/float parameters
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Apr 2008 00:49
I did mean +
I've fixed that problem, it was me calling a __cdecl function using __stdcall It'll be in the update. The update will be within the next day or so.

Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 21st Apr 2008 19:08
Okay thanks I'll guess i'll try to wait
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 23rd Apr 2008 21:20 Edited at: 23rd Apr 2008 21:29
@Tyron
You'd be better off using Box2D directly

@Xlaydos
I've now updated the engine

In addition to fixing the __cdecl vs __stdcall problem, I have added commands to get ContactPoint info, and also added commands to get a list of contact edges for a body. As I said before though, there is always the chance when using this method that a contact may be created and destroyed within the same update!

A contact edge contains four bits of data:
- The next contact edge in the list
- The previous contact edge in the list
- The other body involved in the collision
- The actual contact on that edge

Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 23rd Apr 2008 21:58 Edited at: 23rd Apr 2008 22:00
Great, thanks so so much

*Me wants download*

Edit: *Realises its attached and feels silly*

Thanks again!
Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 23rd Apr 2008 22:25 Edited at: 23rd Apr 2008 23:23
Hmm i think there maybe a slight problem?

It seems to crash when trying to retrieve data about box collisions, but not about circle collisions (i'm yet to test polygons).

Try this code changing UseCircle from 0 to 1



Edit: I've also been reading into the listener. It says on box2d website that it is best to buffer the contactpoint data until later. Am i correct in thinking that you cannot store the pointer to that data (ContactPointID?), you must store the data that you use the ContactPointID to get? (e.g.b2GetContactPointPositionX(ContactPoint))

Thanks
Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 26th Apr 2008 22:11 Edited at: 26th Apr 2008 22:32
I think i've found another strange bug in the collision listener...

If you compile the following code multiple times, sometimes you will get errors saying "trying to get shape which does not exist" and other times it will run smoothly, seems about 50/50 split.


Edit: After further testing i believe it is the listener function recording wrong values for ShapeA and ShapeB.
Alien Menace
AGK Developer
14
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 28th May 2008 03:42
I went to the wiki page and it is blank... ?
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th May 2008 11:39
The site that hosts it is down for a few days. I will hopefully be moving it to a new site soon, thanks to Jerico2Day offering to host a proper wiki

Syncaidius
14
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 22nd Jun 2008 02:26
Wow, nice work on the plugin Diggsey. I love it.

Sunflash
14
Years of Service
User Offline
Joined: 28th Jun 2005
Location: Seattle, Wa
Posted: 4th Jul 2008 19:25
Hey, are there any samples of this DLL in action? I learn better from those

Mountain Dew, happiness in a bottle.
Ed222
11
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: Calgary
Posted: 18th Jul 2008 20:00 Edited at: 18th Jul 2008 20:01
@Diggsey do you think you could include help files? and keywords for the editor? also it'd be nice to include how to install the dll in the folder

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 7th Aug 2008 01:37 Edited at: 7th Aug 2008 01:55
Ok, I've moved the wiki to my new website, and added a ton more pages

It's mostly the 'set' and 'get' commands that are left to do, and seeing as there are still over 340 pages to make, it would be helpful if you could request pages for me to make, or even better, make them yourself if you know how the command works.

Also, I made all the help files! (Well technically, they just redirect to the wiki entry for that command...)

I also updated the plugin itself with a few small bug-fixes.
See the top post for a download.

Yuor signutare was aresed by a deslyxic mud...
Curious? CLICK HERE!
Alien Menace
AGK Developer
14
Years of Service
User Offline
Joined: 11th Jan 2005
Location: Earth (just visiting)
Posted: 11th Aug 2008 10:07
Diggsey, is this still the web address?

http://editthis.info/box2dplugin/Main_Page

Thanks.
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Aug 2008 13:57
No, it's http://www.diggsey.heliohost.org/box2d/wiki like it says in the top post

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 12th Aug 2008 13:58
Thanks a lot diggsey
Hayer
13
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 27th Nov 2008 15:30
Just me or is
http://www.diggsey.heliohost.org/box2d/wiki
down?

Can't get the Version2.0 to work. Not with the compiling but making boxes and things to test it out.

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 27th Nov 2008 17:49
@Hayer
There have been some problems with the host recently (they moved to a new server, and some problems appeared). Hopefully it will be more reliable soon.

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
Hayer
13
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 27th Nov 2008 23:23
Well, maybe u can answer my current problem.

When the dynamic body falls down and its the static body I get a red line crossing my screen and the box disappears. i thought the box just should stop falling



Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Nov 2008 00:53
I answered it in your thread.

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
Xlaydos
15
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 9th Dec 2008 22:00
There appears to be a bug in the contact listener: When a corner of a polygon is in contact, it works fine, but when an edge is in contact it crashes. Circles work fine.

Basically: Vertex/Vertex = Okay (if this is possible... )
Vertex/Edge = Okay
Edge/Edge = Crashes
If you see the attached picture for an example, the image on the left is fine, but the image on the right crashed.

Here is my contact listener code.

Thanks

Attachments

Login to view attachments
Valle
13
Years of Service
User Offline
Joined: 10th Mar 2006
Location: in your girlfriends bed
Posted: 21st Dec 2008 13:34
Hi Diggsey!

Awesome wrapper you wrote there !
I'll probably use it in the next sticksuicide game.

http://www.diggsey.heliohost.org/box2d/wiki seems to be down, could you upload it again?

greetz valle


Serge Adjo
13
Years of Service
User Offline
Joined: 3rd Aug 2006
Location:
Posted: 27th Dec 2008 13:44
hi ! I have a feature request or something for Box2D Wrapper, should I ask ?

pascontent.
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Dec 2008 14:16
@Valle
Thanks, I'm still looking forward to SC3

The hosting I'm using has been having some problems recently, but they should be fixed now. The site works now


@Serge Adjo
Sure If it is a feature in box2D which is missing, rather than in the wrapper, I will pass it on to Erin Catto (who made box2d)

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
Aurum Knight
11
Years of Service
User Offline
Joined: 15th Jul 2008
Location: the suburbs of nowhere
Posted: 7th Apr 2009 18:24
This looks great, I saw this before, but it wasn't much use to me since I would have to work off of examples to figure out the commands

But now that it has help files, it's time for some fun
Valle
13
Years of Service
User Offline
Joined: 10th Mar 2006
Location: in your girlfriends bed
Posted: 8th Apr 2009 22:10
I support this by giving it reply no.50


Login to post a reply

Server time is: 2019-08-24 07:37:11
Your offset time is: 2019-08-24 07:37:11