Java port of Bullet

Post Reply
jezek2
Posts: 40
Joined: Fri Jan 11, 2008 8:33 am

Re: Java port of Bullet

Post by jezek2 » Fri Oct 16, 2009 1:26 pm

vinpowful wrote:Hi, jezek2 !
Since few days, i'm unable to go on the website http://jbullet.advel.cz/ , I get an 403 error :?
I'm a student and i'll surely use JBullet for a big project, is there another place to get the last version and find Javadoc / API reference ?

thank you and keep up the great work :)
Oh, fixed now. Thanks for reporting.

Narutachi
Posts: 5
Joined: Tue Nov 24, 2009 3:58 pm

Re: Java port of Bullet

Post by Narutachi » Tue Nov 24, 2009 4:05 pm

Hi, i am currently trying to integrate jbullet into my own project. I am using netbeans and used the build script to build jbullet. After this i added all generated libraries (jar files in the dist folder) into my own project. Then i integrated (basically copied) some code from the hello world file into my main file and tried to run the program but i get the following error:

Exception in thread "main" java.lang.Error: not instrumented
at cz.advel.stack.Stack.alloc(Stack.java:110)
at com.bulletphysics.collision.broadphase.AxisSweep3Internal.<init>(AxisSweep3Internal.java:90)
at com.bulletphysics.collision.broadphase.AxisSweep3.<init>(AxisSweep3.java:52)
at com.bulletphysics.collision.broadphase.AxisSweep3.<init>(AxisSweep3.java:48)
at environement.Physics.PhysicsWorld.initPhysics(PhysicsWorld.java:65)

I already found something here to solve the problem but i do not understand it.

Can somebody help me?

Thanks,
Thomas

Narutachi
Posts: 5
Joined: Tue Nov 24, 2009 3:58 pm

Re: Java port of Bullet

Post by Narutachi » Wed Nov 25, 2009 8:53 am

I got it to work :) The problem seems strange to me but it seems that cross referencing libraries from the jbullet netbeans project to my own netbeans project produced the bug. If i copy the generated libraries (the generated dist folder of the jbullet project) into some folder without a netbeans project in it and use this libraries in my own netbeans project everything works fine.

Bye,
Thomas

debio264
Posts: 5
Joined: Wed Sep 09, 2009 5:52 pm

Re: Java port of Bullet

Post by debio264 » Fri Dec 04, 2009 1:47 am

