Help me achieve more realism with my dice?

Post Reply
Anthony
Posts: 13
Joined: Sat Feb 11, 2012 8:44 pm

Help me achieve more realism with my dice?

Post by Anthony » Tue Feb 21, 2012 2:41 pm

Hi all,

I've been working on this for the past week or two (and gotten some great help from these forums) and it's coming along great. Now I'd like to see if I can get some more help simulating a more realistic dice rolling experience. Here's a video of what my application currently looks like:

http://youtu.be/C8uspW9DyRE
(sorry for the quality - i had to record it using FaceTime on my Mac)

As you can see, the dice don't bounce around like real dice do. If you were to drop a real die on a table, it would bounce, spin vigorously, and eventually settle. Mine will bounce around the screen but won't bounce vigorously off the ground, and they also settle too fast. I've played around with the restitution of the dice and the ground, set damping of dice to (0,0), and scaled the gravity to -496.63 (because normal dice are 16mm, and I had to make the dice in my app 0.80m to match the size of their respective graphic POD files: (0.8 / .016) * 9.81 = ~496).

What I'd like to see is the dice hit the ground, bounce up a little and spin, and then hit the ground again and roll a couple times before coming to a complete halt. Here are a couple of the values I'm using:

groundRigidBody: restitution:0.3, friction:0.7
diceRigidBody: restitution:1.2, friction:0.35 (I know the restitution is high but any lower and the dice barely bounce at all)

This is my shakeDevice method. I generate random values for the impulse on the Y and Z axes to make each die bounce around differently:

Code: Select all

-(void)shakeDevice:(int)whichDie
{
    switch (whichDie) {
        case 1:
            shakeDie = dieRigidBody;
            break;
        case 2:
            shakeDie = die2RigidBody;
            break;
        case 3:
            shakeDie = die3RigidBody;
            break;
        default:
            break;
    }
    
    if (left)
    {
        shakeDie->applyImpulse(btVector3(70,[self randomNumberWithLowValue:30.0 highValue:40.0],[self randomNumberWithLowValue:50.0 highValue:70.0]), btVector3([self randomNumberWithLowValue:-1.0 highValue:1.0], [self randomNumberWithLowValue:-1.0 highValue:1.0], [self randomNumberWithLowValue:-1.0 highValue:1.0]));
        left = NO;
    } else {
        shakeDie->applyImpulse(btVector3(-70,-([self randomNumberWithLowValue:30.0 highValue:40.0]),[self randomNumberWithLowValue:50.0 highValue:70.0]), btVector3([self randomNumberWithLowValue:-1.0 highValue:1.0], [self randomNumberWithLowValue:-1.0 highValue:1.0], [self randomNumberWithLowValue:-1.0 highValue:1.0] ));
        left = YES;
    }

}
Would anyone be able to offer a suggestion to get more realistic dice than I currently have?

Thanks!
Anthony

Anthony
Posts: 13
Joined: Sat Feb 11, 2012 8:44 pm

Re: Help me achieve more realism with my dice?

Post by Anthony » Tue Feb 21, 2012 6:51 pm

Hmm, perhaps it's my timestep/substeps? Currently, I have:

Code: Select all

-(void)updatePhysics:(ccTime)dt {
	dynamicsWorld->stepSimulation(1/60.f, 10, 1/120.f);

...
}
Maybe it needs more adjusting?

kloplop321
Posts: 55
Joined: Sun Jan 01, 2012 7:37 pm

Re: Help me achieve more realism with my dice?

Post by kloplop321 » Tue Feb 21, 2012 7:11 pm

Instead of applying a randomly centered impulse to the dice, have you tried to make the cage a kinematic body and move the cage identically(but maybe scaled in force/distance) to how the device shakes?
You would need to move the camera and rotate and so on, but I think it would provide a much more realistic response, because that's how it actually would move.

Anthony
Posts: 13
Joined: Sat Feb 11, 2012 8:44 pm

