1module Math.Matrix where
3{-| A high performance linear algebra library using native JS arrays. Geared
4towards 3D graphics and use with `Graphics.WebGL`. All matrices are immutable.
6This library uses the convention that the prefix `make` is creating a new
7array, whereas without the prefix, you are applying some transform to an
14@docs identity, inverseOrthonormal, mul, mulAffine, transpose, makeBasis
18@docs makeFrustrum, makePerspective, makeOrtho, makeOrtho2D, makeLookAt
22@docs makeRotate, rotate, makeScale3, makeScale, scaleM3, scaleM, makeTranslate3, makeTranslate, translate3, translate
27import Math.Vector (Vec3)
31{-| Multiply a vector by a 4x4 matrix: m * v
33mul4x4 : Mat4 -> Vec3 -> Vec3
34mul4x4 = Native.MJS.v3mul4x4
36{-| A matrix with all 0s, except 1s on the diagonal.
39identity = Native.MJS.m4x4identity
41{-| Computes the inverse of the given matrix m, assuming that the matrix is
44inverseOrthonormal : Mat4 -> Mat4
45inverseOrthonormal = Native.MJS.m4x4inverseOrthonormal
47{-| Creates a matrix for a projection frustum with the given parameters.
51 * left - the left coordinate of the frustum
52 * right- the right coordinate of the frustum
53 * bottom - the bottom coordinate of the frustum
54 * top - the top coordinate of the frustum
55 * znear - the near z distance of the frustum
56 * zfar - the far z distance of the frustum
58makeFrustrum : Float -> Float -> Float -> Float -> Float -> Float -> Float -> Mat4
59makeFrustrum = Native.MJS.m4x4makeFrustrum
61{-| Creates a matrix for a perspective projection with the given parameters.
65 * fovy - field of view in the y axis, in degrees
66 * aspect - aspect ratio
67 * znear - the near z distance of the projection
68 * zfar - the far z distance of the projection
70makePerspective : Float -> Float -> Float -> Float -> Mat4
71makePerspective = Native.MJS.m4x4makePerspective
74Creates a matrix for an orthogonal frustum projection with the given parameters.
78 * left - the left coordinate of the frustum
79 * right- the right coordinate of the frustum
80 * bottom - the bottom coordinate of the frustum
81 * top - the top coordinate of the frustum
82 * znear - the near z distance of the frustum
83 * zfar - the far z distance of the frustum
85makeOrtho : Float -> Float -> Float -> Float -> Float -> Float -> Float -> Mat4
86makeOrtho = Native.MJS.m4x4makeOrtho
88{-| Creates a matrix for a 2D orthogonal frustum projection with the given
89parameters. `znear` and `zfar` are assumed to be -1 and 1, respectively.
93 * left - the left coordinate of the frustum
94 * right- the right coordinate of the frustum
95 * bottom - the bottom coordinate of the frustum
96 * top - the top coordinate of the frustum
98makeOrtho2D : Float -> Float -> Float -> Float -> Mat4
99makeOrtho2D = Native.MJS.m4x4makeOrtho2D
101{-| Matrix multiplcation: a * b
103mul : Mat4 -> Mat4 -> Mat4
104mul = Native.MJS.m4x4mul
106{-| Matrix multiplication, assuming a and b are affine: a * b
108mulAffine : Mat4 -> Mat4 -> Mat4
109mulAffine = Native.MJS.m4x4mulAffine
111{-| Creates a transformation matrix for rotation in radians about the
1123-element vector axis.
114makeRotate : Float -> Vec3 -> Mat4
115makeRotate = Native.MJS.m4x4makeRotate
117{-| Concatenates a rotation of angle radians about the axis to the given matrix.
119rotate : Float -> Vec3 -> Mat4 -> Mat4
120rotate = Native.MJS.m4x4rotate
122{-| Creates a transformation matrix for scaling by 3 scalar values, one for
123each of the x, y, and z directions.
125makeScale3 : Float -> Float -> Float -> Mat4
126makeScale3 = Native.MJS.m4x4makeScale3
128{-| Creates a transformation matrix for scaling each of the x, y, and z axes by
129the amount given in the corresponding element of the 3-element vector.
131makeScale : Vec3 -> Mat4
132makeScale = Native.MJS.m4x4makeScale
134{-| Concatenates a scaling to the given matrix.
136scaleM3 : Float -> Float -> Float -> Mat4 -> Mat4
137scaleM3 = Native.MJS.m4x4scale3
139{-| Concatenates a scaling to the given matrix.
141scaleM : Vec3 -> Mat4 -> Mat4
142scaleM = Native.MJS.m4x4scale
145Creates a transformation matrix for translating by 3 scalar values, one for
146each of the x, y, and z directions.
148makeTranslate3 : Float -> Float -> Float -> Mat4
149makeTranslate3 = Native.MJS.m4x4makeTranslate3
151{-| Creates a transformation matrix for translating each of the x, y, and z
152axes by the amount given in the corresponding element of the 3-element vector.
154makeTranslate : Vec3 -> Mat4
155makeTranslate = Native.MJS.m4x4makeTranslate
158Concatenates a translation to the given matrix.
160translate3 : Float -> Float -> Float -> Mat4 -> Mat4
161translate3 = Native.MJS.m4x4translate3
164Concatenates a translation to the given matrix.
166translate : Vec3 -> Mat4 -> Mat4
167translate = Native.MJS.m4x4translate
170Creates a transformation matrix for a camera.
174 * eye - The location of the camera
175 * center - The location of the focused object
176 * up - The "up" direction according to the camera
178makeLookAt : Vec3 -> Vec3 -> Vec3 -> Mat4
179makeLookAt = Native.MJS.m4x4makeLookAt
181{-| "Flip" the matrix across the diagonal by swapping row index and column
184transpose : Mat4 -> Mat4
185transpose = Native.MJS.m4x4transpose
187{-| Creates a transform from a basis consisting of 3 linearly independent vectors.
189makeBasis : Vec3 -> Vec3 -> Vec3 -> Mat4
190makeBasis = Native.MJS.m4x4makeBasis
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list