// Step & render.
void GraphicsCanvas::nextFrame()
{
	float timeStep = (float) m_hrTimer.seconds();

	// Measure frame time
	m_hrTimer.tick();

	// Step & render
	Q_EMIT step(timeStep);

	if (this->isVisible() && this->size() == m_lastSize)
	{
		if (m_officialSize != this->size())
		{
			m_officialSize = this->size();
			Q_EMIT resized(m_officialSize.width(), m_officialSize.height());
		}

		// Draw scene
		Q_EMIT render();
		present();
	}
	m_lastSize = this->size();

	// Compute time to next frame
	int targetFrameDelay = 1000 / targetFPS() - (int) m_hrTimer.milliseconds();

	// Enqueue next frame
	if (!this->isHidden())
		m_timer.start( lean::max(targetFrameDelay, 0) );
}
Beispiel #2
0
void DemoApplication::update(const OTimeIndex& timeIndex)
{
	int deltaTime_us = (timeIndex - _last_timeIndex).toInt();
	char buff[128];

	/* update camera */
	_camCtrl.update(timeIndex);

	/* calculate FPS average and update the text object (to show on the screen) */
	if (targetFPS() == 0) snprintf(buff, 32, "%.02f fps", fpsStats().average());
	else snprintf(buff, 32, "%.02f/%d fps", fpsStats().average(), targetFPS());
	_fpsText->setContent(buff);
	
	/* simulation stats and idle time */
	snprintf(buff, 32, "Perf coef: %.04f", performanceStats().average());
	_perfText->setContent(buff);
	snprintf(buff, 32, "Idle time: %.02f", idleTimeStats().average());
	_idleText->setContent(buff);
	snprintf(buff, 32, "Render time: %.02f", renderTimeStats().average());
	_renderText->setContent(buff);

	OVector3 camSpeed = camera()->state()->motionComponent(1, OState::Scene) * 1e6;
	OVector3 orientation = camera()->state()->orientation().toEulerAngles();
	snprintf(buff, 128, "Camera @ (%.02f, %.02f, %.02f), spd: (%.02f, %.02f, %.02f)/sec, or: Euler(%.02f, %.02f, %.02f)",
		camera()->position().x(), camera()->position().y(), camera()->position().z(),
		camSpeed.x(), camSpeed.y(), camSpeed.z(),
		orientation.x(), orientation.y(), orientation.z()
	);
	_cameraText->setContent(buff);

	/* calculating new positions */
	if (!_pauseFlag) {
		_thetaA = _thetaA + 2 * PI * deltaTime_us / (_periodA * 1000000);
		_thetaB = _thetaB + 2 * PI * deltaTime_us / (_periodB * 1000000);

		if (_thetaA > 2 * PI) _thetaA -= 2 * PI;
		if (_thetaB > 2 * PI) _thetaB -= 2 * PI;
	}
	
	/* update last time index */
	_last_timeIndex = timeIndex;
}
Beispiel #3
0
void DemoApplication::onKeyboardPress(const OKeyboardPressEvent *evt)
{
	switch (evt->code()) {
	case OKeyboardPressEvent::OKey_Space: 
		_pauseFlag = !_pauseFlag;
		break;
	case OKeyboardPressEvent::OKey_L:
	case OKeyboardPressEvent::OKey_l:
		setTargetFPS((targetFPS() == 0) ? 40 : 0);
		break;
	}
}