Page 1 of 1

Lightweight engine for simulating dice?

Posted: Sat Feb 13, 2016 12:03 am
by GameSmith
I'm making a simple dice game and would like to have animated dice rolls but don't really want a full blown physics engine so was wondering what the best approach would be given the simplified constraints:

* Only unit cube rigid bodies (possibly other regular polyhedrons later on)
* Collision planes for the floor and walls
* Only a few rigid bodies to simulate (~5 dice)

I am looking for the most simple, robust method that looks acceptable.

I've tried a few approaches - a point/stick verlet model, a basic single contact impulse model, but it's proving quite difficult to keep things simple and stable.

Any ideas?

Re: Lightweight engine for simulating dice?

Posted: Sat Feb 13, 2016 11:08 am
by DannyChapman
If you only want one die, on a plane for the floor, and a couple of planes for the walls, you can "roll your own" (ha ha - sorry!) using the verlet stick-and-particle method (though getting decent friction is always a pain with that).

If you want any more than that, using Bullet (what platform are you targeting?) will be simpler to code, more reliable, less effort, and probably cheaper computationally. Also, if you want to extend things in the future (fancy shaped dice) it will be trivial.

Re: Lightweight engine for simulating dice?

Posted: Sat Feb 13, 2016 3:48 pm
by GameSmith
It will be java based, either Android or cross compiled with GWT for the web.

So I could use JBullet, but I have a very strong (probably irrational) dislike of bloating an app with large libraries only to use a tiny fraction of their capabilities.
I was hoping there was a simplified way of doing physics that only works well on cubes, but there probably isn't one.

Re: Lightweight engine for simulating dice?

Posted: Tue Feb 16, 2016 10:24 pm
by RandyGaul
Here's a minimalistic 3D library with only 3D AABB collision detection, that does pretty much exactly what you're asking for and not much else: https://github.com/RandyGaul/qu3e

I'm the author of the library, so if you'd still like to implement your own solution I'd be happy to discuss in more detail anything specific. Danny's solution sounds fun to implement but in the end it would probably take more time + maintenance than just using someone else's solution as you seem to have already begun to figure out :)

Once you go to 3D and want something stable the complexity requirements are fairly high and do not budge much. This is just the nature of 3D collision detection, and resolution stability.

Re: Lightweight engine for simulating dice?

Posted: Wed Feb 17, 2016 4:04 pm
by GameSmith
I looked at qu3e, but even that was a bit more complex than I was after (not to mention I would have to port it to Java).

After fixing a few bugs with my 1 die implementation I finally got it stable and looking decent enough to pass muster. I also realized the die/die collisions don't actually need to be that accurate because they hardly ever collide and just pushing them apart when it does happen isn't too noticeable. Likewise the wall collisions can just be simple linear velocity reflections without even worrying about rotation.

Edit:
Here is a WebGL deployed version, just click to roll dice:

http://www.angryoctopus.co.nz/webdice/