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.

Work in Progress / FREE 2D Physics Engine Plugin!

Author
Message
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 20th Jan 2008 18:45
@Diggsey

I've finally started a cool project with Box2d (see "Los Mineros" in game design theory) but I'm having two problems:

1.) (Has been mentioned before, but not answered) Whenever I make a body from a template, it acts completely static and won't move no matter what I do to it.

2.) Is there a way to check whether my character is sitting on another body? Basically, a collision command? I've seen some in the ini file that look promising but I can't figure out how to use them.


[i]"Grow food in dirt? Save time — eat dirt."[i]
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Jan 2008 19:30
1) If you specify 0 density for all the shapes in the template, it will be static. To make it dynamic, just give it some mass by increasing the density

2) Loop through the contact nodes for the body you want to check for collision using 'b2GetBodyFirstContactNode' and 'b2GetNextContactNode'
Once you have the contact node, you can get the actual contact using 'b2GetContactNodeContact'. When you have that, you can get the two bodies involved using 'b2GetContactBody' (The body parameter is either 0 or 1 and represents the two bodies in the collision).
If you need more information, you can get the friction and restitution in the contact using 'b2GetContactFriction' and 'b2GetContactRestitution'. If you need even MORE information, you will have to look through the manifolds for that particular contact. You can do this using 'b2GetContactManifoldCount' and 'b2GetContactManifold'. Once you have the manifold, you can get at the contact points for that manifold using 'b2GetManifoldPointCount' and then one of the commands that begins 'b2GetManifoldContactPoint...'. You can also get the collision normal for the whole manifold using 'b2GetManifoldNormalX' and 'b2GetManifoldNormalY'

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 20th Jan 2008 21:32
1.) Yes, I looked for that, but there I couldn't see any way to change the density of shapes.

2.) Thanks, I'll try that out.

We really need those help files...if I knew more about the plugin I'd do them myself.


[i]"Grow food in dirt? Save time — eat dirt."[i]
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 21st Jan 2008 20:04
Bleh. The contact node commands keep crashing the program with a "LosMineros.exe has generated errors and will be closed by Windows." The work sometimes, but not other times, and I have no idea why.



NoFloors is the number of floors. Floors is an array which holds the IDs of each of the floor objects. Before, I had it so the character would jump only when he was touching another object. But now, I'm starting to make ropes and other things I don't want the character to be able to jump on, so I need a way to find out exactly which body he is touching.
Anybody shed some light on the situation?


[i]"Grow food in dirt? Save time — eat dirt."[i]
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 21st Jan 2008 20:14
@bmaczero
You are using them incorrectly (not your fault, because there are no help files)

Try this instead:


BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 21st Jan 2008 20:23
That works excellently. Thanks a lot!


[i]"Grow food in dirt? Save time — eat dirt."[i]
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 23rd Jan 2008 01:36
Here's some cool functions I made for use in Los Mineros. They have to do with making ropes:



To initiate the ropes, call RopeInit(ImgNumber). ImgNumber is the number in which it will store the rope image, so it needs to be a free image number.

To make a rope, call MakeRope(Links). Links is the number of links the rope will have, experiment to get a good number.

