OpenGL rubiks cube - face rotation with the mouse

I am working on my first real OpenGL project. This is a Rubiks 3x3x3 cube. Here is a link to a simple screenshot of what I still have ( my rubiks cube )

Cube rotation is performed by dragging the mouse while holding the right mouse button. This works using the arcball example from NeHe Tutorials ( NeHe Arcball )

I have a singleCubes class that represents a single cube through 6 real ATVs stored in a display list that can be used in the drawing method. The ComplexCube class has a 3C3x3 singleCubes array and is used as an interface when interacting with a full rubiks cube.

Now I want to rotate each specific face according to the mousedragging left mouse button. I use collection to get the identifier of the corresponding side of one cube that the user clicked on. This also works. Therefore, I click on the side of one cube on the face, and depending on the direction of the drag, I set the rotation and displacement of the cubes that are affected. (I also want to realize that they actually see that the face rotates, and not just changes color)

Now my problem is that when I rotate the rubiks cube in any direction by dragging with the right mouse, it, for example, is turned upside down. Therefore, when I click on the side and want to turn my face to the right, this happens incorrectly, because I can’t track if the cube is upside down or something else. Due to the use of the arcball rotation, I don't have the x or y rotation angle that I could use to determine this.

Question 1: . How can I track or retrieve information later if the cube is upside down, tilted, etc., to translate the drag and drop information with the mouse (while rotating one side) when using the above example arcball?

// In render function
glPushMatrix();
{
    glMultMatrixf(Transform.M); // Rotation applied by arcball object
    complCube.draw();           // Draw all the cubes using display lists
}
glPopMatrix();

Customization: C ++ with Microsoft Visual Studio 2008, GLEW, freeglut

+5
2

gluUnProject 3D- ( ). "" . gluUnProject , .

, "" , ( (1,0,0), (0,1,0), (0,0,1)). , . , ( ):

Example of the vectors used in the explanation

, "" , - . , . . .

,

, , , . , 800x800 , rubiks . , , , .

, gluUnProject ( , ):

p1 : (600, 600) -> (1, -0.5, 0)
p2 : (630, 605) -> (1.3, -0.505, 0)

: p2 - p1 = v = (0,3, -0,05, 0). , " ", , ( 0,3 x) ( rubiks ). "", x, y, z , :

v1 = (0.3, 0, 0)
v2 = (0, -0.05, 0)
v3 = (0, 0, 0)

, v1 = (0,3, 0, 0). . ( (0, 0, 1)). , (0, 1, 0) ( ) ( , , (0.02, 1.2, 0.8) β†’ (0, 1, 0) , ). 0,3 ( , a).

, , ? , . :

p1 : (600, 600) -> (-1, 0.5, 0)
p2 : (630, 605) -> (-1.3, 0.505, 0)

. ? ! , p2 - p1 = v = (-0,3, 0,05, 0). (-0,3, 0, 0). , , .

- , ( ), x z ( ), .

+4

All Articles