@@ -8,6 +8,30 @@ and use with Graphics.WebGL.
9Both vectors and matrices are immutable.
9Both vectors and matrices are immutable.
11+# Constructing and Destructing Vectors
17+@docs add, sub, neg, direction, length, lengthSquared, normalize, scale
21+@docs dot, cross, mul4x4
25+@docs identity, inverseOrthonormal, mul, mulAffine, transpose, makeBasis
29+@docs makeFrustrum, makePerspective, makeOrtho, makeOrtho2D, makeLookAt
33+@docs makeRotate, rotate, makeScale3, makeScale, scaleM3, scaleM, makeTranslate3, makeTranslate, translate3, translate
13import Native.MJS
37import Native.MJS
@@ -15,115 +39,256 @@ import Native.MJS
15data V2 = V2
39data V2 = V2
16data V3 = V3
40data V3 = V3
17data V4 = V4
41data V4 = V4
44+Creates a new 3-element vector with the given values
20v3 : Float -> Float -> Float -> V3
46v3 : Float -> Float -> Float -> V3
21v3 = Native.MJS.v3
47v3 = Native.MJS.v3
50+Convert to a native tuple
23toTuple3 : V3 -> (Float,Float,Float)
52toTuple3 : V3 -> (Float,Float,Float)
24toTuple3 = Native.MJS.toTuple3
53toTuple3 = Native.MJS.toTuple3
56+Vector addition: a + b
26add : V3 -> V3 -> V3
58add : V3 -> V3 -> V3
27add = Native.MJS.v3add
59add = Native.MJS.v3add
62+Vector subtraction: a - b
29sub : V3 -> V3 -> V3
64sub : V3 -> V3 -> V3
30sub = Native.MJS.v3sub
65sub = Native.MJS.v3sub
32neg : V3 -> V3
70neg : V3 -> V3
33neg = Native.MJS.v3neg
71neg = Native.MJS.v3neg
35−{- The normalized direction from v1 to v2 -}
74+The normalized direction from a to b: (a - b) / |a - b|
36direction : V3 -> V3 -> V3
76direction : V3 -> V3 -> V3
37direction = Native.MJS.v3direction
77direction = Native.MJS.v3direction
80+The length of the given vector: |a|
39length : V3 -> Float
82length : V3 -> Float
40length = Native.MJS.v3length
83length = Native.MJS.v3length
86+The square of the length of the given vector: |a|*|a|
42lengthSquared : V3 -> Float
88lengthSquared : V3 -> Float
43lengthSquared = Native.MJS.v3lengthSquared
89lengthSquared = Native.MJS.v3lengthSquared
92+A unit vector with the same direction as the given vector: a / |a|
45normalize : V3 -> V3
94normalize : V3 -> V3
46normalize = Native.MJS.v3normalize
95normalize = Native.MJS.v3normalize
98+Multiply the vector by a scalar: a * k
48scale : V3 -> Float -> V3
100scale : V3 -> Float -> V3
49scale = Native.MJS.v3scale
101scale = Native.MJS.v3scale
104+The dot product of a and b
51dot : V3 -> V3 -> Float
106dot : V3 -> V3 -> Float
52dot = Native.MJS.v3dot
107dot = Native.MJS.v3dot
110+The cross product of a and b
54cross : V3 -> V3 -> V3
112cross : V3 -> V3 -> V3
55cross = Native.MJS.v3cross
113cross = Native.MJS.v3cross
116+Methods for working with 4x4 matrices.
121+Multiple the vector by the 4x4 matrix: m * v
57mul4x4 : M4x4 -> V3 -> V3
123mul4x4 : M4x4 -> V3 -> V3
58mul4x4 = Native.MJS.v3mul4x4
124mul4x4 = Native.MJS.v3mul4x4
60−--m4x4 : V3[16] -> M4x4 ?
126+{-|
61−
127+A matrix with all 0s, except 1s on the diagonal
62identity : M4x4
129identity : M4x4
63identity = Native.MJS.m4x4identity
130identity = Native.MJS.m4x4identity
65−--topLeft3x3 : M4x4 -> M3x3 ?
132+{-|
66−
133+Computes the inverse of the given matrix m, assuming that
67−{- Assumes that m is orthonormal -}
134+the matrix is orthonormal
68inverseOrthonormal : M4x4 -> M4x4
136inverseOrthonormal : M4x4 -> M4x4
69inverseOrthonormal = Native.MJS.m4x4inverseOrthonormal
137inverseOrthonormal = Native.MJS.m4x4inverseOrthonormal
71−--inverseTo3x3 : M4x4 -> M3x3 ?
139+{-|
140+Creates a matrix for a projection frustum with the given parameters.
144+ left - the left coordinate of the frustum
145+ right- the right coordinate of the frustum
146+ bottom - the bottom coordinate of the frustum
147+ top - the top coordinate of the frustum
148+ znear - the near z distance of the frustum
149+ zfar - the far z distance of the frustum
73makeFrustrum : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
151makeFrustrum : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
74makeFrustrum = Native.MJS.m4x4makeFrustrum
152makeFrustrum = Native.MJS.m4x4makeFrustrum
155+Creates a matrix for a perspective projection with the given parameters.
159+ fovy - field of view in the y axis, in degrees
160+ aspect - aspect ratio
161+ znear - the near z distance of the projection
162+ zfar - the far z distance of the projection
76makePerspective : Float -> Float -> Float -> Float -> M4x4
164makePerspective : Float -> Float -> Float -> Float -> M4x4
77makePerspective = Native.MJS.m4x4makePerspective
165makePerspective = Native.MJS.m4x4makePerspective
168+Creates a matrix for an orthogonal frustum projection with the given parameters.
172+ left - the left coordinate of the frustum
173+ right- the right coordinate of the frustum
174+ bottom - the bottom coordinate of the frustum
175+ top - the top coordinate of the frustum
176+ znear - the near z distance of the frustum
177+ zfar - the far z distance of the frustum
79makeOrtho : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
179makeOrtho : Float -> Float -> Float -> Float -> Float -> Float -> Float -> M4x4
80makeOrtho = Native.MJS.m4x4makeOrtho
180makeOrtho = Native.MJS.m4x4makeOrtho
183+Creates a matrix for a 2D orthogonal frustum projection with the given parameters.
184+znear and zfar are assumed to be -1 and 1, respectively.
188+ left - the left coordinate of the frustum
189+ right- the right coordinate of the frustum
190+ bottom - the bottom coordinate of the frustum
191+ top - the top coordinate of the frustum
82makeOrtho2D : Float -> Float -> Float -> Float -> M4x4
193makeOrtho2D : Float -> Float -> Float -> Float -> M4x4
83makeOrtho2D = Native.MJS.m4x4makeOrtho2D
194makeOrtho2D = Native.MJS.m4x4makeOrtho2D
197+Matrix multiplcation: a * b
85mul : M4x4 -> M4x4 -> M4x4
199mul : M4x4 -> M4x4 -> M4x4
86mul = Native.MJS.m4x4mul
200mul = Native.MJS.m4x4mul
203+Matrix multiplication, assuming a and b are affine: a * b
88mulAffine : M4x4 -> M4x4 -> M4x4
205mulAffine : M4x4 -> M4x4 -> M4x4
89mulAffine = Native.MJS.m4x4mulAffine
206mulAffine = Native.MJS.m4x4mulAffine
209+Creates a transformation matrix for rotation by angle radians about the 3-element vector axis.
91makeRotate : Float -> V3 -> M4x4
211makeRotate : Float -> V3 -> M4x4
92makeRotate = Native.MJS.m4x4makeRotate
212makeRotate = Native.MJS.m4x4makeRotate
215+Concatenates a rotation of angle radians about the axis to the given matrix.
94rotate : Float -> V3 -> M4x4 -> M4x4
217rotate : Float -> V3 -> M4x4 -> M4x4
95rotate = Native.MJS.m4x4rotate
218rotate = Native.MJS.m4x4rotate
221+Creates a transformation matrix for scaling by 3 scalar values, one for
222+each of the x, y, and z directions.
97makeScale3 : Float -> Float -> Float -> M4x4
224makeScale3 : Float -> Float -> Float -> M4x4
98makeScale3 = Native.MJS.m4x4makeScale3
225makeScale3 = Native.MJS.m4x4makeScale3
228+Creates a transformation matrix for scaling each of the x, y, and z axes by the amount
229+given in the corresponding element of the 3-element vector.
100makeScale : V3 -> M4x4
231makeScale : V3 -> M4x4
101makeScale = Native.MJS.m4x4makeScale
232makeScale = Native.MJS.m4x4makeScale
235+Concatenates a scaling to the given matrix.
103scaleM3 : Float -> Float -> Float -> M4x4 -> M4x4
237scaleM3 : Float -> Float -> Float -> M4x4 -> M4x4
104scaleM3 = Native.MJS.m4x4scale3
238scaleM3 = Native.MJS.m4x4scale3
241+Concatenates a scaling to the given matrix.
106scaleM : V3 -> M4x4 -> M4x4
243scaleM : V3 -> M4x4 -> M4x4
107scaleM = Native.MJS.m4x4scale
244scaleM = Native.MJS.m4x4scale
247+Creates a transformation matrix for translating by 3 scalar values, one for
248+each of the x, y, and z directions.
109makeTranslate3 : Float -> Float -> Float -> M4x4
250makeTranslate3 : Float -> Float -> Float -> M4x4
110makeTranslate3 = Native.MJS.m4x4makeTranslate3
251makeTranslate3 = Native.MJS.m4x4makeTranslate3
254+Creates a transformation matrix for translating each of the x, y, and z axes by the amount
255+given in the corresponding element of the 3-element vector.
112makeTranslate : V3 -> M4x4
257makeTranslate : V3 -> M4x4
113makeTranslate = Native.MJS.m4x4makeTranslate
258makeTranslate = Native.MJS.m4x4makeTranslate
261+Concatenates a translation to the given matrix.
115translate3 : Float -> Float -> Float -> M4x4 -> M4x4
263translate3 : Float -> Float -> Float -> M4x4 -> M4x4
116translate3 = Native.MJS.m4x4translate3
264translate3 = Native.MJS.m4x4translate3
267+Concatenates a translation to the given matrix.
118translate : V3 -> M4x4 -> M4x4
269translate : V3 -> M4x4 -> M4x4
119translate = Native.MJS.m4x4translate
270translate = Native.MJS.m4x4translate
273+Creates a transformation matrix for a camera.
277+ eye - The location of the camera
278+ center - The location of the focused object
279+ up - The "up" direction according to the camera
121makeLookAt : V3 -> V3 -> V3 -> M4x4
281makeLookAt : V3 -> V3 -> V3 -> M4x4
122makeLookAt = Native.MJS.m4x4makeLookAt
282makeLookAt = Native.MJS.m4x4makeLookAt
285+"Flip" the matrix across the diagonal by swapping row index and column index.
124transpose : M4x4 -> M4x4
287transpose : M4x4 -> M4x4
125transpose = Native.MJS.m4x4transpose
288transpose = Native.MJS.m4x4transpose
127−{- Custom constructor for supplying arbitrary x,y,z axis -}
290+{-|
291+Creates a transform from a basis consisting of 3 linearly independent vectors.
128makeBasis : V3 -> V3 -> V3 -> M4x4
293makeBasis : V3 -> V3 -> V3 -> M4x4
129makeBasis = Native.MJS.m4x4makeBasis
294makeBasis = Native.MJS.m4x4makeBasis