Then, calling DrawRopes(RopeStart) every loop will update the sprites that represent the rope bodies. RopeStart should be the highest sprite number in your program, because the sprites will be numbered from that number up. (For example, if you had one 25-link rope and you put a RopeStart of 100, the first link would be sprite 100, the second sprite 101, the third sprite 102, etc.

I'll probably come up with more stuff to do with your ropes as I work on Los Mineros.

FERSIS
17
Years of Service
User Offline
Joined: 17th May 2006
Location:
Posted: 25th Jan 2008 20:26
Great job Diggsey .
Is there a version of this plugin comming to GDK ?
Or its just better use Box 2D directly ?
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 25th Jan 2008 20:56
It's much better to use Box2D directly if you have the GDK

Graphiboc
17
Years of Service
User Offline
Joined: 16th Jun 2006
Location:
Posted: 26th Jan 2008 18:01
very nice work diggsey!
but i have a question.
I thought about making a kind of worms armageddon and i have a problem : Is it possible to use Box 2d to do that? I don't really know how to do the collisions between bullets and level with box2d. Is it possible? and how?
If it's not possible, could you had something to your dll that could helps to do that?
Or does somebody know how to do physics with a drawed 2d level?

thanks

Sry for mybad english
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 26th Jan 2008 18:08
It's not really possible, but you could either apply impulses to objects if the collide with the level, or you could apporximate the level using boxes or something.

Graphiboc
17
Years of Service
User Offline
Joined: 16th Jun 2006
Location:
Posted: 26th Jan 2008 18:12
yes but the landscape will be damaged during the game and it needs perfect collision system i think.
hmmm i really need a good physic system and box2d was perfect...
I don't know how to get the slope (or the normal vecteur) at a point of a 2dlevel :/

or a solution could be to create a fonction that make a shape from a black/white 2d image....

Sry for mybad english
Ulric
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Belgium
Posted: 29th Jan 2008 13:13 Edited at: 29th Jan 2008 13:26
Hi Diggsey,

First of all congratulations for this wonderful wrapper.
So far I didn't do anything with it by myself...just tested the different program code posted in the forum.

I have a little problem with the rope bridge example.
With the dll that weight about 100kb (the one from the zip file)
The program compiles fine, but when I run it I receive the following error message: Could not find function DeleteJoint in 23: PhysicsPlugin.dll

With the dll that weight about 80kb (the one you posted after)
The program does not compile and the compiler returns the following message: parameter mismatch in expression b2CreateBoxBody at line 17 ... which is:

floorbody = b2CreateBoxBody(myworld,399,50,0,0,0.5)

Any idea what it could be?

Thanks in advance,

Ulric

"I'm not young enough to know everything!"
ASUS P5W-DH - Intel Core2 Duo E6700@3.2GHz - 4Gb DDR2-800MHz nVidia GeForce 8800GTX
Vista Home Premium - DX9c & DX10
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 29th Jan 2008 18:01
It's because with the updates, the commands have changed slightly. If you look at the keywords, there should be an extra friction parameter at the end. If you add this in, it should work

Graphiboc
17
Years of Service
User Offline
Joined: 16th Jun 2006
Location:
Posted: 29th Jan 2008 22:23
hi diggsey. i solved my problem and now i have a physic system that works perfectly with points and with any level
i have an another question :
how exactly works a rigid body? i think that you test if some points of the body are in collisions with other bodies. Then you can calculate the collision response of this point, but how do you calculate the response of all the body?
thanks

Sry for mybad english
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 29th Jan 2008 23:03
@Graphiboc
I didn't write the actual physics engine, although I do kind-of understand how it works. The contact with that occured the earliest is found, and the simulation is rolled back to that time that it occured. Impulses are applied to the objects, and the simulation steps forward again to the correct time. While there are still collisions happening, this will repeat up to the ampunt of times specified by iterations.

Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 3rd Feb 2008 14:56 Edited at: 3rd Feb 2008 18:41
I have couple more questions

1) How do you add properties (restitution, friction, density) to a shape made from a template such as this one


2) How do the manifold commands work? I am trying to calculate the normal of the ground my player is on, but i always seem to crash the program.
EDIT: I've made some progress, i think i have it working fine now, gere is my code:


Thanks a lot

Edit: Also, would it be possible to ignore, collisions between 2 objects and have them move through each other as if they were not there. (Although both objects would have to be able to act upon world objects)

Edit#2: Lots of questions, sorry! What is the relationship between the individual values of friction for each object and the coefiecient of friction in the collision, it doesn't appear to be linear? Likewise for restitution.
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd Feb 2008 22:38
@Xlaydos
restitution, friction and density are additional parameters in the command 'b2AddShapeToBodyTemplate'

The restitution of a contact point is the one of the object with the greatest restitution, so if the two objects have restitution values of 1.0 and 2.0, 2.0 will be used.

The friction of a contact point is calculated using this formula, also known as the geometric mean:
friction# = sqrt(friction1# * friction2#)
(but in C++ code obviously)

You can set which objects collide with which others by playing around with the b2SetShapeGroups command, and b2SetShapeCollides. The first sets which groups the object belongs to, and the second sets which groups it collides with.

Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 3rd Feb 2008 23:50
Thank you very much... i'll give those a shot tomorrow

Thanks again
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 5th Feb 2008 19:16
I get a parameter mismatch when i try to add restitution,density and friction as additional parameters in the command 'b2AddShapeToBodyTemplate'.

I'm also having problems with the b2SetShapeGroups and b2SetShapeCollides commands, everything always seems to collide with everything.

Also, is there the way to get the friction value of a body? I tried playing with b2GetPartFriction but always got 0.

Thanks
NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 8th Feb 2008 22:50 Edited at: 8th Feb 2008 23:06
Might have found another slight bug...



