Mercury Geometry and Math Library
Revisión | d323ee155d290dba44be27ee757af6962141d106 (tree) |
---|---|
Tiempo | 2022-01-24 09:26:57 |
Autor | AlaskanEmily <emily@alas...> |
Commiter | AlaskanEmily |
Add matrix.destructure_matrix and matrix.ortho
@@ -28,6 +28,10 @@ | ||
28 | 28 | :- func frustum(float, float, float, float, float, float) = matrix. |
29 | 29 | |
30 | 30 | %-----------------------------------------------------------------------------% |
31 | +% ortho(Left, Right, Top, Bottom, Near, Far) = Ortho. | |
32 | +:- func ortho(float, float, float, float, float, float) = matrix. | |
33 | + | |
34 | +%-----------------------------------------------------------------------------% | |
31 | 35 | |
32 | 36 | :- func translate(float, float, float) = matrix. |
33 | 37 |
@@ -104,6 +108,20 @@ | ||
104 | 108 | :- func column_c(matrix::in) = (vector.vector4::uo) is det. |
105 | 109 | :- func column_d(matrix::in) = (vector.vector4::uo) is det. |
106 | 110 | |
111 | +%-----------------------------------------------------------------------------% | |
112 | + | |
113 | +:- pred destructure_matrix(matrix, | |
114 | + float, float, float, float, | |
115 | + float, float, float, float, | |
116 | + float, float, float, float, | |
117 | + float, float, float, float). | |
118 | + | |
119 | +:- mode destructure_matrix(in, | |
120 | + out, out, out, out, | |
121 | + out, out, out, out, | |
122 | + out, out, out, out, | |
123 | + out, out, out, out) is det. | |
124 | + | |
107 | 125 | %=============================================================================% |
108 | 126 | :- implementation. |
109 | 127 | %=============================================================================% |
@@ -130,6 +148,17 @@ frustum(Left, Right, Top, Bottom, Near, Far) = matrix( | ||
130 | 148 | |
131 | 149 | %-----------------------------------------------------------------------------% |
132 | 150 | |
151 | +ortho(Left, Right, Top, Bottom, Near, Far) = matrix( | |
152 | + vector(2.0 / (Right - Left), 0.0, 0.0, A), | |
153 | + vector(0.0, 2.0 / (Top - Bottom), 0.0, B), | |
154 | + vector(0.0, 0.0, -2.0 / (Far - Near), C), | |
155 | + vector(0.0, 0.0, 0.0, 1.0)) :- | |
156 | + A = (Right + Left) / (Right - Left), | |
157 | + B = (Top + Bottom) / (Top - Bottom), | |
158 | + C = -(Far + Near) / (Far - Near). | |
159 | + | |
160 | +%-----------------------------------------------------------------------------% | |
161 | + | |
133 | 162 | translate(X, Y, Z) = matrix( |
134 | 163 | vector(1.0, 0.0, 0.0, X), |
135 | 164 | vector(0.0, 1.0, 0.0, Y), |
@@ -225,3 +254,16 @@ column_b(M) = vector(M ^ a ^ y + 0.0, M ^ b ^ y + 0.0, M ^ c ^ y + 0.0, M ^ d ^ | ||
225 | 254 | column_c(M) = vector(M ^ a ^ z + 0.0, M ^ b ^ z + 0.0, M ^ c ^ z + 0.0, M ^ d ^ z + 0.0). |
226 | 255 | column_d(M) = vector(M ^ a ^ w + 0.0, M ^ b ^ w + 0.0, M ^ c ^ w + 0.0, M ^ d ^ w + 0.0). |
227 | 256 | |
257 | +%-----------------------------------------------------------------------------% | |
258 | + | |
259 | +destructure_matrix( | |
260 | + matrix( | |
261 | + vector(V0, V1, V2, V3), | |
262 | + vector(V4, V5, V6, V7), | |
263 | + vector(V8, V9, V10, V11), | |
264 | + vector(V12, V13, V14, V15)), | |
265 | + V0, V1, V2, V3, | |
266 | + V4, V5, V6, V7, | |
267 | + V8, V9, V10, V11, | |
268 | + V12, V13, V14, V15). | |
269 | + |