Rotation

0641056ab1ed2f21accfa478a2ab42e2
0
Astro 101 Apr 13, 2003 at 19:48

I have tried absolutely everything with this piece of code to get it working without success. The output is a scrambled cube but it does not show each rotation as it happens. What am I missing??? If you can think of anything at all, please let me know.

Thanks.

/* Process the main menu when the right mouse button is pressed*/
static void selectMainMenu(int selection)
{
int numb_of_rotations = 1; //maximum number of rotations
int i;

switch (selection)
{
case MAIN_MENU_QUIT:
exit(0); break; //terminates the application

case 1: /* stop cube spinning */
spinStop();
sx=sy=sz=0;/*makes sure no part of the cube is selected when spinning stops*/
break;

case 2: /* help */
//help();

/* windows system call that tells windows to open the help text file */
system(“notepad C:\Program Files\Microsoft Visual Studio\MyProjects\RubikCubefyp\interface.txt”);
break;

case 3:
for( i=0; i < numb_of_rotations; i++)
{
rotcounter = 1;

for(int j=0; j< numb_of_rotations; j++) //to ensure all axis are randomized
{
scramble_cube(); /* call to scramble cube function */

//glutPostRedisplay();
}
//rotcounter = 0;
//sx=sy=sz=0;//nothing is selected, no grey areas
}
rotcounter = 1 ;
break;

case 4: /* reset */
resetcube();
sx=sy=sz=0;/*makes sure no part of the cube is selected when reset*/
break;

case 5: /* spin cube */
spinDisplay();
sx=sy=sz=0;/*makes sure no part of the cube is selected when spinning starts*/
break;

case 6: /* solve */
// solve_cube();
break;
}

/* Scrambles the rubik’s cube */

void scramble_cube(void)
{
int axis ;
char char_axis;
int direction;

axis = rand() % 3;//selects a random axis
cout << “axis = “ << axis << endl ;

switch (axis)
{
case 0:
char_axis = ‘z’;
//rotcounter = 0;
//inputUpdate() ;
break;

case 1:
char_axis = ‘x’;
//rotcounter = 0;
//inputUpdate();
break;

case 2:
char_axis = ‘c’;
//rotcounter = 0;
//inputUpdate() ;
break;
}

cout << “char_axis = “ << char_axis << endl;
Keyboard(char_axis, 0, 0);

direction = rand() % 3 ; //creates a ramdom direction

//from rotate_selected in main
if(direction == 0) //no dierection at start
rotate_selected(-1); //counter-clockwise rotation

else
rotate_selected(1) ; //clockwise rotation
//glutPostRedisplay();
}
}

4 Replies

Please log in or register to post a reply.

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Apr 13, 2003 at 23:25

the code [that you provided above] seems to work. do you have an idea as to where the “error” may be? are you willing to show us your entire program?

mod: there’s two threads. can you please merge? thanks

:yes:

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Apr 13, 2003 at 23:41

do you know of rotate_selected(…) works properly?

:yes:

590e8bdac8129bd87b188df15e62d0e5
0
CyraX 101 Apr 14, 2003 at 06:59

Assuming that your cube is not rotating:
Check the function that does the glRotate().
remember that you might be undoing the rotation… its very genuine.

91fcffbb41940d7cf8d1dd7696095948
0
vinmar 101 Apr 14, 2003 at 08:59

I’m not sure I follow what you mean. Is the problem that when you call the scramble_cube, it isn’t making the cube become randomised. Or is it that cube rotation is not being displayed on your screen?