Changeset 652
- Timestamp:
- Feb 16, 2011, 7:04:08 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/matrix.cpp
r648 r652 63 63 } 64 64 65 template<> float4x4 float4x4::frustum(float left, float right, float bottom, 66 float top, float near, float far) 67 { 68 float invrl = (right != left) ? 1.0f / right - left : 0.0f; 69 float invtb = (top != bottom) ? 1.0f / top - bottom : 0.0f; 70 float invfn = (far != near) ? 1.0f / far - near : 0.0f; 71 72 float4x4 ret(0.0f); 73 ret[0][0] = 2.0f * near * invrl; 74 ret[1][1] = 2.0f * near * invtb; 75 ret[2][0] = (right + left) * invrl; 76 ret[2][1] = (top + bottom) * invtb; 77 ret[2][2] = - (far + near) * invfn; 78 ret[2][3] = -1.0f; 79 ret[3][2] = -2.0f * far * near * invfn; 80 return ret; 81 } 82 83 template<> float4x4 float4x4::perspective(float theta, float width, 84 float height, float near, float far) 85 { 86 float t1 = tanf(theta / 2.0f); 87 float t2 = t1 * height / width; 88 89 return frustum(-near * t1, near * t1, -near * t2, near * t2, near, far); 90 } 91 -
trunk/src/matrix.h
r651 r652 195 195 T det() const; 196 196 Mat4<T> invert() const; 197 198 static Mat4<T> frustum(T left, T right, T bottom, T top, T near, T far); 199 static Mat4<T> perspective(T theta, T width, T height, T near, T far); 197 200 198 201 inline Mat4<T> operator +(Mat4<T> const val) const
Note: See TracChangeset
for help on using the changeset viewer.