0
votes

I want to have a 3d dice that can be dropped onto a surface and land face down. I also want to give the cube a random rotation velocity so the cube rotates in mid air before landing so I get a random result.

I've looked around but I cant find anything on the subject. I know how to render and spawn the dice as well as have it affected by gravity and how to give it a random rotation velocity as well as how to stop it once it hits a surface but how can I make sure it lands face down and then how can I tell which face is facing upward so I can get the value that the dice landed on?

1

1 Answers

2
votes

What you want is rigid body physics simulation. I would recommend using a physics simulation library, such as bullet.

Physics libraries usually provide functions to know if an object is "sleeping" (not moving). This can be used to trigger the dice value readout.

To know which face is facing upward, you can get the transformation matrix M of your cube, apply it to a unit vector and look where this result vector is pointing to.

If you prefer implementing the physics by yourself, those papers are really good to know the basics of rigid body simulation :

https://www.cs.cmu.edu/~baraff/sigcourse/notesd1.pdf https://www.cs.cmu.edu/~baraff/sigcourse/notesd2.pdf