@@ -45,9 +45,6 @@ namespace Math
45
45
const Matrix4& GetViewMatrix () const { return m_ViewMatrix; }
46
46
const Matrix4& GetProjMatrix () const { return m_ProjMatrix; }
47
47
const Matrix4& GetViewProjMatrix () const { return m_ViewProjMatrix; }
48
- const Matrix4& GetReprojectionMatrix () const { return m_ReprojectMatrix; }
49
- const Frustum& GetViewSpaceFrustum () const { return m_FrustumVS; }
50
- const Frustum& GetWorldSpaceFrustum () const { return m_FrustumWS; }
51
48
52
49
protected:
53
50
@@ -60,29 +57,19 @@ namespace Math
60
57
// Redundant data cached for faster lookups.
61
58
Matrix3 m_Basis;
62
59
63
- // Transforms homogeneous coordinates from world space to view space. In this case, view space is defined as +X is
64
- // to the right, +Y is up, and -Z is forward. This has to match what the projection matrix expects, but you might
65
- // also need to know what the convention is if you work in view space in a shader.
60
+ // 0 矩阵变换
61
+ // 1. 渲染目标从模型坐标系转到世界坐标系--->世界变换矩阵
62
+ // 2. 再从世界坐标系转到视角坐标系--->视角变换矩阵 m_ViewMatrix
63
+ // 3. 从视角坐标系转换到投影坐标系--->投影变换矩阵 m_ProjMatrix
64
+
65
+ // 世界坐标系转换到视角坐标系
66
66
Matrix4 m_ViewMatrix; // i.e. "World-to-View" matrix
67
67
68
- // The projection matrix transforms view space to clip space. Once division by W has occurred, the final coordinates
69
- // can be transformed by the viewport matrix to screen space. The projection matrix is determined by the screen aspect
70
- // and camera field of view. A projection matrix can also be orthographic. In that case, field of view would be defined
71
- // in linear units, not angles.
68
+ // 视角坐标系转到投影坐标系
72
69
Matrix4 m_ProjMatrix; // i.e. "View-to-Projection" matrix
73
70
74
- // A concatenation of the view and projection matrices.
71
+ // 从世界坐标系直接转换到投影坐标系
75
72
Matrix4 m_ViewProjMatrix; // i.e. "World-To-Projection" matrix.
76
-
77
- // The view-projection matrix from the previous frame
78
- Matrix4 m_PreviousViewProjMatrix;
79
-
80
- // Projects a clip-space coordinate to the previous frame (useful for temporal effects).
81
- Matrix4 m_ReprojectMatrix;
82
-
83
- Frustum m_FrustumVS; // View-space view frustum
84
- Frustum m_FrustumWS; // World-space view frustum
85
-
86
73
};
87
74
88
75
class Camera : public BaseCamera
@@ -91,16 +78,14 @@ namespace Math
91
78
Camera ();
92
79
93
80
// Controls the view-to-projection matrix
94
- void SetPerspectiveMatrix ( float verticalFovRadians, float aspectHeightOverWidth , float nearZClip, float farZClip );
81
+ void SetPerspectiveMatrix ( float verticalFovRadians, float aspectWidthOverHeight , float nearZClip, float farZClip );
95
82
void SetFOV ( float verticalFovInRadians ) { m_VerticalFOV = verticalFovInRadians; UpdateProjMatrix (); }
96
- void SetAspectRatio ( float heightOverWidth ) { m_AspectRatio = heightOverWidth ; UpdateProjMatrix (); }
83
+ void SetAspectRatio ( float widthOverHeight ) { m_AspectRatio = widthOverHeight ; UpdateProjMatrix (); }
97
84
void SetZRange ( float nearZ, float farZ) { m_NearClip = nearZ; m_FarClip = farZ; UpdateProjMatrix (); }
98
- void ReverseZ ( bool enable ) { m_ReverseZ = enable; UpdateProjMatrix (); }
99
85
100
86
float GetFOV () const { return m_VerticalFOV; }
101
87
float GetNearClip () const { return m_NearClip; }
102
88
float GetFarClip () const { return m_FarClip; }
103
- float GetClearDepth () const { return m_ReverseZ ? 0 .0f : 1 .0f ; }
104
89
105
90
private:
106
91
@@ -110,7 +95,6 @@ namespace Math
110
95
float m_AspectRatio;
111
96
float m_NearClip;
112
97
float m_FarClip;
113
- bool m_ReverseZ; // Invert near and far clip distances so that Z=0 is the far plane
114
98
};
115
99
116
100
inline void BaseCamera::SetEyeAtUp ( Vector3 eye, Vector3 at, Vector3 up )
@@ -137,21 +121,19 @@ namespace Math
137
121
m_Basis = Matrix3 (m_CameraToWorld.GetRotation ());
138
122
}
139
123
140
- inline Camera::Camera () : m_ReverseZ( true )
124
+ inline Camera::Camera ()
141
125
{
142
- SetPerspectiveMatrix ( XM_PIDIV4, 9 .0f / 16 .0f , 1 .0f , 1000 .0f );
126
+ SetPerspectiveMatrix ( XM_PIDIV4, 16 .0f / 9 .0f , 1 .0f , 1000 .0f );
143
127
}
144
128
145
- inline void Camera::SetPerspectiveMatrix ( float verticalFovRadians, float aspectHeightOverWidth , float nearZClip, float farZClip )
129
+ inline void Camera::SetPerspectiveMatrix ( float verticalFovRadians, float aspectWidthOverHeight , float nearZClip, float farZClip )
146
130
{
147
131
m_VerticalFOV = verticalFovRadians;
148
- m_AspectRatio = aspectHeightOverWidth ;
132
+ m_AspectRatio = aspectWidthOverHeight ;
149
133
m_NearClip = nearZClip;
150
134
m_FarClip = farZClip;
151
135
152
136
UpdateProjMatrix ();
153
-
154
- m_PreviousViewProjMatrix = m_ViewProjMatrix;
155
137
}
156
138
157
139
} // namespace Math
0 commit comments