Box2D for ZGE

Use of external libraries (DLLs) from ZGE.

Moderator: Moderators

User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Box2D for ZGE

Post by diki »

An adaption of the Box2D Physics Engine for ZGE 1.1.9b.

Visit the Project Page on Google Code!

Version 1 Features:
  • - World (with Gravity)
    - Static and Dynamic Bodies (rudimentary)
    - Box Shapes
See the included demo projects for information on the intended usage (more detailed documentation will be crafted for later versions with more features :P).
Attachments
Box2DZGE v1.zip
initial release; includes demo projects.
(55.81 KiB) Downloaded 1284 times
Last edited by diki on Sun Mar 07, 2010 12:52 am, edited 1 time in total.
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

How is this going Diki,. need any testing?
I was messing around with Pocket Physics for the DS [ http://tobw.net/index.php?cat_id=3&proj ... et+Physics ] the other night and realised it too uses Box 2D,. it is fun just to build crazy Rube Goldberg machines and watch the sim work out the physics,.. . <pineing>
iterationGAMES.com
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

Uhm, it's a bit on hold currently, but I'm still planning to include at least Circles & Custom Shapes as well as Joints (everything you need for a car ;)).
User avatar
diki
Posts: 140
Joined: Thu Sep 11, 2008 7:53 pm
Location: GMT+1
Contact:

Post by diki »

put it up on google code... please excuse the messy sourcecode for now :P
User avatar
y offs et
Posts: 418
Joined: Wed Apr 22, 2009 4:26 pm
Location: BC, Canada

Post by y offs et »

Here's a twist. Use the RMB to generate a tiny block between the base and big block.
Attachments
Gulliver.zgeproj
(4.83 KiB) Downloaded 1216 times
"great expectations"
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Hi all,

I had a quick look at the current features of Box2D and see the following possible improvements of Box2DZGE:

1. update to the current Box2D library,
2. add more features of Box2D, e.g., more shapes, more properties for bodies, fixtures, joints, sensors, contact detection, raycasting, ..., and
3. compile also for Android.

Question: would anyone like to use such updated Box2DZGE? If so, Diki, can you continue with implementation? If not, then I can.

Waiting for your opinion.
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

That is curious, I was just wondering last night if anyone had advanced to Box2d any further,. and I was going to ask!

Yes, I would be interested in using Box2d,. as it is slightly easier to work with than trying to limit our fully 3d physics option down to 2d. So, for many 2d and/or simple games, it would be my choice if it was ready to use.
iterationGAMES.com
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Ok Jph, I'm going to have a look at it. I'll probably start building a new library from the scratch in VS2010. Or Diki do you think I should continue with your project in Code::Blocks?
User avatar
VilleK
Site Admin
Posts: 2318
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Rado1, maybe if you post an issue on the Google code page then Diki will be notified? He probably does not check this forum regularly.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

VilleK wrote:Rado1, maybe if you post an issue on the Google code page then Diki will be notified? He probably does not check this forum regularly.
Good idea Ville, I sent an issue to Google code page and waiting for reply.

Anyway, in meantime I created own Box2D library adapter which uses the latest version of Box2D. I created it from the scratch, but of course was inspired by the original library from Diki. In addition to the original dll, it allows to specify also rotations of boxes. This is just an example of how simple it can be extended. See the attached ZGE project and dll.

Next steps:
1. Compile for Android.
2. Rethink and rework the API to ZGE to add more features.
3. Create better demos.
4. Put to Google code.

Remark: Just notice how small is this dll, half of size of the original one. Of course, it will grow with features.
Attachments
demo1.zip
Demo project for new version of Box2D library + DLL
(37.65 KiB) Downloaded 860 times
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

I'm glad to announce that we have Box2D for ZGE running on Android! I also added explicit destruction of bodies and the simulation world (click LMB or tap in the demo application). Some more improvements will come later.

BTW any comments and suggestions are welcome; eg., what are your preferences for new features.
Attachments
demo1_v2.zip
ZGE project, Android application, DLL and Android library
(484.02 KiB) Downloaded 934 times
ZGEBox2D on Android
ZGEBox2D on Android
scr.jpg (13.44 KiB) Viewed 31476 times
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

SetLinearVelocity and SetAngularVelocity to get started,. or ApplyForce, ApplyImpulse, ApplyTorque,. not sure the difference,. I am just glancing at an API page,. . A way to get collision data back will be useful as well. So b2ContactListener looks like,. .

I will need to mess with it a bit and learn how the system works more I suppose. If you will add more basic functionality,. I will help with examples and stuff.
iterationGAMES.com
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

I started to implement collisions and would like to know what collision detections would be most useful for you. I already implemented getting of all contacts in the world and contacts of a single body. Contacts are obtained one-by-one by consequent function calls. A contact comprises collided bodies, and collision point. I can also add collision state (new or persisted), normal, normal impulse, tangent impulse and separation. Maybe just state can be useful. For a single body, functions for number of collisions and boolean test whether it is collided are also provided. The proposed/current functions:

Code: Select all

void zb2PrepareAllContacts() {}

// return 0 - no other contact; 1 - next contact returned
int zb2GetNextContact(ref int bodyA, ref int bodyB, ref float x, ref float y) {}

void zb2PrepareBodyContacts(int body) {}

// return 0 - no other contact; 1 - next contact returned
int zb2GetNextBodyContact(ref int body, ref float x, ref float y) {}

int zb2IsCollided(int body) {}

int zb2GetBodyContactCount(int body) {}
I'm asking you because the implementation is still not mature enough and I do not want to spent some time with useless functionality.
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

I have not had time to look into the box2 implementation much yet, so I am just guessing,. ( someone hacked my site,. wrecked up my wordpress install :( it is always something,. . )

anyway, looking here; http://www.box2d.org/manual.html#_Toc258082970
there is a lot possible! Of course, just having circular bodies and raycasts could be enough for a good game, so anything more is gravy.

I will go about the game design based on what you make available, for example "Chain Shapes" would make level design very different than the array based levels i am using for my current project.

Basically, I do not have a particular design in mind, and will instead experiment to see what is possible from whatever you come up with, and how it preforms.
iterationGAMES.com
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Next version of ZGEBox2D library is here. It provides the following functionality:

- creating and destroying the simulation world, stepping the simulation, and global clearing of forces
- dynamic setting of global properties: gravity, sleeping of inactive bodies
- support for static, kinematic and dynamic bodies
- box, circle, polygon and edge shapes
- setting of body properties: position, rotation, linear and angular velocity, linear and angular damping, friction, gravity scale, activation/deactivation, setting as bullet (fast moving object), and mass properties
- getting of body properties: position, rotation, awakening detection and overlapping with point
- reliable global collision detection (obtaining info about contact points)
- simple body collision detection (can be improved in future, if required)
- global raycasting

All these features run also on Android. See the attached demo project with Windows and Android versions of the ZGEBox2D library. The demo shows static and dynamic shapes, global collision detection, test on "mouse over" and it is also possible to drag/drop the selected body.

Even if it is still a testing version, it can be used for your trials, demos and games. Its performance is quite good. Please try and give me your feedback.

In near future I'm going to work on the following features:
- chain shape (maybe with lower priority)
- joints (Box2D has various really nice and useful joint types)
- moving the sources to Google code

Any comments are welcome!
Attachments
demo1_v3.zip
demo project + dll + .so library for Android
(149.6 KiB) Downloaded 857 times
screenshot
screenshot
scr.jpg (43.12 KiB) Viewed 31348 times
Post Reply