Libgdx Bullet Wrapper now in Nightlies

We got a few very nice contributions over the last two weeks for our Bullet SWIG/JNI wrapper, originally contributed by the now lost Sterwill. I added bullet back into our nightlies build, so you can now enjoy the extension on all desktop operating systems and Android. Note that it won’t work with GWT (and i have no plans to remedy this). I will eventually port it to iOS as well, where by port i mean great a freaking XCode project for it…

Here’s a screenshot of one of the tests, you can find the source here

If you want to play around with the extension, you need to add gdx-bullet.jar and gdx-bullet-natives.jar to your desktop project, and gdx-bullet.jar to your Android project. You’ll also need to copy the libgdx-bullet.so files from the extensions/gdx-bullet/armeabi and armeabi-v7a folders to your Android project’s libs/armeabi and armeabi-v7a folders of course.

Enjoy, and thanks to all the awesome contributors who keep working on this!

  • phil

    hi,

    maybe a silly question, but what does it do?

    bye
    phil

  • http://badlogicgames.com Mario

    Bullet is a 3D physics engine, think Box2D for 3D

  • Steffen

    Hi,

    I added the libraries in eclipse as described, but aparently gdx-bullet only contains three classes:
    - Bullet.class
    - BulletBuild.class
    - GdxTest.class

    The structure of my project looks like this:
    + core library
    -bullet is referenced here
    + desktop app
    -bullet is referenced here
    + Android app
    -bullet
    -bullet-natives referenced here

    Did I miss something?

  • http://www.aurelienribon.com Aurelien Ribon

    And here is our first official libgdx optional module :D
    The Project Setup tool will have to get a dedicated section for them!

  • http://badlogicgames.com Mario

    Crap, Steffen, you are right, forgot to add that to the build script. You can run it from source (Github) in the meantime. I’ll try to fix it this weekend.

  • http://badlogicgames.com Mario

    Oki, gdx-bullet extension should contain all necessary files now :D

  • Asif

    May be its a very silly question, not sure, if this is the right place to post this.

    I have been trying to develop a simple 3d basketball game with this new integration.
    I have successfully constructed the physics elements necessary.

    My next step is to attach touch to ball.
    I found 3 ray Testing function of “btDiscreteDynamicsWorld”.

    For example One is:
    public void rayTest(Vector3 rayFromWorld, Vector3 rayToWorld, SWIGTYPE_p_btCollisionWorld__RayResultCallback resultCallback)

    Now, my problem is no how im being able to find a way to create an object
    of type
    SWIGTYPE_p_btCollisionWorld__RayResultCallback.

    SWIGTYPE_p_btCollisionWorld__RayResultCallback this does not have any public constructor.
    And im not finding any other class that i can fed into these functions.

    Facing Same Problem:
    when i am trying to use btRigidBody.setUserPointer()
    to set my own object to body.
    The signature of this function:

    public void setUserPointer(SWIGTYPE_p_void userPointer)

    Here again, finding no way to create an object of type SWIGTYPE_p_void.

    Im really hoping both of these two has really easy solution, which would prove how stupid this question is.
    Please help me with this.

    Thanks :)
    (And keep on going brothers, there are lots of things coming for libgdx contribution from stupids like me…be sure :))

  • http://www.droidaddiction.com Lukethor

    The link published above does not exist anymore. I downloaded the nightly and installed in my game. Unfortunately the game classes are too many to and involve lots of physics to test. COuld you give a link to the testing demo please

  • Xoppa
  • XtrMag

    I had some problems with the test script.
    I had to change the Overrides in the BulletEntity.java

    Here is my code:

    @Override
    public void getWorldTransform (final btTransform worldTrans) {
    worldTrans.setFromOpenGLMatrix(this.transform.val);
    }

    @Override
    public void setWorldTransform (final btTransform worldTrans) {
    float[] m = new float[16];
    worldTrans.getOpenGLMatrix(m);
    transform.set(new Matrix4(m));
    }

    And i had to change every btVector3 to Vector3 in the DebugDrawer.java
    After all, everything works fine.
    (Sorry, for my bad english)

  • http://www.droidaddiction.com eric echeverri

    I have a running game in the app market that uses the jbullet.jar file. Started upgrading the code to the nightly gdx-bullet from jan 6 2013.
    I specifically ran into the same issue Stephan Wagner ran in this post http://code.google.com/p/libgdx/issues/detail?id=780, where the physics instance seems to loose reference of the rigidBodies.

    Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
    j com.badlogic.gdx.physics.bullet.gdxBulletJNI.btDiscreteDynamicsWorld_stepSimulation__SWIG_2(JLcom/badlogic/gdx/physics/bullet/btDiscreteDynamicsWorld;F)I+0
    j com.badlogic.gdx.physics.bullet.btDiscreteDynamicsWorld.stepSimulation(F)I+6
    J de.swagner.physic.PhysicDemo.render()V
    j com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop()V+453
    j com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run()V+27
    v ~StubRoutines::call_stub

    The offending code that is called from the game instance to create a rigidBiody in the physics instance was the following :

    public static btRigidBody constructRigidBody(btCollisionShape shape,float mass,float x,float y,float z)
    {

    Matrix4 tempMatrix = new Matrix4();
    tempMatrix.idt().translate(new Vector3(x,y,z));

    Vector3 localInertia = new Vector3(0,1,0);
    if(mass!=0)
    shape.calculateLocalInertia(mass, localInertia);
    btDefaultMotionState motionState = new btDefaultMotionState(tempMatrix);

    btRigidBodyConstructionInfo
    rigidBodyCI = new btRigidBodyConstructionInfo(mass,motionState,shape,localInertia);
    btRigidBody rigidBody = new btRigidBody(rigidBodyCI);
    return rigidBody;
    }

    The solution was to create an array of btMotionStates so the physics instance can keep track of the motion state

    public static Array motionStates = new Array();

    public static btRigidBody constructRigidBody(btCollisionShape shape,float mass,float x,float y,float z)
    {

    Vector3 localInertia = new Vector3(0,1,0);
    if(mass!=0)
    shape.calculateLocalInertia(mass, localInertia);
    btDefaultMotionState motionState = new btDefaultMotionState(tempMatrix);
    // added this line
    motionStates.add(motionState);
    btRigidBodyConstructionInfo
    rigidBodyCI = new btRigidBodyConstructionInfo(mass,motionState,shape,localInertia);
    btRigidBody rigidBody = new btRigidBody(rigidBodyCI);
    return rigidBody;
    }

    I am not sure why I have to keep track of motion states when I did not have to do that while I was working with the jbullet.jar file. Just trying to find some explanation is all

    Thanks
    Eric

  • Nishant

    I just wanted to know that can we implemented bullet physics in 2d game if yes then how?

  • Nishant

    How can we implemented bullet physics in 2d game built in libgdx platform

  • Ahmed Zargoun

    can you explain how to use the tests please, i really couldnt understand it

  • jdwis

    Hi Mario/Xoppa
    Download tests, and it seems each examples are spreaded into multiple packages and all over the places, its difficult to keep track of whats going on and how to implement a simple collisoin detection and move an object.
    Isnt it possible to make a simple 1 example of such collision detection so that we can learn it quickly and efficently… U know we are not at your stage level of understanding ;)
    thanks