Mercury Geometry and Math Library
リビジョン | 433910f31212e2241658adbc8b8f5da607874987 (tree) |
---|---|
日時 | 2022-01-24 09:26:24 |
作者 | AlaskanEmily <emily@alas...> |
コミッター | AlaskanEmily |
Fix formatting in matrix.m
@@ -6,16 +6,16 @@ | ||
6 | 6 | |
7 | 7 | :- module matrix. |
8 | 8 | |
9 | -%==============================================================================% | |
9 | +%=============================================================================% | |
10 | 10 | :- interface. |
11 | -%==============================================================================% | |
11 | +%=============================================================================% | |
12 | 12 | |
13 | 13 | :- use_module vector. |
14 | 14 | |
15 | 15 | :- include_module matrix.invert. |
16 | 16 | :- use_module matrix.invert. |
17 | 17 | |
18 | -%------------------------------------------------------------------------------% | |
18 | +%-----------------------------------------------------------------------------% | |
19 | 19 | |
20 | 20 | :- type matrix ---> matrix( |
21 | 21 | a::vector.vector4, |
@@ -23,40 +23,40 @@ | ||
23 | 23 | c::vector.vector4, |
24 | 24 | d::vector.vector4). |
25 | 25 | |
26 | -%------------------------------------------------------------------------------% | |
26 | +%-----------------------------------------------------------------------------% | |
27 | 27 | % frustum(Left, Right, Top, Bottom, Near, Far) = Frustum. |
28 | 28 | :- func frustum(float, float, float, float, float, float) = matrix. |
29 | 29 | |
30 | -%------------------------------------------------------------------------------% | |
30 | +%-----------------------------------------------------------------------------% | |
31 | 31 | |
32 | 32 | :- func translate(float, float, float) = matrix. |
33 | 33 | |
34 | -%------------------------------------------------------------------------------% | |
34 | +%-----------------------------------------------------------------------------% | |
35 | 35 | |
36 | 36 | :- func translate(vector.vector3) = matrix. |
37 | 37 | |
38 | -%------------------------------------------------------------------------------% | |
38 | +%-----------------------------------------------------------------------------% | |
39 | 39 | |
40 | 40 | :- func scale(float, float, float) = matrix. |
41 | 41 | |
42 | -%------------------------------------------------------------------------------% | |
42 | +%-----------------------------------------------------------------------------% | |
43 | 43 | |
44 | 44 | :- func scale(vector.vector3) = matrix. |
45 | 45 | |
46 | -%------------------------------------------------------------------------------% | |
46 | +%-----------------------------------------------------------------------------% | |
47 | 47 | |
48 | 48 | :- func rotate(float::in, vector.vector3::in) = (matrix::uo) is det. |
49 | 49 | :- func rotate_old(float::in, vector.vector3::in) = (matrix::uo) is det. |
50 | 50 | |
51 | -%------------------------------------------------------------------------------% | |
51 | +%-----------------------------------------------------------------------------% | |
52 | 52 | |
53 | 53 | :- func identity = matrix. |
54 | 54 | |
55 | -%------------------------------------------------------------------------------% | |
55 | +%-----------------------------------------------------------------------------% | |
56 | 56 | |
57 | 57 | :- func transpose(matrix) = matrix. |
58 | 58 | |
59 | -%------------------------------------------------------------------------------% | |
59 | +%-----------------------------------------------------------------------------% | |
60 | 60 | |
61 | 61 | :- pred transpose(matrix, matrix). |
62 | 62 | :- mode transpose(in, out) is det. |
@@ -67,15 +67,15 @@ | ||
67 | 67 | :- mode transpose(mdi, muo) is det. |
68 | 68 | :- mode transpose(muo, mdi) is det. |
69 | 69 | |
70 | -%------------------------------------------------------------------------------% | |
70 | +%-----------------------------------------------------------------------------% | |
71 | 71 | |
72 | 72 | :- func (matrix::in) * (vector.vector4::in) = (vector.vector4::uo) is det. |
73 | 73 | |
74 | -%------------------------------------------------------------------------------% | |
74 | +%-----------------------------------------------------------------------------% | |
75 | 75 | |
76 | 76 | :- func transform(matrix::in, vector.vector4::in) = (vector.vector4::uo) is det. |
77 | 77 | |
78 | -%------------------------------------------------------------------------------% | |
78 | +%-----------------------------------------------------------------------------% | |
79 | 79 | |
80 | 80 | :- func multiply(matrix, matrix) = matrix. |
81 | 81 | :- mode multiply(in, in) = (uo) is det. |
@@ -97,18 +97,18 @@ | ||
97 | 97 | :- mode multiply2(in, di, uo) is det. |
98 | 98 | :- mode multiply2(di, di, uo) is det. |
99 | 99 | |
100 | -%------------------------------------------------------------------------------% | |
100 | +%-----------------------------------------------------------------------------% | |
101 | 101 | |
102 | 102 | :- func column_a(matrix::in) = (vector.vector4::uo) is det. |
103 | 103 | :- func column_b(matrix::in) = (vector.vector4::uo) is det. |
104 | 104 | :- func column_c(matrix::in) = (vector.vector4::uo) is det. |
105 | 105 | :- func column_d(matrix::in) = (vector.vector4::uo) is det. |
106 | 106 | |
107 | -%==============================================================================% | |
107 | +%=============================================================================% | |
108 | 108 | :- implementation. |
109 | -%==============================================================================% | |
109 | +%=============================================================================% | |
110 | 110 | |
111 | -:- import_module exception. | |
111 | +:- use_module exception. | |
112 | 112 | :- import_module float. |
113 | 113 | :- import_module int. |
114 | 114 | :- use_module math. |
@@ -116,7 +116,7 @@ | ||
116 | 116 | :- import_module vector.vector3. |
117 | 117 | :- import_module vector.vector4. |
118 | 118 | |
119 | -%------------------------------------------------------------------------------% | |
119 | +%-----------------------------------------------------------------------------% | |
120 | 120 | |
121 | 121 | frustum(Left, Right, Top, Bottom, Near, Far) = matrix( |
122 | 122 | vector(2.0 * Near / (Right - Left), 0.0, A, 0.0), |
@@ -128,7 +128,7 @@ frustum(Left, Right, Top, Bottom, Near, Far) = matrix( | ||
128 | 128 | C = -(Far + Near) / (Far - Near), |
129 | 129 | D = -2.0 * Far * Near / (Far - Near). |
130 | 130 | |
131 | -%------------------------------------------------------------------------------% | |
131 | +%-----------------------------------------------------------------------------% | |
132 | 132 | |
133 | 133 | translate(X, Y, Z) = matrix( |
134 | 134 | vector(1.0, 0.0, 0.0, X), |
@@ -136,11 +136,11 @@ translate(X, Y, Z) = matrix( | ||
136 | 136 | vector(0.0, 0.0, 1.0, Z), |
137 | 137 | vector(0.0, 0.0, 0.0, 1.0)). |
138 | 138 | |
139 | -%------------------------------------------------------------------------------% | |
139 | +%-----------------------------------------------------------------------------% | |
140 | 140 | |
141 | 141 | translate(vector(X, Y, Z)) = translate(X, Y, Z). |
142 | 142 | |
143 | -%------------------------------------------------------------------------------% | |
143 | +%-----------------------------------------------------------------------------% | |
144 | 144 | |
145 | 145 | scale(X, Y, Z) = matrix( |
146 | 146 | vector(X, 0.0, 0.0, 0.0), |
@@ -148,15 +148,15 @@ scale(X, Y, Z) = matrix( | ||
148 | 148 | vector(0.0, 0.0, Z, 0.0), |
149 | 149 | vector(0.0, 0.0, 0.0, 1.0)). |
150 | 150 | |
151 | -%------------------------------------------------------------------------------% | |
151 | +%-----------------------------------------------------------------------------% | |
152 | 152 | |
153 | 153 | scale(vector(X, Y, Z)) = scale(X, Y, Z). |
154 | 154 | |
155 | -%------------------------------------------------------------------------------% | |
155 | +%-----------------------------------------------------------------------------% | |
156 | 156 | |
157 | 157 | rotate_old(A, Vec) = M :- transpose(rotate(A, Vec), M). |
158 | 158 | |
159 | -%------------------------------------------------------------------------------% | |
159 | +%-----------------------------------------------------------------------------% | |
160 | 160 | |
161 | 161 | rotate(A, Vec) = matrix( |
162 | 162 | vector(X*X*(1.0-C)+C, X*Y*(1.0-C)-Z*S, X*Z*(1.0-C)+Y*S, 0.0), |
@@ -167,7 +167,7 @@ rotate(A, Vec) = matrix( | ||
167 | 167 | S = math.sin(A), |
168 | 168 | C = math.cos(A). |
169 | 169 | |
170 | -%------------------------------------------------------------------------------% | |
170 | +%-----------------------------------------------------------------------------% | |
171 | 171 | |
172 | 172 | identity = matrix( |
173 | 173 | vector(1.0, 0.0, 0.0, 0.0), |
@@ -175,20 +175,20 @@ identity = matrix( | ||
175 | 175 | vector(0.0, 0.0, 1.0, 0.0), |
176 | 176 | vector(0.0, 0.0, 0.0, 1.0)). |
177 | 177 | |
178 | -%------------------------------------------------------------------------------% | |
178 | +%-----------------------------------------------------------------------------% | |
179 | 179 | |
180 | 180 | (matrix(V1, V2, V3, V4)) * (V) = |
181 | 181 | vector(vector.dot(V, V1), vector.dot(V, V2), vector.dot(V, V3), vector.dot(V, V4)). |
182 | 182 | |
183 | -%------------------------------------------------------------------------------% | |
183 | +%-----------------------------------------------------------------------------% | |
184 | 184 | |
185 | 185 | transform(M, V) = (M * V). |
186 | 186 | |
187 | -%------------------------------------------------------------------------------% | |
187 | +%-----------------------------------------------------------------------------% | |
188 | 188 | |
189 | 189 | transpose(M1) = M2 :- transpose(M1, M2). |
190 | 190 | |
191 | -%------------------------------------------------------------------------------% | |
191 | +%-----------------------------------------------------------------------------% | |
192 | 192 | |
193 | 193 | transpose( |
194 | 194 | matrix( |
@@ -202,7 +202,7 @@ transpose( | ||
202 | 202 | vector(C, G, K, O), |
203 | 203 | vector(D, H, L, P))). |
204 | 204 | |
205 | -%------------------------------------------------------------------------------% | |
205 | +%-----------------------------------------------------------------------------% | |
206 | 206 | |
207 | 207 | multiply(matrix(A, B, C, D), matrix(AIn, BIn, CIn, DIn)) = matrix( |
208 | 208 | vector(vector.dot(A, E), vector.dot(A, F), vector.dot(A, G), vector.dot(A, H)), |
@@ -218,9 +218,10 @@ multiply(M1, M2, multiply(M1, M2)). | ||
218 | 218 | |
219 | 219 | multiply2(M2, M1, multiply(M1, M2)). |
220 | 220 | |
221 | -%------------------------------------------------------------------------------% | |
221 | +%-----------------------------------------------------------------------------% | |
222 | 222 | |
223 | 223 | column_a(M) = vector(M ^ a ^ x + 0.0, M ^ b ^ x + 0.0, M ^ c ^ x + 0.0, M ^ d ^ x + 0.0). |
224 | 224 | column_b(M) = vector(M ^ a ^ y + 0.0, M ^ b ^ y + 0.0, M ^ c ^ y + 0.0, M ^ d ^ y + 0.0). |
225 | 225 | 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 | 226 | 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 | + |