本文整理汇总了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;
}
示例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);
}
}