Convert Figma logo to code with AI

google logoliquidfun

2D physics engine for games

4,698
641
4,698
67

Top Related Projects

A fast and lightweight 2D game physics library.

12,417

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Quick Overview

LiquidFun is an open-source 2D physics engine developed by Google, based on Box2D. It extends Box2D's capabilities by adding fluid and soft body simulation, making it particularly useful for game development and interactive applications. LiquidFun is designed to be fast, portable, and easy to use.

Pros

  • Adds fluid and soft body simulation to Box2D's solid body physics
  • Optimized for performance, suitable for mobile and web applications
  • Cross-platform compatibility (Android, iOS, Windows, macOS, Linux)
  • Well-documented with extensive examples and tutorials

Cons

  • Limited to 2D physics simulations
  • May require more computational resources compared to simpler physics engines
  • Learning curve can be steep for developers new to physics engines
  • Not actively maintained (last update in 2017)

Code Examples

  1. Creating a world and adding a body:
b2World world(b2Vec2(0.0f, -10.0f));

b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(0.0f, 4.0f);
b2Body* body = world.CreateBody(&bodyDef);

b2CircleShape circle;
circle.m_radius = 0.5f;
body->CreateFixture(&circle, 1.0f);
  1. Creating a particle system for fluid simulation:
b2ParticleSystemDef particleSystemDef;
b2ParticleSystem* particleSystem = world.CreateParticleSystem(&particleSystemDef);

b2ParticleGroupDef pd;
pd.flags = b2_waterParticle;
pd.position.Set(0.0f, 10.0f);
pd.shape = &shape;
particleSystem->CreateParticleGroup(pd);
  1. Stepping the simulation:
float timeStep = 1.0f / 60.0f;
int32 velocityIterations = 6;
int32 positionIterations = 2;

world.Step(timeStep, velocityIterations, positionIterations);

Getting Started

  1. Clone the LiquidFun repository:

    git clone https://github.com/google/liquidfun.git
    
  2. Build the library using CMake:

    cd liquidfun
    mkdir build && cd build
    cmake ..
    make
    
  3. Include LiquidFun in your project:

    #include <Box2D/Box2D.h>
    #include <Box2D/Particle/b2Particle.h>
    
  4. Initialize a world and start using LiquidFun features in your application.

Competitor Comparisons

A fast and lightweight 2D game physics library.

Pros of Chipmunk2D

  • Simpler API and easier to integrate into existing projects
  • More lightweight and faster performance for basic 2D physics simulations
  • Better documentation and community support

Cons of Chipmunk2D

  • Lacks advanced fluid simulation capabilities
  • Limited to 2D physics, while LiquidFun supports some 3D features
  • Smaller feature set compared to LiquidFun's extensive physics options

Code Comparison

Chipmunk2D:

cpSpace *space = cpSpaceNew();
cpBody *body = cpBodyNew(1.0, cpMomentForCircle(1.0, 0, 10, cpvzero));
cpSpaceAddBody(space, body);
cpShape *shape = cpCircleShapeNew(body, 10, cpvzero);
cpSpaceAddShape(space, shape);

LiquidFun:

b2World world(b2Vec2(0.0f, -10.0f));
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
b2Body* body = world.CreateBody(&bodyDef);
b2CircleShape circle;
circle.m_radius = 0.5f;
body->CreateFixture(&circle, 1.0f);

Both libraries provide similar functionality for basic physics simulations, but LiquidFun offers more advanced features like fluid dynamics. Chipmunk2D's syntax is generally more concise and easier to read, while LiquidFun's API is more extensive and flexible for complex simulations.

12,417

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Pros of Bullet3

  • More comprehensive physics simulation, including rigid body dynamics, soft body dynamics, and fluid simulation
  • Wider industry adoption and larger community support
  • Supports a broader range of platforms and programming languages

Cons of Bullet3

  • Steeper learning curve due to its extensive feature set
  • Can be more resource-intensive for simpler 2D physics scenarios
  • Less specialized for liquid and soft body simulations compared to LiquidFun

Code Comparison

LiquidFun (C++):

b2World world(gravity);
b2ParticleSystemDef particleSystemDef;
b2ParticleSystem* particleSystem = world.CreateParticleSystem(&particleSystemDef);

Bullet3 (C++):

btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
btRigidBody* body = new btRigidBody(rbInfo);
dynamicsWorld->addRigidBody(body);

LiquidFun focuses on particle-based fluid simulation, while Bullet3 provides a more general-purpose physics engine. LiquidFun's API is simpler for liquid simulations, whereas Bullet3 offers a more comprehensive set of physics objects and interactions. Both libraries are written in C++ and provide similar basic world setup patterns, but Bullet3's API reflects its broader scope and flexibility.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

LiquidFun logo

LiquidFun Version 1.1.0

Welcome to LiquidFun!

LiquidFun is a 2D physics engine for games. Go to our landing page to browse our documentation and see some examples.

LiquidFun is an extension of Box2D. It adds a particle based fluid and soft body simulation to the rigid body functionality of Box2D. LiquidFun can be built for many different systems, including Android, iOS, Windows, OS X, Linux, and JavaScript. Please see Box2D/Documentation/Building/ for details.

Discuss LiquidFun with other developers and users on the LiquidFun Google Group. File issues on the LiquidFun Issues Tracker or post your questions to stackoverflow.com with a mention of liquidfun.

Please see Box2D/Documentation/Building/ to learn how to build LiquidFun and run the testbed.

LiquidFun has a logo that you can use, in your splash screens or documentation, for example. Please see the Programmer's Guide for the graphics and further details.

For applications on Google Play that integrate this tool, usage is tracked. This tracking is done automatically using the embedded version string (b2_liquidFunVersionString), and helps us continue to optimize it. Aside from consuming a few extra bytes in your application binary, it shouldn't affect your application at all. We use this information to let us know if LiquidFun is useful and if we should continue to invest in it. Since this is open source, you are free to remove the version string but we would appreciate if you would leave it in.