I'm about to make a 3D Rubik's cube based game in Flash AS3 and Away3d.

I don't really know how to manage the 2D arrays of the Rubik's cube.

For example, how do I rotate the corresponding arrays if I rotate a side, or just rotate a middle part?

In this stage I also don't know how to rotate those smaller cube parts all together if a side is rotating. First I was thinking of "groups" ( like in sketchup or 3ds max, blender), but that would be tricky, because the group components would change every time.

So I was thinking of just rotating each individual piece along a global axis. However, I just know the Away3d functions to rotate the cube of his local X , Y or Z axis, but how to rotate in global axis?

Does anyone know of a algorithm for doing these types of rotations?

  • \$\begingroup\$ Hey Ace. I edited your question to remove the additional question not related to the rotation. I suggest you ask that in a different question. \$\endgroup\$
    – House
    Jun 27, 2013 at 13:30

1 Answer 1


Since you're dealing with arrays, there doesn't have to be any actual rotations. You're just moving data around inside the arrays. For example imagine the top loop of such an array. It combines 4 of those 2D arrays into a strip. Like so:

enter image description here

The coordinates represent the 3D position of the cube being represented. There are of course duplicates for the corners where two faces of the same cube are represented.

Now, if we were to rotate the top layer, we don't have to do any rotating, we just shift data through the arrays:

enter image description here

There may be very clever ways to do this, but there's also brute force simple ways. Create a function for each axis X,Y and Z. Each of these RotateAround functions will take an input for which layer to rotate (1, 2, 3).

So for example, the RotateAroundY(1) call will do exactly as the image above shows. It will take the first row (from the top) of the Xplus, Zminus, Xminus, Zplus faces, and shift all their values through each other.

Another example, RotateAroundX(2) will take the second row of the (from the left) of the Yplus, Zminus, Yminus, ZPlus faces and shift all their values through each other.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .