//-------------------------------------------------------------- void menu::keyPressed(int key) { if(key == 'c') { //addCircle(ofPoint(mouseX, mouseY)); bAddCircle=true; } else if(key == 'b') { //addBox(ofPoint(mouseX, mouseY)); bAddBox=true; } else if(key == 'q') { //addCircle(ofPoint(mouseX, mouseY)); removeParticles(); } else if(key == '4') bDraw4Forces = !bDraw4Forces; else if(key=='r') fRed=!fRed; else if(key=='f') bDrawFbos=!bDrawFbos; else if(key=='d') swFuerzaDensidad=!swFuerzaDensidad; else if(key=='m') isMousePressed=!isMousePressed; else if(key=='g') bshowdebug=! bshowdebug; isKeyPressed = true; }
void ParticleSystem::update(sf::Time t, bool partAlive) { float deltaTime = static_cast<float>(t.asSeconds()); for (std::size_t i = 0; i < m_particles.size(); ++i) { m_particles[i]->update(deltaTime, partAlive); if (m_particles[i]->getAlive()) { removeParticles(i); } } }
void timer(int) { display(); if(PRESSED_LEFT && !SPEED_PARTICLES) { addParticle(10, 3); //add tiny particle PRESSED_LEFT = false; } if(PRESSED_RIGHT) { addParticle(10000, 10, 0); //add huge particle PRESSED_RIGHT = false; } if(PRESSED_MIDDLE) removeParticles(); //remove all particles for(int i = 0; i < particles.size(); i++) { Particle &p = particles[i]; bool not_fall = true; for(int j = 0; j < particles.size(); j++) { if(j == i || p.m >= 10000) // we consider the 10000 as infinit (big mass) so this particles won't move continue; const Particle &p1 = particles[j]; float d = sqrt((p1.x - p.x)*(p1.x - p.x) + (p1.y - p.y)*(p1.y - p.y)); if(d > p1.r) { p.vx += 0.03 * p1.m / (d*d) * (p1.x - p.x)/d; //f = ma => a = f/m p.vy += 0.03 * p1.m / (d*d) * (p1.y - p.y)/d; } else not_fall = false; } if(not_fall) { p.x += p.vx; p.y += p.vy; } else particles.erase(particles.begin()+i); } glutTimerFunc(1, timer, 0); }
void keyboard(unsigned char key, int x, int y) { switch(key) { case 's': SPEED_PARTICLES = !SPEED_PARTICLES; break; case 27: removeParticles(); glutDestroyWindow(WIN); exit(0); break; } }
void menu::initParticles() { ofLogNotice("oooooooooo ----- initParticles()"); // add objects removeParticles(); // primero borrar las que pudiera haber, porsiaca. for (int i=0; i<150; i++) { // circulos float distR = ofRandom(W_HEIGHT/2)*0.8; float angTmp = ofRandom(TWO_PI); // addCircle(ofPoint(ofGetWidth()/2+ofRandom(200)-100, W_HEIGHT/2+ofRandom(200)-100)); addCircle(ofPoint(ofGetWidth()/2+distR*cos(angTmp), W_HEIGHT/2+distR*sin(angTmp))); distR = ofRandom(W_HEIGHT/2)*0.8; angTmp = ofRandom(TWO_PI); // rectangulos // addBox(ofPoint(ofGetWidth()/2+ofRandom(200)-100, W_HEIGHT/2+ofRandom(200)-100)); addBox(ofPoint(ofGetWidth()/2+distR*cos(angTmp), W_HEIGHT/2+distR*sin(angTmp))); } ptoMed_circles = ptoMedio(circles); ptoMed_boxes = ptoMedio(boxes); bAddCircle = false; bAddBox = false; }
void ScenarioTest::performTests() { auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesMoved = CC_CALLBACK_2(ScenarioTest::onTouchesMoved, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); _particleNumber = _initParticleNum; // get the window size & origin position auto s = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); // add tile map _map1 = TMXTiledMap::create("TileMaps/iso-test.tmx"); _map1->setAnchorPoint( Vec2(0.5, 0.5) ); _map1->setPosition(origin); this->addChild(_map1); _map2 = TMXTiledMap::create("TileMaps/iso-test2.tmx"); _map2->setAnchorPoint( Vec2(0.5, 0.5) ); _map2->setPosition(origin); this->addChild(_map2); // add toggle menu item MenuItemFont::setFontSize(20); _itemToggle = MenuItemToggle::createWithCallback(nullptr, MenuItemFont::create( "Add/Remove Sprite" ), MenuItemFont::create( "Add/Remove Particle"), MenuItemFont::create( "Add/Remove Particle System"), nullptr); _itemToggle->setAnchorPoint(Vec2(0.0f, 0.5f)); _itemToggle->setPosition(Vec2(origin.x, origin.y + s.height / 2)); // add decrease & increase menu item MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", [&](Ref *sender) { int idx = _itemToggle->getSelectedIndex(); switch (idx) { case 0: removeSprites(); break; case 1: removeParticles(); break; case 2: removeParticleSystem(); break; default: break; } }); decrease->setPosition(Vec2(origin.x + s.width / 2 - 80, origin.y + 80)); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", [&](Ref *sender) { int idx = _itemToggle->getSelectedIndex(); switch (idx) { case 0: addNewSprites(_spriteStepNum); break; case 1: addParticles(_parStepNum); break; case 2: addParticleSystem(_parsysStepNum); break; default: break; } }); increase->setColor(Color3B(0,200,20)); increase->setPosition(Vec2(origin.x + s.width / 2 + 80, origin.y + 80)); auto menu = Menu::create(_itemToggle, decrease, increase, nullptr); menu->setPosition(Vec2(0.0f, 0.0f)); addChild(menu, 10); // add tip labels _spriteLabel = Label::createWithTTF("Sprites : 0", "fonts/arial.ttf", 15); _spriteLabel->setAnchorPoint(Vec2(0.0f, 0.5f)); addChild(_spriteLabel, 10); _spriteLabel->setPosition(Vec2(origin.x, origin.y + s.height/2 + 70)); char str[32] = { 0 }; sprintf(str, "Particles : %d", _particleNumber); _particleLabel = Label::createWithTTF(str, "fonts/arial.ttf", 15); _particleLabel->setAnchorPoint(Vec2(0.0f, 0.5f)); addChild(_particleLabel, 10); _particleLabel->setPosition(Vec2(origin.x, origin.y + s.height/2 + 45)); _parsysLabel = Label::createWithTTF("Particle System : 0", "fonts/arial.ttf", 15); _parsysLabel->setAnchorPoint(Vec2(0.0f, 0.5f)); addChild(_parsysLabel, 10); _parsysLabel->setPosition(Vec2(origin.x, origin.y + s.height/2 + 20)); // add sprites addNewSprites(_initSpriteNum); // add particle system addParticleSystem(_initParsysNum); }