Re: Help me achieve more realism with my dice?

Post by Anthony » Tue Feb 21, 2012 8:58 pm

Very interesting idea. That would require some complex additions to my code - but the result might be worth it. Thanks for your suggestion kloplop321. While you're here, do you have any idea why the current implementation yields unrealistic results?

kloplop321
Posts: 55
Joined: Sun Jan 01, 2012 7:37 pm

Re: Help me achieve more realism with my dice?

Post by kloplop321 » Wed Feb 22, 2012 4:47 am

I think its because you are only determining a direction on only one dimension, and using random values to do the rest, completely ignoring the actual context of the phone's movement.

It would be a lot easier if you use Quicktime to record a portion of your screen of an iPhone Simulator than to record from a webcam of a phone, I can't accurately judge what the dice look like from your facetime recording.

I also think that if you are using just single box shapes for your dice, this would be one reason for this failure, since dice have rounded edges and can roll a bit.

[Plus, if you actually make it a real dice simulator, as if it were a box, I think people would like it a lot more and actually consider it fun to mimic reality]

User avatar
Dr.Shepherd
Posts: 168
Joined: Tue Jan 04, 2011 11:47 pm
Contact:

Re: Help me achieve more realism with my dice?

Post by Dr.Shepherd » Wed Feb 22, 2012 12:18 pm

I think the framerate is a bit low, which makes it feel a bit "slow motion"

Anthony
Posts: 13
Joined: Sat Feb 11, 2012 8:44 pm

Re: Help me achieve more realism with my dice?

Post by Anthony » Wed Feb 22, 2012 2:16 pm

Thanks Dr.Shepherd - I kept the framerate at 60 because that's the max that an iPhone can support (I think) but I'll try bumping it up to see if I can get better results. Maybe that will help with the slight ghosting that occurs too.

luispa
Posts: 1
Joined: Sat Mar 03, 2012 9:47 pm

Re: Help me achieve more realism with my dice?

Post by luispa » Sat Mar 03, 2012 9:53 pm

Hi Anthony,

Is it possible for you to share parts of your code so It can help me in my learning. I'm new to Bullet and spend a lot of time investigating, but I'm getting frustrated, as I can't find examples and howto's. I'm also working with 1 dice only, and would like to know best practices for example on how to create the walls. I've done it with mass 0 but don't know if it's correct...

So, if you can share your code (or at least the bullet parts of it) would be of great help.

Thanks in advance,
Luis

Anthony
Posts: 13
Joined: Sat Feb 11, 2012 8:44 pm

Re: Help me achieve more realism with my dice?

Post by Anthony » Tue Mar 13, 2012 11:41 pm

I'm back with another question :)

What is the best method to apply a steady, constant velocity to my dice while the user is shaking his phone? Right now I do an applyImpulse() once to the dice when the user shakes his phone, which gives it initial movement, but I would like the dice to continue moving steadily as the user continues to shake his phone. If I continually do applyImpulse(), the motion of the dice is not constant and steady. Any suggestions?

Anthony

User avatar
Pyritie
Posts: 25
Joined: Thu Aug 11, 2011 6:42 pm

Re: Help me achieve more realism with my dice?

Post by Pyritie » Thu Mar 22, 2012 3:31 pm

Anthony wrote:I'm back with another question :)

What is the best method to apply a steady, constant velocity to my dice while the user is shaking his phone? Right now I do an applyImpulse() once to the dice when the user shakes his phone, which gives it initial movement, but I would like the dice to continue moving steadily as the user continues to shake his phone. If I continually do applyImpulse(), the motion of the dice is not constant and steady. Any suggestions?

Anthony
What about modifying their linear velocity?

If you take their linear velocity, normalise it, then multiply it by a sorta speed constant or something, they'll always move at the same speed but still be able to change direction and stuff.

Then when the user stops shaking, stop modifying the velocity.

Post Reply