# Rubik's cube array rotation

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?

• 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. Jun 27, 2013 at 13:30

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.