Plasma Engine  2.0
Loading...
Searching...
No Matches
ViewData.h
1#pragma once
2
3#include <Core/Graphics/Camera.h>
4#include <Foundation/Math/Rect.h>
5#include <Foundation/Utilities/GraphicsUtils.h>
6#include <RendererCore/Pipeline/ViewRenderMode.h>
7#include <RendererFoundation/Device/SwapChain.h>
8
10struct PL_RENDERERCORE_DLL plViewData
11{
13 {
14 m_ViewPortRect = plRectFloat(0.0f, 0.0f);
15 m_ViewRenderMode = plViewRenderMode::None;
16
17 for (int i = 0; i < 2; ++i)
18 {
19 m_ViewMatrix[i].SetIdentity();
20 m_InverseViewMatrix[i].SetIdentity();
21 m_ProjectionMatrix[i].SetIdentity();
22 m_InverseProjectionMatrix[i].SetIdentity();
23 m_ViewProjectionMatrix[i].SetIdentity();
24 m_InverseViewProjectionMatrix[i].SetIdentity();
25
26 m_LastViewMatrix[i].SetIdentity();
27 m_LastInverseViewMatrix[i].SetIdentity();
28 m_LastProjectionMatrix[i].SetIdentity();
29 m_LastInverseProjectionMatrix[i].SetIdentity();
30 m_LastViewProjectionMatrix[i].SetIdentity();
31 m_LastInverseViewProjectionMatrix[i].SetIdentity();
32 }
33 }
34
35 plGALRenderTargets m_renderTargets;
36 plGALSwapChainHandle m_hSwapChain;
37 plRectFloat m_ViewPortRect;
38 plEnum<plViewRenderMode> m_ViewRenderMode;
39 plEnum<plCameraUsageHint> m_CameraUsageHint;
40
41 // Each matrix is there for both left and right camera lens.
42 plMat4 m_ViewMatrix[2];
43 plMat4 m_InverseViewMatrix[2];
44 plMat4 m_ProjectionMatrix[2];
45 plMat4 m_InverseProjectionMatrix[2];
46 plMat4 m_ViewProjectionMatrix[2];
47 plMat4 m_InverseViewProjectionMatrix[2];
48
49 plMat4 m_LastViewMatrix[2];
50 plMat4 m_LastInverseViewMatrix[2];
51 plMat4 m_LastProjectionMatrix[2];
52 plMat4 m_LastInverseProjectionMatrix[2];
53 plMat4 m_LastViewProjectionMatrix[2];
54 plMat4 m_LastInverseViewProjectionMatrix[2];
55
61 float fScreenPosX, float fScreenPosY, plVec3& out_vRayStartPos, plVec3& out_vRayDir, plCameraEye eye = plCameraEye::Left) const
62 {
63 plVec3 vScreenPos;
64 vScreenPos.x = fScreenPosX;
65 vScreenPos.y = 1.0f - fScreenPosY;
66 vScreenPos.z = 0.0f;
67
68 return plGraphicsUtils::ConvertScreenPosToWorldPos(
69 m_InverseViewProjectionMatrix[static_cast<int>(eye)], 0, 0, 1, 1, vScreenPos, out_vRayStartPos, &out_vRayDir);
70 }
71
72 plResult ComputeScreenSpacePos(const plVec3& vPoint, plVec3& out_vScreenPos, plCameraEye eye = plCameraEye::Left) const
73 {
74 plUInt32 x = (plUInt32)m_ViewPortRect.x;
75 plUInt32 y = (plUInt32)m_ViewPortRect.y;
76 plUInt32 w = (plUInt32)m_ViewPortRect.width;
77 plUInt32 h = (plUInt32)m_ViewPortRect.height;
78
79 if (plGraphicsUtils::ConvertWorldPosToScreenPos(m_ViewProjectionMatrix[static_cast<int>(eye)], x, y, w, h, vPoint, out_vScreenPos).Succeeded())
80 {
81 out_vScreenPos.y = m_ViewPortRect.height - out_vScreenPos.y;
82
83 return PL_SUCCESS;
84 }
85
86 return PL_FAILURE;
87 }
88};
Definition RendererFoundationDLL.h:397
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
Definition RenderTargetSetup.h:9
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Holds view data like the viewport, view and projection matrices.
Definition ViewData.h:11
plResult ComputePickingRay(float fScreenPosX, float fScreenPosY, plVec3 &out_vRayStartPos, plVec3 &out_vRayDir, plCameraEye eye=plCameraEye::Left) const
Returns the start position and direction (in world space) of the picking ray through the screen posit...
Definition ViewData.h:60