Page 1 of 7

3D Physics with ZgeBullet

Posted: Tue Nov 15, 2011 10:17 am
by Rado1
ZGEBullet DLL is a 3D physics library for ZGE. It is created as a wrapper of the Bullet library. Bullet is a high-quality open-source collision detection and rigid body dynamics library.

I took inspiration from GMBullet DLL developed for Game Maker, however, I implemented ZGEBullet from the scratch. ZGEBullet is simpler and smaller.

ZGEBullet is still in an early development stage, ie., it is stable, working well, but incomplete. During next days and weeks (months) I'm going to add more collision shapes, more properties for rigid bodies, constraints, etc.

Attached you will find the ZGEBullet DLL and a small ZGE demo project I'm using as a testbed for the implemented features. Move with arrows, generate single objects with 1,2 or 3, generate formations of objects with 7, 8, or 9, clear the scene with Space.

Note: I decided to create a wrapper for some good physics engine because I was missing this functionality in ZGE for longer time. PAPPE integration in ZGE was interesting, but unfortunately it was excluded from the main development stream of ZGE. Even if the ZGEBullet is bigger than usual 64kb, I hope you will enjoy it in your physics-aware applications.

Any comments are welcome.

Have a fun!

Posted: Tue Nov 15, 2011 3:58 pm
by VilleK
Hi Rado1,

Wow, this is another impressive project of yours!

PAPPE integration could be resumed again one day if there is enough interest in it. I remember there being some problems and small bugs but I see that BeRo updated the code this year so maybe that is solved now.

On the other hand I think that physics is probably one of those features that is best implemented as an extension to a well-known physics engine just like you have done here.

Let me know if you need help. You could put the source on Google Code if you want, just like Diki did with Box2D for ZGE.

Also I'm sure this project could be made to great use in the Visualizer. We are adding features right now, let me know if you want the latest beta!

Posted: Tue Nov 15, 2011 4:30 pm
by Rado1
Putting source code of ZGEBullet to Google Code is a good idea. Once I achieve personal confidence with the code and sufficient feature richness I put it there. The library is still too volatile, I'm fixing and adding new features each day (or rather night).

Yes please, send me the latest beta of Visualizer.

Wow!

Posted: Tue Nov 15, 2011 5:35 pm
by jph_wacheski
Very cool! I will check it out and give any feedback I come up with. Physics is a great addition to ZGE and will make many more advanced gameplay concepts much more possible.

Thanks Rado1.

Posted: Wed Nov 16, 2011 5:52 am
by keymasher
I love the idea of a physics engine, it always reminds me of Sumotori Dreams, I'd love to try my hand at something like that in zge.

I noticed that this requires MSCVR100.dll, some C runtime lib ~300kb
So I'm guessing it would unlikely to be easily cross-compilable for use on osx/nix zge runtimes?

I always thought PAPPE was really nifty as well, I haven't really played with it since it never took off in zge.

Posted: Wed Nov 16, 2011 7:42 am
by Rado1
This particular version of ZGEBullet was compiled in MSVC 2010 Express, so it is Windows-specific. However Bullet declares it can run on PLAYSTATION 3, XBox 360, Wii, PC, Linux, Mac OSX and iPhone. ZGEBullet is quite a simple wrapper which uses nothing special from Windows API; I tried to use generally written Bullet API as much as possible to avoid platform dependency. So if Bullet can be compiled on several platforms, I expect that also ZGEBullet can be. It's just a matter of compilation. But I have no experience with compiling to other platforms. Once, the source files are available, someone can try to compile it also for other platforms.

Posted: Wed Nov 16, 2011 8:49 am
by Rado1
I played little bit with compiler options and reduced the size of the DLL from 504 KB to 284 KB. I hope it can be even better after some more exploration of MSVC.

Posted: Wed Nov 16, 2011 9:27 am
by keymasher
awesome, i'll see if i can give it a go. Just read my post and sorry for being such a buzzkillington. Great work!

Posted: Wed Nov 16, 2011 11:17 am
by Kjell
Hi Rado1,

Nice work :) One small ZGE related tip .. instead of using a bunch of conditions to select which Mesh to render each frame, you can simply set the to-be-rendered Mesh of a RenderMesh component directly once. So ..

Image

.. and then use the following in the OnSpawn node.

Code: Select all

switch(ModelShape)
{
  case 0: ModelMesh.Mesh = BoxMesh; break;
  case 1: ModelMesh.Mesh = SphereMesh; break;
  case 2: ModelMesh.Mesh = CylinderMesh; break;
}
Attached is a basic example ( spawn shapes with key 1, 2 and 3 ).

K

Posted: Wed Nov 16, 2011 12:38 pm
by Rado1
Yes, sure... thank you Kjell for the tip. That's why I like to share source files - learning from others.

Posted: Fri Nov 18, 2011 3:15 am
by StevenM
Thank you!!!

I tried to get bullet workig in ZGE - It seemed impossible - and I had lot of trouble just compiling it - I hate working with SDK's. So this is really appreciated, hope we can get the source code and continue to develop this as a team - there is some great potential here. Bullet is an extraordinary and very popular physics engine - perfect choice. The fact that it is now a part of ZGE is a huge asset.

Posted: Thu Nov 24, 2011 2:53 pm
by jph_wacheski
Gave this a quick look,. it seems very usable (and powerful) so far. Just needs a few more functions to add impulses to objects, and get collisions for interactions, and we will be able to build interesting games using this.

Any updates?

Posted: Sun Nov 27, 2011 10:51 pm
by Rado1
Hi all,

ZGEBullet v2 comes with the following improvements:

- New shapes: cone, capsule, and compound.
- Dynamic setting of more properties of rigid bodies: mass, restitution, hit fraction, and gravity.
- Setting position and rotation of rigid bodies.
- Getting and setting linear and angular velocity of rigid bodies.
- Applying impulses for rigid bodies.
- Constraints and limits.

The demo application has been improved by constraints - press 4 for a worm and 5 for a ragdoll, and velocity - press Enter to shoot a red sphere.

Further plans: even more shapes, collision detection (propagation to ZGE), constraint motors, enabling deactivation and sleeping thresholds, maybe also soft bodies (needs more exploration), etc.

I would really appreciate your testing. Thanks.

Posted: Mon Nov 28, 2011 2:02 pm
by Rado1
Another improvement is removing dependency on MSVCR100.dll. The size increased by 80KB, but this is probably more acceptable than installing C++ runtime libs for VS 2010.

Posted: Mon Nov 28, 2011 2:34 pm
by Kjell
Hi Rado,
Rado1 wrote:Another improvement is removing dependency on MSVCR100.dll. The size increased by 80KB, but this is probably more acceptable than installing C++ runtime libs for VS 2010.
This is definitely the way to go yes.

By the way, using stdcall instead of cdecl should generate a smaller dll.

+ What happened to the movable flag on AddRigidBody? I'm aware it didn't work before, so I'm guessing you've taken it out temporarily?

K