Пример #1
0
bool ModelEntity::setOrthographicCameraShadowMap(const string& lightName, const OrthographicCameraShadowMap2DSP& orthographicCameraShadowMap2D) const
{
	Quaternion baseRotation(-90.0f, Vector3(1.0f, 0.0f, 0.0f));

	baseRotation *= Quaternion(90.0f, Vector3(0.0f, 1.0f, 0.0f));

	auto walker = allLights.begin();

	InstanceNodeSP instanceNode;

	while (walker != allLights.end())
	{
		instanceNode = *walker;

		if (instanceNode->getNode()->getName().compare(lightName) == 0)
		{
			ProgramManagerProxy::setCameraByType(GeneralEntity::currentProgramType, orthographicCameraShadowMap2D->getOrthographicCamera(), instanceNode->getPosition(), instanceNode->getRotation() * baseRotation, true);

			return true;
		}

		walker++;
	}

	return false;
}
Пример #2
0
GLUSboolean updateGame(GLUSfloat deltaTime)
{
	//string currentProgramType = ProgramManager::RENDER_TO_SHADOWMAP_PROGRAM_TYPE;
	string currentProgramType = ProgramManager::DEFAULT_PROGRAM_TYPE;

	if (!updateEngine(deltaTime))
	{
		return GLUS_FALSE;
	}

	// Update everything

	GeneralEntityManager::getInstance()->update();

	//
	// Shadow part
	//

	GeneralEntity::setCurrentValues(ProgramManager::RENDER_TO_SHADOWMAP_PROGRAM_TYPE, orthographicCameraShadowMap2D->getOrthographicCamera(), deltaTime, false);

	// Camera

	modelEntity->setOrthographicShadowCamera("Lamp", orthographicCameraShadowMap2D);

	orthographicCameraShadowMap2D->updateShadowMatrix();

	// Lights, not used, so set to zero lights.

	ProgramManagerProxy::setNumberLightsByType(ProgramManager::RENDER_TO_SHADOWMAP_PROGRAM_TYPE, 0);
	ProgramManagerProxy::setAmbientLightColorByType(ProgramManager::RENDER_TO_SHADOWMAP_PROGRAM_TYPE);
	ProgramManagerProxy::setNoShadowByType(ProgramManager::RENDER_TO_SHADOWMAP_PROGRAM_TYPE);

	//

	GeneralEntityManager::getInstance()->sort();

	//

	orthographicCameraShadowMap2D->use(true);

	glClear(GL_DEPTH_BUFFER_BIT);

	// All the primitves

    glEnable(GL_POLYGON_OFFSET_FILL);
    glFrontFace(GL_CW);

	GeneralEntityManager::getInstance()->render();

    glDisable(GL_POLYGON_OFFSET_FILL);
    glFrontFace(GL_CCW);

	orthographicCameraShadowMap2D->use(false);

	//
	// Color rendering
	//

	ViewportSP defaultViewport = ViewportManager::getInstance()->getDefaultViewport();
	defaultViewport->use();

	GeneralEntity::setCurrentValues(currentProgramType, currentCamera, deltaTime, false);

	// Camera

	if (User::defaultUser.getUserCamera().get())
	{
		ProgramManagerProxy::setCameraByType(currentProgramType, currentCamera, Point4(), Quaternion());
	}
	else
	{
		modelEntity->setCamera("Camera");
	}

	// Lights

	int32_t numberLights = 0;
	numberLights = modelEntity->setLights(numberLights);
	ProgramManagerProxy::setNumberLightsByType(currentProgramType, numberLights);
	ProgramManagerProxy::setAmbientLightColorByType(currentProgramType);
	ProgramManagerProxy::setNoShadowByType(currentProgramType);

	ProgramManagerProxy::setShadowByType(currentProgramType, 0, orthographicCameraShadowMap2D->getShadowMap2D(), orthographicCameraShadowMap2D->getShadowMatrix(), 0);

	//

	GeneralEntityManager::getInstance()->sort();

	//

	glClearColor(0.9f, 0.9f, 0.9f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	// All the primitves

	GeneralEntityManager::getInstance()->render();

	//
	// Debug
	//

	if (drawDebug)
	{
		CameraManager::getInstance()->getDefaultPerspectiveCamera()->debugDraw(Point4(), Quaternion());
	}

	//

	// Debug plane

	groundPlane.draw(currentCamera->getEye(), Color::GREY);

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	// FPS

	FpsPrinter::printer.print(deltaTime);

	// Debug Menu

	FontSP font = FontManager::getInstance()->getFont("CourierNew");
	font->print(760.0f, 10.0f, Color::RED, "Toggle camera:    [c]");

	return GLUS_TRUE;
}