LiquidFun / Box2D - Physics and Game Library for PureBasic

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
seangriffin
New User
New User
Posts: 8
Joined: Wed Jun 28, 2017 3:53 pm

LiquidFun / Box2D - Physics and Game Library for PureBasic

Post by seangriffin »

I'm very proud to announce the first release of my LiquidFun / Box2D Physics Library for PureBasic.

To get a quick idea what this is all about, view my Youtube demonstration video here -> https://youtu.be/zdUW69nzy8w

In case you don't know, LiquidFun (see http://google.github.io/liquidfun) and Box2D (see https://github.com/erincatto/Box2D) are both physics engines. Together they simulate physical systems using particle systems, rigid bodies, joints and collision detection. Box2D is arguably the most prevalent physics engine in existence right now. It's the engine behind many popular physics-based games like Angry Birds, and is also at the core of other advanced physics engines such as Unity. LiquidFun is a particle physics extension to Box2D, created by Google.

This library incorporates many of the functions of LiquidFun and Box2D into PureBasic and utilises PureBasic's great OpenGL features to render the output to the screen. The result is a visual library for 2D physics in PureBasic.

REQUIREMENTS
  • PureBasic version 5.60 (other versions may work but untested)
  • OpenGL versions 1.2 and higher (other versions may work but untested)
  • Windows 7 OS and higher (other versions may work but untested)
LIST OF FUNCTIONS (so far)

This library is split into two halves. LiquidFun-C.pbi includes the functions of the LiquidFun (and Box2D) core. The output of this library is purely mathematical. LiquidFun-C-Ex.pbi is the library I've developed that extends LiquidFun-C.pbi to include additional graphics (OpenGL) and gaming / convenience functions for LiquidFun in PureBasic.

Within the LiquidFun-C.pbi library:
  • b2World_Create
  • b2World_Step
  • b2World_DestroyJoint
  • b2World_CreateBody
  • b2World_DestroyBody
  • b2Body_GetAngularVelocity
  • b2Body_SetAngularVelocity
  • b2Body_GetPosition
  • b2Body_GetAngle
  • b2Body_IsActive
  • b2Body_SetTransform
  • b2Body_ApplyForce
  • b2Body_ApplyTorque
  • b2Body_GetMass
  • b2Body_SetMassData
  • b2Body_GetInertia
  • b2Body_GetLinearVelocity
  • b2Body_SetLinearVelocity
  • b2CircleShape_CreateFixture
  • b2PolygonShape_CreateFixture_3
  • b2PolygonShape_CreateFixture_4
  • b2PolygonShape_CreateFixture_5
  • b2PolygonShape_CreateFixture_6
  • b2PolygonShape_CreateFixture_7
  • b2PolygonShape_CreateFixture_8
  • b2ChainShape_CreateFixture
  • b2Body_DestroyFixture
  • b2World_CreateParticleSystem
  • b2World_DestroyParticleSystem
  • b2ParticleSystem_GetParticleCount
  • b2ParticleSystem_GetPositionBuffer
  • b2ParticleSystem_SetDensity
  • b2ParticleSystem_SetDamping
  • b2ParticleSystem_CreateParticle
  • b2CircleShape_CreateParticleGroup
  • b2ParticleGroup_GetParticleCount
  • b2ParticleGroup_DestroyParticles
  • b2WeldJointDef_Create
  • b2WeldJointDef_InitializeAndCreate
  • b2RevoluteJointDef_Create
  • b2RevoluteJointDef_InitializeAndCreate
  • b2RevoluteJoint_EnableLimit
  • b2RevoluteJoint_EnableMotor
  • b2RevoluteJoint_GetJointAngle
  • b2RevoluteJoint_IsLimitEnabled
  • b2RevoluteJoint_IsMotorEnabled
  • b2RevoluteJoint_SetMotorSpeed
  • b2PrismaticJointDef_Create
  • b2PrismaticJointDef_InitializeAndCreate
  • b2PrismaticJoint_EnableLimit
  • b2PrismaticJoint_EnableMotor
  • b2PrismaticJoint_GetJointTranslation
  • b2PrismaticJoint_GetMotorSpeed
  • b2PrismaticJoint_GetMotorForce
  • b2PrismaticJoint_IsLimitEnabled
  • b2PrismaticJoint_IsMotorEnabled
  • b2PrismaticJoint_SetMotorSpeed
  • b2WheelJointDef_Create
  • b2WheelJointDef_InitializeAndCreate
  • b2WheelJoint_SetMotorSpeed
  • b2WheelJoint_SetSpringFrequencyHz
