Excellent ideas, Van!
So I did this:
// Project: Testing 3D Dice Rolls
// Created: 2015-11-26
// set window properties
SetWindowTitle( "Testing 3D Dice Rolls" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetClearColor(100, 100, 255)
SetCameraPosition(1, 5.0, 5.0, -5.0)
SetCameraLookAt(1, -5.0, 0, 5.0, 0)
// set physics properties
Create3DPhysicsWorld()
Set3DPhysicsGravity(0.0,-.5,0)
FloorObj = CreateObjectPlane(10.0, 10.0)
RotateObjectLocalX(FloorObj, 90.0)
SetObjectColor(FloorObj, 100, 50, 0, 255)
Create3DPhysicsStaticBody(FloorObj)
Wall1Obj = CreateObjectPlane(10.0, 4.0)
SetObjectPosition(Wall1Obj, 0.0, 2.0, 5.0)
SetObjectColor(Wall1Obj, 90, 40, 0, 255)
Create3DPhysicsStaticBody(Wall1Obj)
Wall2Obj = CreateObjectPlane(10.0, 4.0)
RotateObjectLocalY(Wall2Obj, 90.0)
SetObjectPosition(Wall2Obj, -5.0, 2.0, 0.0)
SetObjectColor(Wall2Obj, 80, 30, 0, 255)
Create3DPhysicsStaticBody(Wall2Obj)
gosub MakeDie
SetObjectPosition(BoxObj, 3.0, 5.0, -3.0)
RotateOBjectLocalZ(BoxObj,45.0)
Create3DPhysicsDynamicBody(BoxObj)
SetObjectShapeBox(BoxObj)
SetObject3DPhysicsLinearVelocity(BoxObj, -5, -5, 5, 25)
do
if GetRawKeyReleased(32)
Reset3DPhysicsWorld()
Set3DPhysicsGravity(0.0,-0.5,0)
Create3DPhysicsStaticBody(FloorObj)
Create3DPhysicsStaticBody(Wall1Obj)
Create3DPhysicsStaticBody(Wall2Obj)
SetObjectPosition(BoxObj, 3.0, 5.0, -3.0)
RotateOBjectLocalZ(BoxObj, Random2(0, 359))
Create3DPhysicsDynamicBody(BoxObj)
SetObject3DPhysicsLinearVelocity(BoxObj, -5, -5, 5, 25)
endif
a$=""
Roll = 0
for D = 1 to 6
if GetObjectWorldY(DiceObj[D]) > Roll then Roll = D
next D
a$ = "Your roll is " + str(Roll)
print(a$)
print("Hit SPACEBAR to roll again")
Step3DPhysicsWorld()
Sync()
loop
MakeDie:
ColorWhite = MakeColor(255,255,255)
DiceImg as integer[6]
DiceObj as integer[6]
ClearScreen()
DrawBox(0,0,255,255,ColorWhite, ColorWhite, ColorWhite, ColorWhite, 1)
DrawEllipse(128,128,24,24,0,0,1)
DiceImg[1] = GetImage(0,0,255,255)
ClearScreen()
DrawBox(0,0,255,255,ColorWhite, ColorWhite, ColorWhite, ColorWhite, 1)
DrawEllipse(42,42,24,24,0,0,1)
DrawEllipse(213,213,24,24,0,0,1)
DiceImg[2] = GetImage(0,0,255,255)
ClearScreen()
DrawBox(0,0,255,255,ColorWhite, ColorWhite, ColorWhite, ColorWhite, 1)
DrawEllipse(42,42,24,24,0,0,1)
DrawEllipse(213,213,24,24,0,0,1)
DrawEllipse(128,128,24,24,0,0,1)
DiceImg[3] = GetImage(0,0,255,255)
ClearScreen()
DrawBox(0,0,255,255,ColorWhite, ColorWhite, ColorWhite, ColorWhite, 1)
DrawEllipse(42,42,24,24,0,0,1)
DrawEllipse(42,213,24,24,0,0,1)
DrawEllipse(213,42,24,24,0,0,1)
DrawEllipse(213,213,24,24,0,0,1)
DiceImg[4] = GetImage(0,0,255,255)
ClearScreen()
DrawBox(0,0,255,255,ColorWhite, ColorWhite, ColorWhite, ColorWhite, 1)
DrawEllipse(42,42,24,24,0,0,1)
DrawEllipse(42,213,24,24,0,0,1)
DrawEllipse(213,42,24,24,0,0,1)
DrawEllipse(213,213,24,24,0,0,1)
DrawEllipse(128,128,24,24,0,0,1)
DiceImg[5] = GetImage(0,0,255,255)
ClearScreen()
DrawBox(0,0,255,255,ColorWhite, ColorWhite, ColorWhite, ColorWhite, 1)
DrawEllipse(42,42,24,24,0,0,1)
DrawEllipse(42,128,24,24,0,0,1)
DrawEllipse(42,213,24,24,0,0,1)
DrawEllipse(213,42,24,24,0,0,1)
DrawEllipse(213,128,24,24,0,0,1)
DrawEllipse(213,213,24,24,0,0,1)
DiceImg[6] = GetImage(0,0,255,255)
ClearScreen()
BoxObj = CreateObjectBox(1,1,1)
for d = 1 to 6
DiceObj[d] = CreateObjectPlane(1,1)
SetObjectImage(DiceObj[d], DiceImg[d],0)
FixObjectToObject(DiceObj[d], BoxObj)
next d
SetObjectPosition(DiceObj[1], 0, 0, -0.51)
RotateObjectGlobalX(DiceObj[2], 90.0)
SetObjectPosition(DiceObj[2], 0, .51, 0)
RotateObjectGlobalY(DiceObj[3], 90)
SetObjectPosition(DiceObj[3], -0.51, 0, 0)
RotateObjectGlobalY(DiceObj[4], 90)
SetObjectPosition(DiceObj[4], 0.51, 0, 0)
RotateObjectGlobalX(DiceObj[5], 90.0)
SetObjectPosition(DiceObj[5], 0, -.51, 0)
SetObjectPosition(DiceObj[6], 0, 0, .51)
Return
Makes a "medialess" die and rolls it. The die is a cube, with six planes fixed to it, each with it's own image applied. The code checks to see which face is highest.
Not the most elegant solution - I haven't played around much with friction and bounciness in the physics commands, so the die jitters sometimes.