void App::onEvent() { // handle events Event event; while (window.pollEvent(event)) { switch (event.type) { case Event::Closed: running = false; break; case Event::Resized: glViewport(0, 0, event.size.width, event.size.height); break; case Event::KeyPressed: case Event::KeyReleased: if (event.key.code == Keyboard::Escape) { running = false; } else world->onKeyboardEvent(event); break; case Event::MouseLeft: case Event::MouseMoved: if (Mouse::getPosition(window) != getWindowCenter()) { world->onMouseEvent(Mouse::getPosition(window)); Mouse::setPosition(getWindowCenter(), window); } break; } } }
void SimpleParticlesApp::peerReceived( PeerRef cr ) { //console() << "added " << *cr << endl; Vec2f bv = Vec2f( getWindowSize() ) * Vec2f( .1f, .0f ); bv.rotate( cr->getBearing() ); Vec2f pos = getWindowCenter() + bv; app::App::get()->dispatchSync( [&] { mEmitterController.addEmitter( Vec3f( Vec2f( pos ), 0.f ), Vec3f::zero() ); } ); }
void App::initSFML() { // stwórz okno window.create(VideoMode(windowWidth, windowHeight), "OpenGL", Style::Fullscreen, ContextSettings(32)); window.setFramerateLimit(60); window.setKeyRepeatEnabled(false); window.setMouseCursorVisible(false); Mouse::setPosition(getWindowCenter(), window); }
ExampleApp::ExampleApp() { // you must have at least 1 camera addModifier(new poCamera2D()); // make a rectangle with the size of the requested image poRectShape *shape = addChild(new poRectShape("img1.png")); shape->drawBounds = true; // re-orient the shape around its own center point shape->alignment(PO_ALIGN_CENTER_CENTER); // and place it in the center of the screen shape->position = getWindowCenter(); // attach enter and leave events to the shape shape->addEvent(PO_MOUSE_ENTER_EVENT, this); shape->addEvent(PO_MOUSE_LEAVE_EVENT, this); // up and down events shape->addEvent(PO_MOUSE_DOWN_INSIDE_EVENT, this); shape->addEvent(PO_MOUSE_UP_EVERYWHERE_EVENT, this); // a drag event starts when you click on an object shape->addEvent(PO_MOUSE_DRAG_EVENT, this); // key events will go to all interested parties addEvent(PO_KEY_DOWN_EVENT, this); // and if you care about the window being resized addEvent(PO_WINDOW_RESIZED_EVENT, this); // initialize this variable for safty mask = NULL; // initial text for the mouse coords std::string coords = (text_fmt % 0 % 0).str(); // create a text box with a blah size poTextBox *text = addChild(new poTextBox(400,20)); text->text(coords); // you must call layout after reconfiguring a text box text->layout(); // its a ... mouse move event addEvent(PO_MOUSE_MOVE_EVENT, this); // also hopefully self-explanitory shape->addEvent(PO_MOUSE_DOWN_OUTSIDE_EVENT, this); // all poObjects have a couple of property tweens // see poObject.h and also poTween.h shape->rotation_tween.setTweenFunction(linearFunc).setDuration(10.f).setRepeat(PO_TWEEN_REPEAT_REGULAR); // a global dictionary that reads from and writes to "common.xml" poDictionary *common = poCommon::get(); if(common->has("rotation")) shape->rotation = common->getFloat("rotation"); }
void msaFluidParticlesApp::resize() { particleSystem.setWindowSize( app::getWindowSize()); width = app::getWindowWidth(); height = app::getWindowHeight(); mArcball.setWindowSize( getWindowSize() ); mArcball.setCenter( getWindowCenter() ); mArcball.setRadius( 150 ); resizeFluid = true; }
imageShape_testApp::imageShape_testApp() { setCurrentPath(applicationGetResourceDirectory()); setWindowMouseMoveEnabled(false); addModifier(new poCamera2D()); poImageShape *shp = new poImageShape("test.png"); shp->addEvent(PO_MOUSE_DOWN_INSIDE_EVENT, this); shp->setAlignment(PO_ALIGN_CENTER_CENTER); shp->position = getWindowCenter(); addChild(shp); }
// Only drawing here, do not place logic during drawing or it will slow down OpenGL // Called every frame void HelloWorldApp::draw() { // Clear screen every frame with black ci::gl::clear( ci::Color( 0, 0, 0 ) ); // Create a random color based on the number of frames passed ci::Color aColor = ci::Color( 0, 0, 0 ); aColor.r = fabs( cosf(getElapsedFrames() * 0.008) ); aColor.g = fabs( sinf(getElapsedFrames() * 0.01) ); aColor.b = (float) getMousePos().x / getWindowWidth(); // Set the color and draw a simple line to the mouse ci::gl::color( aColor ); ci::gl::drawLine( ci::Vec2f(getMousePos()), ci::Vec2f( getWindowCenter() ) ); // Test drawing a texture... // Always check if texture loaded before drawing to avoid race condition on app start if ( texture ) { ci::gl::color( ci::ColorA(1.0f, 1.0f, 1.0f, 1.0f) ); ci::gl::draw( texture, getWindowCenter() ); } }
/*Draw method for first projector, Projector1 specific code goes here*/ void SystemCinderApp::drawFirst(){ gl::viewport(getWindowSize()); gl::setMatricesWindow(getWindowSize()); gl::clear(Color::gray(0.5f)); gl::drawSolidCircle(getWindowCenter(), 150.0f); /*loading shaders and/or projector data here*/ //auto img = loadAsset("data.bin"); //gl::Texture2dRef mTex = gl::Texture2d::create(img); //if abouve does not work we can import the points loader Qian created in texture.h/.cpp }
/*Draw method for first projector, Projector2 specific code goes here*/ void SystemCinderApp::drawSecond(){ /* Following code extracted from CINDER Guide's getting started page*/ //----------------------// //CODE FROM CINDER PAGE // //---------------------// gl::clear(); // preserve the default Model matrix gl::pushModelMatrix(); // move to the window center gl::translate(getWindowCenter()); int numCircles = 16; float radius = getWindowHeight() / 2 - 30; for (int c = 0; c < numCircles; ++c) { float rel = c / (float)numCircles; float angle = rel * M_PI * 2; vec2 offset(cos(angle), sin(angle)); // preserve the Model matrix gl::pushModelMatrix(); // move to the correct position gl::translate(offset * radius); // set the color using HSV color gl::color(Color(CM_HSV, rel, 1, 1)); // draw a circle relative to Model matrix gl::drawStrokedCircle(vec2(), 30); // restore the Model matrix gl::popModelMatrix(); } // draw a white circle at window center gl::color(Color(1, 1, 1)); gl::drawSolidCircle(vec2(), 15); // restore the default Model matrix gl::popModelMatrix(); //---------------------------// //CODE FROM CINDER PAGE END // //-------------------------// /*loading shaders and/or projector data here*/ }
void msaFluidParticlesApp::setup() { console() << "ciMSAFluid Demo | (c) 2009 Mehmet Akten | www.memo.tv" << std::endl; // setup fluid stuff fluidSolver.setup(100, 100); fluidSolver.enableRGB(true).setFadeSpeed(0.004).setDeltaT(0.5).setVisc(0.00019).setColorDiffusion(0); fluidDrawer.setup( &fluidSolver ); particleSystem.setFluidSolver( &fluidSolver ); fluidCellsX = 150; drawFluid = true; drawParticles = true; renderUsingVA = true; width = 1024; height = 768; setFrameRate( 60.0f ); setWindowSize(width, height); pMouse = getWindowCenter(); resizeFluid = true; gl::enableAlphaBlending(); gl::Fbo::Format format; format.setSamples( 8 ); //format.setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); mFbo = gl::Fbo(width, height, format); drawFluidTex = false; loadShader(); }
void Road::draw() { Matrix44f scale = Matrix44f::createScale(Vec3f(80, 80, 80)); Matrix44f rotate = Matrix44f::createRotation(Vec3f(-1.58f, 0.0f, 0.0f)); const float viewing_angle = 0.008f; gl::pushModelView(); gl::translate(getWindowCenter()); for (int i = 0; i < Road_Max; ++i) { if (depth[i] <= 10.0f) continue; Matrix44f translate = Matrix44f::createTranslation(Vec3f(0.0f, 50.0f, depth[i] * 18)); for (auto line : lines) { auto begin = line.begin; auto end = line.end; begin = translate * scale * rotate * begin; end = translate * scale * rotate * end; ly::drawLine(begin.xy() / (begin.z * viewing_angle), end.xy() / (end.z * viewing_angle), Color(1, 1, 1)); } } scale = Matrix44f::createScale(Vec3f(80, 80, 500)); Matrix44f translate = Matrix44f::createTranslation(Vec3f(0.0f, 50.0f, 800.0f)); for (auto line : rane) { auto begin = line.begin; auto end = line.end; begin = translate * scale * rotate * begin; end = translate * scale * rotate * end; ly::drawLine(begin.xy() / (begin.z * viewing_angle), end.xy() / (end.z * viewing_angle), Color::white()); } gl::popModelView(); }
void _5_11App::draw() { gl::clear(); gl::pushModelView(); gl::translate(getWindowCenter()); const float viewing_angle = 0.0004f; Matrix44f root_rotate_matrix = Matrix44f::createRotation(root_rotate); Matrix44f root_translate_matrix = Matrix44f::createTranslation(root_translate); for (auto box : boxes) { Matrix44f translate = Matrix44f::createTranslation(box.pos); Matrix44f scale = Matrix44f::createScale(box.scale); Matrix44f rotate = Matrix44f::createRotation(box.rotate); for (auto tri : triangle) { auto posA = tri.posA; auto posB = tri.posB; auto posC = tri.posC; auto col = tri.color; posA = root_translate_matrix * root_rotate_matrix * translate * rotate * scale * posA; posB = root_translate_matrix * root_rotate_matrix * translate * rotate * scale * posB; posC = root_translate_matrix * root_rotate_matrix * translate * rotate * scale * posC; ly::drawSoildTriangle(posA.xy() / (posA.z * viewing_angle), posB.xy() / (posB.z * viewing_angle), posC.xy() / (posC.z * viewing_angle), col); } } ly::drawString("Press A light Up", Vec2f(-200, 100), Color::white(), 50); ly::drawString("Press D light Down", Vec2f(-200, 150), Color::white(), 50); gl::popModelView(); }
void fsExperiments::resize( ResizeEvent event ) { mArcball.setWindowSize( getWindowSize() ); mArcball.setCenter( getWindowCenter() ); mArcball.setRadius( 150 ); }
void ExampleApp::eventHandler(poEvent *event) { // handle key events if(event->type == PO_KEY_DOWN_EVENT) { // return key if(event->keyCode == PO_RETURN_KEY) { // toggle fullscreen the window poWindow *window = applicationCurrentWindow(); applicationMakeWindowFullscreen(window, !window->isFullscreen()); } } // re-center the image else if(event->type == PO_WINDOW_RESIZED_EVENT) { getChild(0)->position = getWindowCenter(); } // turn on image border else if(event->type == PO_MOUSE_ENTER_EVENT) { poShape2D *shape = static_cast<poShape2D*>(event->source); shape->strokeColor = poColor::orange; shape->generateStroke(20); } // turn off image border else if(event->type == PO_MOUSE_LEAVE_EVENT) { poShape2D *shape = static_cast<poShape2D*>(event->source); shape->generateStroke(0); } // start masking the image else if(event->type == PO_MOUSE_DOWN_INSIDE_EVENT) { mask = new poOvalShape(100,100,50); mask->position = event->local_position; event->source->addModifier(new poGeometryMask(mask)); } // stop masking the image else if(event->type == PO_MOUSE_UP_EVERYWHERE_EVENT) { event->source->removeModifier(0, true); mask = NULL; } // we're dragging the mask around! else if(event->type == PO_MOUSE_DRAG_EVENT) { mask->position = event->local_position; } // display the mouse coordinates else if(event->type == PO_MOUSE_MOVE_EVENT) { getChildAs<poTextBox>(1)->text((text_fmt % event->position.x % event->position.y).str())->layout(); } // toggle image rotation else if(event->type == PO_MOUSE_DOWN_OUTSIDE_EVENT) { bool running = event->source->rotation_tween.isRunning(); if(running) event->source->rotation_tween.stop(); else event->source->rotation_tween.set(event->source->rotation + 360).start(); } }