Within the LiquidFun-C-Ex.pbi library:
  • glTexture_Create
  • glTexture_LoadAll
  • glDraw_Fixture
  • glDraw_Fixtures
  • glDraw_ParticleSystem
  • glDraw_Particles
  • glInfo_Get
  • glWindow_Setup
  • glWorld_Setup
  • glWorld_CreateTextures
  • b2Vec2_LinearVelocity
  • b2Vec2_Distance
  • b2Vec2_Vector_at_Angle_Distance
  • b2Vec2_GetAngleBetweenThreePoints
  • b2Vec2Array_IsConvexAndClockwise
  • b2PolygonShape_CreateFixture
  • b2PolygonShape_CrossProductVectorVector
  • b2PolygonShape_ComputeCentroid
  • b2PolygonShape_MoveToZeroCentroid
  • b2Fixture_LoadAll
  • b2Body_LoadAll
  • b2Body_GetLinearVelocityEx
  • b2Body_GetAngularVelocityEx
  • b2Body_GetPositionEx
  • b2Body_SetPosition
  • b2Body_GetAngleEx
  • b2Body_SetAngle
  • b2Body_AddAngle
  • b2Body_AddAngularVelocity
  • b2Body_SetAngularVelocityPercent
  • b2Joint_LoadAll
  • b2ParticleSystem_LoadAll
  • b2ParticleGroup_LoadAll
  • b2World_CreateJointEx
  • b2World_CreateJoints
  • b2World_CreateFixtureEx
  • b2World_CreateFixtures
  • b2World_CreateEx
  • b2World_CreateBodyEx
  • b2World_CreateBodies
  • b2World_CreateBodyAndFixtures
  • b2World_CreateBodyAndFixturesAndJoints
  • b2World_DestroyBodyEx
  • b2World_DestroyBodies
  • b2World_FollowBody
  • b2World_SetFixturesDrawType
  • b2World_DestroyJointEx
  • b2World_DestroyJoints
  • b2World_DestroyBodyAndJoints
  • b2World_CreateParticleSystemEx
  • b2World_CreateParticleSystems
  • b2World_DestroyParticleSystems
  • b2World_CreateParticleGroupEx
  • b2World_CreateParticleGroups
  • b2World_DestroyParticleGroups
  • b2World_CreateAll
  • b2World_DestroyAll
EXAMPLES:

Here is a quick direct link to the demonstration (installer) -> https://github.com/seanhaydongriffin/PB ... _setup.exe

For more details on this demonstration, as well as a simple step-by-step example of the library, see my GitHub page below.

DOWNLOADS:

You can access the library, including demonstration and examples, from the following GitHub page

https://github.com/seanhaydongriffin/PB-LiquidFun-C

Hope you all enjoy!

Cheers,

Sean.
Last edited by seangriffin on Wed Aug 02, 2017 2:08 pm, edited 7 times in total.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: LiquidFun / Box2D - Physics and Game Library for PureBas

Post by djes »

Wow, terribly impressive ! :D Thank you !
Last edited by djes on Wed Aug 02, 2017 2:37 pm, edited 1 time in total.
User avatar
seangriffin
New User
New User
Posts: 8
Joined: Wed Jun 28, 2017 3:53 pm

Re: LiquidFun / Box2D - Physics and Game Library for PureBas

Post by seangriffin »

djes wrote:Wow, terribly impressive ! :D Thank you !

