Beispiel #1
0
void Visual::Display()
{
    //sdkStartTimer(&_timer);

    // run CUDA kernel to generate vertex positions
    RunCuda(&_vboResource);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // set view matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, _translateZ);
    glRotatef(_rotateX, 1.0, 0.0, 0.0);
    glRotatef(_rotateY, 0.0, 1.0, 0.0);

    // render from the _vbo
    glBindBuffer(GL_ARRAY_BUFFER, _vbo);
    glVertexPointer(4, GL_FLOAT, 0, 0);

    glEnableClientState(GL_VERTEX_ARRAY);
    glColor3f(1.0, 0.0, 0.0);
    glDrawArrays(GL_POINTS, 0, MeshWidth * MeshHeight);
    glDisableClientState(GL_VERTEX_ARRAY);

    glutSwapBuffers();

    _anim += 0.01f;

    //sdkStopTimer(&_timer);
    ComputeFPS();
}
Beispiel #2
0
	//----------------------------------------------------------------------------------
	//
	//----------------------------------------------------------------------------------
	bool Core_Imp::DoEvents()
	{
		if (!m_isInitializedByExternal)
		{
			assert(m_window != nullptr);
			assert(m_keyboard != nullptr);
			assert(m_mouse != nullptr);
			assert(m_logger != nullptr);
			assert(m_joystickContainer != nullptr);
		}

		ControlFPS();
		ComputeFPS();

		if (m_isInitializedByExternal)
		{
		}
		else
		{
			m_keyboard->RefreshInputState();
			m_mouse->RefreshInputState();
			m_joystickContainer->RefreshJoysticks();
		}

		// 経過時間計算
		{
			if (deltaTimePreviousTime == 0)
			{
				deltaTimePreviousTime = GetTime();
			}

			auto delta = GetTime() - deltaTimePreviousTime;
			deltaTimePreviousTime = GetTime();
			
			if (framerateMode == FramerateMode::Constant)
			{
				deltaTime = (1.0f / (float) m_targetFPS) * timeSpan;
			}
			else if (framerateMode == FramerateMode::Variable)
			{
				deltaTime = delta / (1000.0f) * timeSpan;
			}
		}

		if (m_isInitializedByExternal)
		{
			return true;
		}

		return m_window->DoEvent();
	}
	//----------------------------------------------------------------------------------
	//
	//----------------------------------------------------------------------------------
	bool Core_Imp::DoEvents()
	{
		if (m_isInitializedByExternal) return true;

		assert(m_window != nullptr);
		assert(m_keyboard != nullptr);
		assert(m_mouse != nullptr);
		assert(m_logger != nullptr);
		assert(m_joystickContainer != nullptr);

		ControlFPS();
		ComputeFPS();

		m_keyboard->RefreshInputState();
		m_mouse->RefreshInputState();
		m_joystickContainer->RefreshJoysticks();

		return m_window->DoEvent();
	}
Beispiel #4
0
static void SimulationLoop()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	settings.hz = settingsHz;

	// call this each frame, to function correctly with devices that may recreate
	// the GL Context without us asking for it
	Resize(width, height);

	test->Step(&settings);

	// Update the state of the particle parameter.
	bool restartTest;
	const bool changed = particleParameter.Changed(&restartTest);
	B2_NOT_USED(changed);


	if (fullscreenUI.GetEnabled())
	{
		// Set framework settings options based on parameters
		const uint32 options = particleParameter.GetOptions();

		settings.strictContacts 	= options &
			ParticleParameter::OptionStrictContacts;
		settings.drawContactPoints	= options &
			ParticleParameter::OptionDrawContactPoints;
		settings.drawContactNormals	= options &
			ParticleParameter::OptionDrawContactNormals;
		settings.drawContactImpulse	= options &
			ParticleParameter::OptionDrawContactImpulse;
		settings.drawFrictionImpulse = options &
			ParticleParameter::OptionDrawFrictionImpulse;
		settings.drawStats 			 = options &
			ParticleParameter::OptionDrawStats;
		settings.drawProfile		 = options &
			ParticleParameter::OptionDrawProfile;

		// The b2Draw based flags must be exactly 0 or 1 currently.
		settings.drawShapes 	= options &
			ParticleParameter::OptionDrawShapes ? 1 : 0;
		settings.drawParticles 	= options &
			ParticleParameter::OptionDrawParticles ? 1 : 0;
		settings.drawJoints		= options &
			ParticleParameter::OptionDrawJoints ? 1 : 0;
		settings.drawAABBs		= options &
			ParticleParameter::OptionDrawAABBs ? 1 : 0;
		settings.drawCOMs 		= options &
			ParticleParameter::OptionDrawCOMs ? 1 : 0;

		// Draw the full screen UI with
		// "test_name [: particle_parameter] / fps" at the bottom of the
		// screen.
		std::string msg = entry->name;
		if (fullscreenUI.GetParticleParameterSelectionEnabled())
		{
			msg += " : ";
			msg += particleParameter.GetName();
		}

		std::stringstream ss;
		ss << int(1000.0f / ComputeFPS());
		msg += " / " + ss.str() + " fps";
		fullscreenUI.Draw(msg);
	}

	test->DrawTitle(entry->name);

	glutSwapBuffers();

	if (testSelection != testIndex || restartTest)
	{
		fullscreenUI.Reset();
		if (!restartTest) particleParameter.Reset();

		testIndex = testSelection;
		delete test;
		entry = g_testEntries + testIndex;
		test = entry->createFcn();
		viewZoom = test->GetDefaultViewZoom();
		settings.viewCenter.Set(0.0f, 20.0f * viewZoom);
		Resize(width, height);
	}

	// print world step time stats every 600 frames
	static int s_printCount = 0;
	static b2Stat st;
	st.Record(settings.stepTimeOut);

	const int STAT_PRINT_INTERVAL = 600;
	if ( settings.printStepTimeStats && st.GetCount() == STAT_PRINT_INTERVAL )
	{
		printf("World Step Time samples %i-%i: %fmin %fmax %favg (ms)\n",
			s_printCount*STAT_PRINT_INTERVAL,
			(s_printCount+1)*STAT_PRINT_INTERVAL-1,
			st.GetMin(), st.GetMax(), st.GetMean());
		st.Clear();
		s_printCount++;
	}
}