Graphics library for Mercury, including OpenGL bindings, TGA image reading, and X11, Win32, and SDL2 windowing and input.
リビジョン | 7a859e0ff44c4e07263dd5422aeacebbd64b132a (tree) |
---|---|
日時 | 2022-04-18 04:20:49 |
作者 | AlaskanEmily <emily@alas...> |
コミッター | AlaskanEmily |
Update mmath
@@ -38,10 +38,11 @@ | ||
38 | 38 | :- use_module maybe. |
39 | 39 | :- use_module time. |
40 | 40 | |
41 | -:- use_module matrix. | |
42 | -:- use_module vector. | |
43 | -:- import_module vector.vector3. | |
44 | -:- import_module vector.vector4. | |
41 | +:- use_module mmath. | |
42 | +:- use_module mmath.matrix. | |
43 | +:- use_module mmath.vector. | |
44 | +:- import_module mmath.vector.vector3. | |
45 | +:- import_module mmath.vector.vector4. | |
45 | 46 | |
46 | 47 | :- use_module saffron. |
47 | 48 | :- use_module saffron.draw. |
@@ -124,10 +125,10 @@ run(Ctx, Win, Group, !IO) :- | ||
124 | 125 | SpinT = Seconds, % / 0.23, |
125 | 126 | Angle = Seconds * 0.87, |
126 | 127 | RotateVector = |
127 | - vector.normalize(vector(math.sin(SpinT), 1.0, math.cos(SpinT))), | |
128 | + mmath.vector.normalize(vector(math.sin(SpinT), 1.0, math.cos(SpinT))), | |
128 | 129 | % In general, you should always normalize vectors being used to build |
129 | 130 | % transformation matrices. |
130 | - Matrix = matrix.rotate(Angle, RotateVector), | |
131 | + Matrix = mmath.matrix.rotate(Angle, RotateVector), | |
131 | 132 | |
132 | 133 | % Here we will push the ortho matrix set in main/2 and then transform |
133 | 134 | % it by our rotation. Then, after drawing, we pop the transformed |
@@ -290,10 +291,10 @@ main(!IO) :- | ||
290 | 291 | % Set the ortho mode |
291 | 292 | AR = float(W) / float(H), |
292 | 293 | |
293 | - Matrix = matrix.ortho(-AR, AR, 1.0, -1.0, -1000.0, 1000.0), | |
294 | + Matrix = mmath.matrix.ortho(-AR, AR, 1.0, -1.0, -1000.0, 1000.0), | |
294 | 295 | saffron.draw.set_matrix(Ctx, Matrix, !IO), |
295 | 296 | |
296 | - saffron.draw.transform(Ctx, matrix.scale(0.4, 0.4, 0.4), !IO), | |
297 | + saffron.draw.transform(Ctx, mmath.matrix.scale(0.4, 0.4, 0.4), !IO), | |
297 | 298 | |
298 | 299 | % Upload the image to create a texture. |
299 | 300 | saffron.gl.create_texture_from_bitmap(Ctx, BMP, TexW, TexH, Texture, !IO), |
@@ -1 +1 @@ | ||
1 | -Subproject commit d803d6f195accd635e33c76a2ad3eb7e027cd016 | |
1 | +Subproject commit 41d171250634ca20db35cab679afc6c030af30ae |
@@ -15,8 +15,9 @@ | ||
15 | 15 | :- use_module thread. |
16 | 16 | :- use_module thread.mvar. |
17 | 17 | |
18 | -:- use_module vector. | |
19 | -:- use_module matrix. | |
18 | +:- use_module mmath. | |
19 | +:- use_module mmath.vector. | |
20 | +:- use_module mmath.matrix. | |
20 | 21 | |
21 | 22 | %-----------------------------------------------------------------------------% |
22 | 23 |
@@ -33,7 +34,7 @@ | ||
33 | 34 | %-----------------------------------------------------------------------------% |
34 | 35 | |
35 | 36 | :- typeclass basic_transform(Ctx) where [ |
36 | - pred set_matrix(Ctx::in, matrix.matrix::in, io.io::di, io.io::uo) is det | |
37 | + pred set_matrix(Ctx::in, mmath.matrix.matrix::in, io.io::di, io.io::uo) is det | |
37 | 38 | ]. |
38 | 39 | |
39 | 40 | %-----------------------------------------------------------------------------% |
@@ -41,7 +42,7 @@ | ||
41 | 42 | % It will often be handled fully in software, where only set_matrix is actually |
42 | 43 | % used, but for GL2 we can just implement this with the GL2 calls. |
43 | 44 | :- typeclass transform_stack(Ctx) where [ |
44 | - pred transform(Ctx::in, matrix.matrix::in, io.io::di, io.io::uo) is det, | |
45 | + pred transform(Ctx::in, mmath.matrix.matrix::in, io.io::di, io.io::uo) is det, | |
45 | 46 | pred identity(Ctx::in, io.io::di, io.io::uo) is det, |
46 | 47 | pred push_matrix(Ctx::in, io.io::di, io.io::uo) is det, |
47 | 48 | % Should throw exception if the matrix stack is empty. |
@@ -57,8 +58,8 @@ | ||
57 | 58 | % Use a type here just to make it structurally required that there is always |
58 | 59 | % one matrix. |
59 | 60 | :- type transform_state ---> transform_state( |
60 | - matrix.matrix, | |
61 | - stack::list.list(matrix.matrix)). | |
61 | + mmath.matrix.matrix, | |
62 | + stack::list.list(mmath.matrix.matrix)). | |
62 | 63 | |
63 | 64 | %-----------------------------------------------------------------------------% |
64 | 65 | % Used to implement transform wiht a stack of matrices and basic_transform. |
@@ -68,11 +69,11 @@ | ||
68 | 69 | |
69 | 70 | %-----------------------------------------------------------------------------% |
70 | 71 | |
71 | -:- func top_matrix(transform_state) = matrix.matrix. | |
72 | +:- func top_matrix(transform_state) = mmath.matrix.matrix. | |
72 | 73 | |
73 | 74 | %-----------------------------------------------------------------------------% |
74 | 75 | |
75 | -:- func 'top_matrix :='(transform_state, matrix.matrix) = transform_state. | |
76 | +:- func 'top_matrix :='(transform_state, mmath.matrix.matrix) = transform_state. | |
76 | 77 | |
77 | 78 | %-----------------------------------------------------------------------------% |
78 | 79 |
@@ -146,13 +147,13 @@ top_matrix(transform_state(_, [Matrix|_])) = Matrix. | ||
146 | 147 | (transform(Ctx, Matrix, !IO) :- |
147 | 148 | MVar = Ctx ^ transform_state, |
148 | 149 | thread.mvar.take(MVar, State, !IO), |
149 | - NewMatrix = matrix.multiply(State ^ top_matrix, Matrix), | |
150 | + NewMatrix = mmath.matrix.multiply(State ^ top_matrix, Matrix), | |
150 | 151 | thread.mvar.put(MVar, State ^ top_matrix := NewMatrix, !IO) ), |
151 | 152 | |
152 | 153 | (identity(Ctx, !IO) :- |
153 | 154 | MVar = Ctx ^ transform_state, |
154 | 155 | thread.mvar.take(MVar, State, !IO), |
155 | - thread.mvar.put(MVar, State ^ top_matrix := matrix.identity, !IO) ), | |
156 | + thread.mvar.put(MVar, State ^ top_matrix := mmath.matrix.identity, !IO) ), | |
156 | 157 | |
157 | 158 | (push_matrix(Ctx, !IO) :- |
158 | 159 | MVar = Ctx ^ transform_state, |
@@ -13,15 +13,16 @@ | ||
13 | 13 | :- use_module array. |
14 | 14 | :- use_module list. |
15 | 15 | |
16 | -:- use_module vector. | |
16 | +:- use_module mmath. | |
17 | +:- use_module mmath.vector. | |
17 | 18 | |
18 | 19 | :- use_module saffron.texture. |
19 | 20 | |
20 | 21 | %-----------------------------------------------------------------------------% |
21 | 22 | |
22 | 23 | :- type vertex(Vec) ---> vertex(vec::Vec, u::float, v::float). |
23 | -:- type vertex2d == vertex(vector.vector2). | |
24 | -:- type vertex3d == vertex(vector.vector3). | |
24 | +:- type vertex2d == vertex(mmath.vector.vector2). | |
25 | +:- type vertex3d == vertex(mmath.vector.vector3). | |
25 | 26 | |
26 | 27 | %-----------------------------------------------------------------------------% |
27 | 28 | % This is intended to be used as if it was a functor for vertex, to construct |
@@ -187,8 +188,8 @@ | ||
187 | 188 | :- implementation. |
188 | 189 | %=============================================================================% |
189 | 190 | |
190 | -:- use_module vector.vector2. | |
191 | -:- use_module vector.vector3. | |
191 | +:- use_module mmath.vector.vector2. | |
192 | +:- use_module mmath.vector.vector3. | |
192 | 193 | |
193 | 194 | %-----------------------------------------------------------------------------% |
194 | 195 |
@@ -216,13 +217,13 @@ | ||
216 | 217 | |
217 | 218 | %-----------------------------------------------------------------------------% |
218 | 219 | |
219 | -vertex(X, Y, U, V) = vertex(vector.vector2.vector(X, Y), U, V). | |
220 | -vertex(X, Y, U, V, vertex(vector.vector2.vector(X, Y), U, V)). | |
220 | +vertex(X, Y, U, V) = vertex(mmath.vector.vector2.vector(X, Y), U, V). | |
221 | +vertex(X, Y, U, V, vertex(mmath.vector.vector2.vector(X, Y), U, V)). | |
221 | 222 | |
222 | 223 | %-----------------------------------------------------------------------------% |
223 | 224 | |
224 | -vertex(X, Y, Z, U, V) = vertex(vector.vector3.vector(X, Y, Z), U, V). | |
225 | -vertex(X, Y, Z, U, V, vertex(vector.vector3.vector(X, Y, Z), U, V)). | |
225 | +vertex(X, Y, Z, U, V) = vertex(mmath.vector.vector3.vector(X, Y, Z), U, V). | |
226 | +vertex(X, Y, Z, U, V, vertex(mmath.vector.vector3.vector(X, Y, Z), U, V)). | |
226 | 227 | |
227 | 228 | %-----------------------------------------------------------------------------% |
228 | 229 |
@@ -102,9 +102,10 @@ | ||
102 | 102 | :- implementation. |
103 | 103 | %=============================================================================% |
104 | 104 | |
105 | -:- use_module vector. | |
106 | -:- use_module vector.vector2. | |
107 | -:- use_module vector.vector3. | |
105 | +:- use_module mmath. | |
106 | +:- use_module mmath.vector. | |
107 | +:- use_module mmath.vector.vector2. | |
108 | +:- use_module mmath.vector.vector3. | |
108 | 109 | |
109 | 110 | :- pragma foreign_import_module("C", saffron.gl). |
110 | 111 | :- pragma foreign_import_module("C", saffron.geometry). |
@@ -15,7 +15,8 @@ | ||
15 | 15 | :- interface. |
16 | 16 | %=============================================================================% |
17 | 17 | |
18 | -:- use_module vector. | |
18 | +:- use_module mmath. | |
19 | +:- use_module mmath.vector. | |
19 | 20 | |
20 | 21 | :- use_module saffron.draw. |
21 | 22 | :- use_module saffron.geometry. |
@@ -79,14 +80,14 @@ | ||
79 | 80 | %-----------------------------------------------------------------------------% |
80 | 81 | |
81 | 82 | :- type vertex(Vec) == saffron.geometry.vertex(Vec). |
82 | -:- type vertex2d == vertex(vector.vector2). | |
83 | -:- type vertex3d == vertex(vector.vector3). | |
83 | +:- type vertex2d == vertex(mmath.vector.vector2). | |
84 | +:- type vertex3d == vertex(mmath.vector.vector3). | |
84 | 85 | |
85 | 86 | %-----------------------------------------------------------------------------% |
86 | 87 | |
87 | 88 | :- type buffer(Vec) == saffron.soft.buffer(vertex(Vec)). |
88 | -:- type buffer2d ---> buffer(buffer(vector.vector2)). | |
89 | -:- type buffer3d ---> buffer(buffer(vector.vector3)). | |
89 | +:- type buffer2d ---> buffer(buffer(mmath.vector.vector2)). | |
90 | +:- type buffer3d ---> buffer(buffer(mmath.vector.vector3)). | |
90 | 91 | |
91 | 92 | %-----------------------------------------------------------------------------% |
92 | 93 |
@@ -100,12 +101,12 @@ | ||
100 | 101 | |
101 | 102 | %-----------------------------------------------------------------------------% |
102 | 103 | |
103 | -:- instance saffron.geometry.buffer(context(Ctx), buffer2d, vector.vector2) | |
104 | +:- instance saffron.geometry.buffer(context(Ctx), buffer2d, mmath.vector.vector2) | |
104 | 105 | <= saffron.gl.context(Ctx). |
105 | 106 | |
106 | 107 | %-----------------------------------------------------------------------------% |
107 | 108 | |
108 | -:- instance saffron.geometry.buffer(context(Ctx), buffer3d, vector.vector3) | |
109 | +:- instance saffron.geometry.buffer(context(Ctx), buffer3d, mmath.vector.vector3) | |
109 | 110 | <= saffron.gl.context(Ctx). |
110 | 111 | |
111 | 112 | %-----------------------------------------------------------------------------% |
@@ -125,8 +126,8 @@ | ||
125 | 126 | %-----------------------------------------------------------------------------% |
126 | 127 | |
127 | 128 | :- type shape(Vec) == saffron.soft.shape(Vec, texture). |
128 | -:- type shape2d ---> shape(shape(vector.vector2)). | |
129 | -:- type shape3d ---> shape(shape(vector.vector3)). | |
129 | +:- type shape2d ---> shape(shape(mmath.vector.vector2)). | |
130 | +:- type shape3d ---> shape(shape(mmath.vector.vector3)). | |
130 | 131 | |
131 | 132 | %-----------------------------------------------------------------------------% |
132 | 133 |
@@ -151,8 +152,8 @@ | ||
151 | 152 | %-----------------------------------------------------------------------------% |
152 | 153 | |
153 | 154 | :- type group(Vec) == saffron.soft.group(Vec, texture). |
154 | -:- type group2d ---> group(group(vector.vector2)). | |
155 | -:- type group3d ---> group(group(vector.vector3)). | |
155 | +:- type group2d ---> group(group(mmath.vector.vector2)). | |
156 | +:- type group3d ---> group(group(mmath.vector.vector3)). | |
156 | 157 | |
157 | 158 | %-----------------------------------------------------------------------------% |
158 | 159 |
@@ -197,9 +198,9 @@ | ||
197 | 198 | :- use_module array. |
198 | 199 | :- use_module list. |
199 | 200 | |
200 | -:- use_module matrix. | |
201 | -:- import_module vector.vector2. | |
202 | -:- import_module vector.vector3. | |
201 | +:- use_module mmath.matrix. | |
202 | +:- import_module mmath.vector.vector2. | |
203 | +:- import_module mmath.vector.vector3. | |
203 | 204 | |
204 | 205 | %-----------------------------------------------------------------------------% |
205 | 206 |
@@ -385,10 +386,10 @@ supports_extension(_, _) :- false. | ||
385 | 386 | |
386 | 387 | %-----------------------------------------------------------------------------% |
387 | 388 | |
388 | -:- pred transform(matrix.matrix::in, io.io::di, io.io::uo) is det. | |
389 | +:- pred transform(mmath.matrix.matrix::in, io.io::di, io.io::uo) is det. | |
389 | 390 | |
390 | 391 | transform(Matrix, !IO) :- |
391 | - matrix.destructure_matrix(Matrix, | |
392 | + mmath.matrix.destructure_matrix(Matrix, | |
392 | 393 | V0, V1, V2, V3, |
393 | 394 | V4, V5, V6, V7, |
394 | 395 | V8, V9, V10, V11, |
@@ -443,7 +444,7 @@ transform(Matrix, !IO) :- | ||
443 | 444 | <= saffron.gl.context(Ctx) where [ |
444 | 445 | |
445 | 446 | (saffron.draw.set_matrix(_, Matrix, !IO) :- |
446 | - matrix.destructure_matrix(Matrix, | |
447 | + mmath.matrix.destructure_matrix(Matrix, | |
447 | 448 | V0, V1, V2, V3, |
448 | 449 | V4, V5, V6, V7, |
449 | 450 | V8, V9, V10, V11, |
@@ -506,7 +507,7 @@ transform(Matrix, !IO) :- | ||
506 | 507 | |
507 | 508 | %-----------------------------------------------------------------------------% |
508 | 509 | |
509 | -:- instance saffron.geometry.buffer(context(Ctx), buffer2d, vector.vector2) | |
510 | +:- instance saffron.geometry.buffer(context(Ctx), buffer2d, mmath.vector.vector2) | |
510 | 511 | <= saffron.gl.context(Ctx) where [ |
511 | 512 | |
512 | 513 | create_buffer_list(_, Vertices, buffer(array.from_list(Vertices)), !IO), |
@@ -515,7 +516,7 @@ transform(Matrix, !IO) :- | ||
515 | 516 | |
516 | 517 | %-----------------------------------------------------------------------------% |
517 | 518 | |
518 | -:- instance saffron.geometry.buffer(context(Ctx), buffer3d, vector.vector3) | |
519 | +:- instance saffron.geometry.buffer(context(Ctx), buffer3d, mmath.vector.vector3) | |
519 | 520 | <= saffron.gl.context(Ctx) where [ |
520 | 521 | |
521 | 522 | create_buffer_list(_, Vertices, buffer(array.from_list(Vertices)), !IO), |
@@ -600,12 +601,12 @@ transform(Matrix, !IO) :- | ||
600 | 601 | |
601 | 602 | %-----------------------------------------------------------------------------% |
602 | 603 | |
603 | -:- func get_shape2d(shape2d) = shape(vector.vector2). | |
604 | +:- func get_shape2d(shape2d) = shape(mmath.vector.vector2). | |
604 | 605 | get_shape2d(shape(Shape)) = Shape. |
605 | 606 | |
606 | 607 | %-----------------------------------------------------------------------------% |
607 | 608 | |
608 | -:- func get_shape3d(shape3d) = shape(vector.vector3). | |
609 | +:- func get_shape3d(shape3d) = shape(mmath.vector.vector3). | |
609 | 610 | get_shape3d(shape(Shape)) = Shape. |
610 | 611 | |
611 | 612 | %-----------------------------------------------------------------------------% |
@@ -746,7 +747,7 @@ draw_vertex3d(saffron.geometry.vertex(vector(X, Y, Z), U, V), C, !IO) :- | ||
746 | 747 | |
747 | 748 | %-----------------------------------------------------------------------------% |
748 | 749 | |
749 | -:- pred draw_shape2d(shape(vector.vector2)::in, io.io::di, io.io::uo) is det. | |
750 | +:- pred draw_shape2d(shape(mmath.vector.vector2)::in, io.io::di, io.io::uo) is det. | |
750 | 751 | draw_shape2d(Shape, !IO) :- |
751 | 752 | saffron.gl.bind_texture(Shape ^ saffron.soft.texture, !IO), |
752 | 753 | saffron.gl.primitive_type(Shape ^ saffron.soft.primitive_type, Type), |
@@ -756,7 +757,7 @@ draw_shape2d(Shape, !IO) :- | ||
756 | 757 | |
757 | 758 | %-----------------------------------------------------------------------------% |
758 | 759 | |
759 | -:- pred draw_shape3d(shape(vector.vector3)::in, io.io::di, io.io::uo) is det. | |
760 | +:- pred draw_shape3d(shape(mmath.vector.vector3)::in, io.io::di, io.io::uo) is det. | |
760 | 761 | draw_shape3d(Shape, !IO) :- |
761 | 762 | saffron.gl.bind_texture(Shape ^ saffron.soft.texture, !IO), |
762 | 763 | saffron.gl.primitive_type(Shape ^ saffron.soft.primitive_type, Type), |