本文整理汇总了C++中Matrix4x4::PerspectiveFov方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4x4::PerspectiveFov方法的具体用法?C++ Matrix4x4::PerspectiveFov怎么用?C++ Matrix4x4::PerspectiveFov使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix4x4
的用法示例。
在下文中一共展示了Matrix4x4::PerspectiveFov方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawScene
//[-------------------------------------------------------]
//[ Private virtual SPMultiView functions ]
//[-------------------------------------------------------]
void SPMultiViewFixedFunctions::DrawScene(uint32 nScene)
{
// Get the used renderer
Renderer &cRenderer = GetRenderer();
// Fixed functions support required
FixedFunctions *pFixedFunctions = cRenderer.GetFixedFunctions();
if (pFixedFunctions) {
{ // Setup light
FixedFunctions::Light sLight;
pFixedFunctions->GetDefaultLightSettings(sLight);
sLight.cAmbient.SetRGBA(0.1f, 0.1f, 0.1f, 1.0f);
sLight.cDiffuse.SetRGBA(1.0f, 1.0f, 1.0f, 1.0f);
sLight.nType = FixedFunctions::LightType::Point;
sLight.vPosition.SetXYZ(0.0f, 0.0f, 1.5f);
sLight.fLinearAttenuation = 0.3f;
pFixedFunctions->SetTransformState(FixedFunctions::Transform::World, Matrix4x4::Identity);
pFixedFunctions->SetLightEnabled(0, false);
pFixedFunctions->SetLight (0, sLight);
pFixedFunctions->SetLightEnabled(0, true);
}
{ // Set the world matrix
// Build a rotation matrix by using a given Euler angle around the y-axis
Matrix4x4 mWorld;
mWorld.FromEulerAngleY(static_cast<float>(m_fRotation*Math::DegToRad));
pFixedFunctions->SetTransformState(FixedFunctions::Transform::World, mWorld);
}
{ // Set the view matrix
Matrix4x4 mView;
mView.SetTranslation(0.0f, 0.0f, -10.0f);
pFixedFunctions->SetTransformState(FixedFunctions::Transform::View, mView);
}
{ // Set the projection matrix
Matrix4x4 mProj;
const float fAspect = 1.0f;
const float fAspectRadio = cRenderer.GetViewport().GetWidth()/(cRenderer.GetViewport().GetHeight()*fAspect);
mProj.PerspectiveFov(static_cast<float>(45.0f*Math::DegToRad), fAspectRadio, 0.001f, 1000.0f);
pFixedFunctions->SetTransformState(FixedFunctions::Transform::Projection, mProj);
}
// Draw the mesh handler representing the scene to draw
switch (nScene) {
case 0:
m_pMeshHandlerSphere->Draw();
break;
case 1:
m_pMeshHandlerTorus->Draw();
break;
case 2:
m_pMeshHandlerCube->Draw();
break;
}
}
}
示例2: OnPaint
//[-------------------------------------------------------]
//[ Private virtual PLRenderer::SurfacePainter functions ]
//[-------------------------------------------------------]
void SPTriangleFixedFunctions::OnPaint(Surface &cSurface)
{
// Get the used renderer
Renderer &cRenderer = GetRenderer();
// Clear the content of the current used render target by using gray (this way, in case on an graphics error we might still see at least something)
cRenderer.Clear(Clear::Color | Clear::ZBuffer, Color4::Gray);
// Fixed functions support required
FixedFunctions *pFixedFunctions = cRenderer.GetFixedFunctions();
if (pFixedFunctions) {
{ // Set the world matrix
// Build a rotation matrix by using a given Euler angle around the y-axis
Matrix4x4 mWorld;
mWorld.FromEulerAngleY(static_cast<float>(m_fRotation*Math::DegToRad));
pFixedFunctions->SetTransformState(FixedFunctions::Transform::World, mWorld);
// Increase the rotation by the current time difference (time past since the last frame)
// -> Normally, such work should NOT be performed within the rendering step, but we want
// to keep the implementation simple in here...
m_fRotation += Timing::GetInstance()->GetTimeDifference()*50;
}
{ // Set the view matrix
Matrix4x4 mView;
mView.SetTranslation(0.0f, 0.0f, -5.0f);
pFixedFunctions->SetTransformState(FixedFunctions::Transform::View, mView);
}
{ // Set the projection matrix
const float fAspect = 1.0f;
const float fAspectRadio = cRenderer.GetViewport().GetWidth()/(cRenderer.GetViewport().GetHeight()*fAspect);
Matrix4x4 mProj;
mProj.PerspectiveFov(static_cast<float>(45.0f*Math::DegToRad), fAspectRadio, 0.001f, 1000.0f);
pFixedFunctions->SetTransformState(FixedFunctions::Transform::Projection, mProj);
}
// Normally this vertex buffer we created is NEVER a null pointer, but in this sample
// we want to go for sure
if (m_pVertexBuffer) {
// Bind our vertex buffer
pFixedFunctions->SetVertexBuffer(m_pVertexBuffer);
// No back face culling, please. Else we can only see one 'side' of the triangle
cRenderer.SetRenderState(RenderState::CullMode, Cull::None);
// Now draw the primitives of our cool triangle.
// The primitive type is 'triangles', we start at vertex 0 and draw '3' vertices.
cRenderer.DrawPrimitives(Primitive::TriangleList, 0, 3);
}
}
}
示例3: OnPaint
//[-------------------------------------------------------]
//[ Public virtual PLRenderer::SurfacePainter functions ]
//[-------------------------------------------------------]
void SPScene::OnPaint(Surface &cSurface)
{
// Get the used renderer
Renderer &cRenderer = GetRenderer();
// Get camera
SNCamera *pCamera = nullptr;
SceneRenderer *pSceneRenderer = nullptr;
if (m_pCameraNodeHandler->GetElement()) {
pCamera = static_cast<SNCamera*>(m_pCameraNodeHandler->GetElement());
if (pCamera)
pSceneRenderer = pCamera->GetSceneRenderer();
}
SNCamera::SetCamera(pCamera, &cRenderer);
// Check the used scene renderer
if (!pSceneRenderer)
pSceneRenderer = GetDefaultSceneRenderer();
// Check the used scene renderer
if (pSceneRenderer) {
// Get the root scene container
SceneContainer *pRootContainer = GetRootContainer();
if (pRootContainer) {
// Get the cull query
SQCull *pCullQuery = static_cast<SQCull*>(m_pCullQuery->GetElement());
if (pCullQuery) {
// Set camera (can be a null pointer)
if (pCamera) {
// Setup render query
SceneContainer *pCameraContainer = pCamera->GetContainer();
pCullQuery->SetCameraContainer((pCameraContainer && pCameraContainer->IsCell()) ? pCameraContainer : nullptr);
pCullQuery->SetCameraPosition(pCamera->GetTransform().GetPosition());
pCullQuery->SetViewFrustum(pCamera->GetFrustum(cRenderer.GetViewport()));
pCullQuery->SetProjectionMatrix(pCamera->GetProjectionMatrix(cRenderer.GetViewport()));
pCullQuery->SetViewMatrix(pCamera->GetViewMatrix());
pCullQuery->SetViewProjectionMatrix(pCullQuery->GetProjectionMatrix()*pCamera->GetViewMatrix());
} else {
// Set default states
pCullQuery->SetCameraContainer(nullptr);
pCullQuery->SetCameraPosition(Vector3::Zero);
Matrix4x4 mProj;
mProj.PerspectiveFov(static_cast<float>(90.0f*Math::DegToRad), 1.0f, 0.001f, 10000.0f);
Frustum cFrustum;
cFrustum.CreateViewPlanes(mProj, false);
pCullQuery->SetViewFrustum(cFrustum);
}
// Perform the visibility determination
pCullQuery->PerformQuery();
}
// Get the scene container (can be a null pointer)
SceneContainer *pContainer = GetSceneContainer();
// Pre all scene nodes
DrawPre(cRenderer, *pRootContainer);
// Draw all scene nodes solid
DrawSolid(cRenderer, *pRootContainer);
// Draw the scene container (if there's one)
if (pContainer && pCullQuery)
pSceneRenderer->DrawScene(cRenderer, *pCullQuery);
// Draw all scene nodes transparent
DrawTransparent(cRenderer, *pRootContainer);
// Debug all scene nodes
DrawDebug(cRenderer, *pRootContainer);
// Post all scene nodes
DrawPost(cRenderer, *pRootContainer);
}
}
}
示例4: OnPaint
//[-------------------------------------------------------]
//[ Private virtual PLRenderer::SurfacePainter functions ]
//[-------------------------------------------------------]
void SPRTTShaders::OnPaint(Surface &cSurface)
{
// Get the used renderer
Renderer &cRenderer = GetRenderer();
// Clear the content of the current used render target by using gray (this way, in case on an graphics error we might still see at least something)
cRenderer.Clear(Clear::Color | Clear::ZBuffer, Color4::Gray);
// Backup current render target and set the new one to render in our texture buffer
Surface *pRenderSurfaceBackup = cRenderer.GetRenderTarget();
if (cRenderer.SetRenderTarget(m_pRenderTarget)) {
if (m_pColorTarget1)
cRenderer.SetColorRenderTarget(static_cast<TextureBuffer*>(m_pColorTarget1), 1);
if (m_pColorTarget2)
cRenderer.SetColorRenderTarget(static_cast<TextureBuffer*>(m_pColorTarget2), 2);
if (m_pColorTarget3)
cRenderer.SetColorRenderTarget(static_cast<TextureBuffer*>(m_pColorTarget3), 3);
// Draw the scene
DrawScene(cRenderer);
// Reset render target
cRenderer.SetRenderTarget(pRenderSurfaceBackup);
}
// This code is similar to the code of the triangle sample. But instead of a
// triangle we will draw three rotating quadrangles. Further the used vertex
// buffer has texture coordinates and we apply the 'teapot' texture buffer on the primitives.
// Clear the content of the current used render target
// Make our program to the current one
if (cRenderer.SetProgram(m_pProgram)) {
// Set program vertex attributes, this creates a connection between "Vertex Buffer Attribute" and "Vertex Shader Attribute"
m_pProgram->Set("VertexPosition", m_pPositionVertexBuffer, VertexBuffer::Position);
m_pProgram->Set("VertexTextureCoordinate", m_pPositionVertexBuffer, VertexBuffer::TexCoord);
m_pProgram->Set("VertexColor", m_pColorVertexBuffer, VertexBuffer::Color);
// Set color factor
m_pProgram->Set("ColorFactor", 0.0f);
// Calculate the composed view projection matrix - we need it multiple times
Matrix4x4 mViewProjection;
{
// Calculate the view matrix
Matrix4x4 mView;
{
mView.SetTranslation(0.0f, 0.0f, -5.0f);
}
// Calculate the projection matrix
Matrix4x4 mProjection;
{
const float fAspect = 1.0f;
const float fAspectRadio = cRenderer.GetViewport().GetWidth()/(cRenderer.GetViewport().GetHeight()*fAspect);
mProjection.PerspectiveFov(static_cast<float>(45.0f*Math::DegToRad), fAspectRadio, 0.001f, 1000.0f);
}
// Calculate the composed view projection matrix
mViewProjection = mProjection*mView;
}
// No back face culling, please. Else we can only see one 'side' of the quadrangle
cRenderer.SetRenderState(RenderState::CullMode, Cull::None);
Matrix4x4 mWorld;
{ // Draw quadrangle 1: Primary render target
// Set object space to clip space matrix uniform
ProgramUniform *pProgramUniform = m_pProgram->GetUniform("ObjectSpaceToClipSpaceMatrix");
if (pProgramUniform) {
mWorld.SetTranslationMatrix(2.0f, 1.0f, 0.0f);
pProgramUniform->Set(mViewProjection*mWorld);
}
{ // Set the texture buffer we rendered our teapot in as the current texture buffer
const int nTextureUnit = m_pProgram->Set("DiffuseMap", m_pRenderTarget->GetTextureBuffer());
if (nTextureUnit >= 0) {
// Disable mip mapping - this is required because we created/filled no mipmaps for your texture buffer
cRenderer.SetSamplerState(nTextureUnit, Sampler::MagFilter, TextureFiltering::Linear);
cRenderer.SetSamplerState(nTextureUnit, Sampler::MinFilter, TextureFiltering::Linear);
cRenderer.SetSamplerState(nTextureUnit, Sampler::MipFilter, TextureFiltering::None);
}
}
// Draw
cRenderer.DrawPrimitives(Primitive::TriangleStrip, 0, 4);
}
{ // Draw quadrangle 2: Color render target 1
// Set object space to clip space matrix uniform
ProgramUniform *pProgramUniform = m_pProgram->GetUniform("ObjectSpaceToClipSpaceMatrix");
if (pProgramUniform) {
mWorld.FromEulerAngleY(static_cast<float>(m_fRotation*Math::DegToRad));
mWorld.SetTranslation(-2.0f, 1.0f, 0.0f);
pProgramUniform->Set(mViewProjection*mWorld);
}
{ // Set the texture buffer we rendered our teapot in as the current texture buffer
//.........这里部分代码省略.........
示例5: DrawScene
/**
* @brief
* Draws the scene
*/
void SPRTTShaders::DrawScene(Renderer &cRenderer)
{
// Clear the content of the current used render target by using gray (this way, in case on an graphics error we might still see at least something)
cRenderer.Clear(Clear::Color | Clear::ZBuffer, Color4::Gray);
// Make our program to the current one
if (cRenderer.SetProgram(m_pSceneProgram)) {
// Calculate the world matrix
Matrix4x4 mWorld;
{
// Build a rotation matrix by using a given Euler angle around the y-axis
mWorld.FromEulerAngleY(static_cast<float>(m_fRotation*Math::DegToRad));
}
// Set program uniforms
ProgramUniform *pProgramUniform = m_pSceneProgram->GetUniform("ObjectSpaceToClipSpaceMatrix");
if (pProgramUniform) {
// Calculate the view matrix
Matrix4x4 mView;
{
mView.SetTranslation(0.0f, -0.1f, -0.5f);
}
// Calculate the projection matrix
Matrix4x4 mProjection;
{
const float fAspect = 1.0f;
const float fAspectRadio = cRenderer.GetViewport().GetWidth()/(cRenderer.GetViewport().GetHeight()*fAspect);
mProjection.PerspectiveFov(static_cast<float>(45.0f*Math::DegToRad), fAspectRadio, 0.001f, 1000.0f);
}
// Calculate the final composed world view projection matrix
const Matrix4x4 mWorldViewProjection = mProjection*mView*mWorld;
// Set object space to clip space matrix uniform
pProgramUniform->Set(mWorldViewProjection);
}
// Set object space to world space matrix uniform
pProgramUniform = m_pSceneProgram->GetUniform("ObjectSpaceToWorldSpaceMatrix");
if (pProgramUniform)
pProgramUniform->Set(mWorld);
// Set world space light direction
pProgramUniform = m_pSceneProgram->GetUniform("LightDirection");
if (pProgramUniform)
pProgramUniform->Set(Vector3::UnitZ);
// Get the used mesh
const Mesh *pMesh = m_pMeshHandler->GetMesh();
if (pMesh) {
// Get the mesh LOD level to use
const MeshLODLevel *pLODLevel = pMesh->GetLODLevel(0);
if (pLODLevel && pLODLevel->GetIndexBuffer()) {
// Get and use the index buffer of the mesh LOD level
cRenderer.SetIndexBuffer(pLODLevel->GetIndexBuffer());
// Get the vertex buffer of the mesh handler
VertexBuffer *pVertexBuffer = m_pMeshHandler->GetVertexBuffer();
if (pVertexBuffer) {
// Set program vertex attributes, this creates a connection between "Vertex Buffer Attribute" and "Vertex Shader Attribute"
ProgramAttribute *pProgramAttribute = m_pSceneProgram->GetAttribute("VertexPosition");
if (pProgramAttribute)
pProgramAttribute->Set(pVertexBuffer, VertexBuffer::Position);
pProgramAttribute = m_pSceneProgram->GetAttribute("VertexNormal");
if (pProgramAttribute)
pProgramAttribute->Set(pVertexBuffer, VertexBuffer::Normal);
// Loop through all geometries of the mesh
const Array<Geometry> &lstGeometries = *pLODLevel->GetGeometries();
for (uint32 nGeo=0; nGeo<lstGeometries.GetNumOfElements(); nGeo++) {
// Is this geometry active?
const Geometry &cGeometry = lstGeometries[nGeo];
if (cGeometry.IsActive()) {
// Draw the geometry
cRenderer.DrawIndexedPrimitives(
cGeometry.GetPrimitiveType(),
0,
pVertexBuffer->GetNumOfElements()-1,
cGeometry.GetStartIndex(),
cGeometry.GetIndexSize()
);
}
}
}
}
}
}
}