Lightweight engine for simulating dice?

Please don't post Bullet support questions here, use the above forums instead.
Post Reply
GameSmith
Posts: 3
Joined: Fri Feb 12, 2016 11:50 pm

Lightweight engine for simulating dice?

Post by GameSmith » Sat Feb 13, 2016 12:03 am

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?

DannyChapman
Posts: 85
Joined: Sun Jan 07, 2007 4:29 pm
Location: Oxford, England
Contact:

Re: Lightweight engine for simulating dice?

Post by DannyChapman » Sat Feb 13, 2016 11:08 am

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.

GameSmith
Posts: 3
Joined: Fri Feb 12, 2016 11:50 pm

Re: Lightweight engine for simulating dice?

Post by GameSmith » Sat Feb 13, 2016 3:48 pm

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.

RandyGaul
Posts: 43
Joined: Mon May 20, 2013 8:01 am
Location: Redmond, WA

Re: Lightweight engine for simulating dice?

Post by RandyGaul » Tue Feb 16, 2016 10:24 pm

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.

GameSmith
Posts: 3
Joined: Fri Feb 12, 2016 11:50 pm

Re: Lightweight engine for simulating dice?

Post by GameSmith » Wed Feb 17, 2016 4:04 pm

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/

Post Reply