vector<Snapshot> Snapshot::TakeSnapshot(float time) { ParticleFactory& factory = ParticleFactory::getInstance(); vector<Snapshot> polygons; set<MovingParticle*> pset; while (true) { bool bdone = true; for (set<MovingParticle*>::iterator it = factory.activeSet.begin(); it != factory.activeSet.end(); ++it) { MovingParticle* p = *it; if (pset.find(p) == pset.end()) { vector<MovingParticle*> vp = MovingParticle::vectorize(p); Snapshot shot(time, time, vp); bdone = false; polygons.push_back(shot); for (int i = 0; i < vp.size(); ++i) { pset.insert(vp[i]); } } } if (bdone) break; } return polygons; }
void CNWayShot::CreateAttack(const mymath::Vec3f& pos, int n, float angle, float interval, float speed, float acc, bool centerFlag) { for (int i = 0; i < n; ++i) { charabase::CharBase shot(shot_.obj()); // 座標、角度、画像、初速度 // 座標 shot.pos = pos; // 発射角 shot.angle = angle + (interval * ((centerFlag) ? static_cast<float>(i - n / 2) : static_cast<float>(i))); if (shot.angle >= 360.f) shot.angle -= 360.f; else if (shot.angle < 0.f) shot.angle += 360.f; // 発射角に合わせて初速度や加速度の向きを変える const float rad = math::Calc_DegreeToRad(shot.angle); const float c = std::cosf(rad); const float s = std::sinf(rad); shot.add.x = speed * c; shot.add.y = speed * -s; shot.add.z = 0.f; mymath::Vec3f a(acc * c, acc * -s); // 加速度 CShot shot_info(shot, a); // 追加用 shot_info.start(); // 当たり判定領域のコピー shot_info.SetCollisionAreas(shot_); // 登録 gm()->AddObject(ObjPtr(new CShot(shot_info))); } }
void GameState::handleEvents(SDL_Event &e) { switch (e.type) { case SDL_KEYDOWN: if (e.key.keysym.sym == SDLK_LEFT) catChar_->turnLeft(); else if (e.key.keysym.sym == SDLK_RIGHT) catChar_->turnRight(); else if (e.key.keysym.sym == SDLK_UP) catChar_->turnUp(); else if (e.key.keysym.sym == SDLK_DOWN) catChar_->turnDown(); else if (e.key.keysym.sym == SDLK_SPACE) shot(catChar_->getDestination()); break; case SDL_QUIT: retCause_ = -1; run_ = false; break; default: run_ = true; break; } }
SnapshotMetaData* Snapshot::parseSnapshotData(QString snapshotPath) { if (!QFile(snapshotPath).exists()) { return NULL; } QUrl url; if (snapshotPath.right(3) == "jpg") { QImage shot(snapshotPath); // no location data stored if (shot.text(URL).isEmpty()) { return NULL; } // parsing URL url = QUrl(shot.text(URL), QUrl::ParsingMode::StrictMode); } else { return NULL; } SnapshotMetaData* data = new SnapshotMetaData(); data->setURL(url); return data; }
int finalize_field(struct Player* gamer){ int i, j; for (i = 0; i < gamer->field->width; i++) for (j = 0; j < gamer->field->height; j++) shot(gamer, i, j, NULL, NULL, NULL); return 0; }
SnapshotMetaData* Snapshot::parseSnapshotData(QString snapshotPath) { if (!QFile(snapshotPath).exists()) { return NULL; } QImage shot(snapshotPath); // no location data stored if (shot.text(LOCATION_X).isEmpty() || shot.text(LOCATION_Y).isEmpty() || shot.text(LOCATION_Z).isEmpty()) { return NULL; } SnapshotMetaData* data = new SnapshotMetaData(); data->setLocation(glm::vec3(shot.text(LOCATION_X).toFloat(), shot.text(LOCATION_Y).toFloat(), shot.text(LOCATION_Z).toFloat())); data->setOrientation(glm::quat(shot.text(ORIENTATION_W).toFloat(), shot.text(ORIENTATION_X).toFloat(), shot.text(ORIENTATION_Y).toFloat(), shot.text(ORIENTATION_Z).toFloat())); data->setDomain(shot.text(DOMAIN_KEY)); return data; }
void MetamenuPlugin::onDestroyed() { m_added = false; m_menuBar = 0; delete m_menu; m_menu = new MetaMenuController(this); QTimer::singleShot(1000, this, SLOT(shot())); }
void Shoter::startShoter() { shot(QApplication::desktop()->winId()); m_pal.setColor(QPalette::WindowText,Qt::black); m_linkLabel.setPalette(m_pal); m_linkLabel.setText(" Click \"Send\" to get the link!"); show(); }
static int handle_key_dn(SDL_Event *e) { int d = 1; int c = e->key.keysym.sym; /* SDL made me do it. */ #ifdef __APPLE__ if (c == SDLK_q && e->key.keysym.mod & KMOD_GUI) return 0; #endif #ifdef _WIN32 if (c == SDLK_F4 && e->key.keysym.mod & KMOD_ALT) return 0; #endif switch (c) { case KEY_SCREENSHOT: shot(); break; case KEY_FPS: config_tgl_d(CONFIG_FPS); break; case KEY_WIREFRAME: if (config_cheat()) toggle_wire(); break; case KEY_RESOURCES: if (config_cheat()) { light_load(); mtrl_reload(); } break; case SDLK_RETURN: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1); break; case KEY_EXIT: d = st_keybd(KEY_EXIT, 1); break; default: if (config_tst_d(CONFIG_KEY_FORWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), -1.0f); else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y0), +1.0f); else if (config_tst_d(CONFIG_KEY_LEFT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), -1.0f); else if (config_tst_d(CONFIG_KEY_RIGHT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X0), +1.0f); else d = st_keybd(e->key.keysym.sym, 1); } return d; }
void Cannon::updateStill() { target = world->getNearestTarget(pos, getRange()); if (target) { shot(target); state = State::COOLDOWN; cooldown = getCooldown(); } }
void EnemyTank::AI() { aiFrame = (aiFrame+1)%2000; if (aiFrame == 0) { int temp = static_cast<int>(direction); temp = (temp+1)%MoveObject::DIR_NUM; direction = static_cast<MoveObject::Dir>(temp); angle = (270+45*direction)%360; shot(); } }
bool ShipSystem::update(const float& dt, bool warp, ParticleSystem& Psystem, BulletSystem& Bsystem, unsigned int& score) { shot(Bsystem, Psystem); bool isChanged = false; for (unsigned int i = 0; i < numberofShips; i++) { if (!shipList[i]->Update(dt, warp, Psystem, Bsystem, assignTarget())) { if (shipList[i]->isaPlayer()) { delete shipList[i]; for (unsigned int j = i; j < numberofShips - 1; j++) { shipList[j] = shipList[j + 1]; } numberofShips--; isChanged = true; break; } else { delete shipList[i]; for (unsigned int j = i; j < numberofShips - 1; j++) { shipList[j] = shipList[j + 1]; } numberofShips--; isChanged = true; } } } if (isChanged) { Spaceship** newList = new Spaceship*[numberofShips]; for (unsigned int i = 0; i < numberofShips; i++) { newList[i] = shipList[i]; } delete[] shipList; shipList = newList; if (numberofPlayers() > 0) { score += 100; } } return(numberofPlayers() > 0); }
void Shoter::reShot() { ui->label_2->clear(); if (ui->comboBox_2->currentIndex() == 0) { shot(QApplication::desktop()->winId()); } else if (ui->comboBox_2->currentIndex() == 1) { #if defined Q_OS_WIN HWND winf = GetForegroundWindow(); shot(winf); #elif defined Q_OS_LINUX Window winf; Display *dpy; dpy = XOpenDisplay(0); int ret; XGetInputFocus(dpy, &winf, &ret); shot(winf); #endif } setVisible(true); setFocus(); showNormal(); }
void Octorok::update(float deltaTime) { _time -= deltaTime; if (_time < 0) { _time += 2; directions dirAux = directions(pointsToDirection4(getPosition(),_scene->getPlayer()->getPosition())); if (dirAux == _dir && _blocked) dirAux = directions(rand()%4); _dir = dirAux; } if (std::rand()%(FRAMERATE*3) == 0) shot(); _moving = true; Enemy::update(deltaTime); _blocked = false; }
void Enemy::aggressive(btDiscreteDynamicsWorld* dynamicsWorld, vec3* playerPosition, bool &isPlayerDead) { if (seesPlayer(dynamicsWorld, playerPosition)) { lastSeenPlayerPosition.x = playerPosition->x; lastSeenPlayerPosition.y = playerPosition->y; lastSeenPlayerPosition.z = playerPosition->z; seeing_count = 0; } goToPlace(&lastSeenPlayerPosition); if (abs(position.x - lastSeenPlayerPosition.x) <= 0.3f && abs(position.z - lastSeenPlayerPosition.z) <= 0.3f && seesPlayer(dynamicsWorld, playerPosition) == false || seeing_count >= 200) { seeing_count = 0; model->setAnimation(walk); state = State::WALKING; return; } seeing_count++; if (distanceBetween2Points(position.x, position.z, playerPosition->x, playerPosition->z) < shot_distance && seesPlayer(dynamicsWorld, playerPosition) && shotCount == 0) { rigidBody->setLinearVelocity(btVector3(0, 0, 0)); if (isPointing == false) { isPointing = true; model->setAnimation(holdWeapon); } shot(dynamicsWorld, playerPosition, isPlayerDead); shotCount++; } else { if (shotCount == shot_anim_length && (distanceBetween2Points(position.x, position.z, playerPosition->x, playerPosition->z) > shot_distance || seesPlayer(dynamicsWorld, playerPosition) == false)) { if (isPointing == true) { isPointing = false; model->setAnimation(run); } movement(); } shotCount++; if (shotCount == breakBetweenShots) shotCount = 0; } }
void EnemyEntity::shoot(int speed, e_ptr target, float deg) { float xDiff = target->getX() - x; float yDiff = target->getY() - (y +( sprite->getHeight()/2)); float rads = atan2f(xDiff,yDiff); int gunX = getX(); int gunY = getY() + (sprite->getHeight()/2); e_ptr shot(new EnemyShotEntity(game, gunX, gunY, polarity)); shot->setHorizontalMovement(speed * sin(rads + qDegreesToRadians(deg))); shot->setVerticalMovement(speed * cos(rads + qDegreesToRadians(deg))); game->getEntities().push_back(shot); }
/** * \brief Do a screen shot. * \param bitmap_name The name of the bitmap file where we'll dump image. */ void bear::visual::screen::shot( const std::string& bitmap_name ) const { std::ofstream f(bitmap_name.c_str()); if (!f) claw::logger << claw::log_warning << "bear::visual::screen::shot: Can't open file '" << bitmap_name << "'" << std::endl; else { claw::graphic::bitmap bmp( get_size().x, get_size().y ); shot(bmp); bmp.save(f); f.close(); } } // screen::shot()
QRect Bullet::shotRect() const{ cout << "shotRect" << endl; QRect shot(0, 0, 6, 6); //double shootAngle = 90; double time = battleField->timerCount; double velocity = 2; //double rad = shootAngle * 3.14159265 / 180; double velx = 0; //velocity * cos(rad); double vely = - velocity * 1; //-velocity * sin(rad); double x = posShot.x() + velx * time; double y = posShot.y() + vely * time; shot.moveCenter(QPoint(qRound(x), qRound(y))); cout << "xShot: " << shot.x() << " yShot: " << shot.y(); cout << ", shotWidth: " << shot.width() << " shotHeight: " << shot.height() << endl; return shot; }
void Player::handleInput() { if (!Game::Instance()->gameOver()) { if (Game::Instance()->isKeyDown(SDL_SCANCODE_UP)) { m_velocity.setY(-m_moveSpeed); m_direction = UP; } else if(Game::Instance()->isKeyDown(SDL_SCANCODE_RIGHT)) { m_velocity.setX(m_moveSpeed); m_direction = RIGHT; } else if(Game::Instance()->isKeyDown(SDL_SCANCODE_DOWN)) { m_velocity.setY(m_moveSpeed); m_direction = DOWN; } else if(Game::Instance()->isKeyDown(SDL_SCANCODE_LEFT)) { m_velocity.setX(-m_moveSpeed); m_direction = LEFT; } // test if (Game::Instance()->isKeyDown(SDL_SCANCODE_DELETE)) { collision(); } static bool canShot = true; if (Game::Instance()->isKeyDown(SDL_SCANCODE_LCTRL) && canShot) { shot(); canShot = false; } else if(!Game::Instance()->isKeyDown(SDL_SCANCODE_LCTRL)) { canShot = true; } } }
void Enemy03::update(){ move(); hitCircleUpdate(); collision = active = isActive(); if(active){ shot(); } needDelete = ! isAlive(); if(life <= 0.0f){ ScoreMng.addScore(1000); PlaySound(SoundMng.get(SE_EXPLOSION02)); dropItem(); ObjectMng.set(ENEMY_EXPLOSION, new EnemyExplosion(ImageMng.get(EE_01), position)); } privActive = active; }
void MetamenuPlugin::shot() { QWidget* window = oneOfChatWindows(); if(!m_menuBar && window) QMetaObject::invokeMethod(window, "getMenuBar", Q_RETURN_ARG(QMenuBar*, m_menuBar)); QMenu* mainMenu = m_menu->menu(false); mainMenu->setTitle("&qutIM"); if(m_menuBar && !m_added) { qDebug() << mainMenu; m_menuBar->addMenu(mainMenu); m_added = true; } if(!m_added) QTimer::singleShot(1000, this, SLOT(shot())); else connect(window, SIGNAL(destroyed()), this, SLOT(onDestroyed())); }
/** \brief Splits the current survey chunk at stationIndex This will split the this chunk into two pieces, if it's valid to split there, ie the station Index, is valid. This will create a new chunk, that the caller is responsible for deleting */ cwSurveyChunk* cwSurveyChunk::splitAtStation(int stationIndex) { if(stationIndex < 1 || stationIndex >= Stations.size()) { return NULL; } cwSurveyChunk* newChunk = new cwSurveyChunk(this); newChunk->Stations.append(cwStation()); //Add an empty station to the front //Copy the points from one chunk to another for(int i = stationIndex; i < Stations.size(); i++) { //Get the current stations and shots cwStation station = Stations[i]; cwShot currentShot = shot(i - 1); newChunk->Stations.append(station); if(currentShot.isValid()) { newChunk->Shots.append(currentShot); } } int stationEnd = Stations.size() - 1; int shotEnd = Shots.size() - 1; //Remove the stations and shots from the list int shotIndex = stationIndex - 1; QList<cwStation>::iterator stationIter = Stations.begin() + stationIndex; QList<cwShot>::iterator shotIter = Shots.begin() + shotIndex; Stations.erase(stationIter, Stations.end()); Shots.erase(shotIter, Shots.end()); emit stationsRemoved(stationIndex, stationEnd); emit shotsRemoved(shotIndex, shotEnd); //Append a new last station appendNewShot(); return newChunk; }
void PLAYER :: control(){ bool fFlag = false; bool bFlag = false; bool upFlag = false; bool rRFlag = false; bool lRFlag = false; bool vFlag = false; //速度制御 if(CheckHitKey(KEY_INPUT_UP)){ vFlag = true; } //左右回転制御 if(CheckHitKey(KEY_INPUT_D)){ //左回転 lRFlag = true; } if(CheckHitKey(KEY_INPUT_A)){ rRFlag = true; } //前後移動制御 if(CheckHitKey(KEY_INPUT_W)){ //前移動 fFlag = true; } if(CheckHitKey(KEY_INPUT_S)){ //後ろ移動 bFlag =true; } //上昇 if(CheckHitKey(KEY_INPUT_LSHIFT)){ upFlag = true; } //移動 move(fFlag, bFlag, upFlag, rRFlag, lRFlag, vFlag); //弾の発射 sflag = false; if(CheckHitKey(KEY_INPUT_SPACE)){ if(shot()) sflag = true; } //カメラアングル cRotate = rotateY; //カメラ位置指定 if(CheckHitKey(KEY_INPUT_DOWN)){ return; } if(CheckHitKey(KEY_INPUT_RIGHT)){ cRotate -= PI/4.0; } if(CheckHitKey(KEY_INPUT_LEFT)){ cRotate += PI/4.0; } if(cRotate > 2*PI) cRotate -= 2*PI; if(cRotate < 0) cRotate += 2*PI; cx = x + x0 + 1500*sinf(cRotate); cy = y + y0 + 300.0f; cz = z + z0 + 1500*cosf(cRotate); }
static int loop(void) { SDL_Event e; int d = 1; int c; /* Process SDL events. */ while (d && SDL_PollEvent(&e)) { switch (e.type) { case SDL_QUIT: return 0; case SDL_MOUSEMOTION: st_point(+e.motion.x, -e.motion.y + config_get_d(CONFIG_HEIGHT), +e.motion.xrel, config_get_d(CONFIG_MOUSE_INVERT) ? +e.motion.yrel : -e.motion.yrel); break; case SDL_MOUSEBUTTONDOWN: d = st_click(e.button.button, 1); break; case SDL_MOUSEBUTTONUP: d = st_click(e.button.button, 0); break; case SDL_KEYDOWN: c = e.key.keysym.sym; if (config_tst_d(CONFIG_KEY_FORWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), -JOY_MAX); else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), +JOY_MAX); else if (config_tst_d(CONFIG_KEY_LEFT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), -JOY_MAX); else if (config_tst_d(CONFIG_KEY_RIGHT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), +JOY_MAX); else switch (c) { case SDLK_F10: shot(); break; case SDLK_F9: config_tgl_d(CONFIG_FPS); break; case SDLK_F8: config_tgl_d(CONFIG_NICE); break; case SDLK_F7: if (config_cheat()) toggle_wire(); break; case SDLK_RETURN: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 1); break; case SDLK_ESCAPE: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 1); break; default: if (SDL_EnableUNICODE(-1)) d = st_keybd(e.key.keysym.unicode, 1); else d = st_keybd(e.key.keysym.sym, 1); } break; case SDL_KEYUP: c = e.key.keysym.sym; if (config_tst_d(CONFIG_KEY_FORWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1); else if (config_tst_d(CONFIG_KEY_BACKWARD, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_Y), 1); else if (config_tst_d(CONFIG_KEY_LEFT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1); else if (config_tst_d(CONFIG_KEY_RIGHT, c)) st_stick(config_get_d(CONFIG_JOYSTICK_AXIS_X), 1); else switch (c) { case SDLK_RETURN: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_A), 0); break; case SDLK_ESCAPE: d = st_buttn(config_get_d(CONFIG_JOYSTICK_BUTTON_EXIT), 0); break; default: d = st_keybd(e.key.keysym.sym, 0); } case SDL_ACTIVEEVENT: if (e.active.state == SDL_APPINPUTFOCUS) if (e.active.gain == 0 && video_get_grab()) goto_pause(); break; case SDL_JOYAXISMOTION: st_stick(e.jaxis.axis, e.jaxis.value); break; case SDL_JOYBUTTONDOWN: d = st_buttn(e.jbutton.button, 1); break; case SDL_JOYBUTTONUP: d = st_buttn(e.jbutton.button, 0); break; } } /* Process events via the tilt sensor API. */ if (tilt_stat()) { int b; int s; st_angle((int) tilt_get_x(), (int) tilt_get_z()); while (tilt_get_button(&b, &s)) { const int X = config_get_d(CONFIG_JOYSTICK_AXIS_X); const int Y = config_get_d(CONFIG_JOYSTICK_AXIS_Y); const int L = config_get_d(CONFIG_JOYSTICK_DPAD_L); const int R = config_get_d(CONFIG_JOYSTICK_DPAD_R); const int U = config_get_d(CONFIG_JOYSTICK_DPAD_U); const int D = config_get_d(CONFIG_JOYSTICK_DPAD_D); if (b == L || b == R || b == U || b == D) { static int pad[4] = { 0, 0, 0, 0 }; /* Track the state of the D-pad buttons. */ if (b == L) pad[0] = s; else if (b == R) pad[1] = s; else if (b == U) pad[2] = s; else if (b == D) pad[3] = s; /* Convert D-pad button events into joystick axis motion. */ if (pad[0] && !pad[1]) st_stick(X, -JOY_MAX); else if (pad[1] && !pad[0]) st_stick(X, +JOY_MAX); else st_stick(X, 1); if (pad[2] && !pad[3]) st_stick(Y, -JOY_MAX); else if (pad[3] && !pad[2]) st_stick(Y, +JOY_MAX); else st_stick(Y, 1); } else d = st_buttn(b, s); } } return d; }
int main(int argc, char *argv[]) { SDL_Joystick *joy = NULL; int t1, t0, uniform; if (!fs_init(argv[0])) { fprintf(stderr, "Failure to initialize virtual file system: %s\n", fs_error()); return 1; } lang_init("neverball"); parse_args(argc, argv); config_paths(data_path); make_dirs_and_migrate(); /* Initialize SDL system and subsystems */ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) == -1) { fprintf(stderr, "%s\n", SDL_GetError()); return 1; } /* Intitialize the configuration */ config_init(); config_load(); /* Initialize the joystick. */ if (config_get_d(CONFIG_JOYSTICK) && SDL_NumJoysticks() > 0) { joy = SDL_JoystickOpen(config_get_d(CONFIG_JOYSTICK_DEVICE)); if (joy) SDL_JoystickEventState(SDL_ENABLE); } /* Initialize the audio. */ audio_init(); tilt_init(); /* Initialize the video. */ if (!video_init(TITLE, ICON)) return 1; init_state(&st_null); /* Initialise demo playback. */ if (demo_path && fs_add_path(dir_name(demo_path)) && progress_replay(base_name(demo_path, NULL))) { demo_play_goto(1); goto_state(&st_demo_play); } else goto_state(&st_title); /* Run the main game loop. */ uniform = config_get_d(CONFIG_UNIFORM); t0 = SDL_GetTicks(); while (loop()) { t1 = SDL_GetTicks(); if (uniform) { /* Step the game uniformly, as configured. */ int u; for (u = 0; u < abs(uniform); ++u) { st_timer(DT); t0 += (int) (DT * 1000); } } else { /* Step the game state at least up to the current time. */ while (t1 > t0) { st_timer(DT); t0 += (int) (DT * 1000); } } /* Render. */ st_paint(0.001f * t0); video_swap(); if (uniform < 0) shot(); if (config_get_d(CONFIG_NICE)) SDL_Delay(1); } /* Gracefully close the game */ if (joy) SDL_JoystickClose(joy); tilt_free(); SDL_Quit(); config_save(); return 0; }
void BattleScene::shotToScene(QPointF pos) { qDebug() << "shot from scene to pos " << pos.x() << " : " << pos.y(); QPoint shotPos = BattleScene::getCellPos(pos); shot(shotPos); }
void SingleShotNode::trigger() { shot(); timerNodeManager->remove(this); }
bool ParticleSimulator::Simulate(float endtime, float delta, bool bdebug) { ParticleFactory* factory = ParticleFactory::getInstance(); float snapTime = delta; bool bSuccess = true; for (set<MovingParticle*>::iterator it = factory->activeSet.begin(); it != factory->activeSet.end(); ++it) { (*it)->updateEvent(); } { vector<Snapshot> shots = Snapshot::TakeSnapshot(time); snapshots.insert(snapshots.end(), shots.begin(), shots.end()); } int iter = 0; while (time < endtime) { iter++; vector<Snapshot> shots = Snapshot::TakeSnapshot(time); //temporary MovingParticle* p = MovingParticle::getNextEvent(); if (p == NULL) break; if (p->getEvent().t > endtime) break; if (p->id == 255) p->id += 0; for (set<MovingParticle*>::iterator it = factory->activeSet.begin(); it != factory->activeSet.end(); ++it) { (*it)->update(p->getEvent().t - time); } time = p->getEvent().t; if (p->applyEvent() == false) break; p->getEvent().print(); MovingParticle::removeUnstable(); if (time >= snapTime) { vector<Snapshot> shots = Snapshot::TakeSnapshot(time); snapshots.insert(snapshots.end(), shots.begin(), shots.end()); snapTime += delta; } MovingParticle::quickFinish(); if (bdebug && MovingParticle::sanityCheck() == false) { printf("Violation of sanity check found at %f.\n", time); vector<Snapshot> shots = Snapshot::TakeSnapshot(time); snapshots.insert(snapshots.end(), shots.begin(), shots.end()); bSuccess = false; break; } //find closed regions vector<vector<MovingParticle*>> regions = MovingParticle::clusterParticles(); for (int i = 0; i < regions.size(); ++i) { //if (clockWise(regions[i]) > 0) { vector<MovingParticle*> tr = MovingParticle::traceBackPolygon(regions[i]); vector<vector<MovingParticle*>> areas = MovingParticle::closedRegions(tr); for (int j = 0; j < areas.size(); ++j) { Snapshot shot(0.0f, areas[j]); if (find(closedRegions.begin(), closedRegions.end(), shot) == closedRegions.end()) { closedRegions.push_back(shot); } } //if (tr.size() > 10) //forget small ones { Snapshot shot(0.0f, tr); if (find(traces.begin(), traces.end(), shot) == traces.end()) { traces.push_back(Snapshot(0, tr)); polygons.push_back(Snapshot(time, regions[i])); } } } } doneEvents.push_back(p->getEvent()); //for (set<MovingParticle*>::iterator it = factory->updateQueue.begin(); it != factory->updateQueue.end(); ++it) for (set<MovingParticle*>::iterator it = factory->activeSet.begin(); it != factory->activeSet.end(); ++it) { (*it)->updateEvent(); } factory->updateQueue.clear(); } for (int i = 0; i < factory->particles.size(); ++i) { MovingParticle* p = factory->particles[i]; if (p->bActive == false && p->time > p->init_event_time && p->init_event_time >= 0) { printf("%d %f %f %f %d\n", p->id, p->created, p->time, p->init_event_time, p->event.type); } } return bSuccess; }
bool MetamenuPlugin::load () { QTimer::singleShot(2000, this, SLOT(shot())); m_menu = new MetaMenuController(this); return true; }
bool ParticleSimulator::Simulate(float endtime, float delta, bool bdebug) { ParticleFactory& factory = ParticleFactory::getInstance(); PolygonFactory& pfactory = PolygonFactory::getInstance(); float snapTime = delta; bool bSuccess = true; for (set<MovingParticle*>::iterator it = factory.activeSet.begin(); it != factory.activeSet.end(); ++it) { (*it)->updateEvent(); } { vector<Snapshot> shots = Snapshot::TakeSnapshot(time); snapshots.insert(snapshots.end(), shots.begin(), shots.end()); } int iter = 0; while (time < endtime) { iter++; MovingParticle* p = MovingParticle::getNextEvent(); if (p == NULL) break; if (p->getEvent().t > endtime) break; if (p->id == 19 && p->event.q->id == 22) iter += 0; for (set<MovingParticle*>::iterator it = factory.activeSet.begin(); it != factory.activeSet.end(); ++it) { (*it)->update(p->getEvent().t - time); } time = p->getEvent().t; pair<MovingParticle*, MovingParticle*> pnew = p->applyEvent(); /*if (p->event.type == SplitEvent || p->event.type == CollisionEvent) { if (p->polygon->getId() == p->event.q->polygon->getId()) { //split the same polygon into two dag.add(p->polygon, pnew.first->polygon); dag.add(p->polygon, pnew.second->polygon); } else { //merge two polygons into one dag.add(pnew.first->polygon, p->polygon); dag.add(pnew.first->polygon, p->event.q->polygon); } }*/ p->getEvent().print(); //MovingParticle::removeUnstable(); if (time >= snapTime) { vector<Snapshot> shots = Snapshot::TakeSnapshot(time); snapshots.insert(snapshots.end(), shots.begin(), shots.end()); snapTime += delta; } MovingParticle::quickFinish(); if (bdebug && MovingParticle::sanityCheck() == false) { printf("Violation of sanity check found at %f.\n", time); vector<Snapshot> shots = Snapshot::TakeSnapshot(time); snapshots.insert(snapshots.end(), shots.begin(), shots.end()); bSuccess = false; break; } //find closed regions vector<vector<MovingParticle*>> regions = MovingParticle::clusterParticles(); for (int i = 0; i < regions.size(); ++i) { vector<MovingParticle*> tr = MovingParticle::traceBackPolygon(regions[i]); vector<vector<MovingParticle*>> areas = MovingParticle::closedRegions(tr); Snapshot shot0(time, time, regions[i]); for (int j = 0; j < areas.size(); ++j) { Snapshot shot(time, 0.0f, areas[j]); if (find(closedRegions.begin(), closedRegions.end(), shot) == closedRegions.end()) { closedRegions.push_back(shot); //Polygon* poly = pfactory.makePolygon(areas[j], time); traces.push_back(shot0); } } /*if (find(traces.begin(), traces.end(), shot0) == traces.end()) { polygons.push_back(Snapshot(time, time, regions[i])); }*/ } doneEvents.push_back(p->getEvent()); //for (set<MovingParticle*>::iterator it = factory->updateQueue.begin(); it != factory->updateQueue.end(); ++it) for (set<MovingParticle*>::iterator it = factory.activeSet.begin(); it != factory.activeSet.end(); ++it) { (*it)->updateEvent(); } factory.updateQueue.clear(); } for (int i = 0; i < factory.particles.size(); ++i) { //factory.particles[i]->printParentTree("\t"); } return bSuccess; }