///-------------------------------------------------------------- void Scene2::draw() { BaseScene::drawPre(); switch(backgroundMode) { case SceneBgModeVideo: { if (videoPlayer.isPlaying()) { videoPlayer.draw(0, 0, ofGetViewportWidth(), ofGetViewportHeight()); } break; } case SceneBgModeImages: { ofSetColor(255, 255, 255, int(bgImageAlpha)); bgImage1.draw(ofGetViewportWidth()/2, ofGetViewportHeight()/2, ofGetViewportWidth() * bgImageScale, ofGetViewportHeight() * bgImageScale); ofSetColor(255, 255, 255, 255-int(bgImageAlpha)); bgImage2.draw(ofGetViewportWidth()/2, ofGetViewportHeight()/2, ofGetViewportWidth() * bgImageScale, ofGetViewportHeight() * bgImageScale); break; } case SceneBgModeNone: default: break; } ofEnableBlendMode(OF_BLENDMODE_ADD); { for (unsigned int i = 0; i < numObjects; ++i) objects[i]->draw(); } ofDisableBlendMode(); bool showTUIOCursors; #ifdef OF_DEBUG showTUIOCursors = SettingsManager::getInstance().debugShowTUIOCursors; #else showTUIOCursors = SettingsManager::getInstance().releaseShowTUIOCursors; #endif if (showTUIOCursors) { ofxTuioClient *tuioClient = TUIOHandler::getInstance().tuioClient; tuioClient->drawCursors(0.5, 1, 0); } #ifdef OF_DEBUG ofSetColor(ofColor::white); ofDrawBitmapString("Artist: " + ofToString(artistIndex), 0, ofGetHeight()/2); #endif BaseScene::drawPost(); }
//-------------------------- void ofxGrabCam::mouseDragged(ofMouseEventArgs &args) { float dx = (args.x - mouseP.x) / ofGetViewportWidth(); float dy = (args.y - mouseP.y) / ofGetViewportHeight(); mouseP.x = args.x; mouseP.y = args.y; if (!mouseActions) return; if (!this->mouseDown) return; if (mouseP.z == 1.0f) mouseP.z = 0.5f; ofVec3f p = ofCamera::getPosition(); ofVec3f uy = ofCamera::getUpDir(); ofVec3f ux = ofCamera::getSideDir(); float ar = float(ofGetViewportWidth()) / float(ofGetViewportHeight()); if (handDown) { //dolly ofCamera::move(2 * (mouseW - p) * dy); } else { if (args.button==0 && !altDown) { //orbit ofVec3f arcEnd(dx, -dy, -trackballRadius); arcEnd = arcEnd; arcEnd.normalize(); ofQuaternion orientation = this->getGlobalOrientation(); rotation.makeRotate(orientation * ofVec3f(0.0f, 0.0f, -1.0f), orientation * arcEnd); if (fixUpwards) { ofQuaternion rotToUp; ofVec3f sideDir = ofCamera::getSideDir() * rotation; rotToUp.makeRotate(sideDir, sideDir * ofVec3f(1.0f, 0, 1.0f)); rotation *= rotToUp; } this->setOrientation(this->getGlobalOrientation() * rotation); ofCamera::setPosition((p - mouseW) * rotation + mouseW); } else { //pan float d = (p - mouseW).length(); //ofCamera::getFov() doesn't exist!! ofCamera::move(dx * -ux * d * ar); ofCamera::move(dy * uy * d); } } }
//---------------------------------------------------------- void ofGLRenderer::setupScreenOrtho(float width, float height, bool vFlip, float nearDist, float farDist) { if(width == 0) width = ofGetViewportWidth(); if(height == 0) height = ofGetViewportHeight(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); ofSetCoordHandedness(OF_RIGHT_HANDED); #ifndef TARGET_OPENGLES if(vFlip) { glOrtho(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); } else glOrtho(0, width, 0, height, nearDist, farDist); #else if(vFlip) { ofMatrix4x4 ortho = ofxMatrix4x4::newOrthoMatrix(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); glMultMatrixf(ortho.getPtr()); }else{ ofMatrix4x4 ortho = ofxMatrix4x4::newOrthoMatrix(0, width, 0, height, nearDist, farDist); glMultMatrixf(ortho.getPtr()); } #endif glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
void DelaunayVisualization::update(){ triangulator.reset(); /* triangulator.addPoint(0,0, 0); triangulator.addPoint(ofGetViewportWidth(), 0, 0); triangulator.addPoint(0, ofGetViewportHeight(), 0); triangulator.addPoint(ofGetViewportWidth(), ofGetViewportHeight(), 0); */ vector<int> reaper; ofPoint centerOfMass; float totalWeight = 0; for (cursorMap::iterator i = cursors.begin(); i != cursors.end(); ++i) { tuioCursor *tc = &(i->second); float weight = (150 - tc->age); // fresh points weigh 3 times more than oldest ones totalWeight += weight; centerOfMass.x += tc->x * weight; centerOfMass.y += tc->y * weight; } centerOfMass.x /= totalWeight; //cursors.size(); centerOfMass.y /= totalWeight; //cursors.size(); for (cursorMap::iterator i = cursors.begin(); i != cursors.end(); ++i) { tuioCursor *tc = &(i->second); if (++tc->age < 100) { if (COLLAPSING) { triangulator.addPoint(tc->x * ofGetViewportWidth(), tc->y * ofGetViewportHeight(), 0); if (tc->age<=3) { tc->dx = 0; tc->dy = 0; } if (tc->age > 3) { tc->x += tc->dx; tc->y += tc->dy; tc->dx += (tc->x > centerOfMass.x) ? -0.00003 : 0.00003; tc->dy += (tc->y > centerOfMass.y) ? -0.00003 : 0.00003; // friction //float v = sqrt(tc->dx*tc->dx + tc->dy*tc->dy); } } } else { reaper.push_back(i->first); } } for (vector<int>::iterator i = reaper.begin(); i != reaper.end(); ++i) { cursors.erase(*i); } // triangulator.addPoint(tc.x * ofGetViewportWidth(), tc.y * ofGetViewportHeight(), 0); triangulator.triangulate(); }
//---------------------------------------- void ofCamera::setupPerspective(bool vFlip, float fov, float nearDist, float farDist, const ofVec2f & lensOffset){ float viewW = ofGetViewportWidth(); float viewH = ofGetViewportHeight(); float eyeX = viewW / 2; float eyeY = viewH / 2; float halfFov = PI * fov / 360; float theTan = tanf(halfFov); float dist = eyeY / theTan; if(nearDist == 0) nearDist = dist / 10.0f; if(farDist == 0) farDist = dist * 10.0f; setFov(fov); setNearClip(nearDist); setFarClip(farDist); setLensOffset(lensOffset); setForceAspectRatio(false); setPosition(eyeX,eyeY,dist); lookAt(ofVec3f(eyeX,eyeY,0),ofVec3f(0,1,0)); if(vFlip){ setScale(1,-1,1); } }
//---------------------------------------------------------- void ofSetupScreenPerspective(float width, float height, bool vFlip, float fov, float nearDist, float farDist) { if(width == 0) width = ofGetViewportWidth(); if(height == 0) height = ofGetViewportHeight(); float eyeX = width / 2; float eyeY = height / 2; float halfFov = PI * fov / 360; float theTan = tanf(halfFov); float dist = eyeY / theTan; float aspect = (float) width / height; if(nearDist == 0) nearDist = dist / 10.0f; if(farDist == 0) farDist = dist * 10.0f; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fov, aspect, nearDist, farDist); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0, 0, 1, 0); ofSetCoordHandedness(OF_RIGHT_HANDED); if(vFlip) { glScalef(1, -1, 1); // invert Y axis so increasing Y goes down. glTranslatef(0, -height, 0); // shift origin up to upper-left corner. ofSetCoordHandedness(OF_LEFT_HANDED); } }
Workspace::Workspace() { // create log viewers for each REPL replLog = new ReplLog(repl); screplLog = new ReplLog(screpl); createEditor(repl); createEditor(screpl); #ifdef SPLIT_SCREEN // 3rd editor for split screen Editor* ed = createEditor(); subThread.setEditor(ed); subThread.startThread(true); #endif repl.start("data/tidalStartup.hss"); screpl.start("data/scStartup.scd"); currentEditor = 0; showReplBuffer = true; // force resize to position editors int w = (ofGetWindowMode() == OF_WINDOW) ? ofGetViewportWidth() : ofGetScreenWidth(); int h = (ofGetWindowMode() == OF_WINDOW) ? ofGetViewportHeight() : ofGetScreenHeight(); resize(w, h); }
//-------------------------------------------------------------- void testApp::setup() { x = ofGetViewportWidth() / 2; y = ofGetViewportHeight() / 2; radius = 100; }
void tuioVisContainer::draw() { if (currentVisualization >= 0) visualizations[currentVisualization].draw(); // draw the fade curtain, if any if (stageFadeAlpha < 1.0) { ofSetColor(0, 0, 0, 255*(1.0 - stageFadeAlpha)); ofRect(0, 0, ofGetViewportWidth(), ofGetViewportHeight()); } }
void ofxLayout::update(float dt){ if(tuioEnabled){ tuioClient.getMessage(); } width = ofGetViewportWidth(); height = ofGetViewportHeight(); am.update(dt); assets.update(); contextTreeRoot.update(dt); }
//-------------------------------------------------------------- void ofApp::draw() { ofClear( 0, 0, 0, 255 ); ofDisableDepthTest(); glEnable( GL_CULL_FACE ); glCullFace( GL_BACK ); // size of 1 pixel in a texture if the texture coordinate range from 0..1 ofVec2f inverseResolution( 1.0f / (float)ofGetViewportWidth(), 1.0f / (float)ofGetViewportHeight() ); if ( true ) { m_vignetteShader.begin(); m_fsQuadVbo.draw(); m_vignetteShader.end(); } if ( false ) { m_blurShader.begin(); m_blurShader.setUniformTexture( "uTexture", m_texture, 0 ); m_fsQuadVbo.draw(); m_blurShader.end(); } if ( false ) { m_filmGrainShader.begin(); m_filmGrainShader.setUniformTexture( "uTexture", m_texture, 0 ); m_filmGrainShader.setUniform2f( "uTexelSize", inverseResolution ); m_fsQuadVbo.draw(); m_filmGrainShader.end(); } if ( false ) { m_sobelShader.begin(); m_sobelShader.setUniformTexture( "uTexture", m_texture, 0 ); m_sobelShader.setUniform2f( "uTexelSize", inverseResolution ); m_fsQuadVbo.draw(); m_sobelShader.end(); } }
//---------- void Controller::closeActiveDialog() { if (this->activeDialog) { this->onDialogClose.notifyListeners(this->activeDialog); this->activeDialog.reset(); //setup the size of the root group ofResizeEventArgs resizeArgs = { ofGetViewportWidth(), ofGetViewportHeight() }; this->windowResized(resizeArgs); } }
//-------------------------------------------------------------- void ofApp::draw(){ ofTranslate(ofGetViewportWidth()/2.0f,ofGetViewportHeight()/2.0f); ofRotateZ(angleDegrees); ofSetColor(0,0,0); ofFill(); ofLine(-50,0,50,0); ofCircle(50,0,10); ofCircle(-50,0,10); ofSetColor(175,175,175); ofCircle(50,0,8); ofCircle(-50,0,8); }
void ofCairoRenderer::setupScreenOrtho(float width, float height, bool vFlip, float nearDist, float farDist){ if(!b3D) return; if(width == 0) width = ofGetViewportWidth(); if(height == 0) height = ofGetViewportHeight(); ofSetCoordHandedness(OF_RIGHT_HANDED); if(vFlip) { projection.makeOrthoMatrix(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); }else{ projection.makeOrthoMatrix(0, width, 0, height, nearDist, farDist); } modelView.makeIdentityMatrix(); };
void Circle::update() { positionX += velX; positionY += velY; if (positionX + radius >= ofGetViewportWidth() || positionX - radius <= 0) { velX = (-1) * velX; } if (positionY + radius >= ofGetViewportHeight() || positionY - radius <= 0) { velY = (-1) * velY; } }
//---------- void Controller::setActiveDialog(PanelPtr panel) { if (panel) { auto bounds = ofGetCurrentViewport(); //first get a cached draw for the background this->activeDialogBackground.grabScreen(0, 0, ofGetWindowWidth(), ofGetWindowHeight()); //setup the active Dialog this->activeDialog = panel; //setup the size of the Dialog ofResizeEventArgs resizeArgs = { ofGetViewportWidth(), ofGetViewportHeight() }; this->windowResized(resizeArgs); } else { this->closeActiveDialog(); } }
//---------------------------------------------------------- void ofSetupScreenOrtho(float width, float height, bool vFlip, float nearDist, float farDist) { if(width == 0) width = ofGetViewportWidth(); if(height == 0) height = ofGetViewportHeight(); #ifndef TARGET_OPENGLES glMatrixMode(GL_PROJECTION); glLoadIdentity(); ofSetCoordHandedness(OF_RIGHT_HANDED); if(vFlip) { glOrtho(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); } else glOrtho(0, width, 0, height, nearDist, farDist); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); #else //FIX: is here http://stackoverflow.com/questions/2847574/opengl-es-2-0-equivalent-of-glortho ofLog(OF_LOG_ERROR, "ofSetupScreenOrtho - you can't use glOrtho with iphone / ES at the moment"); #endif }
void SelectableMovableObjectClass::OnDragged( int x, int y, int button ) { SelectableObjectClass::OnDragged( x, y, button ); // Move along the axis selected { // Different directions depending on axis selected ofVec3f offset; { // Get different axis depending on selected switch ( *AxisSelected ) { case 0: // Blue forward offset = getLookAtDir(); break; case 1: // Red right offset = getSideDir(); break; case 2: // Green up offset = -getUpDir(); break; default: break; } } // Calculate direction of axis in screen space ofVec2f direction = Camera->worldToScreen( getPosition() - offset, ofGetCurrentViewport() ); direction /= ofVec2f( ofGetViewportWidth(), ofGetViewportHeight() ); // Calculate the position of the object in screen space ofVec2f position = Camera->worldToScreen( getPosition(), ofGetCurrentViewport() ); position /= ofVec2f( ofGetViewportWidth(), ofGetViewportHeight() ); // Get the direction vector from these two aspects ofVec2f axisdir = direction - position; axisdir.normalize(); // Check the movement of the cursor in relation to the axis line ofVec2f mousedir = LastMouse - ofVec2f( *mouseX, *mouseY ); mousedir.y *= -1; float length = mousedir.length(); { if ( length > 10 ) { length = 10; } } float directionamount = axisdir.dot( mousedir ) * length / 2; // Check for snapping enabled if ( KeyPressed[OF_KEY_SHIFT] ) { if ( abs( directionamount ) > GRID_SNAP_FORCE ) { // Get the length along this axis ofVec3f nodedir = getPosition() * offset; float length = nodedir.length(); if ( ( nodedir.x > 0 ) || ( nodedir.z > 0 ) ) { length *= -1; } // Divide and floor to get closest minimum grid snap point on this axis length = floor( length / GRID_SNAP_DISTANCE ); // Correct to move in the right direction (i.e. backwards or forwards along the vector) if ( signbit( directionamount ) ) { // Take 1 to move to the next grid point length--; } else { // Plus 1 to move to the next grid point length++; } // Move length *= GRID_SNAP_DISTANCE; ofVec3f pos = getPosition(); { if ( offset.x != 0 ) { pos.x = length; } if ( offset.y != 0 ) { pos.y = -length; } if ( offset.z != 0 ) { pos.z = length; } } setPosition( pos ); } } else { // Move the object move( offset * directionamount ); } // Update lastmouse to this frame for mousedir calculation LastMouse = ofVec2f( *mouseX, *mouseY ); // Update slider variables SliderX = CLAMP( getPosition().x, -AXISLIMIT_X, AXISLIMIT_X ); SliderY = CLAMP( getPosition().y, -AXISLIMIT_Y, AXISLIMIT_Y ); SliderZ = CLAMP( getPosition().z, -AXISLIMIT_Z, AXISLIMIT_Z ); } }
void ofCairoRenderer::setup(string _filename, Type _type, bool multiPage_, bool b3D_, ofRectangle _viewport){ if( _viewport.width == 0 || _viewport.height == 0 ){ _viewport.set(0, 0, ofGetViewportWidth(), ofGetViewportHeight()); } filename = _filename; type = _type; streamBuffer.clear(); if(type == FROM_FILE_EXTENSION){ string ext = ofFilePath::getFileExt(filename); if(ofToLower(ext)=="svg"){ type = SVG; }else if(ofToLower(ext)=="pdf"){ type = PDF; }else{ // default to image type = IMAGE; } } if(filename != "") { switch(type) { case PDF: case SVG: case IMAGE: ofFilePath::createEnclosingDirectory(filename); case FROM_FILE_EXTENSION: break; } } switch(type){ case PDF: if(filename==""){ surface = cairo_pdf_surface_create_for_stream(&ofCairoRenderer::stream_function,this,_viewport.width, _viewport.height); }else{ surface = cairo_pdf_surface_create(ofToDataPath(filename).c_str(),_viewport.width, _viewport.height); } break; case SVG: if(filename==""){ surface = cairo_svg_surface_create_for_stream(&ofCairoRenderer::stream_function,this,_viewport.width, _viewport.height); }else{ surface = cairo_svg_surface_create(ofToDataPath(filename).c_str(),_viewport.width, _viewport.height); } break; case IMAGE: imageBuffer.allocate(_viewport.width, _viewport.height, OF_PIXELS_BGRA); imageBuffer.set(0); surface = cairo_image_surface_create_for_data(imageBuffer.getData(),CAIRO_FORMAT_ARGB32,_viewport.width, _viewport.height,_viewport.width*4); break; case FROM_FILE_EXTENSION: ofLogFatalError("ofCairoRenderer") << "setup(): couldn't determine type from extension for filename: \"" << _filename << "\"!"; break; default: ofLogError("ofCairoRenderer") << "setup(): encountered unknown type for filename \"" << _filename << "\""; break; } cr = cairo_create(surface); cairo_set_antialias(cr,CAIRO_ANTIALIAS_SUBPIXEL); viewportRect = _viewport; originalViewport = _viewport; viewport(viewportRect); page = 0; b3D = b3D_; multiPage = multiPage_; }
void ofImage_<PixelType>::grabScreen(int _x, int _y, int _w, int _h){ allocate(_w, _h, OF_IMAGE_COLOR); int sw = ofGetViewportWidth(); int sh = ofGetViewportHeight(); // if we are in a FBO or other viewport, this fails: ofGetHeight(); if (!((width == _w) && (height == _h))){ resize(_w, _h); } #ifndef TARGET_OPENGLES _y = sh - _y; _y -= _h; // top, bottom issues glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT ); // be nice to anyone else who might use pixelStore glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(_x, _y, _w, _h, ofGetGlInternalFormat(pixels), GL_UNSIGNED_BYTE, pixels.getPixels()); // read the memory.... glPopClientAttrib(); int sizeOfOneLineOfPixels = pixels.getWidth() * pixels.getBytesPerPixel(); PixelType * tempLineOfPix = new PixelType[sizeOfOneLineOfPixels]; PixelType * linea; PixelType * lineb; for (int i = 0; i < pixels.getHeight()/2; i++){ linea = pixels.getPixels() + i * sizeOfOneLineOfPixels; lineb = pixels.getPixels() + (pixels.getHeight()-i-1) * sizeOfOneLineOfPixels; memcpy(tempLineOfPix, linea, sizeOfOneLineOfPixels); memcpy(linea, lineb, sizeOfOneLineOfPixels); memcpy(lineb, tempLineOfPix, sizeOfOneLineOfPixels); } delete [] tempLineOfPix; #else int numPixels = width*height; if( numPixels == 0 ){ ofLog(OF_LOG_ERROR, "grabScreen width or height is 0 - returning"); return; } int numRGBA = numPixels*4; GLubyte *bufferRGBA = (GLubyte *) malloc(numRGBA); if(ofGetOrientation() == OF_ORIENTATION_DEFAULT) { _y = sh - _y; // screen is flipped vertically. _y -= _h; glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA); for(int y = 0; y < _h; y++){ for(int x = 0; x < _w; x++){ int i = y * _w * 3 + x * 3; int j = (_h-1-y) * _w * 4 + x * 4; // rotate 90. pixels.getPixels()[i] = bufferRGBA[j]; pixels.getPixels()[i+1] = bufferRGBA[j+1]; pixels.getPixels()[i+2] = bufferRGBA[j+2]; } } } else if(ofGetOrientation() == OF_ORIENTATION_180) { _x = sw - _x; // screen is flipped horizontally. _x -= _w; glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA); for(int y = 0; y < _h; y++){ for(int x = 0; x < _w; x++){ int i = y * _w * 3 + x * 3; int j = y * _w * 4 + (_w-1-x) * 4; // rotate 90. pixels.getPixels()[i] = bufferRGBA[j]; pixels.getPixels()[i+1] = bufferRGBA[j+1]; pixels.getPixels()[i+2] = bufferRGBA[j+2]; } } } else if(ofGetOrientation() == OF_ORIENTATION_90_RIGHT) { int tempW = _w; // swap width and height. _w = _h; _h = tempW; int tempY = _y; // swap x and y. _y = _x; _x = tempY; glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA); for(int y = 0; y < _h; y++){ for(int x = 0; x < _w; x++){ int i = x * _h * 3 + y * 3; int j = y * _w * 4 + x * 4; pixels.getPixels()[i] = bufferRGBA[j]; pixels.getPixels()[i+1] = bufferRGBA[j+1]; pixels.getPixels()[i+2] = bufferRGBA[j+2]; } } } else if(ofGetOrientation() == OF_ORIENTATION_90_LEFT) { int tempW = _w; // swap width and height. _w = _h; _h = tempW; int tempY = _y; // swap x and y. _y = _x; _x = tempY; _x = sw - _x; // screen is flipped horizontally. _x -= _w; _y = sh - _y; // screen is flipped vertically. _y -= _h; glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(_x, _y, _w, _h, GL_RGBA, GL_UNSIGNED_BYTE, bufferRGBA); for(int y = 0; y < _h; y++){ for(int x = 0; x < _w; x++){ int i = x * _h * 3 + y * 3; int j = (_h-1-y) * _w * 4 + (_w-1-x) * 4; pixels.getPixels()[i] = bufferRGBA[j]; pixels.getPixels()[i+1] = bufferRGBA[j+1]; pixels.getPixels()[i+2] = bufferRGBA[j+2]; } } } free(bufferRGBA); #endif update(); }
//-------------------------------------------------------------- void ofxGLEditor::resize() { int w = (ofGetWindowMode() == OF_WINDOW) ? ofGetViewportWidth() : ofGetScreenWidth(); int h = (ofGetWindowMode() == OF_WINDOW) ? ofGetViewportHeight() : ofGetScreenHeight(); resize(w, h); }
void ofCairoRenderer::setupScreenOrtho(float width, float height, ofOrientation orientation, bool vFlip, float nearDist, float farDist){ if(!b3D) return; if(width == 0) width = ofGetWidth(); if(height == 0) height = ofGetHeight(); if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation(); float viewW = ofGetViewportWidth(); float viewH = ofGetViewportHeight(); ofSetCoordHandedness(OF_RIGHT_HANDED); if(vFlip) { ofSetCoordHandedness(OF_LEFT_HANDED); } projection.makeOrthoMatrix(0, viewW, 0, viewH, nearDist, farDist); modelView.makeIdentityMatrix(); //note - theo checked this on iPhone and Desktop for both vFlip = false and true switch(orientation) { case OF_ORIENTATION_180: modelView.glRotate(-180,0,0,1); if(vFlip){ modelView.glScale(-1,-1,1); modelView.glTranslate(width,0,0); }else{ modelView.glTranslate(width,-height,0); } break; case OF_ORIENTATION_90_RIGHT: modelView.glRotate(-90,0,0,1); if(vFlip){ modelView.glScale(1,1,1); }else{ modelView.glScale(1,-1,1); modelView.glTranslate(-width,-height,0); } break; case OF_ORIENTATION_90_LEFT: modelView.glRotate(90,0,0,1); if(vFlip){ modelView.glScale(1,1,1); modelView.glTranslate(0,-height,0); }else{ modelView.glScale(1,-1,1); modelView.glTranslate(0,0,0); } break; case OF_ORIENTATION_DEFAULT: default: if(vFlip){ modelView.glScale(-1,-1,1); modelView.glTranslate(-width,-height,0); } break; } };
void ofCairoRenderer::setupScreenPerspective(float width, float height, ofOrientation orientation, bool vFlip, float fov, float nearDist, float farDist){ if(!b3D) return; if(width == 0) width = ofGetWidth(); if(height == 0) height = ofGetHeight(); if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation(); float viewW = ofGetViewportWidth(); float viewH = ofGetViewportHeight(); float eyeX = viewW / 2; float eyeY = viewH / 2; float halfFov = PI * fov / 360; float theTan = tanf(halfFov); float dist = eyeY / theTan; float aspect = (float) viewW / viewH; if(nearDist == 0) nearDist = dist / 10.0f; if(farDist == 0) farDist = dist * 10.0f; projection.makePerspectiveMatrix(fov,aspect,nearDist,farDist); modelView.makeLookAtViewMatrix(ofVec3f(eyeX,eyeY,dist),ofVec3f(eyeX,eyeY,0),ofVec3f(0,1,0)); //note - theo checked this on iPhone and Desktop for both vFlip = false and true switch(orientation) { case OF_ORIENTATION_180: modelView.glRotate(-180,0,0,1); if(vFlip){ modelView.glScale(-1,-1,1); modelView.glTranslate(width,0,0); }else{ modelView.glTranslate(width,-height,0); } break; case OF_ORIENTATION_90_RIGHT: modelView.glRotate(-90,0,0,1); if(vFlip){ modelView.glScale(1,1,1); }else{ modelView.glScale(1,-1,1); modelView.glTranslate(-width,-height,0); } break; case OF_ORIENTATION_90_LEFT: modelView.glRotate(90,0,0,1); if(vFlip){ modelView.glScale(1,1,1); modelView.glTranslate(0,-height,0); }else{ modelView.glScale(1,-1,1); modelView.glTranslate(0,0,0); } break; case OF_ORIENTATION_DEFAULT: default: if(vFlip){ modelView.glScale(-1,-1,1); modelView.glTranslate(-width,-height,0); } break; } };
//---------------------------------------------------------- void ofGLRenderer::setupScreenPerspective(float width, float height, ofOrientation orientation, bool vFlip, float fov, float nearDist, float farDist) { if(width == 0) width = ofGetWidth(); if(height == 0) height = ofGetHeight(); float viewW = ofGetViewportWidth(); float viewH = ofGetViewportHeight(); float eyeX = viewW / 2; float eyeY = viewH / 2; float halfFov = PI * fov / 360; float theTan = tanf(halfFov); float dist = eyeY / theTan; float aspect = (float) viewW / viewH; if(nearDist == 0) nearDist = dist / 10.0f; if(farDist == 0) farDist = dist * 10.0f; glMatrixMode(GL_PROJECTION); glLoadIdentity(); ofMatrix4x4 persp; persp.makePerspectiveMatrix(fov, aspect, nearDist, farDist); loadMatrix( persp ); //gluPerspective(fov, aspect, nearDist, farDist); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ofMatrix4x4 lookAt; lookAt.makeLookAtViewMatrix( ofVec3f(eyeX, eyeY, dist), ofVec3f(eyeX, eyeY, 0), ofVec3f(0, 1, 0) ); loadMatrix( lookAt ); //gluLookAt(eyeX, eyeY, dist, eyeX, eyeY, 0, 0, 1, 0); //note - theo checked this on iPhone and Desktop for both vFlip = false and true if(ofDoesHWOrientation()){ if(vFlip){ glScalef(1, -1, 1); glTranslatef(0, -height, 0); } }else{ if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation(); switch(orientation) { case OF_ORIENTATION_180: glRotatef(-180, 0, 0, 1); if(vFlip){ glScalef(1, -1, 1); glTranslatef(-width, 0, 0); }else{ glTranslatef(-width, -height, 0); } break; case OF_ORIENTATION_90_RIGHT: glRotatef(-90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); }else{ glScalef(-1, -1, 1); glTranslatef(0, -height, 0); } break; case OF_ORIENTATION_90_LEFT: glRotatef(90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); glTranslatef(-width, -height, 0); }else{ glScalef(-1, -1, 1); glTranslatef(-width, 0, 0); } break; case OF_ORIENTATION_DEFAULT: default: if(vFlip){ glScalef(1, -1, 1); glTranslatef(0, -height, 0); } break; } } }
std::vector<Shape3D*> ofEasyFingerCam::glSelect(int x, int y) { std::vector<Shape3D*> result = std::vector<Shape3D*>(); GLuint buff[512] = {0}; GLint hits, view[4]; GLfloat proj_matrix[16]; /* This choose the buffer where store the values for the selection data */ glSelectBuffer(256, buff); /* This retrieves info about the viewport */ glGetIntegerv(GL_VIEWPORT, view); glGetFloatv(GL_PROJECTION_MATRIX, proj_matrix); /* Switching in selecton mode */ glRenderMode(GL_SELECT); /* Clearing the names' stack This stack contains all the info about the objects */ glInitNames(); /* Now modify the viewing volume, restricting selection area around the cursor */ glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); /* restrict the draw to an area around the cursor */ gluPickMatrix(x, ofGetHeight() - y, 15.0, 15.0, view); float width = ofGetWidth(); float height = ofGetHeight(); float viewW = ofGetViewportWidth(); float viewH = ofGetViewportHeight(); float fov = 60; float eyeX = viewW / 2; float eyeY = viewH / 2; float halfFov = PI * fov / 360; float theTan = tanf(halfFov); float dist = eyeY / theTan; float aspect = (float) viewW / viewH; float nearDist = dist / 10.0f; float farDist = dist * 15.0f; gluPerspective(fov, aspect, nearDist, farDist); /* Draw the objects onto the screen */ glMatrixMode(GL_MODELVIEW); /* draw only the names in the stack, and fill the array */ draw(); glMatrixMode(GL_PROJECTION); glPopMatrix(); /* get number of objects drawed in that area and return to render mode */ hits = glRenderMode(GL_RENDER); /* Print a list of the objects */ result = list_hits(hits, buff); glMatrixMode(GL_MODELVIEW); return result; }
//---------------------------------------------------------- void ofGLRenderer::setupScreenOrtho(float width, float height, ofOrientation orientation, bool vFlip, float nearDist, float farDist) { if(width == 0) width = ofGetWidth(); if(height == 0) height = ofGetHeight(); float viewW = ofGetViewportWidth(); float viewH = ofGetViewportHeight(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); ofSetCoordHandedness(OF_RIGHT_HANDED); if(vFlip) { ofMatrix4x4 ortho = ofMatrix4x4::newOrthoMatrix(0, width, height, 0, nearDist, farDist); ofSetCoordHandedness(OF_LEFT_HANDED); } ofMatrix4x4 ortho = ofMatrix4x4::newOrthoMatrix(0, viewW, 0, viewH, nearDist, farDist); glMultMatrixf(ortho.getPtr()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //note - theo checked this on iPhone and Desktop for both vFlip = false and true if(ofDoesHWOrientation()){ if(vFlip){ glScalef(1, -1, 1); glTranslatef(0, -height, 0); } }else{ if( orientation == OF_ORIENTATION_UNKNOWN ) orientation = ofGetOrientation(); switch(orientation) { case OF_ORIENTATION_180: glRotatef(-180, 0, 0, 1); if(vFlip){ glScalef(1, -1, 1); glTranslatef(-width, 0, 0); }else{ glTranslatef(-width, -height, 0); } break; case OF_ORIENTATION_90_RIGHT: glRotatef(-90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); }else{ glScalef(-1, -1, 1); glTranslatef(0, -height, 0); } break; case OF_ORIENTATION_90_LEFT: glRotatef(90, 0, 0, 1); if(vFlip){ glScalef(-1, 1, 1); glTranslatef(-width, -height, 0); }else{ glScalef(-1, -1, 1); glTranslatef(-width, 0, 0); } break; case OF_ORIENTATION_DEFAULT: default: if(vFlip){ glScalef(1, -1, 1); glTranslatef(0, -height, 0); } break; } } }
void Chessboard::draw(float x, float y) { this->draw(x, y, ofGetViewportWidth(), ofGetViewportHeight()); }
ofxLayout::ofxLayout(){ mouseTransformation = ofMatrix4x4::newIdentityMatrix(); init(0,0,ofGetViewportWidth(),ofGetViewportHeight()); }
//-------------------------------------------------------------- void testApp::setup() { //width = ofGetWindowWidth(); width = ofGetViewportWidth(); //height = ofGetWindowHeight(); height = ofGetViewportHeight(); /* light.setDirectional(); light.setPosition(100,120,100); diffuseColor.set(1.02f,1.1f,1.04f,1.0f); ambientColor.set(0.2f,0.1f,0.0f,1.0f); specularColor.set(.01f,.02f,.04f,.0f); light.setAmbientColor(ambientColor); light.setDiffuseColor(diffuseColor); light.setSpecularColor(specularColor); */ //some model / light stuff vidGrabber.setDeviceID(1); vidGrabber.initGrabber(width, height); vidGrabber.listDevices(); //shader.load("shaders/pointlight.vert", "shaders/pointlight.frag"); colorImage.allocate(width, height); grayImage.allocate(width, height); grayThres.allocate(width, height); scultura_132.loadModel("sculpture_132_ID.3DS",1.0); scultura_134.loadModel("sculpture_134_ID.3DS",1.0); scultura_193.loadModel("sculpture_193_ID.3DS",1.0); scultura_194.loadModel("sculpture_194_ID.3DS",1.0); scultura_195.loadModel("sculpture_195_ID.3DS",1.0); scultura_196.loadModel("sculpture_196_ID.3DS",1.0); scultura_198.loadModel("sculpture_198_ID.3DS",1.0); //sculture_134.setScale(0.5,0.5,0.5); // This uses the default camera calibration and marker file artk.setup(width, height); // The camera calibration file can be created using GML: // http://graphics.cs.msu.ru/en/science/research/calibration/cpp // and these instructions: // http://studierstube.icg.tu-graz.ac.at/doc/pdf/Stb_CamCal.p // This only needs to be done once and will aid with detection // for the specific camera you are using // Put that file in the data folder and then call setup like so: // artk.setup(width, height, "myCamParamFile.cal", "markerboard_480-499.cfg"); // Set the threshold // ARTK+ does the thresholding for us // We also do it in OpenCV so we can see what it looks like for debugging threshold = 85; artk.setThreshold(threshold); thresoldV = false; ofBackground(127,127,127); }