A 2d Java physics engine, native java port of the C++ physics engines Box2D and LiquidFun

Overview

jbox2d

Please see the project's BountySource page to vote on issues that matter to you. Commenting/voting on issues helps me prioritize the small amount of time I have to maintain this library :)

JBox2d is a Java port of the C++ physics engines LiquidFun and Box2d.

If you're looking for help, see the wiki or come visit us at the Java Box2d subforum. Please post bugs here on the issues page.

If you're planning on maintaining/customizing your own copy of the code, please join our group so we can keep you updated.

If you're looking to deploy on the web, see PlayN, which compiles JBox2d through GWT so it runs in the browser. The JBox2d library has GWT support out of the box. Also, TeaVM support jbox2d in the browser as well.

If you've downloaded this as an archive, you should find the built java jars in the 'target' directories of each project.

======

jbox2d-library - this is the main physics library. The only dependency is the SLF4J logging library.

jbox2d-serialization - this adds serialization tools. Requires google's protocol buffer library installed to fully build (http://code.google.com/p/protobuf/), but this is optional, as the generated sources are included.

jbox2d-testbed - A simple framework for creating and running physics tests.

jbox2d-testbed-jogl - The testbed with OpenGL rendering.

jbox2d-jni-broadphase - Experiment with moving parts of the engine to C++. Not faster.

