Person::Person() { //Compile the basic structures, a circle & square that will have transformations applied to model the person circleIndex = glGenLists(1); glNewList(circleIndex, GL_COMPILE); circleMidpoint(); glEndList(); squareIndex = glGenLists(1); glNewList(squareIndex, GL_COMPILE); drawSquare(); glEndList(); }//end Constructor
//Pre: //Post: void Planet::render() { glPushMatrix(); glColor3f(1,1,1); glBegin(GL_LINES); glVertex2f(0,500); glVertex2f(0,-500); glEnd(); glRotatef(90,1,0,0); circleMidpoint(oRadius); glPopMatrix(); glColor3f(color[0], color[1], color[2]); glRotatef(360.0 * dayOfYear / year, 0, 1, 0);//rotate glTranslatef(oRadius, 0, 0); glPushMatrix(); glRotatef(360 * hourOfDay / day, 0,1,0); //Rotate planet on its axis glutWireSphere(pRadius, 50,50); glPopMatrix(); }//end render
void Sun::draw() { circleMidpoint(x, y, radiusRelative); }
//-------------------------------------------------------------- void ofApp::update(){ ofBackground(100,100,100); unsigned char serialBuffer[480]; for (int i=0; i<sizeof(serialBuffer); i+=3) { serialBuffer[i] = 'f'; serialBuffer[i+1] = 'u'; serialBuffer[i+2] = 'k'; } if (serial.available()>0) { tempByte = serial.readByte(); cout << "from arduino:" << tempByte << endl; if (firstContact == false) { if (tempByte == 'A') { serial.flush(); // clear the serial port buffer firstContact = true; // you've had first contact from the microcontroller serial.writeByte('A'); // ask for more } } // //serial.flush(true, false); // serial.writeBytes(&serialBuffer[0], sizeof(serialBuffer)); } bool bNewFrame = false; #ifdef _USE_LIVE_VIDEO vidGrabber.update(); bNewFrame = vidGrabber.isFrameNew(); #else vidPlayer.update(); bNewFrame = vidPlayer.isFrameNew(); #endif if (bNewFrame){ #ifdef _USE_LIVE_VIDEO pixelStripBoxFull = vidGrabber.getPixelsRef(); #else pixelStripBoxFull = vidPlayer.getPixelsRef(); #endif int g=0; while (g < pixelStripBoxFull.getHeight()) { //move to new row int g_prime = g; int vertSubSize = subDivisionSize; if (subDivisionSize + g >= pixelStripBoxFull.getHeight()) { g_prime = pixelStripBoxFull.getHeight() - g; vertSubSize = g_prime; } int i = 0; while (i < pixelStripBoxFull.getWidth()) { //fill in row int i_prime = i; int horSubSize = subDivisionSize; if (subDivisionSize + i >= pixelStripBoxFull.getWidth()) { i_prime = pixelStripBoxFull.getWidth() - i; horSubSize = i_prime; } //get colors in top-left and bottom-right corners of matrix ofColor a = pixelStripBoxFull.getColor(i, g); ofColor b = pixelStripBoxFull.getColor(subDivisionSize+i_prime-1, subDivisionSize+g_prime-1); //linear interpretation between colors ofColor lerpedBox = b.lerp(a, 0.5); //fill all pixels in submatrix with lerpd color for (int j=0; j < horSubSize; j++) { for (int k=0; k < vertSubSize; k++) { int indexAdjX = j+i; int indexAdjY = k+g; // if(k+g < pixelStripBoxFull.getHeight()) pixelStripBoxFull.setColor(indexAdjX, indexAdjY, lerpedBox); pixelStripBoxFull.setColor(indexAdjX, indexAdjY, lerpedBox); switch (g) { case 0: //insert values from lerpedBox into LEDColorBuffer[indexAdjX] break; default: break; } } } i+=subDivisionSize; } g+=subDivisionSize; } circleMidpoint_get(videoWidth/2-70, videoHeight/2-50, horizonRadius, ofColor::mediumAquaMarine); circleLine.loadData(circlePixels); circleMidpoint(videoWidth/2-70, videoHeight/2-50, horizonRadius, ofColor::floralWhite); // for (int t=0; t < circlePixels.size()/5; t++) { // serialPixels[t] = circlePixels[t]*127/255; // } circleSimple(videoWidth/2, videoHeight/2, 100, ofColor::magenta); //fillColorArray(videoWidth, videoHeight , subDivisionSize, pixelStripBoxFull, LEDColorBuffer); lerpFull.loadData(pixelStripBoxFull); for(int cir = 0; cir < serialPixels.getWidth(); cir++){ serialPixels.setColor(cir, 0, circlePixels.getColor(cir*circlePixels.getWidth()/serialPixels.getWidth(), 0)); } outPixels.allocate(serialPixels.getWidth(), serialPixels.getHeight(), serialPixels.getNumChannels()); for (int out=0; out < outPixels.size(); out++) { outPixels[out] = serialPixels[out]*127/255; } long long timePerFrame = 100; long long currentTime = ofGetElapsedTimeMillis() ; if(currentTime - lastTime > timePerFrame){ serial.writeBytes(&outPixels[0], outPixels.size()); lastTime = currentTime; } // for(int s = 0; s<outPixels.size(); s+=3){ // cout << (int)s/3 << ": ("<< "r: " << (int)outPixels[s] << "g: " << (int)outPixels[s+1] << "b: " << (int)outPixels[s+2] << ")" << endl; // } } }