This code should do... nothing, right? It's setting a variable with itself. However, the moment I rotate cha(slot).body, it goes ballistic. Without the command, it runs fine. (trying to implement some kind of air resistance) Am I not understanding the commands?

I am going to guess that one of the commands is not going through the units converter.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 9th Feb 2008 01:01
@Nex
You are probably right

Box2D V2.0 is VERY nearly out, (and it's half term for me now) so if it is released soon, I should get a new version out fixing all of these bugs. I will probably remake most of it from scratch

MadrMan
18
Years of Service
User Offline
Joined: 17th Dec 2005
Location: 0x5AB63C
Posted: 15th Feb 2008 19:35
I just can't get the sleeping to work. I tried every possible value i could put in at the b2CreateWorld but nothing seems to have any effect..

Ulric
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Belgium
Posted: 21st Feb 2008 15:08
@Diggsey: Thanks for your quick answer...and sorry for my dumbness...and my late reply!!!

"I'm not young enough to know everything!"
ASUS P5W-DH - Intel Core2 Duo E6700@3.2GHz - 4Gb DDR2-800MHz nVidia GeForce 8800GTX
Vista Home Premium - DX9c & DX10
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 27th Feb 2008 06:13
H4ck1d:

Are you still around? If so, I'd be glad to help out with the help files (heh). I can use Frontpage to put the info you have together, or I can come up with the info as far as my experience allows me to.

If you're not, I'll probably start working on my own...I think people really need these to use Box2D effectively (including me ). It would be nice to have the progress you've already made, though.


Powered by Box2D Physics. Thanks Diggsey!
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 4th Mar 2008 03:20 Edited at: 5th Mar 2008 04:03
EDIT:

I've updated the download, it now includes all the current Box2D commands and an index of them. Extract it to your Help/commands folder and you're ready to go! Once again, please report any errors or misinformation you find.

Happy coding!

Attachments

Login to view attachments
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 4th Mar 2008 12:31
Thanks very much for the help files, here are a few descriptions of some of the ones you missed:

b2ApplyForce - This applies an accleration to the specified point on the body of Force/Mass in the specified directions

b2ApplyImpulse - This does the same except produces an instantenous change in velocity of Force/Mass.

b2EnableJointLimit - Allows revolute, or prismatic joints (possibly pulley and gear joints) a limit

b2SetJointLimit - This will stop the joint exceeding these specified values, When the joint is created it is at 0 offset. The limits must be specified in your given units from b2setunits and by default will be radians for revolute joints and meters for prismatic joints. Note that to prevent jumping when the engine starts, the range specified by set joint limit must include 0

I've not had success with usage of the others.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 4th Mar 2008 16:01
Thanks for those, Xlaydos. I've updated my files. I'm also working on an overall menu of the Box2D commands right now. I'll upload the whole thing, updated, this afternoon.

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 4th Mar 2008 22:21 Edited at: 4th Mar 2008 22:23
Thanks!

Xlaydos explained those commands well, here are the definitions of the other functions:

b2GetBodyFirstJointNode
Every body has a linked list of the joints connected to it. This list contains 'nodes' This function will get the first node of the list of joints for a body. If it returns 0, there are no nodes in the list, and so no joints attached to the body.

b2GetNextJointNode
This will return the node in the list following the one provided as the parameter. If there are no more nodes, it will return 0.

b2GetPreviousJointNode
This will return the node in the list before the one provided as the parameter. If there are no more nodes, it will return 0.

b2GetJointNodeBody
This will get the OTHER body ID that the joint that this node represents, links to.

b2GetJointNodeJoint
This will return the joint ID that the node represents.

b2GetPartGlobalX
This will return the global X position of the part specified.

b2GetPartGlobalY
This will return the global Y position of the part specified.

b2GetPartGlobalAngle
This will return the global angle of the part specified.

b2GetPartFriction
This will return the friction value of the part specified.

b2GetPartRestitution
This will return the restitution value of the part specified.

b2GetPartBody
This will return the body that the part belongs to.

b2GetPartType
This will return the type of the part (eg. polygon/box/circle)

The following commands I suspect may be broken due to Box2D not allowing the group or collides flags to be changes AFTER the body has been created:
b2SetShapeGroups
b2SetShapeCollides
b2SetPartGroups
b2SetPartCollides


ViewGUI - FREE GUI plugin + WYSIWYG editor

[href=www.lost.eu/733c8]Curious? CLICK HERE![/href]
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 5th Mar 2008 03:59
Hooray!

Thanks guys, I think I got all of them. I will update the download in a minute or two with the new commands and an overall index of the Box2D commands.

Just one question still: how do you find the ID of a part? Is it just 1, 2, 3, 4 or what?

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 5th Mar 2008 19:05
@bmaczero

I made those functions, but I must have forgotten to prefix them with the export symbols! I just hope Box2D V2.0 is released soon so I can start afresh


ViewGUI - FREE GUI plugin + WYSIWYG editor

[href=www.lost.eu/733c8]Curious? CLICK HERE![/href]
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 6th Mar 2008 00:50
Whoops

I hope we get v2.0 soon also. I'm having a lot of trouble with bodies made from templates. I thought people were only having trouble with density, restitution, and friction, but my bodies don't even collide with other bodies! They're kind of an important part in Los Mineros.

Ah well, I'll maybe work on the inventory system until then...

MadrMan
18
Years of Service
User Offline
Joined: 17th Dec 2005
Location: 0x5AB63C
Posted: 6th Mar 2008 17:45
so umm as i asked at top of the page, how to stop the bodies from shaking?
they don't seem to go to sleep no matter what i put in the params :/
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 7th Mar 2008 21:22
@MadrMan
Try using different values for b2SetUnits


ViewGUI - FREE GUI plugin + WYSIWYG editor

[href=www.lost.eu/733c8]Curious? CLICK HERE![/href]
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 11th Mar 2008 21:23
In case any of you haven't seen, Erin just released Box2D v2.0!!!

I have already started work on wrapping it, but I have started again from scratch, so it will likely take almost a week

Here is some of the extra features from the previous versions:
- You will be able to check if any type of object exists
- You can see how much memory is being used by Box2D
- Better names (What were previously called shapes are actually shape templates, they only become shapes when the body is created, which is why I had to add 'parts' later on which were never really very useful.
- Settings which can only be set before a body is created were previously setting them after creation, which meant that they didn't work. This will be fixed.
- No more nasty 'blah.exe has encountered a problem and needs to close' errors when an invalid ID is used!

Here are some possible additions:
- Concave shape decomposition (you supply a concave shape, and it creates multiple convex shapes for use with Box2D)

If anybody has any other suggestions, please suggest them early on, so that if they require any severe changes to the wrapper, I won't have to do a load of extra work

Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 11th Mar 2008 22:41
Sounds great, thanks a lot
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 12th Mar 2008 04:37
Yippee!!

My only requests are:

1.) Fix the problem where bodies made from templates do not have density, restitution, and friction, and do not collide with other shapes, so that my levels on Los Mineros actually work properly

2.)Keep the command names the same as much as possible so I don't have to do so much work on the help files

Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 12th Mar 2008 22:14 Edited at: 12th Mar 2008 22:35
There are a much larger number of options for each command now


