/* * The Rubik's cube. * * Sed - april 1999 / december 2003. * * This program is in the public domain. *-------------------- * The cube related stuff (init, project, rotate, so on) */ #ifndef _CUBE_H_ #define _CUBE_H_ #define IS_ROTATE 1 typedef struct { short x, y, z; /* position of small cube in big cube */ short colors[6]; /* colors of faces of small cube */ } small_cube; #include typedef struct { small_cube cubes[26]; /* list of small cubes */ int center; /* center of active face */ int rotated; /* the face that is currently rotated */ int anim; /* should we animate rotation */ int orient; /* orient = clockwise/counterclockwise */ int letters; /* use letter signs */ double angle; /* angle for rotate animation */ double matrix[3][3]; /* orthogonal matrix = position of cube */ struct timeval time; /* time */ } CUBE; /* init pos. all angles=0. x25 x22 x20 x 1 x24 x19 x23 x21 x18( x 5 x17 x15 x 2 x 3 x16 x14 x 4 x13 x10 x8(1, -1, -1) x12 x7 x11 x9 x6 x 0 (-1, -1, 1) (1, -1, 1) -------------------------------->X | y x2 x6 | | | | x3 x7 | | | | | -------x | /(160,120) | / x0 x4 | / | z x1 x5 | V Y 0 319 y ---------------------------->x ^ -1 1 | | 1|0 | | .(X, Y) ^ | | 1| | | | | -1|239 z <------.------------ v 2 1 (2-1)/(2-z)=Y/y (2-1)/(2-z)=X/x (2-1)/(2-z)*y=Y (2-1)/(2-z)*x=X 319/Xp=2/(X+1) => Xp=319/2*(X+1) 239/Yp=-2/(Y-1) => Yp=-239/2*(Y-1) */ #include "screen.h" void load_cube(CUBE *, char *); void save_cube(CUBE *); void init_cube(CUBE *, char *, int); void display_cube(CUBE *, SCREEN *); void cube_event(CUBE *); void cube_rotate(SCREEN *, CUBE *, double, double); void reset_cube(CUBE *); void cube_generate_rotate(CUBE *, SCREEN *, int); #endif /* _CUBE_H_ */