Roulette physics

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

Roulette physics

Post by dcp »

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. I have a feeling I am doing something wrong in that function.

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
dcp
Posts: 9
Joined: Tue Jul 13, 2010 7:52 pm

Re: Roulette physics

Post by dcp »

I got the physics to work by passing in 3 points at a time and creating a ConvexShape out of those 3 points. This however creates too many collision objects. Any ideas as to why passing in triangle by triangle works, but when i pass in a list of vertices the physics is all wrong?
Alkane
Posts: 7
Joined: Sat Jul 10, 2010 8:34 pm

Re: Roulette physics

Post by Alkane »

The answer is probably that your shape is somehow concave, when using a ConvexHullShape, it'll take all the points and produce some kind of bounding box out of these, (you can't have holes or acute angles on the outside, I hope you understand what i mean, i'm not a native English speaker, huh)
You'll need to use a CompoundShape with a few ConvexHull to make it work better.
Also do you use the debug drawing ? that helps a lot in those cases :o
dcp
Posts: 9
Joined: Tue Jul 13, 2010 7:52 pm

Re: Roulette physics

Post by dcp »

So I was able to get the physics working properly by using TriangleIndexVertexArray with BvhTriangleMeshShape. Everything is working fine in the physics world.

The only obstacle I have now is getting the rendered wheel to spin with the physics wheel. I got the wheel to spin in the physics engine but when I try to get the rotation and pass it to the rendered wheel nothing happens. I am using Ardor3d with jBullet.

I use setAngularvelocity to rotate the object. Then i do the following to get the rotation:

Code: Select all

      Transform t = new Transform();
      body.getMotionState().getWorldTransform(t);
      t.setIdentity();
      Quat4f temp = new Quat4f();
      t.getRotation(temp);
The value in temp is always the same and never changes.

Any ideas?
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Roulette physics

Post by razer »

BvhTriangleMeshShape is slow. Use compound convex or just many convex objects.
I do not think you will have realistic simulation with reasonable resource consumption.
If you are doing real time game then you should consider to code your own hacki algorythm.
e.g. record how ball jumps simlating in bullet and playing it in your game insteading of real time simulation.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Roulette physics

Post by Erwin Coumans »

You need to remove t.setIdentity();

There should be no problem with a static btBvhTriangleMeshShape.
Thanks,
Erwin
dcp
Posts: 9
Joined: Tue Jul 13, 2010 7:52 pm

Re: Roulette physics

Post by dcp »

I use btBvhTriangleMeshShape for the static and kinematic part of the roulette wheel. Should I use something different for the kinematic part?

I got the rotation working.

What is the best way to have the roulette ball spin around the wheel?
dcp
Posts: 9
Joined: Tue Jul 13, 2010 7:52 pm

Re: Roulette physics

Post by dcp »

So I have everything up and running but I cannot get the physics to simulate spinning a roulette bar properly. When I spin the ball it goes around the wheel many times but verrrrry slowly and after a few minutes of turtle like speeds, the ball slowly starts to move towards the center.

I am doing the following for step simulation:

dynamicsWorld.stepSimulation((float) timer.getTimePerFrame(), 10, 1f/60);

If I put a huge number, perhaps time since the program started running, everything seems to work properly but the bouncing of the ball is a bit off.

Why does this happen?
cowwoc
Posts: 1
Joined: Thu Nov 04, 2010 3:19 am

Re: Roulette physics

Post by cowwoc »

I am having the exact same problem. If I invoke:

Code: Select all

dynamicsWorld.stepSimulation((float) secondsSinceLastFrame, 10, 1f/60);
the simulation runs unnaturally slow. If I multiply secondsSinceLastFrame by a factor of 10 the speed is right but the simulation loses precision (the resulting behavior looks unnatural).

Any ideas?
Post Reply