Comments
  • NaN on particles at high speeds

    NaN on particles at high speeds

    https://github.com/formula1/jbox2d/blob/d8b11344998ffdf41ffa3d9d3f37d3a6ed1cf22f/jbox2d-testbed/src/main/java/org/jbox2d/testbed/tests/DeadParticle.java

    https://github.com/dmurph/jbox2d/blob/master/jbox2d-library/src/main/java/org/jbox2d/particle/ParticleSystem.java On lines 811 and 812 appears to be the first place the NaNs are showing up. This is caused by certian contacts having NaN weight and normal values.

    What I know

    1. The NaNs are associated primarilly with ParticleContacts
    2. There is no NaNs on Creation of a Particle Contact
    3. I cannot find where the particle contacts are updating other than indexes
    4. Not all of the contacts are getting NaNs, usually there is a big chunk before and a smaller chunk after the area that has errors
    5. There is a pattern (every 35 or every 5) which may be caused by just the fact that theres a pattern in the particles themselves. 6a) This pattern is effected by radius increasing the number of errors the smaller it is, and increasing the number contacts between each error contact 6b) maximum radius errors start to appear is around .4761904

    in addition solveSpring also has a division by 0 problem, but I believe thats more due to the NaNs showing up than anything else.

    opened by formula1 9
  • Extreme unstable of particles

    Extreme unstable of particles

    I am playing around with the particles in jbox2d. At first glance it was working fine, creating a few particles for one group works and was running stable. Now i creating more groups, but joining it together and even with two groups, it gets unstable very fast - particles jump like crazy.

    I am creating particles like this, doing nothing special and later render it using opengl. And yes i am creating particle groups for every lava tile in my map.

            world.setParticleRadius(0.1f * worldScale);
            world.setParticleDamping(0.2f);
            world.setParticleDensity(0.1f);
    
            ParticleGroup lastGroup = null;
            Vec2f tileFluidExt = new Vec2f(1f * worldScale * 0.5f, 1f * worldScale * 0.5f);
            Transform pxf = new Transform();
            pxf.setIdentity();
            CircleShape pshape = new CircleShape();
            for (int y = 0; y < tileFluidsLayer.getHeight(); y++) {
                for (int x = 0; x < tileFluidsLayer.getWidth()-1; x++) {
                    int tile = tileFluidsLayer.getTile(x, y);
                    if (tile == tileFluidsSet.getFirstId() + TileFluid.LAVA) {
                        final Vec2f fluidPos = createTilePosition(new Vec2f(x + 0.5f, y + 0.5f), tileFluidExt);
                        ParticleGroupDef pgf = new ParticleGroupDef();
                        pshape = new CircleShape();
                        pshape.m_radius = (1f - 0.2f) * worldScale;
                        pxf.setIdentity();
                        world.destroyParticlesInShape(pshape, pxf);
                        pgf.shape = pshape;
                        pgf.flags = ParticleType.b2_viscousParticle;
                        pgf.position.set(fluidPos.getX(), fluidPos.getY());
                        ParticleGroup newGroup = world.createParticleGroup(pgf);
                        if (lastGroup != null) {
                            world.joinParticleGroups(lastGroup, newGroup);
                        }
                        lastGroup = newGroup;
                    }
                }
            }
    
    opened by f1nalspace 6
  • Switch to strict floating point math?

    Switch to strict floating point math?

    Lately, I have been concerned about the cross-platform capabilities of my program and thus added the strictfp tag to all float-calculating functions (except for rendering) and switched from using Math to StrictMath. This is not triggered by default as it made a fairly large difference on old systems, but now, my testing shows < 1% difference. It is difficult to allow the user to choose without using some Reflection madness.

    opened by RyanTaker 5
  • Swimming WeldJoint when high distance on impact

    Swimming WeldJoint when high distance on impact

    weldjoints are soft which is good and this issue doesn't happen when all bodies are connected to eachother by weldjoints

    But this issue is particularly relevant attempting to take advantage of a weldjoints softness


    Reasoned Hypothesis -Collision is registered by the body a --passes collision information to body main -nobody else gets the memo (which is fine, everything will get figured out)

    Next TimeStep -This may be where the issue is -main is in incorrect location according to body b --applys impulse to account for that -main is in incorrect location according to body c --applys impulse to account for that

    Next Time step -main is in incorrect location according to body a --applys impulse to account for that

    the loop begins

    Possible Solution(s)

    ==Down the Chain== On impact -Solve velocities, if body b has Weldjoints -for(weldjoint w :body.jointList()) When Solving WeldJoints


    this can be recreated with....

    private Body function createGenericBody(float x, float y){ BodyDef bd = new BodyDef(); bd.bodytype = BodyType.DYNAMIC; bd.position.set(new Vec2(x,y)); Body b = wold.createBody(bd);

    CircleShape c = new CircleShape(); c.setRadius(5);

    FixtureDef fd = new FixtureDef(); fd.shape = c; fd.friction = .3; fd.density = 1;

    }

    public void createSwimmingWeldJoints(){

    Body main = createGenericBody(0,100); Body a = createGenericBody(0,60); Body b = createGenericBody(40,100); Body c = createGenericBody(0,140);

    WeldJointDef wjd =new WeldJointDef(); wjd.initialize(main, a, main.getPosition()); world.createJoint(wjd);

    wjd =new WeldJointDef(); wjd.initialize(main, b, main.getPosition()); world.createJoint(wjd);

    wjd =new WeldJointDef(); wjd.initialize(main, c, main.getPosition()); world.createJoint(wjd);

    }

    opened by formula1 5
  • A change I needed for my project

    A change I needed for my project

    Settings.velocityThresold needs to be modifiable, as it is in other languages.

    I needed that because my world has no gravity, and objects without friction and with full restitution. Having velocityThreshold caused my bodies to stick to walls.

    opened by michaelboccara 5
  • RevoluteJoint weird movement

    RevoluteJoint weird movement

    I am trying to use body and joint to build robot and found that if 2 bodies are connected by 2 joint, revolutejoint, then this robot will move in a strange way. It will rotate by itself without any force or motors involved. But if the 2 bodies are just connected by 1 joint, then it is fine and the robot will just stay on the ground without any weird movements. I am not sure if this is an issue or reasonable in physics.

    opened by shenlirobot 4
  • JavaFX port of testbed

    JavaFX port of testbed

    Here's the code mentioned in issue #43. I created a separate jbox2d-testbed-javafx project, to make it cleaner. But note there are some changes in jbox2d-testbed.

    opened by hallvard 3
  • TimeOfImpact loop fixes

    TimeOfImpact loop fixes

    These are some small fixes for the TimeOfImpact class. I was experiencing occasional stalls in the main loop under certain circumstances. These changes seem to fix those.

    I compared the TimeOfImpact class to the latest C++ Box2D source and ported some of the changes found there.

    b83f937 is not based on the Box2D source and is probably the most important change here as it prevents a whole lot of useless loop iterations under certain conditions. If the root loop is exhausted (performs 50 iterations without reaching a solution) nothing will have changed in the enclosing loop (since neither t1 nor t2 will have changed), so the enclosing loop will continue looping and calculating the same thing without reaching a solution.

    opened by JayH5 3
  • No Target in the builds

    No Target in the builds

    In the README it says: "If you've downloaded this an archive, you should find the built java jars in the 'target' directories of each project." But in the 2.3-BETA or 2.2.1 there is no target directory. If I download the 2.2.1 build from google code, there is a target directory.

    opened by Biodiscus 3
  • ParticleType.b2_colorMixingParticle

    ParticleType.b2_colorMixingParticle

    Incorrect results when Particles are flagged as b2_colorMixingParticle:

    Error: bytewise color-difference https://github.com/jbox2d/jbox2d/blob/master/jbox2d-library/src/main/java/org/jbox2d/particle/ParticleSystem.java#L1178

    Fix: & 0xFF before subtraction

            int dr = (colorMixing256 * ((colorB.r & 0xFF) - (colorA.r & 0xFF))) >> 8;
            int dg = (colorMixing256 * ((colorB.g & 0xFF) - (colorA.g & 0xFF))) >> 8;
            int db = (colorMixing256 * ((colorB.b & 0xFF) - (colorA.b & 0xFF))) >> 8;
            int da = (colorMixing256 * ((colorB.a & 0xFF) - (colorA.a & 0xFF))) >> 8;
    
    opened by diwi 2
  • Spelling Mistake in Sweep class

    Spelling Mistake in Sweep class

    There is a spelling mistake on line 30. "the body origin, which may no coincide with the center of mass. However, to support dynamics we" should be changed to: "the body origin, which may not coincide with the center of mass. However, to support dynamics we"

    sweep spelling mistake

    opened by JordanScarrott 2
  • I got the following error in Bubble-Picker using jbox2d.

    I got the following error in Bubble-Picker using jbox2d.

    When removing items from bubble-picker by using Jbox2d.

    a source with a bug: https://github.com/tuxxon/Bubble-Picker

        Process: com.touchizen.bubblepicker, PID: 30187
        java.lang.AssertionError
            at org.jbox2d.collision.broadphase.DynamicTree.destroyProxy(DynamicTree.java:115)
            at org.jbox2d.collision.broadphase.BroadPhase.destroyProxy(BroadPhase.java:104)
            at org.jbox2d.dynamics.Fixture.destroyProxy(Fixture.java:314)
            at org.jbox2d.dynamics.World.destroyBody(World.java:344)
            at com.igalata.bubblepicker.physics.Engine.move(Engine.kt:66)
            at com.igalata.bubblepicker.rendering.PickerRenderer.onDrawFrame(PickerRenderer.kt:75)
            at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1571)
            at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
    

    More detail = https://stackoverflow.com/questions/65137339/when-removing-items-on-bubble-picker-the-following-errors-occur

    Does anyone help me?

    opened by tuxxon 0
  • Applying a force to a ParticleGroup

    Applying a force to a ParticleGroup

    It seems like JBox2d is missing the API from liquidfun to apply a force to a ParticleGroup. How could I do it with the current JBox2D API? Alternatively, is there any workaround? If not, how would I go about adding support for this?

    Thx.

    opened by dukke 1
  • add particle iteration handling from the C++ lib

    add particle iteration handling from the C++ lib

    This takes the code from the C++ particle solver that handles iterations and ports it to Java. It works in the cases that we are using it in, but I haven't tested it very broadly. It seems to follow the C++ code pretty closely, however.

    opened by deecewan 2
  • update mvn repo

    update mvn repo

    Hello, could you please update maven repo with latest stable version? As I can see, maven repo contain 5-years old version.

    Currently I'm trying to pull changes from jitpack, but I'm waiting more than hour and dependencies still not resolved. Have no idea what is going wrong there, but most probably I will pull repo as archive.

    opened by degr 1
  • can we create a polygonshape-world?

    can we create a polygonshape-world?

    The version of the lib is 2.2.1.1. Can we create a polygonshape-world? Here is the constructor. World(Vec2 gravity) World(Vec2 gravity, IWorldPool pool) World(Vec2 gravity, IWorldPool argPool, BroadPhaseStrategy broadPhaseStrategy)

    Show me a demo please. I'll appreciate it very much.

    opened by liruidong183 0
