///-------------------------------------------------------------- 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 ofImage_<PixelType>::grabScreen(int _x, int _y, int _w, int _h){ allocate(_w, _h, OF_IMAGE_COLOR); int screenHeight = ofGetViewportHeight(); // if we are in a FBO or other viewport, this fails: ofGetHeight(); _y = screenHeight - _y; _y -= _h; // top, bottom issues if (!((width == _w) && (height == _h))){ resize(_w, _h); } #ifndef TARGET_OPENGLES glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT ); // be nice to anyone else who might use pixelStore #endif glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(_x, _y, _w, _h, ofGetGlInternalFormat(pixels), GL_UNSIGNED_BYTE, pixels.getPixels()); // read the memory.... #ifndef TARGET_OPENGLES glPopClientAttrib(); #endif 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; update(); }
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 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); } }
//-------------------------------------------------------------- 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 ofApp::draw(){ float x = amplitude * cos(TWO_PI * ofGetFrameNum() / period); ofFill(); ofSetColor(0,0,0); ofTranslate(ofGetWindowWidth()/2, ofGetViewportHeight()/2); ofLine(0,0,x,0); ofSetColor(0,0,0); ofCircle(x,0,22); ofSetColor(175,175,175); ofCircle(x,0,20); }
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; } }
// r g b, b fill full first, then g, then r unsigned int SelectableObjectClass::CheckSelected( float mousex, float mousey ) { // Read colour of clicked pixel to determine object unsigned char colour[4]; glReadPixels( mousex, ofGetViewportHeight() - mousey, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &colour ); // Handle selection logic unsigned int id = 0; { id += colour[0] * 255 * 255; id += colour[1] * 255; id += colour[2]; } printf( "id: %i\n", id ); printf( "col: %i %i %i\n", colour[0], colour[1], colour[2] ); return id; }
//---------------------------------------------------------- void ofTexture::loadScreenData(int x, int y, int w, int h){ int screenHeight = ofGetViewportHeight(); // this call fails if we are in a different viewport or FBO: ofGetHeight(); y = screenHeight - y; y -= h; // top, bottom issues texData.bFlipTexture = true; if ( w > texData.tex_w || h > texData.tex_h) { ofLogError("ofTexture") << "loadScreenData(): " << w << "x" << h << " image data too big for " << texData.tex_w << "x " << texData.tex_h << " allocated texture, not uploading"; return; } //update our size with the new dimensions - this should be the same size or smaller than the allocated texture size texData.width = w; texData.height = h; //texData.glType = GL_RGB; // this was probably a bug, because you might be resetting the glType to something other than what the texture was created for //compute new tex co-ords based on the ratio of data's w, h to texture w,h; #ifndef TARGET_OPENGLES // DAMIAN if (texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB){ texData.tex_t = (float)(w); texData.tex_u = (float)(h); } else #endif { texData.tex_t = (float)(w) / (float)texData.tex_w; texData.tex_u = (float)(h) / (float)texData.tex_h; } enableTextureTarget(0); glBindTexture(texData.textureTarget, (GLuint)texData.textureID); glCopyTexSubImage2D(texData.textureTarget, 0,0,0,x,y,w,h); disableTextureTarget(0); if (bWantsMipmap) { generateMipmap(); } }
//---------------------------------------------------------- void ofTexture::loadScreenData(int x, int y, int w, int h){ // TODO: this should go into the renderers so it // doesn't depend on global calls int screenHeight = ofGetViewportHeight(); y = screenHeight - y; y -= h; // top, bottom issues texData.bFlipTexture = true; if ( w > texData.tex_w || h > texData.tex_h) { ofLogError("ofTexture") << "loadScreenData(): " << w << "x" << h << " image data too big for " << texData.tex_w << "x " << texData.tex_h << " allocated texture, not uploading"; return; } //update our size with the new dimensions - this should be the same size or smaller than the allocated texture size texData.width = w; texData.height = h; //compute new tex co-ords based on the ratio of data's w, h to texture w,h; #ifndef TARGET_OPENGLES // DAMIAN if (texData.textureTarget == GL_TEXTURE_RECTANGLE_ARB){ texData.tex_t = (float)(w); texData.tex_u = (float)(h); } else #endif { texData.tex_t = (float)(w) / (float)texData.tex_w; texData.tex_u = (float)(h) / (float)texData.tex_h; } glBindTexture(texData.textureTarget,texData.textureID); glCopyTexSubImage2D(texData.textureTarget, 0,0,0,x,y,w,h); glBindTexture(texData.textureTarget,0); if (bWantsMipmap) { generateMipmap(); } }
//---------- 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 ofEasyFingerCam::findCursor() { //read z value from depth buffer at mouse coords if(fingers.size()==3) { ofVec3f mouseP; mouseP.x = (fingers[0]->getX()*ofGetWidth()+fingers[1]->getX()*ofGetWidth()+fingers[2]->getX()*ofGetWidth())/3; mouseP.y = (fingers[0]->getY()*ofGetHeight()+fingers[1]->getY()*ofGetHeight()+fingers[2]->getY()*ofGetHeight())/3; if (mouseP.z == 1.0f) mouseP.z = 0.5f; glReadPixels(mouseP.x, ofGetHeight()-1-mouseP.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &mouseP.z); //if we get nothing, scatter until we get something //we search in a spiral until we hit something if (mouseP.z == 1.0f) { float sx, sy; // search this spot in screen space float r, theta; // search is in polar coords for (int iteration=0; iteration < ofEasyFingerCam_SEARCH_MAX_ITERATIONS; iteration++) { r = ofEasyFingerCam_SEARCH_WIDTH * float(iteration) / float(ofEasyFingerCam_SEARCH_MAX_ITERATIONS); theta = ofEasyFingerCam_SEARCH_WINDINGS * 2 * PI * float(iteration) / float(ofEasyFingerCam_SEARCH_MAX_ITERATIONS); sx = ofGetWidth() * r * cos(theta) + mouseP.x; sy = ofGetHeight() * r * sin(theta) + mouseP.y; if (!viewportRect.inside(sx, sy)) continue; glReadPixels(sx, ofGetViewportHeight()-1-sy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &mouseP.z); if (mouseP.z != 1.0f) break; } } if (mouseP.z == 1.0f) return; GLdouble c[3]; gluUnProject(mouseP.x, ofGetHeight()-1-mouseP.y, mouseP.z, matM, matP, viewport, c, c+1, c+2); cursor.x = c[0]; cursor.y = c[1]; cursor.z = c[2]; } }
//---------------------------------------------------------- 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 }
ofVec3f ofxGrabCam::getPosition3f(float _x, float _y) { float _z; //read z value from depth buffer at mouse coords glReadPixels(_x, ofGetHeight()-1-_y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &_z); //if we get nothing, scatter until we get something //we search in a spiral until we hit something if (_z == 1.0f) { float sx, sy; // search this spot in screen space float r, theta; // search is in polar coords for (int iteration=0; iteration < OFXGRABCAM_SEARCH_MAX_ITERATIONS; iteration++) { r = OFXGRABCAM_SEARCH_WIDTH * float(iteration) / float(OFXGRABCAM_SEARCH_MAX_ITERATIONS); theta = OFXGRABCAM_SEARCH_WINDINGS * 2 * PI * float(iteration) / float(OFXGRABCAM_SEARCH_MAX_ITERATIONS); sx = ofGetWidth() * r * cos(theta) + _x; sy = ofGetHeight() * r * sin(theta) + _y; if (!viewportRect.inside(sx, sy)) continue; glReadPixels(sx, ofGetViewportHeight()-1-sy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &_z); if (_z != 1.0f) break; } } if (_z == 1.0f) return ofVec3f(); GLdouble c[3]; gluUnProject(_x, ofGetHeight()-1-_y, _z, matM, matP, viewport, c, c+1, c+2); c[ 2 ] += ofRandom(1, 1.8); return ofVec3f(c[0], c[1], c[2]); }
//-------------------------- void ofxGrabCam::findCursor() { //read z value from depth buffer at mouse coords glReadPixels(mouseP.x, ofGetHeight()-1-mouseP.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &mouseP.z); //if we get nothing, scatter until we get something //we search in a spiral until we hit something if (mouseP.z == 1.0f) { float sx, sy; // search this spot in screen space float r, theta; // search is in polar coords for (int iteration=0; iteration < OFXGRABCAM_SEARCH_MAX_ITERATIONS; iteration++) { r = OFXGRABCAM_SEARCH_WIDTH * float(iteration) / float(OFXGRABCAM_SEARCH_MAX_ITERATIONS); theta = OFXGRABCAM_SEARCH_WINDINGS * 2 * PI * float(iteration) / float(OFXGRABCAM_SEARCH_MAX_ITERATIONS); sx = ofGetWidth() * r * cos(theta) + mouseP.x; sy = ofGetHeight() * r * sin(theta) + mouseP.y; if (!viewportRect.inside(sx, sy)) continue; glReadPixels(sx, ofGetViewportHeight()-1-sy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &mouseP.z); if (mouseP.z != 1.0f) break; } } if (mouseP.z == 1.0f) return; GLdouble c[3]; gluUnProject(mouseP.x, ofGetHeight()-1-mouseP.y, mouseP.z, matM, matP, viewport, c, c+1, c+2); mouseW.x = c[0]; mouseW.y = c[1]; mouseW.z = c[2]; }
ofxLayout::ofxLayout(){ mouseTransformation = ofMatrix4x4::newIdentityMatrix(); init(0,0,ofGetViewportWidth(),ofGetViewportHeight()); }
//---------------------------------------------------------- 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 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; } } }
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_; }