on master help sign in
Split MJS into Math.Vector and Math.Matrix
9bed911Evan Czaplicki
compiler/SourceSyntax/Literal.hs+4−4
@@ -29,10 +29,10 @@ glTipeName glTipe =
29 case glTipe of
29 case glTipe of
30 Int -> "Int"
30 Int -> "Int"
31 Float -> "Float"
31 Float -> "Float"
32− V2 -> "MJS.V2"
32+ V2 -> "Math.Vector.Vec2"
33− V3 -> "MJS.V3"
33+ V3 -> "Math.Vector.Vec3"
34− V4 -> "MJS.V4"
34+ V4 -> "Math.Vector.Vec4"
35− M4 -> "MJS.M4x4"
35+ M4 -> "Math.Matrix.Mat4"
36 Texture -> "Graphics.WebGL.Texture"
36 Texture -> "Graphics.WebGL.Texture"
37
37
38data GLShaderTipe = GLShaderTipe
38data GLShaderTipe = GLShaderTipe
libraries/MJS.elm → libraries/Math/Matrix.elmrenamed+33−104
@@ -1,118 +1,47 @@
1−module MJS where
1+module Math.Matrix where
2
2
3{-| A high performance linear algebra library using native JS arrays. Geared
3{-| A high performance linear algebra library using native JS arrays. Geared
4−towards 3D graphics and use with `Graphics.WebGL`.
4+towards 3D graphics and use with `Graphics.WebGL`. All matrices are immutable.
5
5
6−Both vectors and matrices are immutable.
6+This library uses the convention that the prefix `make` is creating a new
7+array, whereas without the prefix, you are applying some transform to an
8+existing matrix.
7
9
8−# Constructing and Destructing Vectors
10+@docs mul4x4
9
11
10−@docs v3, toTuple3
11−
12−# Vector Math
13−
14−@docs add, sub, neg, direction, length, lengthSquared, normalize, scale
15−
16−# Vector Operations
12+# Operations
17−
18−@docs dot, cross, mul4x4
19−
20−Matrix operations
21
13
22@docs identity, inverseOrthonormal, mul, mulAffine, transpose, makeBasis
14@docs identity, inverseOrthonormal, mul, mulAffine, transpose, makeBasis
23
15
24−Matrix projections
16+# Projections
25
17
26@docs makeFrustrum, makePerspective, makeOrtho, makeOrtho2D, makeLookAt
18@docs makeFrustrum, makePerspective, makeOrtho, makeOrtho2D, makeLookAt
27
19
28−Matrix transforms
20+# Transforms
29
21
30@docs makeRotate, rotate, makeScale3, makeScale, scaleM3, scaleM, makeTranslate3, makeTranslate, translate3, translate
22@docs makeRotate, rotate, makeScale3, makeScale, scaleM3, scaleM, makeTranslate3, makeTranslate, translate3, translate
31
23
32-}
24-}
33
25
34import Native.MJS
26import Native.MJS
27+import Math.Vector (Vec3)
35
28
36−data V2 = V2
29+data Mat4 = Mat4
37−data V3 = V3
38−data V4 = V4
39−
40−{-| Creates a new 3-element vector with the given values
41−-}
42−v3 : Float -> Float -> Float -> V3
43−v3 = Native.MJS.v3
44−
45−{-| Convert to a native tuple
46−-}
47−toTuple3 : V3 -> (Float,Float,Float)
48−toTuple3 = Native.MJS.toTuple3
49−
50−{-| Vector addition: a + b
51−-}
52−add : V3 -> V3 -> V3
53−add = Native.MJS.v3add
54−
55−{-| Vector subtraction: a - b
56−-}
57−sub : V3 -> V3 -> V3
58−sub = Native.MJS.v3sub
59−
60−{-| Vector negation: -a
61−-}
62−neg : V3 -> V3
63−neg = Native.MJS.v3neg
64−
65−{-| The normalized direction from a to b: (a - b) / |a - b|
66−-}
67−direction : V3 -> V3 -> V3
68−direction = Native.MJS.v3direction
69−
70−{-| The length of the given vector: |a|
71−-}
72−length : V3 -> Float
73−length = Native.MJS.v3length
74−
75−{-| The square of the length of the given vector: |a| * |a|
76−-}
77−lengthSquared : V3 -> Float
78−lengthSquared = Native.MJS.v3lengthSquared
79−
80−{-| A unit vector with the same direction as the given vector: a / |a|
81−-}
82−normalize : V3 -> V3
83−normalize = Native.MJS.v3normalize
84−
85−{-| Multiply the vector by a scalar: a * k
86−-}
87−scale : V3 -> Float -> V3
88−scale = Native.MJS.v3scale
89−
90−{-| The dot product of a and b
91−-}
92−dot : V3 -> V3 -> Float
93−dot = Native.MJS.v3dot
94−
95−{-| The cross product of a and b
96−-}
97−cross : V3 -> V3 -> V3
98−cross = Native.MJS.v3cross
99−
100−data M4x4 = M4x4
101
30
102{-| Multiply a vector by a 4x4 matrix: m * v
31{-| Multiply a vector by a 4x4 matrix: m * v
103-}
32-}
104−mul4x4 : M4x4 -> V3 -> V3
33+mul4x4 : Mat4 -> Vec3 -> Vec3
105mul4x4 = Native.MJS.v3mul4x4
34mul4x4 = Native.MJS.v3mul4x4
106
35
107{-| A matrix with all 0s, except 1s on the diagonal.
36{-| A matrix with all 0s, except 1s on the diagonal.
108-}
37-}
109−identity : M4x4
38+identity : Mat4
110identity = Native.MJS.m4x4identity
39identity = Native.MJS.m4x4identity
111
40
112{-| Computes the inverse of the given matrix m, assuming that the matrix is
41{-| Computes the inverse of the given matrix m, assuming that the matrix is
113orthonormal.
42orthonormal.
114-}
43-}
115−inverseOrthonormal : M4x4 -> M4x4
44+inverseOrthonormal : Mat4 -> Mat4
116inverseOrthonormal = Native.MJS.m4x4inverseOrthonormal
45inverseOrthonormal = Native.MJS.m4x4inverseOrthonormal
117
46
118{-| Creates a matrix for a projection frustum with the given parameters.
47{-| Creates a matrix for a projection frustum with the given parameters.
@@ -126,7 +55,7 @@ Parameters:
126 * znear - the near z distance of the frustum
55 * znear - the near z distance of the frustum
127 * zfar - the far z distance of the frustum
56 * zfar - the far z distance of the frustum
128-}
57-}
129−makeFrustrum : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
58+makeFrustrum : Float -> Float -> Float -> Float -> Float -> Float -> Float -> Mat4
130makeFrustrum = Native.MJS.m4x4makeFrustrum
59makeFrustrum = Native.MJS.m4x4makeFrustrum
131
60
132{-| Creates a matrix for a perspective projection with the given parameters.
61{-| Creates a matrix for a perspective projection with the given parameters.
@@ -138,7 +67,7 @@ Parameters:
138 * znear - the near z distance of the projection
67 * znear - the near z distance of the projection
139 * zfar - the far z distance of the projection
68 * zfar - the far z distance of the projection
140-}
69-}
141−makePerspective : Float -> Float -> Float -> Float -> M4x4
70+makePerspective : Float -> Float -> Float -> Float -> Mat4
142makePerspective = Native.MJS.m4x4makePerspective
71makePerspective = Native.MJS.m4x4makePerspective
143
72
144{-|
73{-|
@@ -153,7 +82,7 @@ Parameters:
153 * znear - the near z distance of the frustum
82 * znear - the near z distance of the frustum
154 * zfar - the far z distance of the frustum
83 * zfar - the far z distance of the frustum
155-}
84-}
156−makeOrtho : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
85+makeOrtho : Float -> Float -> Float -> Float -> Float -> Float -> Float -> Mat4
157makeOrtho = Native.MJS.m4x4makeOrtho
86makeOrtho = Native.MJS.m4x4makeOrtho
158
87
159{-| Creates a matrix for a 2D orthogonal frustum projection with the given
88{-| Creates a matrix for a 2D orthogonal frustum projection with the given
@@ -166,75 +95,75 @@ Parameters:
166 * bottom - the bottom coordinate of the frustum
95 * bottom - the bottom coordinate of the frustum
167 * top - the top coordinate of the frustum
96 * top - the top coordinate of the frustum
168-}
97-}
169−makeOrtho2D : Float -> Float -> Float -> Float -> M4x4
98+makeOrtho2D : Float -> Float -> Float -> Float -> Mat4
170makeOrtho2D = Native.MJS.m4x4makeOrtho2D
99makeOrtho2D = Native.MJS.m4x4makeOrtho2D
171
100
172{-| Matrix multiplcation: a * b
101{-| Matrix multiplcation: a * b
173-}
102-}
174−mul : M4x4 -> M4x4 -> M4x4
103+mul : Mat4 -> Mat4 -> Mat4
175mul = Native.MJS.m4x4mul
104mul = Native.MJS.m4x4mul
176
105
177{-| Matrix multiplication, assuming a and b are affine: a * b
106{-| Matrix multiplication, assuming a and b are affine: a * b
178-}
107-}
179−mulAffine : M4x4 -> M4x4 -> M4x4
108+mulAffine : Mat4 -> Mat4 -> Mat4
180mulAffine = Native.MJS.m4x4mulAffine
109mulAffine = Native.MJS.m4x4mulAffine
181
110
182{-| Creates a transformation matrix for rotation in radians about the
111{-| Creates a transformation matrix for rotation in radians about the
1833-element vector axis.
1123-element vector axis.
184-}
113-}
185−makeRotate : Float -> V3 -> M4x4
114+makeRotate : Float -> Vec3 -> Mat4
186makeRotate = Native.MJS.m4x4makeRotate
115makeRotate = Native.MJS.m4x4makeRotate
187
116
188{-| Concatenates a rotation of angle radians about the axis to the given matrix.
117{-| Concatenates a rotation of angle radians about the axis to the given matrix.
189-}
118-}
190−rotate : Float -> V3 -> M4x4 -> M4x4
119+rotate : Float -> Vec3 -> Mat4 -> Mat4
191rotate = Native.MJS.m4x4rotate
120rotate = Native.MJS.m4x4rotate
192
121
193{-| Creates a transformation matrix for scaling by 3 scalar values, one for
122{-| Creates a transformation matrix for scaling by 3 scalar values, one for
194each of the x, y, and z directions.
123each of the x, y, and z directions.
195-}
124-}
196−makeScale3 : Float -> Float -> Float -> M4x4
125+makeScale3 : Float -> Float -> Float -> Mat4
197makeScale3 = Native.MJS.m4x4makeScale3
126makeScale3 = Native.MJS.m4x4makeScale3
198
127
199{-| Creates a transformation matrix for scaling each of the x, y, and z axes by
128{-| Creates a transformation matrix for scaling each of the x, y, and z axes by
200the amount given in the corresponding element of the 3-element vector.
129the amount given in the corresponding element of the 3-element vector.
201-}
130-}
202−makeScale : V3 -> M4x4
131+makeScale : Vec3 -> Mat4
203makeScale = Native.MJS.m4x4makeScale
132makeScale = Native.MJS.m4x4makeScale
204
133
205{-| Concatenates a scaling to the given matrix.
134{-| Concatenates a scaling to the given matrix.
206-}
135-}
207−scaleM3 : Float -> Float -> Float -> M4x4 -> M4x4
136+scaleM3 : Float -> Float -> Float -> Mat4 -> Mat4
208scaleM3 = Native.MJS.m4x4scale3
137scaleM3 = Native.MJS.m4x4scale3
209
138
210{-| Concatenates a scaling to the given matrix.
139{-| Concatenates a scaling to the given matrix.
211-}
140-}
212−scaleM : V3 -> M4x4 -> M4x4
141+scaleM : Vec3 -> Mat4 -> Mat4
213scaleM = Native.MJS.m4x4scale
142scaleM = Native.MJS.m4x4scale
214
143
215{-|
144{-|
216Creates a transformation matrix for translating by 3 scalar values, one for
145Creates a transformation matrix for translating by 3 scalar values, one for
217each of the x, y, and z directions.
146each of the x, y, and z directions.
218-}
147-}
219−makeTranslate3 : Float -> Float -> Float -> M4x4
148+makeTranslate3 : Float -> Float -> Float -> Mat4
220makeTranslate3 = Native.MJS.m4x4makeTranslate3
149makeTranslate3 = Native.MJS.m4x4makeTranslate3
221
150
222{-| Creates a transformation matrix for translating each of the x, y, and z
151{-| Creates a transformation matrix for translating each of the x, y, and z
223axes by the amount given in the corresponding element of the 3-element vector.
152axes by the amount given in the corresponding element of the 3-element vector.
224-}
153-}
225−makeTranslate : V3 -> M4x4
154+makeTranslate : Vec3 -> Mat4
226makeTranslate = Native.MJS.m4x4makeTranslate
155makeTranslate = Native.MJS.m4x4makeTranslate
227
156
228{-|
157{-|
229Concatenates a translation to the given matrix.
158Concatenates a translation to the given matrix.
230-}
159-}
231−translate3 : Float -> Float -> Float -> M4x4 -> M4x4
160+translate3 : Float -> Float -> Float -> Mat4 -> Mat4
232translate3 = Native.MJS.m4x4translate3
161translate3 = Native.MJS.m4x4translate3
233
162
234{-|
163{-|
235Concatenates a translation to the given matrix.
164Concatenates a translation to the given matrix.
236-}
165-}
237−translate : V3 -> M4x4 -> M4x4
166+translate : Vec3 -> Mat4 -> Mat4
238translate = Native.MJS.m4x4translate
167translate = Native.MJS.m4x4translate
239
168
240{-|
169{-|
@@ -246,16 +175,16 @@ Parameters:
246 * center - The location of the focused object
175 * center - The location of the focused object
247 * up - The "up" direction according to the camera
176 * up - The "up" direction according to the camera
248-}
177-}
249−makeLookAt : V3 -> V3 -> V3 -> M4x4
178+makeLookAt : Vec3 -> Vec3 -> Vec3 -> Mat4
250makeLookAt = Native.MJS.m4x4makeLookAt
179makeLookAt = Native.MJS.m4x4makeLookAt
251
180
252{-| "Flip" the matrix across the diagonal by swapping row index and column
181{-| "Flip" the matrix across the diagonal by swapping row index and column
253index.
182index.
254-}
183-}
255−transpose : M4x4 -> M4x4
184+transpose : Mat4 -> Mat4
256transpose = Native.MJS.m4x4transpose
185transpose = Native.MJS.m4x4transpose
257
186
258{-| Creates a transform from a basis consisting of 3 linearly independent vectors.
187{-| Creates a transform from a basis consisting of 3 linearly independent vectors.
259-}
188-}
260−makeBasis : V3 -> V3 -> V3 -> M4x4
189+makeBasis : Vec3 -> Vec3 -> Vec3 -> Mat4
261makeBasis = Native.MJS.m4x4makeBasis
190makeBasis = Native.MJS.m4x4makeBasis
libraries/Math/Vector.elmnew file+126
@@ -0,0 +1,126 @@
1+module Math.Vector where
2+
3+{-| A high performance linear algebra library using native JS arrays. Geared
4+towards 3D graphics and use with `Graphics.WebGL`.
5+
6+All vectors are immutable.
7+
8+# Create
9+@docs v3, i, j, k
10+
11+# Get and Set
12+The set functions create a new copy of the vector, updating a single field.
13+
14+@docs getX, getY, getZ, setX, setY, setZ, toTuple, toRecord
15+
16+# Operations
17+@docs add, sub, neg, direction, length, lengthSquared, normalize, scale, dot, cross
18+
19+-}
20+
21+import Native.MJS
22+
23+data Vec2 = Vec2
24+data Vec3 = Vec3
25+data Vec4 = Vec4
26+
27+{-| Creates a new 3-element vector with the given values.
28+-}
29+v3 : Float -> Float -> Float -> Vec3
30+v3 = Native.MJS.v3
31+
32+{-| The unit vector î which points in the x direction: `v3 1 0 0` -}
33+i : Vec3
34+i = Native.MJS.v3 1 0 0
35+
36+{-| The unit vector ĵ which points in the y direction: `v3 0 1 0` -}
37+j : Vec3
38+j = Native.MJS.v3 0 1 0
39+
40+{-| The unit vector &kcirc; which points in the z direction: `v3 0 0 1` -}
41+k : Vec3
42+k = Native.MJS.v3 0 0 1
43+
44+{-| Extract the x component of a vector. -}
45+getX : Vec3 -> Float
46+getX = Native.MJS.getX
47+
48+{-| Extract the y component of a vector. -}
49+getY : Vec3 -> Float
50+getY = Native.MJS.getY
51+
52+{-| Extract the z component of a vector. -}
53+getZ : Vec3 -> Float
54+getZ = Native.MJS.getZ
55+
56+{-| Update the x component of a vector. -}
57+setX : Vec3 -> Float
58+setX = Native.MJS.setX
59+
60+{-| Update the y component of a vector. -}
61+setY : Vec3 -> Float
62+setY = Native.MJS.setY
63+
64+{-| Update the z component of a vector. -}
65+setZ : Vec3 -> Float
66+setZ = Native.MJS.setZ
67+
68+{-| Convert a vector to a tuple.
69+-}
70+toTuple : Vec3 -> (Float,Float,Float)
71+toTuple = Native.MJS.toTuple3
72+
73+{-| Convert a vector to a record.
74+-}
75+toRecord : Vec3 -> { x:Float, y:Float, z:Float }
76+toRecord = Native.MJS.toRecord3
77+
78+{-| Vector addition: a + b
79+-}
80+add : Vec3 -> Vec3 -> Vec3
81+add = Native.MJS.v3add
82+
83+{-| Vector subtraction: a - b
84+-}
85+sub : Vec3 -> Vec3 -> Vec3
86+sub = Native.MJS.v3sub
87+
88+{-| Vector negation: -a
89+-}
90+neg : Vec3 -> Vec3
91+neg = Native.MJS.v3neg
92+
93+{-| The normalized direction from a to b: (a - b) / |a - b|
94+-}
95+direction : Vec3 -> Vec3 -> Vec3
96+direction = Native.MJS.v3direction
97+
98+{-| The length of the given vector: |a|
99+-}
100+length : Vec3 -> Float
101+length = Native.MJS.v3length
102+
103+{-| The square of the length of the given vector: |a| * |a|
104+-}
105+lengthSquared : Vec3 -> Float
106+lengthSquared = Native.MJS.v3lengthSquared
107+
108+{-| A unit vector with the same direction as the given vector: a / |a|
109+-}
110+normalize : Vec3 -> Vec3
111+normalize = Native.MJS.v3normalize
112+
113+{-| Multiply the vector by a scalar: a * k
114+-}
115+scale : Vec3 -> Float -> Vec3
116+scale = Native.MJS.v3scale
117+
118+{-| The dot product of a and b
119+-}
120+dot : Vec3 -> Vec3 -> Float
121+dot = Native.MJS.v3dot
122+
123+{-| The cross product of a and b
124+-}
125+cross : Vec3 -> Vec3 -> Vec3
126+cross = Native.MJS.v3cross
libraries/Native/MJS.js+42−64
@@ -30,7 +30,7 @@
30 * File: mjs
30 * File: mjs
31 *
31 *
32 * Vector and Matrix math utilities for JavaScript, optimized for WebGL.
32 * Vector and Matrix math utilities for JavaScript, optimized for WebGL.
33− * Edited to work with Elm Programming Language
33+ * Edited to work with the Elm Programming Language
34 */
34 */
35
35
36Elm.Native.MJS = {};
36Elm.Native.MJS = {};
@@ -56,7 +56,7 @@ Elm.Native.MJS.make = function(elm) {
56 * For potentially more performance, the assert methods can be
56 * For potentially more performance, the assert methods can be
57 * commented out in each place where they are called.
57 * commented out in each place where they are called.
58 */
58 */
59− //var MJS_DO_ASSERT = true;
59+ var MJS_DO_ASSERT = false;
60
60
61 /*
61 /*
62 * Constant: MJS_FLOAT_ARRAY_TYPE
62 * Constant: MJS_FLOAT_ARRAY_TYPE
@@ -73,14 +73,15 @@ Elm.Native.MJS.make = function(elm) {
73 //MJS_FLOAT_ARRAY_TYPE = Float64Array;
73 //MJS_FLOAT_ARRAY_TYPE = Float64Array;
74 //MJS_FLOAT_ARRAY_TYPE = Array;
74 //MJS_FLOAT_ARRAY_TYPE = Array;
75
75
76− //if (MJS_DO_ASSERT) {
76+ if (MJS_DO_ASSERT) {
77− //function MathUtils_assert(cond, msg) {
77+ function MathUtils_assert(cond, msg) {
78− //if (!cond)
78+ if (!cond) {
79− //throw "Assertion failed: " + msg;
79+ throw "Assertion failed: " + msg;
80+ }
80− //}
81+ }
81− //} else {
82+ } else {
82− function MathUtils_assert() { }
83+ function MathUtils_assert() { }
83− //}
84+ }
84
85
85 /*
86 /*
86 * Class: V3
87 * Class: V3
@@ -104,11 +105,6 @@ Elm.Native.MJS.make = function(elm) {
104 V3.$ = function V3_$(x, y, z) {
105 V3.$ = function V3_$(x, y, z) {
105 return [x, y, z];
106 return [x, y, z];
106 };
107 };
107−
108− V3.clone = function V3_clone(a) {
109− //MathUtils_assert(a.length == 3, "a.length == 3");
110− return [a[0], a[1], a[2]];
111− };
112 } else {
108 } else {
113 V3.x = new MJS_FLOAT_ARRAY_TYPE([1.0, 0.0, 0.0]);
109 V3.x = new MJS_FLOAT_ARRAY_TYPE([1.0, 0.0, 0.0]);
114 V3.y = new MJS_FLOAT_ARRAY_TYPE([0.0, 1.0, 0.0]);
110 V3.y = new MJS_FLOAT_ARRAY_TYPE([0.0, 1.0, 0.0]);
@@ -131,34 +127,21 @@ Elm.Native.MJS.make = function(elm) {
131 V3.$ = function V3_$(x, y, z) {
127 V3.$ = function V3_$(x, y, z) {
132 return new MJS_FLOAT_ARRAY_TYPE([x, y, z]);
128 return new MJS_FLOAT_ARRAY_TYPE([x, y, z]);
133 };
129 };
134−
135− /*
136− * Function: V3.clone
137− *
138− * Clone the given 3-element vector.
139− *
140− * Parameters:
141− *
142− * a - the 3-element vector to clone
143− *
144− * Returns:
145− *
146− * A new vector with the same values as the passed-in one.
147− */
148−
149− V3.clone = function V3_clone(a) {
150− //MathUtils_assert(a.length == 3, "a.length == 3");
151− return new MJS_FLOAT_ARRAY_TYPE(a);
152− };
153 }
130 }
154
131
155 V3.u = V3.x;
132 V3.u = V3.x;
156 V3.v = V3.y;
133 V3.v = V3.y;
157
134
158− /* Function: V3.toTuple3
135+ V3.getX = function V3_getX(a) {
159− *
136+ return a[0];
160− * Turn into an Elm Tuple
137+ }
161− */
138+ V3.getY = function V3_getY(a) {
139+ return a[1];
140+ }
141+ V3.getZ = function V3_getZ(a) {
142+ return a[2];
143+ }
144+
162 V3.toTuple3 = function V3_toTuple3(a) {
145 V3.toTuple3 = function V3_toTuple3(a) {
163 return {
146 return {
164 ctor:"_Tuple3",
147 ctor:"_Tuple3",
@@ -167,6 +150,21 @@ Elm.Native.MJS.make = function(elm) {
167 _2:a[2]
150 _2:a[2]
168 };
151 };
169 };
152 };
153+ V3.fromTuple3 = function V3_fromTuple3(t) {
154+ return new MJS_FLOAT_ARRAY_TYPE([t._0, t._1, t._2]);
155+ };
156+
157+ V3.toRecord3 = function V3_toRecord3(a) {
158+ return {
159+ _:{},
160+ x:a[0],
161+ y:a[1],
162+ z:a[2]
163+ };
164+ };
165+ V3.fromRecord3 = function V3_fromRecord3(r) {
166+ return new MJS_FLOAT_ARRAY_TYPE([r.x, r.y, r.z]);
167+ };
170
168
171 /*
169 /*
172 * Function: V3.add
170 * Function: V3.add
@@ -506,14 +504,6 @@ Elm.Native.MJS.make = function(elm) {
506 m08, m09, m10, m11,
504 m08, m09, m10, m11,
507 m12, m13, m14, m15];
505 m12, m13, m14, m15];
508 };
506 };
509−
510− M4x4.clone = function M4x4_clone(m) {
511− //MathUtils_assert(m.length == 16, "m.length == 16");
512− return new [m[0], m[1], m[2], m[3],
513− m[4], m[5], m[6], m[7],
514− m[8], m[9], m[10], m[11],
515− m[12], m[13], m[14], m[15]];
516− };
517 } else {
507 } else {
518 M4x4.I = new MJS_FLOAT_ARRAY_TYPE([1.0, 0.0, 0.0, 0.0,
508 M4x4.I = new MJS_FLOAT_ARRAY_TYPE([1.0, 0.0, 0.0, 0.0,
519 0.0, 1.0, 0.0, 0.0,
509 0.0, 1.0, 0.0, 0.0,
@@ -543,24 +533,6 @@ Elm.Native.MJS.make = function(elm) {
543 m08, m09, m10, m11,
533 m08, m09, m10, m11,
544 m12, m13, m14, m15]);
534 m12, m13, m14, m15]);
545 };
535 };
546−
547− /*
548− * Function: M4x4.clone
549− *
550− * Clone the given 4x4 matrix.
551− *
552− * Parameters:
553− *
554− * m - the 4x4 matrix to clone
555− *
556− * Returns:
557− *
558− * A new matrix with the same values as the passed-in one.
559− */
560− M4x4.clone = function M4x4_clone(m) {
561− //MathUtils_assert(m.length == 16, "m.length == 16");
562− return new MJS_FLOAT_ARRAY_TYPE(m);
563− };
564 }
536 }
565
537
566 M4x4.identity = M4x4.I;
538 M4x4.identity = M4x4.I;
@@ -1740,7 +1712,13 @@ Elm.Native.MJS.make = function(elm) {
1740 return {
1712 return {
1741 V3: V3,
1713 V3: V3,
1742 v3: F3(V3.$),
1714 v3: F3(V3.$),
1715+ getX: V3.getX,
1716+ getY: V3.getY,
1717+ getZ: V3.getZ,
1743 toTuple3: V3.toTuple3,
1718 toTuple3: V3.toTuple3,
1719+ toRecord3: V3.toRecord3,
1720+ fromTuple3: V3.fromTuple3,
1721+ fromRecord3: V3.fromRecord3,
1744 v3add: F2(V3.add),
1722 v3add: F2(V3.add),
1745 v3sub: F2(V3.sub),
1723 v3sub: F2(V3.sub),
1746 v3neg: V3.neg,
1724 v3neg: V3.neg,