예제 #1
0
 sf::Color LightSystem::getLightMapPixel(const sf::View& view, unsigned int x, unsigned int y)
 {
     sf::Image lightMap = getLightMap();
     x -= view.getViewport().left;
     y -= view.getViewport().top;
     if(x>=0&&y>=0&&x<lightMap.getSize().x&&y<lightMap.getSize().y) return lightMap.getPixel(x,y);
     else return sf::Color::Black;
 }
예제 #2
0
파일: MeshScene.cpp 프로젝트: fallahn/CHUF
void MeshScene::SetView(const sf::View& view)
{
	//we only want to do this if the aspect ratio has changed
	//to avoid unnecessary calls to tan
	const float aspect = view.getSize().x / view.getSize().y;
	if (m_camera->GetAspectRatio() != aspect)//potentially rendered moot by float comparison...
	{
		m_camera->SetAspectRatio(aspect);
		const float angle = std::tan(m_camera->GetFOV() / 2.f * 0.0174532925f);
		m_cameraZ = (static_cast<float>(view.getSize().y) / 2.f) / angle;
		m_cameraZ *= -m_sceneScale;
	}
	//set position
	m_camera->SetPosition(-view.getCenter().x * m_sceneScale,
						view.getCenter().y * m_sceneScale,
						m_cameraZ);

	//update viewport
	sf::Vector2u winSize = m_renderWindow.getSize();
	GLuint x = static_cast<GLuint>(view.getViewport().left * static_cast<float>(winSize.x));
	GLuint y = static_cast<GLuint>((1.f - view.getViewport().top) * static_cast<float>(winSize.y));
	GLuint w = static_cast<GLuint>(view.getViewport().width * static_cast<float>(winSize.x));
	GLuint h = static_cast<GLuint>(view.getViewport().height * static_cast<float>(winSize.y));

	//invert position
	y -= h;
	glViewport(x, y, w, h);

	//update directional light
	if (m_useDirectionalLight)
	{
		glm::vec3 pos = m_camera->GetPosition();
		m_directionalLight->SetPosition(-pos.x + lightPosOffset.x, -pos.y + lightPosOffset.y, directionalLightNear);
		m_directionalLight->SetTarget(-pos.x + lightTargetOffset.x, -pos.y + lightTargetOffset.y, directionalLightFar);
	}
}