I stumbled onto JBullet today, and I'm very impressed with it. It runs very well and, at least on my system, it's hard to tell it apart from the original Bullet. I do, however, have some questions:
Why are you using a separate library for stack allocation when automatic stack allocation was added in Java 6? ( http://www.ibm.com/developerworks/java/ ... 09275.html )
Do you plan to implement the KinematicCharacterController, and/or would it be difficult for someone with less experience (like me) to implement?


Edit:
I seem to have answered my own questions to a certain degree.
It looks like KinematicCharacterController is already in the repository after someone on JavaGaming.org implemented it, and I'm seeing people complaining that Java's stack allocation is really too conservative.

jezek2
Posts: 40
Joined: Fri Jan 11, 2008 8:33 am

Re: Java port of Bullet

Post by jezek2 » Wed Dec 09, 2009 12:23 am

debio264 wrote:Why are you using a separate library for stack allocation when automatic stack allocation was added in Java 6? ( http://www.ibm.com/developerworks/java/ ... 09275.html )
Please note the article publish date, it was written before Java 6 release and the actual release didn't have such capability. Current status is that in some development builds of Java 7 there is such option but only available on Server VM. There is probably backport to some Java 6 update, but would need to check. On older computers Server VM introduces serious lags throughput the whole application run so it's not option for interactive applications.
debio264 wrote: ... and I'm seeing people complaining that Java's stack allocation is really too conservative.
Not sure what you mean, can you describe it more?

debio264
Posts: 5
Joined: Wed Sep 09, 2009 5:52 pm

Re: Java port of Bullet

Post by debio264 » Wed Dec 09, 2009 6:47 am

jezek2 wrote:
debio264 wrote:Why are you using a separate library for stack allocation when automatic stack allocation was added in Java 6? ( http://www.ibm.com/developerworks/java/ ... 09275.html )
Please note the article publish date, it was written before Java 6 release and the actual release didn't have such capability. Current status is that in some development builds of Java 7 there is such option but only available on Server VM. There is probably backport to some Java 6 update, but would need to check. On older computers Server VM introduces serious lags throughput the whole application run so it's not option for interactive applications.
debio264 wrote: ... and I'm seeing people complaining that Java's stack allocation is really too conservative.
Not sure what you mean, can you describe it more?
Escape analysis is available as an experimental feature in JRE 6u14 (see http://java.dzone.com/articles/escape-a ... a-6-update), so yea, you're right, it's not mainstream yet. You should probably try it out though.
As for the conservative thing, it's a comment I saw in a few places, but given that it's still an experimental feature, I should probably just ignore those until it becomes official. By conservative, the posters meant that escape analysis was too cautious in its optimizations.

guiramos
Posts: 11
Joined: Fri Dec 18, 2009 7:19 pm

Re: Java port of Bullet

Post by guiramos » Fri Dec 18, 2009 7:22 pm

Exception in thread "main" java.lang.Error: not instrumented
at cz.advel.stack.Stack.alloc(Stack.java:110)
at com.bulletphysics.collision.broadphase.AxisSweep3Internal.<init>(AxisSweep3Internal.java:90)
at com.bulletphysics.collision.broadphase.AxisSweep3.<init>(AxisSweep3.java:52)
at com.bulletphysics.collision.broadphase.AxisSweep3.<init>(AxisSweep3.java:48)
at environement.Physics.PhysicsWorld.initPhysics(PhysicsWorld.java:65)


I am still having troubles on Eclipse trying to debug the application. And yes, I succeded building the source via ANT. But the only way I found to run is via ANT though. So I cannot debug it.
Is there a way to run and debug the code "normally" ?

Somebody can please help me?

Thank you.

debio264
Posts: 5
Joined: Wed Sep 09, 2009 5:52 pm

Re: Java port of Bullet

Post by debio264 » Sat Dec 19, 2009 5:02 am

Take a look at the build instructions - you've missed a step somewhere if you're getting that error.
Are you sure you built the project with Ant, and if so, what command did you use?

guiramos
Posts: 11
Joined: Fri Dec 18, 2009 7:19 pm

Re: Java port of Bullet

Post by guiramos » Mon Dec 21, 2009 4:01 pm

I've made my way and it worked.

Now, another question. It's possible to load a custom model and use its mesh to run some simulations?

Thank you.

debio264
Posts: 5
Joined: Wed Sep 09, 2009 5:52 pm

Re: Java port of Bullet

Post by debio264 » Mon Dec 21, 2009 5:18 pm

Yes, the same way you would with plain old Bullet. Check the demos for examples.
A physics library wouldn't be very useful if it could only use hardcoded primitives.

guiramos
Posts: 11
Joined: Fri Dec 18, 2009 7:19 pm

Re: Java port of Bullet

Post by guiramos » Fri Dec 25, 2009 6:00 pm

Sure debio.

But there is only the MovingConcaveDemo(bunny thing) that reads a static array of vertices and faces indexes.

So I've been trying to write my own Model Loader based on that structure(vertices and indexes). The routing reads the data from a file generated from a maxscript exporter I wrote.
And it didn't worked.

The exception below just keep coming and I cannot figure it out.

Code: Select all

java.lang.IndexOutOfBoundsException
	at java.nio.Buffer.checkIndex(Buffer.java:520)
	at java.nio.DirectByteBuffer.getFloat(DirectByteBuffer.java:806)
	at com.bulletphysics.collision.shapes.ByteBufferVertexData.getVertex(ByteBufferVertexData.java:58)
	at com.bulletphysics.extras.gimpact.TrimeshPrimitiveManager.get_vertex(TrimeshPrimitiveManager.java:121)
	at com.bulletphysics.extras.gimpact.TrimeshPrimitiveManager.get_primitive_triangle(TrimeshPrimitiveManager.java:138)
	at com.bulletphysics.extras.gimpact.TrimeshPrimitiveManager.get_primitive_box(TrimeshPrimitiveManager.java:128)
	at com.bulletphysics.extras.gimpact.GImpactBvh.buildSet(GImpactBvh.java:127)
	at com.bulletphysics.extras.gimpact.GImpactShapeInterface.calcLocalAABB(GImpactShapeInterface.java:204)
	at com.bulletphysics.extras.gimpact.GImpactShapeInterface.updateBound(GImpactShapeInterface.java:71)
	at com.bulletphysics.extras.gimpact.GImpactMeshShape.calcLocalAABB(GImpactMeshShape.java:237)
	at com.bulletphysics.extras.gimpact.GImpactShapeInterface.updateBound(GImpactShapeInterface.java:71)
	at br.com.rsl.temp.ModelLoader.buildTriMesh(ModelLoader.java:45)
The data generated looks like this:

Code: Select all

6
0.0 -0.907649 0.419731
0.0 -0.907649 0.419731
0.0 -0.907649 0.419731
0.900354 0.0 0.435159
0.0 0.907649 0.419731
0.0 0.0 -1.0
8
1.0 2.0 3.0
1.0 3.0 4.0
1.0 4.0 5.0
1.0 5.0 2.0
2.0 6.0 3.0
3.0 6.0 4.0
4.0 6.0 5.0
5.0 6.0 2.0
6 vertices and 8 faces.
It's a simple piramid. A primitive in 3ds max.

It seems the problem is floating around the "vertex stride" thing. Which I am using the same value(4 * 3) from the bunny example: MovingConcaveDemo.java:111

Why is 4*3? And why the ByteBuffer objects are being created by multiplying the vertices and indexes by 4?

Code: Select all

ByteBuffer.allocateDirect(indexes.length * 4).order(ByteOrder.nativeOrder());
How can I determine an adaptive way to load my custom models?
Please help me.

And merry christmas to all of you.

Thank you.

guiramos
Posts: 11
Joined: Fri Dec 18, 2009 7:19 pm

Re: Java port of Bullet

Post by guiramos » Fri Jan 08, 2010 3:26 pm

The model loading issue was solved.


But I got another doubt. How is the best way to implement a altimeter?

Given a position x,y,z a ray must be cast down on the Y axis until hit something. The distance between this object is your altitude. Right?

So, how can I do that?

thanks

.jayderyu
Posts: 19
Joined: Sat Jan 17, 2009 10:51 am

Re: Java port of Bullet

Post by .jayderyu » Mon Feb 01, 2010 9:17 am

Hi, i'm having some troubles with the IDebugDraw.


here is the initialization code

Code: Select all

		iDebugDraw = new JPCTDebugDraw(world, buffer);
		iDebugDraw.setDebugMode(DebugDrawModes.DRAW_WIREFRAME);
		dynamicWorld.setDebugDrawer(iDebugDraw);
called in the draw loop

Code: Select all

                dynamicWorld.debugDrawWorld();
the implemented IDebugDraw

Code: Select all

package jpctbullet;

import java.awt.Color;
import java.awt.Graphics;
import javax.vecmath.Vector3f;

import com.threed.jpct.*;

import com.bulletphysics.linearmath.IDebugDraw;
import com.bulletphysics.linearmath.VectorUtil;

public class JPCTDebugDraw extends IDebugDraw{
  private int _debugMode;
  private World _world;
  private FrameBuffer _buffer;
  
  private SimpleVector Vec3fToSVec(Vector3f vector)
  {
    // JPCT uses a inverted ZY axis and coordinates so flip them
    return new SimpleVector(vector.x, -vector.y, -vector.z);
  }
  
  
  public JPCTDebugDraw(World w, FrameBuffer b)
  {
    _world = w;
    _buffer = b;
  }
  
  
  public void setDebugMode(int debugMode)
  {
    _debugMode = debugMode;
  }
  
  public int getDebugMode()
  {
    return _debugMode;
  }
  
  
  public void drawLine(Vector3f from, Vector3f to, Vector3f color)
  { 
    if(_debugMode > 0)
    {
      Camera cam = _world.getCamera();
      Graphics g = _buffer.getGraphics();
      Color lastColour = g.getColor();

      SimpleVector pointA = Interact2D.project3D2D(cam, _buffer, Vec3fToSVec(from));
      SimpleVector pointB = Interact2D.project3D2D(cam, _buffer, Vec3fToSVec(to));
      
      g.setColor(new Color(color.x, color.y, color.z));
      
      // do not know why, but some times pointB is null
      if(pointA != null && pointB != null){
        g.drawLine((int)pointA.x, (int)pointA.y, (int)pointB.x, (int)pointB.y);
      }
      g.setColor(lastColour);
    }
  }
  
  
  public void draw3dText(Vector3f location, String textString)
  {
    Camera cam = _world.getCamera();
    Graphics g = _buffer.getGraphics();
    SimpleVector loc = Interact2D.project3D2D(cam, _buffer, Vec3fToSVec(location));
    
    g.drawString(textString, (int)loc.x, (int)loc.y);
  }
  
  
  public void drawContactPoint(Vector3f pointOnB, Vector3f normalOnB, float distance, int lifeTime, Vector3f color)
  {
    
  }
  
  
  public void reportErrorWarning(String warningString)
  {
    System.out.println(warningString);
  }

}

It's not like the code doesn't do anything. I does. It draws RGB axis lines regardless of what I set it too. I would like to get it to work so I can see the wireframe rigid bodies.

lesto
Posts: 1
Joined: Sun Mar 21, 2010 3:30 am

Re: Java port of Bullet

Post by lesto » Sun Mar 21, 2010 3:32 am

Hi, a little big question: is JBullet deterministic? has anyone test this? It was developed thinking about it or if I found jbullet acting in deterministic way is just a lucky shoot?
thanks for reply :mrgreen:

dcp
Posts: 9
Joined: Tue Jul 13, 2010 7:52 pm

Re: Java port of Bullet

Post by dcp » Tue Jul 13, 2010 7:58 pm

I am trying to create a roulette game using jBullet for the spinning of the ball. I am not sure what collision shape to use for the wheel.

I chose ConvexHullShape and passed in the vertices of the model, however I am not sure I have done this part properly.

Code: Select all

    ConvexShape staticScenario = new ConvexHullShape(ModelPhysics.getVertices3f(node));
    Transform startTransform = new Transform();
    startTransform.setIdentity();

    float mass = 0f;

    startTransform.origin.set(new Vector3f(0, 0, 0));

    RigidBodyConstructionInfo info = new RigidBodyConstructionInfo(mass, new DefaultMotionState(
      startTransform), staticScenario, new Vector3f(0, 0, 0));
    wheel = new RigidBody(info);
    wheel.setCollisionFlags(wheel.getCollisionFlags() | CollisionFlags.STATIC_OBJECT);
    dynamicsWorld.addRigidBody(wheel);
ModelPhysics.getVertices3f(node) just passes through all the nodes of my model and returns the vertices.

When I drop a ball into the model, it stops around 25 units on top of the floor and then proceeds to role/hover to the edge of the model and fall off. Why is the ball not touching the model surfaces?

Any help would be appreciated.

Thanks,
Dave

Post Reply