当前位置: 首页>>代码示例>>C++>>正文


C++ View::getViewport方法代码示例

本文整理汇总了C++中sf::View::getViewport方法的典型用法代码示例。如果您正苦于以下问题:C++ View::getViewport方法的具体用法?C++ View::getViewport怎么用?C++ View::getViewport使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::View的用法示例。


在下文中一共展示了View::getViewport方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getLightMapPixel

 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;
 }
开发者ID:DaiMysha,项目名称:LightSystem,代码行数:8,代码来源:LightSystem.cpp

示例2: SetView

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);
	}
}
开发者ID:fallahn,项目名称:CHUF,代码行数:36,代码来源:MeshScene.cpp


注:本文中的sf::View::getViewport方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。