Edit: I had no luck trying to compile. There' a lot of polink errors... The exe/installer works nicely. What should I do ?
Thank you so much djes. This has been a very long journey for me indeed. My love for physics engines stems way, way back to the 1980's when some of the first true physics-based games appeared on home computers. Games like Jeremy Smith's Thrust (https://en.wikipedia.org/wiki/Thrust_(video_game)) and Exile (https://en.wikipedia.org/wiki/Exile_(1988_video_game)). I was breath-taken from what these talented individuals could achieve 30 years ago. Here we are in 2017. I am now 30 years older and surprisingly still developing an engine which in principle is almost the same as what they achieved back then. I'm dumb-founded by this.

All the same, I feel absolutely privileged to have been able to do this. Erin Catto, the man behind Box2D, is simply a genius and equally the Google team for layering LiquidFun on top.

Many weeks ago I set out to integrate Box2D within a simple scripting language (such as AutoIT), such that people can access the power of this great physics engine without the overhead of learning an advanced programming language (like C++). Not being satisfied with the performance of AutoIT I moved through various graphics engines (SFML, Irrlicht, Direct2D, GDI+), and also attempts using FreeBasic, and ultimately arriving here. PureBasic has fulfilled my dreams. I'm a happy man. :D
Fred
Administrator
Administrator
Posts: 16664
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: LiquidFun / Box2D - Physics and Game Library for PureBas

Post by Fred »

Very nice work !
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: LiquidFun / Box2D - Physics and Game Library for PureBas

Post by djes »

I understand. We're living a great period for that can be achieved. We have grown with computers and now, their power seems so big that we could merely get "into" them with VR and so on. I'm very happy that you've done such a program that we can incorporate and use easily, thank you again. :D

Anyway, I have no luck trying to compile. There' a lot of polink errors... The exe/installer works nicely. It's certainly a little compiler option or maybe a dll or file missing. Could you help me ?
User avatar
seangriffin
New User
New User
Posts: 8
Joined: Wed Jun 28, 2017 3:53 pm

Re: LiquidFun / Box2D - Physics and Game Library for PureBas

Post by seangriffin »

djes wrote:Wow, terribly impressive ! :D Thank you !

Edit: I had no luck trying to compile. There' a lot of polink errors... The exe/installer works nicely. What should I do ?
In answer to your question on the errors. Below is the process I follow with success. By the way I'm running Windows 8 64-bit with PureBasic 5.60 x86 ...
I just tried this again myself with success. Can others please confirm it works also?

Note - PB_LiquidFun_OpenGL_demo.pb is dependant on the file LiquidFun-C.pbi in the same folder. In turn this file is dependant on LiquidFun-C.lib and LiquidFun-C.dll in the same folder. So long as all the following 5 files are in the same folder you shouldn't get any polink errors to my knowledge:
  • PB_LiquidFun_OpenGL_demo.pb
  • LiquidFun-C.dll
  • LiquidFun-C.lib
  • LiquidFun-C.pbi
  • LiquidFun-C-Ex.pbi
Also check permissions (like administrator rights) on the files. A friend of mine found Windows 10 by default wasn't giving enough permissions to some files to run.

For PureBasic compiler options I don't believe I've changed anything from the defaults. My Library Subsystem is still blank, Executable format Windows All CPU, Linker options file blank. The only Compiler Option that's checked is "Enable modern theme support". The Compile / Run tab just has Enable Debugger checked.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: LiquidFun / Box2D - Physics and Game Library for PureBas

Post by Lunasole »

I was playing with that Box2D but finally changed to Chipmunk 2D (which is probably worst for liquids, but more optimized and nicely done, that was really cool for me to learn it sources even thought at that moment I was without actual C experience, after pause for a lot of years ^^). Thanks, will be interesting to check your Box2D now
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: LiquidFun / Box2D - Physics and Game Library for PureBas

Post by djes »

seangriffin wrote:PureBasic 5.60 x86 ...
Don't look further ! I've switched to x86, loaded the latest master file and it works flawlessly :)
Joubarbe
Enthusiast
Enthusiast
Posts: 555
Joined: Wed Sep 18, 2013 11:54 am
Location: France

Re: LiquidFun / Box2D - Physics and Game Library for PureBas

Post by Joubarbe »

This really is impressive. I've learned programming with PureBasic and I always missed a proper 2D physics engine. Now there's your LiquidFun and Chipmunk. That's what PB needs, now that proper drawing (vectorDrawing) has been taken care of. Thank you for your work :) Besides, your library seems to manage world and camera, which is really great.

EDIT: a weird thing I noticed though is that in your readme, you said you tested your demo on x64 systems, included Win7, but for me it doesn't work. Same as the previous post from djes, polink errors. Works fine on x86.
madmedicsoft
New User
New User
Posts: 1
Joined: Thu Oct 26, 2017 2:52 am

Re: LiquidFun / Box2D - Physics and Game Library for PureBas

Post by madmedicsoft »

brilliantly
Post Reply