Java port of Brainxyz's Artificial Life, a simple program to simulate primitive Artificial Life using simple rules of attraction or repulsion among atom-like particles, producing complex self-organzing life-like patterns.

ParticleSimulation simple Java port of Brainxyz's Artificial Life A simple program to simulate primitive Artificial Life using simple rules of attract

Koonts 3 Oct 5, 2022
Minecraft Multi-Threading Mod Fabric Port

MCMTFabric - Minecraft Multi-Threading Mod Fabric Port This mod is based on the amazing work on JMT-MCMT. Please check that repository for details. No

Grider 108 Dec 30, 2022
OptiFine 1.7.3 HD MT G2 (+ Long Distance Patch) port to Fabric.

Fabric Example Mod with StationAPI and BIN Mappings for beta 1.7.3 server + client Setup See the StationAPI wiki. Common Issues Here. License This tem

null 4 Dec 2, 2022
Port of the forge api to fabric, under the same path.

MinecraftForge Forge is a free, open-source modding API all of your favourite mods use! Version Support 1.18.x Active 1.16.x LTS Download Forum Discor

null 16 Dec 6, 2022
LITIENGINE is a free and open source Java 2D Game Engine

LITIENGINE is a free and open source Java 2D Game Engine. It provides a comprehensive Java library and a dedicated map editor to create tile-based 2D games.

