kzcMatrix4x4CreateOrthogonalProjection的源码
时间: 2024-01-20 17:04:00 浏览: 70
以下是kanzi的kzcMatrix4x4CreateOrthogonalProjection函数的源码:
```c++
kzcMatrix4x4 kzcMatrix4x4CreateOrthogonalProjection(float left, float right, float bottom, float top, float nearVal, float farVal)
{
kzcMatrix4x4 projectionMatrix = KZC_MATRIX4X4_IDENTITY;
projectionMatrix.m00 = 2.0f / (right - left);
projectionMatrix.m03 = -(right + left) / (right - left);
projectionMatrix.m11 = 2.0f / (top - bottom);
projectionMatrix.m13 = -(top + bottom) / (top - bottom);
projectionMatrix.m22 = -2.0f / (farVal - nearVal);
projectionMatrix.m23 = -(farVal + nearVal) / (farVal - nearVal);
projectionMatrix.m33 = 1.0f;
return projectionMatrix;
}
```
该函数首先创建一个4x4的单位矩阵`projectionMatrix`,然后根据传入的参数计算正交投影矩阵的各个元素,最后返回该矩阵。其中,`left`、`right`、`bottom`、`top`、`nearVal`和`farVal`分别表示矩阵的左、右、下、上、近和远平面的位置。函数先计算了x、y、z轴上的缩放因子,并根据这些因子计算出了整个矩阵的各个元素。
阅读全文