@bmaczero
1) I think that might have been a misunderstanding between the engine and me (I thought it initialized all the settings in the constructor, but apparently it didn't. The new version DOES anyway.)

2) The way things work will be pretty much the same, but some of the names will change a bit (nothing that can't be fixed with a few copy+pastes) such as shapes now being called shape templates, and parts now being called shapes

Attachments

Login to view attachments
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 13th Mar 2008 21:15 Edited at: 16th Mar 2008 21:06
Exactly 400 functions, and I've finished!

Settings
World
Shape templates
Body templates
Joint templates
Shapes
Bodies
Joints
Contacts
Manifolds

PREPARE FOR RELEASE

Phosphoer
16
Years of Service
User Offline
Joined: 8th Dec 2007
Location: Seattle
Posted: 14th May 2008 21:31 Edited at: 14th May 2008 21:42
Hey guys, is there a command that will test for collision? I mean my boxes and things bounce off each other fine but how do I get a return when they hit so that I can trigger things?

Thanks much

----EDIT----
Just looked through the above posts and saw the thing about contact nodes, will try that out

Nevah mind!

This is a random sentence about squirrels.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 15th May 2008 07:08 Edited at: 15th May 2008 07:09
Yep, check out the help files I made a little ways above to find out how to use all those. Also, Diggsey has given a nice code snippet demonstrating how to check collision a page or two back.

But before you get too far, head over to the Program Announcements board and check out Box2D V2.0.0. It is a bit more confusing than this version, but it has many more commands and features to make it worthwhile.

Edit: Box2D V2.0.0

Unterseeboot - Has you played it?
Los Mineros are on leave...

Login to post a reply

Server time is: 2024-05-06 11:19:11
Your offset time is: 2024-05-06 11:19:11