Gurkenlabs 572 Jan 7, 2023
LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan), audio (OpenAL), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR) applications.

LWJGL - Lightweight Java Game Library 3 LWJGL (https://www.lwjgl.org) is a Java library that enables cross-platform access to popular native APIs usef

Lightweight Java Game Library 4k Dec 29, 2022
A Java Game Engine created in Java with LWJGL!

?? Suffler Engine Suffler Game Engine is an engine created in java using OpenGL to Graphics. Currently being developed at Eclipse, and Visual Studio C

Suffler Engine 2 Jul 23, 2022
Java / JavaFX / Kotlin Game Library (Engine)

About JavaFX Game Development Framework Why FXGL? No installation or setup required "Out of the box": Java 8-15, Win/Mac/Linux/Android 8+/iOS 11.0+/We

Almas Baimagambetov 3k Jan 2, 2023
A Java Swing based game engine

faypixelengine A Java Swing based game engine What is it? A Java game engine that uses swing and can be used to develop interactive games. The idea fo

null 9 Aug 26, 2022
Orbital a java 2D game engine

Orbital Orbital is a under-development 2D game engine. Installation Orbital is avaliable on Jitpack. See below for the installation: Gradle allproject

null 22 Dec 12, 2022
A modern engine for modded Minecraft.

Flywheel A modern engine for modded Minecraft. About The goal of this project is to provide tools for mod developers so they no longer have to worry a

null 136 Dec 30, 2022
My Game Engine tested via my Cubecraft Game

My Game Engine tested via my Cubecraft Game Install: mvn -P {your OS name} clean install mvn -P mac clean install mvn -P linux clean install mvn -P wi

null 30 Oct 3, 2022
Minecraft mod running on the TTCp engine to load modules written in JS at runtime - with runtime deobfuscation!

PolyFire ClickGUI opens with NUMROW_0 How to use: Run -jsmodules to initialize Navigate to your .minecraft folder Go to config/pf/modules/ Copy Exampl

Daniel H. 8 Nov 18, 2022
Blaze4D - Minecraft but with Vulkan using the Rosella engine.

Information Blaze4D is a Fabric mod that changes Minecraft's rendering engine to use the Vulkan Graphics Library, it is currently in Early Development

Kiln Graphics 257 Dec 30, 2022
HackLights - Simple framebuffer based lighting engine for libGDX

HackLights Simple framebuffer based lighting engine for libGDX. Example See: Sample Code Sample Light Images: Installation Open or create gradle.prope

Ali Asif Khan 13 Dec 5, 2022
A simple puzzle game made with Unity to practice the game engine

A simple puzzle game made with Unity to practice the game engine.

Eyüb Salih Özdemir 1 Mar 30, 2022
Forge example mod showing how to implement native hwid.

auth-client What is this? A forge mod showing how to use this How to use? Copy into your mod or use the base and make your own. You have to compile th

Jake Priddle 6 Jul 1, 2021
Jetserver is a high speed nio socket based multiplayer java game server written using Netty and Mike Rettig's Jetlang.It is specifically tuned for network based multiplayer games and supports TCP and UDP network protocols.

Note New version of Jetserver is called Nadron and is in a new netty 4 branch of this same repo. JetServer is a java nio based server specifically des

Abraham Menacherry 1.2k Dec 14, 2022
With the games: brick breakers, tic-tac-toe, snake and tetris With the apps: calculator, stopwatch and text editor Themes, and hyperlinks

Game-Launcher --------------------- ABOUT THE GAME LAUNCHER ------------------------- With the games: brick breakers, tic-tac-toe, snake and tetris Wi

João Devesa 2 Dec 26, 2021