@@ -1,10 +1,7 @@
1module MJS where
1module MJS where
5−A high performance linear algebra library using
3+{-| A high performance linear algebra library using native JS arrays. Geared
6−native JS arrays. Geared towards 3D graphics
7−and use with Graphics.WebGL.
4+towards 3D graphics and use with `Graphics.WebGL`.
9Both vectors and matrices are immutable.
6Both vectors and matrices are immutable.
@@ -40,126 +37,106 @@ data V2 = V2
40data V3 = V3
37data V3 = V3
41data V4 = V4
38data V4 = V4
44−Creates a new 3-element vector with the given values
40+{-| Creates a new 3-element vector with the given values
46v3 : Float -> Float -> Float -> V3
42v3 : Float -> Float -> Float -> V3
47v3 = Native.MJS.v3
43v3 = Native.MJS.v3
50−Convert to a native tuple
45+{-| Convert to a native tuple
52toTuple3 : V3 -> (Float,Float,Float)
47toTuple3 : V3 -> (Float,Float,Float)
53toTuple3 = Native.MJS.toTuple3
48toTuple3 = Native.MJS.toTuple3
56−Vector addition: a + b
50+{-| Vector addition: a + b
58add : V3 -> V3 -> V3
52add : V3 -> V3 -> V3
59add = Native.MJS.v3add
53add = Native.MJS.v3add
62−Vector subtraction: a - b
55+{-| Vector subtraction: a - b
64sub : V3 -> V3 -> V3
57sub : V3 -> V3 -> V3
65sub = Native.MJS.v3sub
58sub = Native.MJS.v3sub
68−Vector negation: -a
60+{-| Vector negation: -a
70neg : V3 -> V3
62neg : V3 -> V3
71neg = Native.MJS.v3neg
63neg = Native.MJS.v3neg
74−The normalized direction from a to b: (a - b) / |a - b|
65+{-| The normalized direction from a to b: (a - b) / |a - b|
76direction : V3 -> V3 -> V3
67direction : V3 -> V3 -> V3
77direction = Native.MJS.v3direction
68direction = Native.MJS.v3direction
80−The length of the given vector: |a|
70+{-| The length of the given vector: |a|
82length : V3 -> Float
72length : V3 -> Float
83length = Native.MJS.v3length
73length = Native.MJS.v3length
86−The square of the length of the given vector: |a|*|a|
75+{-| The square of the length of the given vector: |a| * |a|
88lengthSquared : V3 -> Float
77lengthSquared : V3 -> Float
89lengthSquared = Native.MJS.v3lengthSquared
78lengthSquared = Native.MJS.v3lengthSquared
92−A unit vector with the same direction as the given vector: a / |a|
80+{-| A unit vector with the same direction as the given vector: a / |a|
94normalize : V3 -> V3
82normalize : V3 -> V3
95normalize = Native.MJS.v3normalize
83normalize = Native.MJS.v3normalize
98−Multiply the vector by a scalar: a * k
85+{-| Multiply the vector by a scalar: a * k
100scale : V3 -> Float -> V3
87scale : V3 -> Float -> V3
101scale = Native.MJS.v3scale
88scale = Native.MJS.v3scale
104−The dot product of a and b
90+{-| The dot product of a and b
106dot : V3 -> V3 -> Float
92dot : V3 -> V3 -> Float
107dot = Native.MJS.v3dot
93dot = Native.MJS.v3dot
110−The cross product of a and b
95+{-| The cross product of a and b
112cross : V3 -> V3 -> V3
97cross : V3 -> V3 -> V3
113cross = Native.MJS.v3cross
98cross = Native.MJS.v3cross
116−Methods for working with 4x4 matrices.
118data M4x4 = M4x4
100data M4x4 = M4x4
121−Multiple the vector by the 4x4 matrix: m * v
102+{-| Multiply a vector by a 4x4 matrix: m * v
123mul4x4 : M4x4 -> V3 -> V3
104mul4x4 : M4x4 -> V3 -> V3
124mul4x4 = Native.MJS.v3mul4x4
105mul4x4 = Native.MJS.v3mul4x4
127−A matrix with all 0s, except 1s on the diagonal
107+{-| A matrix with all 0s, except 1s on the diagonal.
129identity : M4x4
109identity : M4x4
130identity = Native.MJS.m4x4identity
110identity = Native.MJS.m4x4identity
133−Computes the inverse of the given matrix m, assuming that
112+{-| Computes the inverse of the given matrix m, assuming that the matrix is
134−the matrix is orthonormal
113+orthonormal.
136inverseOrthonormal : M4x4 -> M4x4
115inverseOrthonormal : M4x4 -> M4x4
137inverseOrthonormal = Native.MJS.m4x4inverseOrthonormal
116inverseOrthonormal = Native.MJS.m4x4inverseOrthonormal
140−Creates a matrix for a projection frustum with the given parameters.
118+{-| Creates a matrix for a projection frustum with the given parameters.
142Parameters:
120Parameters:
144− left - the left coordinate of the frustum
122+ * left - the left coordinate of the frustum
145− right- the right coordinate of the frustum
123+ * right- the right coordinate of the frustum
146− bottom - the bottom coordinate of the frustum
124+ * bottom - the bottom coordinate of the frustum
147− top - the top coordinate of the frustum
125+ * top - the top coordinate of the frustum
148− znear - the near z distance of the frustum
126+ * znear - the near z distance of the frustum
149− zfar - the far z distance of the frustum
127+ * zfar - the far z distance of the frustum
151makeFrustrum : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
129makeFrustrum : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
152makeFrustrum = Native.MJS.m4x4makeFrustrum
130makeFrustrum = Native.MJS.m4x4makeFrustrum
155−Creates a matrix for a perspective projection with the given parameters.
132+{-| Creates a matrix for a perspective projection with the given parameters.
157−Parameters:
134+Parameters:
159− fovy - field of view in the y axis, in degrees
136+ * fovy - field of view in the y axis, in degrees
160− aspect - aspect ratio
137+ * aspect - aspect ratio
161− znear - the near z distance of the projection
138+ * znear - the near z distance of the projection
162− zfar - the far z distance of the projection
139+ * zfar - the far z distance of the projection
164makePerspective : Float -> Float -> Float -> Float -> M4x4
141makePerspective : Float -> Float -> Float -> Float -> M4x4
165makePerspective = Native.MJS.m4x4makePerspective
142makePerspective = Native.MJS.m4x4makePerspective
@@ -169,76 +146,68 @@ Creates a matrix for an orthogonal frustum projection with the given parameters.
170Parameters:
147Parameters:
172− left - the left coordinate of the frustum
149+ * left - the left coordinate of the frustum
173− right- the right coordinate of the frustum
150+ * right- the right coordinate of the frustum
174− bottom - the bottom coordinate of the frustum
151+ * bottom - the bottom coordinate of the frustum
175− top - the top coordinate of the frustum
152+ * top - the top coordinate of the frustum
176− znear - the near z distance of the frustum
153+ * znear - the near z distance of the frustum
177− zfar - the far z distance of the frustum
154+ * zfar - the far z distance of the frustum
179makeOrtho : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
156makeOrtho : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
180makeOrtho = Native.MJS.m4x4makeOrtho
157makeOrtho = Native.MJS.m4x4makeOrtho
183−Creates a matrix for a 2D orthogonal frustum projection with the given parameters.
159+{-| Creates a matrix for a 2D orthogonal frustum projection with the given
184−znear and zfar are assumed to be -1 and 1, respectively.
160+parameters. `znear` and `zfar` are assumed to be -1 and 1, respectively.
186Parameters:
162Parameters:
188− left - the left coordinate of the frustum
164+ * left - the left coordinate of the frustum
189− right- the right coordinate of the frustum
165+ * right- the right coordinate of the frustum
190− bottom - the bottom coordinate of the frustum
166+ * bottom - the bottom coordinate of the frustum
191− top - the top coordinate of the frustum
167+ * top - the top coordinate of the frustum
193makeOrtho2D : Float -> Float -> Float -> Float -> M4x4
169makeOrtho2D : Float -> Float -> Float -> Float -> M4x4
194makeOrtho2D = Native.MJS.m4x4makeOrtho2D
170makeOrtho2D = Native.MJS.m4x4makeOrtho2D
197−Matrix multiplcation: a * b
172+{-| Matrix multiplcation: a * b
199mul : M4x4 -> M4x4 -> M4x4
174mul : M4x4 -> M4x4 -> M4x4
200mul = Native.MJS.m4x4mul
175mul = Native.MJS.m4x4mul
203−Matrix multiplication, assuming a and b are affine: a * b
177+{-| Matrix multiplication, assuming a and b are affine: a * b
205mulAffine : M4x4 -> M4x4 -> M4x4
179mulAffine : M4x4 -> M4x4 -> M4x4
206mulAffine = Native.MJS.m4x4mulAffine
180mulAffine = Native.MJS.m4x4mulAffine
209−Creates a transformation matrix for rotation by angle radians about the 3-element vector axis.
182+{-| Creates a transformation matrix for rotation in radians about the
183+3-element vector axis.
211makeRotate : Float -> V3 -> M4x4
185makeRotate : Float -> V3 -> M4x4
212makeRotate = Native.MJS.m4x4makeRotate
186makeRotate = Native.MJS.m4x4makeRotate
215−Concatenates a rotation of angle radians about the axis to the given matrix.
188+{-| Concatenates a rotation of angle radians about the axis to the given matrix.
217rotate : Float -> V3 -> M4x4 -> M4x4
190rotate : Float -> V3 -> M4x4 -> M4x4
218rotate = Native.MJS.m4x4rotate
191rotate = Native.MJS.m4x4rotate
221−Creates a transformation matrix for scaling by 3 scalar values, one for
193+{-| Creates a transformation matrix for scaling by 3 scalar values, one for
222each of the x, y, and z directions.
194each of the x, y, and z directions.
224makeScale3 : Float -> Float -> Float -> M4x4
196makeScale3 : Float -> Float -> Float -> M4x4
225makeScale3 = Native.MJS.m4x4makeScale3
197makeScale3 = Native.MJS.m4x4makeScale3
228−Creates a transformation matrix for scaling each of the x, y, and z axes by the amount
199+{-| Creates a transformation matrix for scaling each of the x, y, and z axes by
229−given in the corresponding element of the 3-element vector.
200+the amount given in the corresponding element of the 3-element vector.
231makeScale : V3 -> M4x4
202makeScale : V3 -> M4x4
232makeScale = Native.MJS.m4x4makeScale
203makeScale = Native.MJS.m4x4makeScale
235−Concatenates a scaling to the given matrix.
205+{-| Concatenates a scaling to the given matrix.
237scaleM3 : Float -> Float -> Float -> M4x4 -> M4x4
207scaleM3 : Float -> Float -> Float -> M4x4 -> M4x4
238scaleM3 = Native.MJS.m4x4scale3
208scaleM3 = Native.MJS.m4x4scale3
241−Concatenates a scaling to the given matrix.
210+{-| Concatenates a scaling to the given matrix.
243scaleM : V3 -> M4x4 -> M4x4
212scaleM : V3 -> M4x4 -> M4x4
244scaleM = Native.MJS.m4x4scale
213scaleM = Native.MJS.m4x4scale
@@ -250,9 +219,8 @@ each of the x, y, and z directions.
250makeTranslate3 : Float -> Float -> Float -> M4x4
219makeTranslate3 : Float -> Float -> Float -> M4x4
251makeTranslate3 = Native.MJS.m4x4makeTranslate3
220makeTranslate3 = Native.MJS.m4x4makeTranslate3
254−Creates a transformation matrix for translating each of the x, y, and z axes by the amount
222+{-| Creates a transformation matrix for translating each of the x, y, and z
255−given in the corresponding element of the 3-element vector.
223+axes by the amount given in the corresponding element of the 3-element vector.
257makeTranslate : V3 -> M4x4
225makeTranslate : V3 -> M4x4
258makeTranslate = Native.MJS.m4x4makeTranslate
226makeTranslate = Native.MJS.m4x4makeTranslate
@@ -273,7 +241,7 @@ translate = Native.MJS.m4x4translate
273Creates a transformation matrix for a camera.
241Creates a transformation matrix for a camera.
275Parameters:
243Parameters:
277 * eye - The location of the camera
245 * eye - The location of the camera
278 * center - The location of the focused object
246 * center - The location of the focused object
279 * up - The "up" direction according to the camera
247 * up - The "up" direction according to the camera
@@ -281,14 +249,13 @@ Parameters:
281makeLookAt : V3 -> V3 -> V3 -> M4x4
249makeLookAt : V3 -> V3 -> V3 -> M4x4
282makeLookAt = Native.MJS.m4x4makeLookAt
250makeLookAt = Native.MJS.m4x4makeLookAt
285−"Flip" the matrix across the diagonal by swapping row index and column index.
252+{-| "Flip" the matrix across the diagonal by swapping row index and column
287transpose : M4x4 -> M4x4
255transpose : M4x4 -> M4x4
288transpose = Native.MJS.m4x4transpose
256transpose = Native.MJS.m4x4transpose
291−Creates a transform from a basis consisting of 3 linearly independent vectors.
258+{-| Creates a transform from a basis consisting of 3 linearly independent vectors.
293makeBasis : V3 -> V3 -> V3 -> M4x4
260makeBasis : V3 -> V3 -> V3 -> M4x4
294makeBasis = Native.MJS.m4x4makeBasis
261makeBasis = Native.MJS.m4x4makeBasis