示例#1
0
文件: viewer.cpp 项目: ethz-asl/iclcv
void run(){
  static FPSLimiter fps(pa("-maxfps"),10);
  
  gui["image"] = grabber.grab();
  gui["fps"].render();
  fps.wait();
}
示例#2
0
void run()
{
  //delay the simulation for a second
  if(delay++ < fps.getMaxFPS()){
    scene.step(0.f);
  } else {
    scene.step();
  }
  gui["draw"].render();
  fps.wait();
}
示例#3
0
void run(){
  static ButtonHandle mem = gui["mem"];
  static ButtonHandle add = gui["add"];
  static DrawHandle3D draw = gui["draw"];
  static FPSLimiter fpslimit(10,10);

  fpslimit.setMaxFPS(parse<int>(gui["maxFPS"].as<std::string>()));

  paper->setTextureVisible(gui["showTexture"]);
  paper->setCubesVisible(gui["showCubes"]);
  paper->setShowAllConstraints(gui["showLinks"]);

  static float lastMargin = -1;
  float currMargin = gui["cm"];
  if(lastMargin != currMargin){
    paper->getSoftBody()->getCollisionShape()->setMargin(icl2bullet(currMargin));
    lastMargin = currMargin;
  }

  if(mem.wasTriggered()){
    paper->memorizeDeformation();
  }
  static bool first = true;
  if(add.wasTriggered() || (first && pa("-a"))){
    first = false;
    add_clutter(&scene,&scene,30);
    //TODO CHECK THIS OUT add_clutter(&scene, &world, 1, 5, false);
  }
  remove_fallen_objects(&scene, &scene);


  static Time lastTime = Time::now();
  Time now = Time::now();
  double dt = (now-lastTime).toSecondsDouble();
  lastTime = now;
  if(gui["run"]){
    paper->applyAllForces(gui["attractorStreangth"],gui["vertexMoveFactor"]);
    scene.Scene::lock();
    paper->lock();
    scene.step( dt * 5, 1);
    paper->unlock();
    scene.Scene::unlock();
  }

  foldLine.visualize(**draw);
  draw.render();
  gui["fps"].render();

  if(capturer){
    capturer->capture();
  }
  fpslimit.wait();
}
示例#4
0
	void swapGLBuffer()
	{
		fpsLimiter.delay();
		SDL_GL_SwapWindow(threadData->window);

		++frameCount;

		threadData->ethread->notifyFrame();
	}
示例#5
0
	GraphicsPrivate(RGSSThreadData *rtData)
	    : scRes(DEF_SCREEN_W, DEF_SCREEN_H),
	      scSize(scRes),
	      winSize(rtData->config.defScreenW, rtData->config.defScreenH),
	      screen(scRes.x, scRes.y),
	      threadData(rtData),
	      glCtx(SDL_GL_GetCurrentContext()),
	      frameRate(DEF_FRAMERATE),
	      frameCount(0),
	      brightness(255),
	      fpsLimiter(frameRate),
	      frozen(false)
	{
		recalculateScreenSize(rtData);
		updateScreenResoRatio(rtData);

		TEXFBO::init(frozenScene);
		TEXFBO::allocEmpty(frozenScene, scRes.x, scRes.y);
		TEXFBO::linkFBO(frozenScene);

		TEXFBO::init(currentScene);
		TEXFBO::allocEmpty(currentScene, scRes.x, scRes.y);
		TEXFBO::linkFBO(currentScene);

		FloatRect screenRect(0, 0, scRes.x, scRes.y);
		screenQuad.setTexPosRect(screenRect, screenRect);

		TEXFBO::init(transBuffer);
		TEXFBO::allocEmpty(transBuffer, scRes.x, scRes.y);
		TEXFBO::linkFBO(transBuffer);

		fpsLimiter.resetFrameAdjust();
		
		const std::string &olImage = rtData->config.touchOverlay.image;
		if (!olImage.empty())
		{
			SDL_RWops *ops = SDL_RWFromFile(olImage.c_str(), "rb");
			SDL_Surface *surf = IMG_Load_RW(ops, 1);

			if (surf)
			{
				overlayTex = TEX::gen();

				TEX::bind(overlayTex);
				TEX::setRepeat(false);
				TEX::setSmooth(true);
				TEX::uploadImage(surf->w, surf->h, surf->pixels, GL_RGBA);

				overlayTexSize = Vec2i(surf->w, surf->h);
			}
			else
			{
				Debug() << "failed to load overlay image:" << SDL_GetError();
			}
		}
	}
