Get ‘top’ face material of a cube after rotation

Software: Away3D 2.x

Seabird, Newbie
Posted: 08 May 2012 07:43 AM   Total Posts: 5

Hi,

In my application I need my users to throw a dice.

I’m using the code published on http://active.tutsplus.com/tutorials/3d/throwing-dice-with-the-jiglib-physics-engine-and-away3d/ .

This all works fine, and I really love the effect, but I can’t find any method to calculate what face is on top after the dice has been thrown.

In the comments someone posts a solution, but this only works with Away3D 3.6, and I’m using 2.3.3. It depends on the deltaTransformVector of the Matrix3D. I can’t find the equivalent of this method in 2.3.3.

Does someone has a solution to find the top faced material after the dice rotation, that works in 2.3.3? smile

   

John Brookes, Moderator
Posted: 08 May 2012 09:50 AM   Total Posts: 732   [ # 1 ]

This is for away4 and awayPhysics

private function checkDie():int 
{
 
var topFace:int
 
if (Math.abs (diceRb.up.y) >0.5)
 
{
  
if (diceRb.up.0)
  
topFace 3
  
else
  
topFace 4
 }
 
 
if (Math.abs (diceRb.front.y) == >0.5)
 
{
  
if (diceRb.front.>0)
  
topFace 2
  
else
  
topFace 5
 }
 
if (Math.abs (diceRb.right.y) == >0.5)
 
{
  
if (diceRb.right.>0)
  
topFace 6
  
else
  
topFace 1
 }
 trace
("You threw a " +topFace)
 return 
topFace;

For 3.6 you can use

Matrix3DUtils.getforward(yourMesh.transform)
instead of
diceRb.front etc

Just change the top face numbers to how you have your material mapped to the die.

   

Seabird, Newbie
Posted: 08 May 2012 10:24 AM   Total Posts: 5   [ # 2 ]

Thanks for your reply.

Ah, how I was wrong. The example is using Away 2.3.3 for Flash Player 9. I tried to port the example code to 3.6, but all the sudden only two of the six materials are placed on all the six faces. They are using the following code to apply the materials to the faces. This should work in 3.6 too, right?

  Cube(Away3dMesh(dice.skin).mesh).cubeMaterials.left = diceTextures[0] 
  Cube(Away3dMesh(dice.skin).mesh).cubeMaterials.right = diceTextures[1] 
  Cube(Away3dMesh(dice.skin).mesh).cubeMaterials.front = diceTextures[2] 
  Cube(Away3dMesh(dice.skin).mesh).cubeMaterials.back = diceTextures[3] 
  Cube(Away3dMesh(dice.skin).mesh).cubeMaterials.top = diceTextures[4] 
  Cube(Away3dMesh(dice.skin).mesh).cubeMaterials.bottom = diceTextures[5]

   
   
‹‹ 3d to 2d

X

Away3D Forum

Member Login

Username

Password

Remember_me



X