diff options
-rw-r--r-- | rubik.c | 196 |
1 files changed, 104 insertions, 92 deletions
@@ -48,12 +48,12 @@ static void initRubik (CompScreen *s) { - RUBIK_SCREEN (s); - CUBE_SCREEN (s); + RUBIK_SCREEN (s); + CUBE_SCREEN (s); - rs->tempTransform = malloc (sizeof(CompTransform)); - vStrips = rubikGetNumberStrips(s); - hStrips = rubikGetNumberStrips(s); + rs->tempTransform = malloc (sizeof(CompTransform)); + vStrips = rubikGetNumberStrips(s); + hStrips = rubikGetNumberStrips(s); rs->th = malloc (vStrips*sizeof(float)); rs->oldTh = malloc (vStrips*sizeof(float)); @@ -64,115 +64,120 @@ initRubik (CompScreen *s) int i; - for (i=0; i<vStrips; i++) { + for (i=0; i<vStrips; i++) + { rs->th[i] = 0.0; rs->oldTh[i] = rs->th[i]; } - for (i=0; i<hStrips; i++) { + for (i=0; i<hStrips; i++) + { rs->psi[i] = 0.0; rs->oldPsi[i] = rs->psi[i]; } - currentVStrip = NRAND(vStrips); - currentHStrip = NRAND(hStrips); - currentStripCounter = 0; - currentStripDirection = 1; - rotationAxis = NRAND(1); - - rs->w = NULL; - rs->numDesktopWindows = 0; - speedFactor = rubikGetSpeedFactor(s); + currentVStrip = NRAND(vStrips); + currentHStrip = NRAND(hStrips); + currentStripCounter = 0; + currentStripDirection = 1; + rotationAxis = NRAND(1); - initializeWorldVariables(s->hsize, cs->distance); + rs->w = NULL; + rs->numDesktopWindows = 0; + speedFactor = rubikGetSpeedFactor(s); + + initializeWorldVariables(s->hsize, cs->distance); + + rs->faces = malloc(6*sizeof(faceRec)); + + for (i=0; i<6; i++) + { + rs->faces[i].square = malloc(hStrips*vStrips*sizeof(squareRec)); + } - - rs->faces = malloc (6*sizeof(faceRec)); - for (i=0; i<6; i++) { - rs->faces[i].square = malloc (hStrips*vStrips*sizeof(squareRec)); - } - //sides - setSpecifiedColor (rs->faces[0].color, RED); - setSpecifiedColor (rs->faces[1].color, YELLOW); - setSpecifiedColor (rs->faces[2].color, BLUE); - setSpecifiedColor (rs->faces[3].color, GREEN); + setSpecifiedColor(rs->faces[0].color, RED); + setSpecifiedColor(rs->faces[1].color, YELLOW); + setSpecifiedColor(rs->faces[2].color, BLUE); + setSpecifiedColor(rs->faces[3].color, GREEN); - //top and bottom - setSpecifiedColor (rs->faces[4].color, WHITE); - setSpecifiedColor (rs->faces[5].color, ORANGE); + //top and bottom + setSpecifiedColor(rs->faces[4].color, WHITE); + setSpecifiedColor(rs->faces[5].color, ORANGE); - - initFaces (s); + initFaces(s); } void initializeWorldVariables(int hs, float perpDistCentreToWall) { //precalculate some values - hSize = hs; - q = (float) hSize; + hSize = hs; + q = (float) hSize; - distance = perpDistCentreToWall; - radius = perpDistCentreToWall/sinf(PI*(0.5-1/q)); + distance = perpDistCentreToWall; + radius = perpDistCentreToWall/sinf(PI*(0.5-1/q)); } + void initFaces (CompScreen *s) { - - RUBIK_SCREEN (s); - int i,j,k; - - for (k=0; k<6; k++) { - for (j=0; j< vStrips; j++) { - for (i=0; i< hStrips; i++) { - int index=j*hStrips+i; - - rs->faces[k].square[index].side = k; - rs->faces[k].square[index].x = i;//NRAND(vStrips);//i; - rs->faces[k].square[index].y = j;//NRAND(hStrips);//j; + RUBIK_SCREEN(s); + int i, j, k; - rs->faces[k].square[index].psi = 0; - } - } + for (k=0; k<6; k++) + { + for (j=0; j< vStrips; j++) + { + for (i=0; i< hStrips; i++) + { + int index=j*hStrips+i; + + rs->faces[k].square[index].side = k; + rs->faces[k].square[index].x = i;//NRAND(vStrips);//i; + rs->faces[k].square[index].y = j;//NRAND(hStrips);//j; + + rs->faces[k].square[index].psi = 0; + } } + } } static void freeRubik (CompScreen *s) { - RUBIK_SCREEN (s); - - if (rs->tempTransform) - free (rs->tempTransform); - - if (rs->th) - free (rs->th); - - if (rs->oldTh) - free (rs->oldTh); - - if (rs->psi) - free (rs->psi); - - if (rs->oldPsi) - free (rs->oldPsi); + RUBIK_SCREEN (s); + if (rs->tempTransform) + free(rs->tempTransform); - if (rs->faces) { - int i; - for (i=0; i<6; i++) { - if (rs->faces[i].square) - free (rs->faces[i].square); - } - - free (rs->faces); + if (rs->th) + free(rs->th); + + if (rs->oldTh) + free(rs->oldTh); + + if (rs->psi) + free(rs->psi); + + if (rs->oldPsi) + free(rs->oldPsi); + + if (rs->faces) + { + int i; + for (i=0; i<6; i++) + { + if (rs->faces[i].square) + free(rs->faces[i].square); } - - if (rs->w) - free (rs->w); - + + free(rs->faces); + } + + if (rs->w) + free(rs->w); } static void @@ -333,7 +338,8 @@ static void rubikPaintInside (CompScreen *s, screenCounter++; winCounter = 0; - for (w = s->windows; w; w = w->next) { + for (w = (cs->invert>0 ? s->windows : s->reverseWindows); w; + w = (cs->invert>0 ? w->next : w->prev)) { if (!coloredSides) { if (w->destroyed) continue; @@ -414,6 +420,12 @@ static void rubikPaintInside (CompScreen *s, glPushMatrix(); + if (cs->invert<0) { + glRotatef (180,0,0,1); + glRotatef (180,1,0,0); + glScalef(-1.0f, 1.0f, 1.0f); + } + if(rotationAxis==0) { if (i<4) { if (hs == currentHStrip) @@ -474,7 +486,6 @@ static void rubikPaintInside (CompScreen *s, } - if (i<4) glRotatef (90*i, 0, 1, 0); else if (i==4) @@ -1157,7 +1168,8 @@ RubikPaintTransformedOutput (CompScreen *s, } static Bool RubikPaintWindow(CompWindow *w, const WindowPaintAttrib *attrib, - const CompTransform *transform, Region region, unsigned int mask){ + const CompTransform *transform, Region region, unsigned int mask) +{ CompTransform wTransform = *transform; @@ -1456,22 +1468,22 @@ rubikInitScreen (CompPlugin *p, //WRAP (rs, s, disableOutputClipping, RubikDisableOutputClipping); - return TRUE; + return TRUE; } static void rubikFiniScreen (CompPlugin *p, CompScreen *s) { - RUBIK_SCREEN (s); - CUBE_SCREEN (s); + RUBIK_SCREEN (s); + CUBE_SCREEN (s); - freeRubik (s); + freeRubik(s); - UNWRAP (rs, s, donePaintScreen); - UNWRAP (rs, s, preparePaintScreen); - UNWRAP (rs, cs, clearTargetOutput); - UNWRAP (rs, cs, paintInside); + UNWRAP (rs, s, donePaintScreen); + UNWRAP (rs, s, preparePaintScreen); + UNWRAP (rs, cs, clearTargetOutput); + UNWRAP (rs, cs, paintInside); UNWRAP (rs, s, paintWindow); UNWRAP (rs, s, paintOutput); @@ -1483,8 +1495,8 @@ rubikFiniScreen (CompPlugin *p, //UNWRAP (rs, s, drawWindowTexture); //UNWRAP (rs, s, disableOutputClipping); - - free (rs); + + free(rs); } static Bool |