• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Mercury Geometry and Math Library


Commit MetaInfo

Revisiónd323ee155d290dba44be27ee757af6962141d106 (tree)
Tiempo2022-01-24 09:26:57
AutorAlaskanEmily <emily@alas...>
CommiterAlaskanEmily

Log Message

Add matrix.destructure_matrix and matrix.ortho

Cambiar Resumen

Diferencia incremental

--- a/matrix.m
+++ b/matrix.m
@@ -28,6 +28,10 @@
2828 :- func frustum(float, float, float, float, float, float) = matrix.
2929
3030 %-----------------------------------------------------------------------------%
31+% ortho(Left, Right, Top, Bottom, Near, Far) = Ortho.
32+:- func ortho(float, float, float, float, float, float) = matrix.
33+
34+%-----------------------------------------------------------------------------%
3135
3236 :- func translate(float, float, float) = matrix.
3337
@@ -104,6 +108,20 @@
104108 :- func column_c(matrix::in) = (vector.vector4::uo) is det.
105109 :- func column_d(matrix::in) = (vector.vector4::uo) is det.
106110
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+
107125 %=============================================================================%
108126 :- implementation.
109127 %=============================================================================%
@@ -130,6 +148,17 @@ frustum(Left, Right, Top, Bottom, Near, Far) = matrix(
130148
131149 %-----------------------------------------------------------------------------%
132150
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+
133162 translate(X, Y, Z) = matrix(
134163 vector(1.0, 0.0, 0.0, X),
135164 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 ^
225254 column_c(M) = vector(M ^ a ^ z + 0.0, M ^ b ^ z + 0.0, M ^ c ^ z + 0.0, M ^ d ^ z + 0.0).
226255 column_d(M) = vector(M ^ a ^ w + 0.0, M ^ b ^ w + 0.0, M ^ c ^ w + 0.0, M ^ d ^ w + 0.0).
227256
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+