2

I'm a newbie in c++ and openGL so keep in mind that my coding skills are not top notch but I'm a quick learner.

So,because my favorite puzzle is the Rubik's Cube,I decided to unleash my creativity so now I'm currently making a 3D Rubik's Cube and I'm representing each cubie piece(26 pieces excluding the core piece) individually using quads.(planning to use textures in the future after I learn how to use them)

Right now I'm able to rotate the camera around using glRotatef and see the whole cube.

The main problem I have stumbled upon is rotating each face by its own and also keeping track of the cubies to determine which faces they now belong to which will also determine if they will be affected if the face rotated.

At this point I have realized that using glRotatef will bring no good in moving forward so I searched around and found out about Quaternions so I have read a bunch of tutorials about them but I have no idea how to implement them and use them.

This is the last tutorial I have been reading:

http://www.cprogramming.com/tutorial/3d/quaternions.html

My request would be a very simple example on how to implement it and use it in my display function.

As for keeping track of the cubies,I'm currently thinking of using 6 booleans for each piece to determine their position through the center pieces.

If you have any other better ideas or concepts on managing face rotations please do tell.

Regards,,

  • There are some details here http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation – Caribou Nov 17 '12 at 19:39
  • Unclear. Do you have a problem with changing the state of the cube from one operation to the other (like 'rotate left face 90 deg CW') or a problem with smooth animating each operation? These are completely different problems and you have to solve them independently. – Yakov Galka Nov 17 '12 at 20:38
  • Matrices are easier to work with than quaternions. If you dont really really need them stay with matrices. The above does not require quaternions. –  Nov 17 '12 at 21:56

1 Answers1

0

The main problem I have stumbled upon is rotating each face by its own and also keeping track of the cubies to determine which faces they now belong to which will also determine if they will be affected if the face rotated.

That's your whole algorithm right there basically. What you can do is have a data structure that holds 6 "Faces". These faces are the sides of the cube. Each face will have a pointer to the NorthFace,SouthFace,EastFace, and WestFace. Also each face will contain 3 rows of 3 column cubes. You should now have the necessary operation to move a face up down and so on.

dchhetri
  • 6,926
  • 4
  • 43
  • 56