Beispiel #1
0
	void MainApplication::draw()
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		for (ComponentIterator it = m_components.begin(); it != m_components.end(); ++it)
		{
			(*it)->draw();
		}

		if (m_debug)
		{
			DebugIterator dit = m_debugComponents.find(m_currentLevel);
			if (dit != m_debugComponents.end())
			{
				ComponentCollection components = dit->second;
				for (ComponentIterator it = components.begin(); it != components.end(); it++)
				{
					(*it)->draw();
				}
			}
		}

		std::stringstream ss;
		ss << "Cloth Simulation Demo" << std::endl;
		ss << std::setiosflags(std::ios::fixed) << std::setprecision(1);
		ss << std::endl;
		
		if (m_help) {
			ss << "<Space> Start/reset simulation" << std::endl;
			ss << "<Enter> Toggle BVH visualization" << std::endl;
			ss << "<+/-> Adjust BVH visualization level";
			if (m_debug) { ss << " (" << m_currentLevel << ")"; } ss << std::endl;
			ss << "<c> Toggle constrained corners: " << (m_constrained ? "true" : "false") << std::endl;
			ss << "<v> Toggle moving ball: " << (m_animate ? "true" : "false") << std::endl;
			ss << "<Numpad 1-9> Adjust wind speed" << std::endl;
			ss << "<h> Show this help (reduces fps)" << std::endl;
			ss << std::endl;
			ss << "Friction: " << SoftBody::FRICTION << std::endl;
			ss << "Iteration count: " << SoftBody::ITERATION_COUNT << std::endl;
			ss << "Cloth size: " << SoftBody::WIDTH << "x" << SoftBody::LENGTH << std::endl;
		}
		ss << "Wind: (" << SoftBody::WIND.x << ", " << SoftBody::WIND.y << ", " << SoftBody::WIND.z << ")" << std::endl;

		std::string text = ss.str();

		display_text(text.c_str(), 10, 15);

		GLenum err = glGetError();
		if (err != GL_NO_ERROR)
			Trace::error("OpenGL error: %d\n", err);
	}