// testface: given cube at lattice (i, j, k), and four corners of face, // if surface crosses face, compute other four corners of adjacent cube // and add new cube to cube stack void IsoSurfacePolygonizer::testFace(int i, int j, int k, const StackedCube &oldCube, CubeFace face, CubeCorner c1, CubeCorner c2, CubeCorner c3, CubeCorner c4) { static int facebit[6] = {2, 2, 1, 1, 0, 0}; int bit = facebit[face]; bool c1Positive = oldCube.m_corners[c1]->m_positive; // test if no surface crossing, cube out of bounds, or already visited: if(oldCube.m_corners[c2]->m_positive == c1Positive && oldCube.m_corners[c3]->m_positive == c1Positive && oldCube.m_corners[c4]->m_positive == c1Positive) { return; } // create new cube: StackedCube newCube(i, j, k,0); if(!addToDoneSet(newCube.m_key)) { return; } newCube.m_corners[FLIP(c1, bit)] = oldCube.m_corners[c1]; newCube.m_corners[FLIP(c2, bit)] = oldCube.m_corners[c2]; newCube.m_corners[FLIP(c3, bit)] = oldCube.m_corners[c3]; newCube.m_corners[FLIP(c4, bit)] = oldCube.m_corners[c4]; for(int n = 0; n < ARRAYSIZE(newCube.m_corners); n++) { if(newCube.m_corners[n] == NULL) { newCube.m_corners[n] = getCorner(i+BIT(n,2), j+BIT(n,1), k+BIT(n,0)); } } if( !m_boundingBox.contains(*newCube.m_corners[LBN]) || !m_boundingBox.contains(*newCube.m_corners[RTF])) { return; } pushCube(newCube); }
void IcpFramedTracker::initTracker() { /* copy and extend the search window */ SelectionCube::Ptr newCube(new SelectionCube(*searchWindow)); newCube->setSx( newCube->getSx() + boarderSize ); newCube->setSy( newCube->getSy() + boarderSize ); newCube->setSz( newCube->getSz() + boarderSize ); searchWindow = newCube; /* init trace */ trace->clip = clip; trace->coordinateFrame = coordinateFrame; /* init position */ currentTransform.setIdentity(); currentTransform.translate(cloudTemplate->center); }
// ************************************************************ int main( void) { // double t; short v, i, j; char start; char roll; char s[32], kj; // init offsets x0 = 125; y0 = 100; z0 = 200; // hardware and video initialization MMBInit(); initVideo(); initMatrix( mw, AOFFS, BOFFS, GOFFS, x0, y0, z0); // 3. main loop while( 1) { roll = 1; start = 0; gClearScreen(); // splash screen setColor( 2); // red AT(8, 1); putsV( "Rubik's Cube Demo"); AT(8, 3); putsV( " LDJ v1.0"); AT(8, 5); putsV( " for PIC32MX4 MMB"); copyV(); // update visible screen while( !MMBReadKey()); srand( ReadCoreTimer()); // clear all objects objc = MAXOBJ; pyc = MAXPOLY; pc = MAXP; // init all objects angles for( i=0; i<MAXOBJ; i++) a[i] = b[i] = g[i] = 0; // create the rubik cube newCube(); // init cursor and define grid qx = 1; qy = 1; initGrid(); while ( roll) { // paint cube in current position (with cursor) gClearScreen(); // clear the hidden screen for( i=objc; i<MAXOBJ; i++) { initMatrix( mo, 0, 0, 0, 0, 0, 0); drawObject( mo, i); } drawCursor( qx, qy); copyV(); // read the joystick and rotate center rows kj = MMBGetKey(); if ( kj & 0x80) // long pressure { switch( kj & 0x7F){ case JOY_RIGHT: // rotate whole cube rotateCube( 0, +1, 0); break; case JOY_LEFT: // rotate whole cube rotateCube( 0, -1, 0); break; case JOY_UP: // rotate whole cube rotateCube( -1, 0, 0); break; case JOY_DOWN: // rotate whole cube rotateCube( +1, 0, 0); break; case JOY_SELECT: // rotate face counter clockwise rotateRow( 0, 0, 1, 2, +1); break; } } else // short pressure { switch( kj){ case JOY_RIGHT: // rotate only the current row if (qx == 2) rotateRow( 0, 1, 0, qy, +1); else qx++; break; case JOY_LEFT: // rotate only the current row if (qx == 0) rotateRow( 0, 1, 0, qy, -1); else qx--; break; case JOY_UP: // rotate only the current row if (qy == 2) rotateRow( 1, 0, 0, qx, -1); else qy++; break; case JOY_DOWN: // rotate only the current row if (qy == 0) rotateRow( 1, 0, 0, qx, +1); else qy--; break; case JOY_SELECT: // rotate face clockwise rotateRow( 0, 0, 1, 2, -1); break; } // switch } // short pressure } //roll } // main loop } // main
int main(int argc, char *argv[]){ getinfo(&screen); clear(0); Triangle tri[] = { {-1,0,1, -1,1,1, -2,0,1, 0xFFFF},{-2,1,1, -1,1,1, -2,0,1, 0xFFFF}, {-1,0,0, -1,1,0, -2,0,0, 0xFFFF},{-2,1,0, -1,1,0, -2,0,0, 0xFFFF}, {-1,0,0, -1,0,1, -2,0,0, 0xFFFF},{-2,0,0, -1,0,1, -2,0,1, 0xFFFF}, {-1,1,0, -1,1,1, -2,1,0, 0xFFFF},{-2,1,0, -1,1,1, -2,1,1, 0xFFFF}, {-1,0,0, -1,1,1, -1,0,1, 0xFFFF},{-1,0,0, -1,1,1, -1,1,0, 0xFFFF}, {-2,0,0, -2,1,1, -2,0,1, 0xFFFF},{-2,0,0, -2,1,1, -2,1,0, 0xFFFF} }; Line complex[] = { {2,2,2, 3,2,2, 0xFFFFFF}, {2,2,2, 2,2,3, 0xFFFFFF}, {3,2,2, 3,2,3, 0xFFFFFF}, {2,2,3, 3,2,3, 0xFFFFFF}, {2,2,2, 2.5,1,2.5, 0xFFFFFF}, {2,2,3, 2.5,1,2.5, 0xFFFFFF}, {3,2,2, 2.5,1,2.5, 0xFFFFFF}, {3,2,3, 2.5,1,2.5, 0xFFFFFF} }; Camera defaultcam = {0, 0, -2, 0, 0, 0, 0, 0, 1}; Player p = {defaultcam, {100,2,0.5,0.25, //size defaultcam.cx,defaultcam.cy,defaultcam.cz, //position 0,0,0, //velocity 0,0,0, //force defaultcam.ox,defaultcam.oy,defaultcam.oz, //orientation 0,0,0, //angular speed 0,0,0 //torque }}; int i; Cube c[] = {newCube(0.25, 0, 0, 0, 0xFF), newCube(0.5, 1, 1, 1, 0xFF00), newCube(1, -2, 2, 2, 0xFF0000)}; char update = 1; while(!checkkey(KEYQ)){ if(checkkey(KEYW)) movePlayer(&p, 0, 0, 0.2); if(checkkey(KEYA)) movePlayer(&p, 0.2, 0, 0); if(checkkey(KEYS)) movePlayer(&p, 0, 0, -0.2); if(checkkey(KEYD)) movePlayer(&p, -0.2, 0, 0); if(checkkey(KEYSPACE) & p.o.y==0){ p.o.vy = 0.2; } //if(checkkey(KEYLEFTCONTROL)) movePlayer(&p, 0, -0.2, 0); if(checkkey(KEYK)>0 & p.o.ox < M_PI/2) p.o.ox += 0.05; if(checkkey(KEYI)>0 & p.o.ox > -M_PI/2) p.o.ox -= 0.05; if(checkkey(KEYL)) p.o.oy += 0.05; if(checkkey(KEYJ)) p.o.oy -= 0.05; if(checkkey(KEYE)==1) wireframe = !wireframe; if(checkkey(KEYX)) resetPlayer(&p, defaultcam); updatePlayer(&p); clear(0); drawTriangles3D(tri, sizeof(tri)/sizeof(Triangle), p.c); drawSphere(1,1,-1,0.2,0xFF00FF,p.c); for(i = 0; i < sizeof(c)/sizeof(Cube); i++) drawCube(c[i], p.c); drawLines3D(complex, sizeof(complex)/sizeof(Line), p.c); drawtext(0,0,"Wireframe test. Press q to exit.",0xFFFFFF); drawline(screen.x/2-8,screen.y/2,screen.x/2+8,screen.y/2,0xFFFFFF); drawline(screen.x/2,screen.y/2-8,screen.x/2,screen.y/2+8,0xFFFFFF); for(i = 0; i < 7; i++) hlt(); } reset(); return 0; }
PCommitable SessionInfoCube::copy() const { checkNotCheckedOut(); PSessionInfoCube newCube(new SessionInfoCube(*this)); return newCube; }