示例#6
0
void IMainGame::run() {

    if (!init()) return;

    FPSLimiter limiter;
    limiter.setMaxFPS(60.0f);

    m_isRunning = true;
    while (m_isRunning) {
        limiter.begin();

        inputManager.update();
        update();
        if (m_isRunning) {
            draw();

            m_fps = limiter.end();
            m_window.swapBuffer();
        }
    }
}
示例#7
0
	void checkSyncLock()
	{
		if (!threadData->syncPoint.mainSyncLocked())
			return;

		/* Releasing the GL context before sleeping and making it
		 * current again on wakeup seems to avoid the context loss
		 * when the app moves into the background on Android */
		SDL_GL_MakeCurrent(threadData->window, 0);
		threadData->syncPoint.waitMainSync();
		SDL_GL_MakeCurrent(threadData->window, glCtx);

		fpsLimiter.resetFrameAdjust();
	}
示例#8
0
void App::run()
{
	FPSLimiter fps;
	fps.setMaxFPS(60.0f);

	while (state == State::PLAY)
	{
		fps.begin();

		long rightNowTick = SDL_GetTicks();
		_step = (_now == 0 ? 0 : rightNowTick - _now);
		_now = rightNowTick;

		processInput();

		update();

		draw();

		SDL_GL_SwapWindow(_window);

		_fps = fps.end();
	}
}
示例#9
0
文件: crop.cpp 项目: ethz-asl/iclcv
void run(){
  bool c_arg = pa("-c");
  
  static FPSLimiter fpsLimit(30);
  fpsLimit.wait();

  const ImgBase *image = grabber.grab();
  DrawHandle draw = gui["draw"];
  ImageHandle cropped = gui["cropped"];

  draw = image;

  static RotateOp rot;
  if(c_arg){
    rot.setAngle(0);
  }else{
    rot.setAngle(parse<int>(gui["rot"]));
  }

  const ImgBase *cro = 0;
  if(c_arg || gui["rect"].as<bool>()){
    static Img8u roi;
    std::vector<utils::Rect> rs = mouse_2->getRects();
    ICLASSERT_THROW(rs.size() == 1, ICLException("expected exactly one rectangle"));
    lastRect = rs[0];
    mouse_2->visualize(**draw);
    SmartPtr<const ImgBase> tmp = image->shallowCopy(rs[0] & image->getImageRect());
    roi.setChannels(tmp->getChannels());
    roi.setFormat(tmp->getFormat());
    roi.setSize(tmp->getROISize());
    tmp->convertROI(&roi);
    cro = rot.apply(&roi);

    draw->color(0,255,0,255);
    draw->text(str(rs[0]), rs[0].x, rs[0].y);

  }else{
    draw->draw(mouse_1->vis());
    Size32f s(gui["s1"],gui["s2"]);
    Point32f ps[4] = { mouse_1->ps[0],  mouse_1->ps[1],  mouse_1->ps[2],  mouse_1->ps[3] };
    switch(image->getDepth()){
#define ICL_INSTANTIATE_DEPTH(D)                                \
      case depth##D:{                                           \
        static ImageRectification<icl##D> ir;                   \
        try{                                                    \
          cro = rot.apply(&ir.apply(ps,*image->as##D(),s));     \
        }catch(...){}                                           \
        break;                                                  \
      }
      ICL_INSTANTIATE_ALL_DEPTHS;
#undef ICL_INSTANTIATE_DEPTH
    }
  }
  if(cro){
    cropped = cro;
    currMutex.lock();
    cro->convert(&curr);
    currMutex.unlock();
  }

  gui["draw"].render();
  gui["fps"].render();
}