Rotating meshes around a point

Software: Away3D 4.x

rory, Newbie
Posted: 01 October 2012 12:00 PM   Total Posts: 2

HI,

First of all - great 3d package! I’ve managed to add it to my current Flex project with only minor problems (my mistakes) and I’ve been very impressed so far.

On to the problem - I have 64 cubes contained in an ObjectContainer3D and I’d like them to rotate 90 degrees on a different axis when I press a button. It kind-of-works (the gimbal lock threw me for a bit) but I’m hoping there’s a better way. My hope for this is to develop something similar to a Rubik’s cube - like a number puzzle.

Here’s what I’ve done so far in order to make the container rotate:

public function rotateCube(axis:Stringdeg:int 90):void
{
 
if (!Tweener.isTweening(cubeContainer)) {
  
var mat:Matrix3D dummyCube.transform.clone();
  switch (
axis{
   
case 'x':
    
mat.appendRotation(deg, new Vector3D(100));
    break;
   case 
'y':
    
mat.appendRotation(deg, new Vector3D(010));
    break;
   case 
'z':
    
mat.appendRotation(deg, new Vector3D(001));
    break;
  
}
  dummyCube
.transform mat;

  
// Tween it!
  
Tweener.addTween(cubeContainer{ rotationXdummyCube.rotationXrotationYdummyCube.rotationYrotationZdummyCube.rotationZtime0.7transition:'easeOutBack' });
 
}

A matrix transformation is applied to a dummy cube, then the Tweener rotates the container to match the rotationX/Y/Z of the dummy. It has potential, but I think I’m doing it wrong and would welcome some advice.

Cheers

   

rory, Newbie
Posted: 07 October 2012 09:44 AM   Total Posts: 2   [ # 1 ]

I’ve managed to fix this issue by re-evaluating the problem (had to stop thinking it was a rubik’s cube).

Just in case anyone would like the code:

public function rotateCubes(axis:Stringdeg:int 90):void
{
 
if (isRotatable{
 
  
// Disbale rotation
  
isRotatable false;
    
  var 
i:uintcube:Meshimax:int cubeContainer.numChildrendestX:intdestY:intdestZ:intatan2:Numberdist:int;
  for (
0i<imaxi++) {
     
   
// The cube
   
cube cubeContainer.getChildAt(i) as Mesh;
     
   switch(
axis)
   
{
    
case 'x'// up/down
    
{
     atan2 
Math.atan2(cube.ycube.z) + ( deg * (Math.PI/180) );
     
dist Math.ceil(Math.sqrt((cube.cube.y) + (cube.cube.z)));
     
destX cube.x;
     
destY Math.sin(atan2) * dist;
     
destZ Math.cos(atan2) * dist;
     break;
    
}
    
case 'y'// left/right
    
{
     atan2 
Math.atan2(cube.xcube.z) + ( deg * (Math.PI/180) );
     
dist Math.ceil(Math.sqrt((cube.cube.x) + (cube.cube.z)));
     
destX Math.sin(atan2) * dist;
     
destY cube.y;
     
destZ Math.cos(atan2) * dist;
     break;
    
}
    
case 'z'// clock/counter
    
{
     atan2 
Math.atan2(cube.ycube.x) + ( deg * (Math.PI/180) );
     
dist Math.ceil(Math.sqrt((cube.cube.y) + (cube.cube.x)));
     
destX Math.cos(atan2) * dist;
     
destY Math.sin(atan2) * dist;
     
destZ cube.z;
     break;
    

   }
     
   TweenLite
.to(cube0.6{xdestXydestYzdestZonComplete:enableRotate});
     
  
}
 }
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X