//---------- void Controller::init(shared_ptr<Panels::Groups::Base> rootGroup) { ofBackground(30); ofAddListener(ofEvents().update, this, &Controller::update); ofAddListener(ofEvents().draw, this, &Controller::draw); ofAddListener(ofEvents().mouseMoved, this, &Controller::mouseMoved); ofAddListener(ofEvents().mousePressed, this, &Controller::mousePressed); ofAddListener(ofEvents().mouseReleased, this, &Controller::mouseReleased); ofAddListener(ofEvents().mouseDragged, this, &Controller::mouseDragged); ofAddListener(ofEvents().keyPressed, this, &Controller::keyPressed); ofAddListener(ofEvents().fileDragEvent, this, &Controller::filesDragged); ofAddListener(ofEvents().windowResized, this, &Controller::windowResized); ofxAssets::Register::X().addAddon("ofxCvGui"); rootGroup->setBounds(ofGetCurrentViewport()); this->rootGroup = rootGroup; this->currentPanel = PanelPtr(); this->currentPanelBounds = ofGetCurrentViewport(); //cache fonts ofxAssets::font("ofxCvGui::swisop3", 12); ofxAssets::font("ofxCvGui::swisop3", 14); ofxAssets::font("ofxCvGui::swisop3", 18); ofxAssets::font("ofxCvGui::swisop3", 24); this->initialised = true; }
//--------- void appWrapper::drawOverlay() { ofPushStyle(); ofEnableAlphaBlending(); ofSetColor(0, 0, 0, 150); ofRect(ofGetCurrentViewport()); ofNoFill(); ofSetColor(255); ofPoint position; string message = "compiling"; position.x = ofGetWidth() / 2 - message.length() * 8 / 2; position.y = ofGetHeight() / 2 - 15; ofDrawBitmapString(message, position); position.x += 1; ofDrawBitmapString(message, position); message = "Please wait...."; position.y += 15; position.x = ofGetWidth() / 2 - message.length() * 8 / 2; ofDrawBitmapString(message, position); ofPopStyle(); }
//---------- void Scene::draw() { if (!this->initialised) { ofSystemAlertDialog("You are calling ofxGrabScene::draw without first calling init, we're exiting!"); ofExit(); } this->camera->begin(); ofPushStyle(); ofEnableAlphaBlending(); this->drawNodesAndElements(); this->camera->updateCursorWorld(); this->drawIndexBuffer(); this->drawOutlines(); ofPopStyle(); //// //cache values for unprojection of mouse this->viewport = ofGetCurrentViewport(); glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix.getPtr()); glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrix.getPtr()); glGetDoublev(GL_MODELVIEW_MATRIX, viewDoubles); glGetDoublev(GL_PROJECTION_MATRIX, projectionDoubles); // //// this->camera->end(); this->drawOverlay(); }
//-------------------------------------------------------------- void testApp::draw(){ ofRectangle viewLeft = ofGetCurrentViewport(); viewLeft.width /= 2.0f; ofRectangle viewRight = viewLeft; viewRight.x += viewLeft.width; ofPushStyle(); ofNoFill(); ofSetColor(255); ofRect(viewLeft); ofRect(viewRight); ofPopStyle(); if (!(indexLeft == cameraIndices.end() || indexRight == cameraIndices.end())) { CorrespondenceSetd::iterator it; ofMesh pointsLeft, pointsRight; for (it = dataSet.begin(); it != dataSet.end(); it++) { if (it->cameraID1 == *indexLeft && it->cameraID2 == *indexRight) { pointsLeft.addVertex(it->getXY1()); pointsLeft.addColor(ofFloatColor((it->xy2[0] + 1.0f) / 2.0f, (1.0f - it->xy2[1]) / 2.0f, 0)); pointsRight.addVertex(it->getXY2()); pointsRight.addColor(ofFloatColor((it->xy1[0] + 1.0f) / 2.0f, (1.0f - it->xy1[1]) / 2.0f, 0)); } } ofPushView(); glPointSize(5.0f); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ofViewport(viewLeft); pointsLeft.drawVertices(); ofViewport(viewRight); pointsRight.drawVertices(); ofPopView(); } if (indexLeft != cameraIndices.end()) ofDrawBitmapString(ofToString(*indexLeft), viewLeft.x + 10, viewLeft.height - 10); if (indexRight != cameraIndices.end()) ofDrawBitmapString(ofToString(*indexRight), viewRight.x + 10, viewRight.height - 10); stringstream message; message << "Cameras {"; set<int>::iterator it; for (it = cameraIndices.begin(); it != cameraIndices.end(); it++) { if (it != cameraIndices.begin()) message << ", "; message << *it; } message << "}" << endl; ofDrawBitmapString(message.str(), 20, 30); }
//---------- void Controller::draw(ofEventArgs& args) { if (!initialised) { return; } DrawArguments rootDrawArguments; rootDrawArguments.chromeEnabled = this->chromeVisible; rootDrawArguments.naturalBounds = ofGetCurrentViewport(); rootDrawArguments.globalTransform = ofMatrix4x4(); rootDrawArguments.globalScale = 1.0f; rootDrawArguments.localBounds = ofRectangle(0, 0, rootDrawArguments.naturalBounds.getWidth(), rootDrawArguments.naturalBounds.getHeight()); rootDrawArguments.globalBounds = rootDrawArguments.naturalBounds; auto currentPanel = this->currentPanel.lock(); if (this->activeDialog) { this->activeDialogBackground.draw(rootDrawArguments.naturalBounds); ofPushStyle(); { //draw light box background ofEnableAlphaBlending(); ofSetColor(0, 200); ofDrawRectangle(rootDrawArguments.naturalBounds); //shadow for dialog ofFill(); ofSetColor(0, 100); ofPushMatrix(); { ofTranslate(5, 5); ofDrawRectangle(this->activeDialog->getBounds()); } ofPopMatrix(); //background for dialog ofSetColor(80); ofDrawRectangle(this->activeDialog->getBounds()); } ofPopStyle(); this->activeDialog->draw(rootDrawArguments); } else { if (this->maximised) { currentPanel->draw(rootDrawArguments); } else { //highlight panel if (currentPanel) { ofPushStyle(); ofEnableAlphaBlending(); ofSetColor(40, 40, 40, 100); ofDrawRectangle(this->currentPanelBounds); ofPopStyle(); } this->rootGroup->draw(rootDrawArguments); } } }
//-------------------------------------------------------------- void testApp::draw() { if(scene != NULL) { ofRectangle viewport(ofGetCurrentViewport()); scene->draw(viewport); } }
//-------------------------------------------------------------- void ViewUbo::update(const ofCamera & camera) { const auto bounds = ofGetCurrentViewport(); this->data.viewportSize = glm::vec2(bounds.width, bounds.height); this->data.rcpViewportSize = 1.0f / this->data.viewportSize; this->data.nearClip = camera.getNearClip(); this->data.farClip = camera.getFarClip(); this->data.viewMatrix = camera.getModelViewMatrix(); this->data.inverseViewMatrix = glm::inverse(this->data.viewMatrix); this->ubo.updateData(sizeof(Data), &this->data); }
//---------- void Controller::toggleMaximised() { if (!this->maximised) { //maximise current panel auto currentPanel = this->currentPanel.lock(); if (currentPanel) { this->setMaximised(currentPanel); currentPanel->setBounds(ofGetCurrentViewport()); } } else { //clear maximise this->clearMaximised(); } }
//-------------------------------------------------------------- void ofApp::draw(){ ofClear(0); auto viewport = ofGetCurrentViewport(); mFbo->draw(viewport); if (bDebugVisible) { for (auto& gui : mGui) gui->draw(); } }
void ofApp::drawInteractionArea(){ ofRectangle vp = ofGetCurrentViewport(); float r = MIN(vp.width, vp.height) * 0.5f; float x = vp.width * 0.5f; float y = vp.height * 0.5f; ofPushStyle(); ofSetLineWidth(3); ofSetColor(255, 255, 0); ofNoFill(); glDepthMask(false); ofDrawCircle(x, y, r); glDepthMask(true); ofPopStyle(); }
//-------------------------------------------------------------- void testApp::setup(){ // init logs ofSetLogLevel(OF_LOG_VERBOSE); ofLogVerbose() << "setup started"; tripno.mass = 1.0; tripno.velocity = 0; tripno.position = ofPoint(0, 0); // init scene objects timeElapsed = 0; currentIndex = 1; minFreqLog = 100; maxFreqLog = 0; maxSignal = 0; for (int i = 0; i < SEGMENTS_STORED; ++i) { ceilHeights[i] = floorHeights[i] = 0; earthline[i] = skyline[i] = ofRectangle(0,0,0,0); } gameField = paddingTop = paddingBottom = ofRectangle(0,0,0,0); viewPort = ofGetCurrentViewport(); // init vertical sync and some graphics ofSetVerticalSync(true); ofSetCircleResolution(6); ofBackground(47, 52, 64); // init audio soundStream.listDevices(); fft = ofxFft::create(AUDIO_BUFFER_SIZE, OF_FFT_WINDOW_RECTANGULAR); soundStream.setup(this, 0, 2, SAMPLE_RATE, AUDIO_BUFFER_SIZE, 4); fftOutput = new float[fft->getBinSize()]; // seed random ofSeedRandom(); //update config readConfig(); ofLogVerbose() << "setup finished"; }
//-------------------------------------------------------------- void ofApp::update(){ ofSetWindowTitle("oF Application: " + ofToString(ofGetFrameRate(), 1)); uDeltaTime = ofGetElapsedTimef() - uElapsedTime; uElapsedTime = ofGetElapsedTimef(); for (auto& b : bundles) b.receiver.receive(b.texture); mFbo->begin(); auto viewport = ofGetCurrentViewport(); ofClear(0); for (int i = 0; i < bundles.size(); i++) { auto& b = bundles[i]; if (b.texture.isAllocated()) b.texture.draw(screen_width * i, 0, screen_width, screen_height); } mFbo->end(); }
// ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ // ofVec3f MousePosOnPlane::getMousePosOnPlane( float _mouseX, float _mouseY, ofVec3f _planeNormal, ofVec3f _pointOnPlane, ofCamera* _camera ) { ofMatrix4x4 modelViewMat; ofMatrix4x4 projectionMat; ofRectangle viewport; if( _camera != NULL ) { modelViewMat = _camera->getModelViewMatrix(); projectionMat = _camera->getProjectionMatrix(); viewport = ofGetCurrentViewport(); return getMousePosOnPlane( _mouseX, _mouseY, _planeNormal, _pointOnPlane, &modelViewMat, &projectionMat, &viewport ); } else { return getMousePosOnPlane( _mouseX, _mouseY, _planeNormal, _pointOnPlane, NULL, NULL, NULL ); } }
//-------------------------------------------------------------- bool testApp::shouldRemoveBullet(Bullet &b) { if(b.bRemove) return true; bool bRemove = false; // get the rectangle of the OF world ofRectangle rec = ofGetCurrentViewport(); // check if the bullet is inside the world if(rec.inside(b.pos) == false) { bRemove = true; } return bRemove; }
//---------- 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(); } }
ofVec3f ofxMapamok::worldToScreen(ofVec3f WorldXYZ, ofRectangle viewport) { if (!calibrationReady) { return WorldXYZ; } if (viewport.isZero()) { viewport = ofGetCurrentViewport(); } begin(); ofMatrix4x4 modelViewMatrix = ofGetCurrentMatrix(OF_MATRIX_MODELVIEW); ofMatrix4x4 projectionMatrix = ofGetCurrentMatrix(OF_MATRIX_PROJECTION); end(); ofVec3f CameraXYZ = WorldXYZ * modelViewMatrix * projectionMatrix; ofVec3f ScreenXYZ; ScreenXYZ.x = (CameraXYZ.x + 1.0f) / 2.0f * viewport.width + viewport.x; ScreenXYZ.y = (1.0f - CameraXYZ.y) / 2.0f * viewport.height + viewport.y; ScreenXYZ.z = CameraXYZ.z; return ScreenXYZ; }
//-------------------------------------------------------------- // Adapted from ofGLRenderer::drawString(string textString, float x, float y, float z, ofDrawBitmapMode mode) void Page::stringDraw(string text, float x, float y, float z) { // this is copied from the ofTrueTypeFont //GLboolean blend_enabled = glIsEnabled(GL_BLEND); //TODO: this is not used? GLint blend_src, blend_dst; glGetIntegerv( GL_BLEND_SRC, &blend_src ); glGetIntegerv( GL_BLEND_DST, &blend_dst ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); int len = (int)text.length(); //float yOffset = 0; float fontSize = 8.0f; bool bOrigin = false; float sx = 0; float sy = -fontSize; /////////////////////////// // APPLY TRANSFORM / VIEW /////////////////////////// // bool hasModelView = false; bool hasProjection = false; bool hasViewport = false; ofRectangle rViewport; //our aim here is to draw to screen //at the viewport position related //to the world position x,y,z //gluProject method GLdouble modelview[16], projection[16]; GLint view[4]; double dScreenX, dScreenY, dScreenZ; glGetDoublev(GL_MODELVIEW_MATRIX, modelview); glGetDoublev(GL_PROJECTION_MATRIX, projection); glGetIntegerv(GL_VIEWPORT, view); view[0] = 0; view[1] = 0; //we're already drawing within viewport gluProject(x, y, z, modelview, projection, view, &dScreenX, &dScreenY, &dScreenZ); if (dScreenZ >= 1) return; rViewport = ofGetCurrentViewport(); hasProjection = true; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); hasModelView = true; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(-1, -1, 0); glScalef(2/rViewport.width, 2/rViewport.height, 1); glTranslatef(dScreenX, dScreenY, 0); // EZ: Make sure to flip here. glScalef(1, -1, 1); // (c) enable texture once before we start drawing each char (no point turning it on and off constantly) //We do this because its way faster ofDrawBitmapCharacterStart(text.size()); for(int c = 0; c < len; c++){ if(text[c] == '\n'){ sy += bOrigin ? -1 : 1 * (fontSize*1.7); sx = 0; //glRasterPos2f(x,y + (int)yOffset); } else if (text[c] >= 32){ // < 32 = control characters - don't draw // solves a bug with control characters // getting drawn when they ought to not be ofDrawBitmapCharacter(text[c], (int)sx, (int)sy); sx += fontSize; } } //We do this because its way faster ofDrawBitmapCharacterEnd(); if (hasModelView) glPopMatrix(); if (hasProjection) { glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } if (hasViewport) ofPopView(); glBlendFunc(blend_src, blend_dst); }
//-------------------------------------------------------------- void testApp::draw(){ //----- // draw image if (!this->recorder.getIsRecording()) { if (this->selectionView.isAllocated()) { this->selectionView.draw(ofGetCurrentViewport()); } else { this->grabber.draw(0,0, ofGetWidth(), ofGetHeight()); } } //----- timeStart = this->recorder.getFirstTimestamp(); timeWindow = MAX(this->recorder.getDuration(), 1); //---- //draw frame ticks ofPushStyle(); ofEnableAlphaBlending(); ofSetColor(ofColor(255, 100)); for (auto &it : recorder) { float position = it.first; position -= timeStart; position /= timeWindow; position *= ofGetWidth(); ofLine(position, ofGetHeight() - 150, position, ofGetHeight() - 50); } ofPopStyle(); //----- //----- //draw selection ofPushStyle(); { float x = selectionTimestamp; x -= timeStart; x /= timeWindow; x *= ofGetWidth(); float width = selectionDuration; width *= ofGetWidth() / (float) timeWindow; ofSetColor(ofColor(255, 100)); ofSetLineWidth(0); ofRect(x, ofGetHeight() - 150, width, 200); ofSetLineWidth(1.0f); ofSetColor(ofColor(255, 200)); ofLine(x, ofGetHeight() - 150, x, ofGetHeight()); } ofPopStyle(); //----- //----- //draw time ticks //find scale of time int timeScale = floor(log((float) timeWindow) / log(10.0f) + 0.5f); double timeScaleMinor = pow(10, timeScale - 2); double firstTick = floor(timeStart / timeScaleMinor) * timeScaleMinor; double time = firstTick; int i = 0; while (time < timeStart + timeWindow) { //convert to screen space float x = (time - timeStart) / timeWindow; x *= ofGetWidth(); float height; float y2; if (i % 10 == 0) { height = 10.0f; string label; if (timeScale >= 6) { label = ofToString((time - timeStart) / 1e6, 2) + "s"; } else if (timeScale >= 3) { label = ofToString((time - timeStart) / 1e3, 2) + "ms"; } else { label = ofToString((time - timeStart) , 2) + "us"; } ofDrawBitmapString(label, x, ofGetHeight() - 3); y2 = ofGetHeight() - 3.0f; } else if (i % 5 == 0) { height = 5.0f; y2 = ofGetHeight() - 15.0f; } else { height = 2.0f; y2 = ofGetHeight() - 18.0f; } ofLine(x, ofGetHeight() - 20.0f, x, y2); time += timeScaleMinor; i++; } // //----- //----- // draw pipet selections ofPushStyle(); for (auto pipet : pipets) { auto drawLocation = pipet * ofVec2f(ofGetWidth(), ofGetHeight()); //background ofSetColor(0, 100); ofRect(drawLocation.x, drawLocation.y, 24, 20); //number ofSetColor(255); if (recorder.count(this->selectionTimestamp) > 0) { auto value = this->getValue(this->selectionTimestamp, pipet); ofDrawBitmapString(ofToString((int) value), drawLocation.x + 2, drawLocation.y + 18); } //line ofLine(drawLocation.x, drawLocation.y, drawLocation.x, drawLocation.y + 20); //other lines ofLine(drawLocation.x, drawLocation.y - 3, drawLocation.x, drawLocation.y - 10); ofLine(drawLocation.x - 3, drawLocation.y, drawLocation.x - 10, drawLocation.y); ofLine(drawLocation.x + 3, drawLocation.y, drawLocation.x + 10, drawLocation.y); } ofPopStyle(); //----- }
//---------- void Controller::clearMaximised() { this->maximised = false; rootGroup->setBounds(ofGetCurrentViewport()); this->updateCurrentPanel(); }
void ramBeginCamera(ofRectangle viewport) { ofRectangle v = viewport; if (v.isEmpty()) v = ofGetCurrentViewport(); ramCameraManager::instance().getActiveCamera().begin(v); }
//---------- void Controller::setMaximised(PanelPtr panel) { this->maximised = true; this->currentPanel = panel; this->currentPanelBounds = ofGetCurrentViewport(); panel->setBounds(ofRectangle(0, 0, ofGetScreenWidth(), ofGetScreenHeight())); }
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 ); } }
// selfDraw draws in 3D using the default ofEasyCamera // you can change the camera by returning getCameraRef() void CloudsVisualSystem3DModelLoader::selfDraw() { //???: update... for some reason the selfUpdate is being called in stand alone. // bLeftCamIsActive = bFrontCamIsActive = bPlanCamIsActive = bPerspCamIsActive = false; glDisable(GL_CULL_FACE); if( cursorIsOverGUI() ) { leftCam.disableMouseInput(); planCam.disableMouseInput(); frontCam.disableMouseInput(); perspCam.disableMouseInput(); } else { if( bLeftCamIsActive && !leftCam.getMouseInputEnabled()) leftCam.enableMouseInput(); if( bFrontCamIsActive && !frontCam.getMouseInputEnabled()) frontCam.enableMouseInput(); if( bPlanCamIsActive && !planCam.getMouseInputEnabled()) planCam.enableMouseInput(); if( bPerspCamIsActive && !perspCam.getMouseInputEnabled()) perspCam.enableMouseInput(); } updateModelTransform(); aimMultipleViews( modelTransform.getPosition() ); //draw from single view if( bFourView ) { //MA: changed ofGetWidth() to GetCanvasWidth() and ofGetHeight() to GetCanvasHeight() int hw = getCanvasWidth()/2; int hh = getCanvasHeight()/2; drawSceneLeft( ofRectangle(0,0,hw,hh) ); drawSceneFront( ofRectangle(hw,0,hw,hh) ); drawScenePlan( ofRectangle(0,hh,hw,hh) ); drawScenePerspective( ofRectangle(hw,hh,hw,hh) ); } else if(currentSingleCam == &perspCam) { drawScenePerspective( ofGetCurrentViewport() ); } else if(currentSingleCam == &leftCam) { drawSceneLeft(); } else if(currentSingleCam == &frontCam) { drawSceneFront(); } else if(currentSingleCam == &planCam) { drawScenePlan(); } else if(currentSingleCam == &pathCamera) { if(bUseDuration) pathCamera.update(); else pathCamera.update( pathCameraPosition ); drawSceneCamera( &pathCamera ); } }