on master help sign in
Remove WebGL from libraries
commit6564b2bebc83100544b7ed311534c4e9be3491d0 authorEvan Czaplicki <info@elm-lang.org> dateFri 9 May 2014, 17:43 (12 years ago) parent22c6e71
10 files changed−3199
libraries/Graphics/WebGL.elm−85 libraries/Math/Matrix4.elm−196 libraries/Math/Vector2.elm−104 libraries/Math/Vector3.elm−128 libraries/Math/Vector4.elm−120 libraries/Native/Graphics/WebGL.js−365 libraries/Native/MJS.js−1789 libraries/Native/Math/Vector2.js−186 libraries/Native/Math/Vector4.js−224 libraries/elm_dependencies.json−2
libraries/Graphics/WebGL.elmdeleted−85
@@ -1,85 +0,0 @@
1−module Graphics.WebGL (mapTriangle, zipTriangle, unsafeCoerceGLSL, loadTex, model, webgl) where
2−
3−{-| The WebGL API is for high performance drawing.
4−
5−# Triangle Convenience Functions
6−@docs Triangle, mapTriangle, zipTriangle
7−
8−# Shaders
9−@docs Shader
10−
11−Shaders are created using inline GLSL blocks. The type of the Shader is determined by the top-level attribute, uniform, and varying declarations of the parsed GLSL source code. The type parameters to Shader are records with field names matching the names of the declarations.
12−
13−```haskell
14−vertex : Shader { a | pos : V3 } { b | model : M4x4 } {}
15−vertex = [glsl|
16−
17−attribute vec3 pos;
18−uniform mat4 model;
19−
20−void main () {
21− gl_Position = model * vec4(pos,1.0);
22−}
23−
24−\]
25−```
26−
27−GLSL attribute variables are per-vertex values. For example, it could hold the position or color of a specific vertex of a specific triangle in your model.
28−
29−GLSL uniform variables are global values which will be applied for all vertices of all triangles of the model.
30−
31−GLSL varying variables are shared between stages; they are output variables for vertex shaders, and input variables for fragment shaders.
32−
33−@docs unsafeCoerceGLSL
34−
35−# Loading Textures
36−@docs loadTex
37−
38−# Packaging Models
39−@docs model
40−
41−# WebGL Element
42−@docs webgl
43−
44−-}
45−
46−import Graphics.Element (Element)
47−import Http (Response)
48−import Native.Graphics.WebGL
49−import Signal (Signal)
50−
51−{-| Triangles are only homogenous 3-tuples. Each element describes something about each vertex, and must be a record to be used with GLSL shaders.
52−-}
53−type Triangle a = (a,a,a)
54−
55−{-| Apply a function to each vertex -}
56−mapTriangle : (a -> b) -> Triangle a -> Triangle b
57−mapTriangle f (x,y,z) = (f x, f y, f z)
58−
59−{-| Apply an arity-2 function element-wise on 2 triangles -}
60−zipTriangle : (a -> b -> c) -> Triangle a -> Triangle b -> Triangle c
61−zipTriangle f (x,y,z) (x',y',z') = (f x x', f y y', f z z')
62−
63−data Shader attr unif vary = Shader
64−
65−{-| Libary writers can use this function to create shader combinators. -}
66−unsafeCoerceGLSL : String -> Shader attribute uniform varying
67−unsafeCoerceGLSL = Native.Graphics.WebGL.unsafeCoerceGLSL
68−
69−data Texture = Texture
70−
71−{-| Loads a texture from the given url. PNG and JPEG are the preferred and tested-compatible source image format. -}
72−loadTex : String -> Signal (Response Texture)
73−loadTex = Native.Graphics.WebGL.loadTex
74−
75−data Model = Model
76−
77−{-| Packages a vertex shader, a fragment shader, triangle data, and uniform variables as a opaque Model.
78−This is a simple container; however, externally there is no type information.
79−-}
80−model : Shader attribute uniform varying -> Shader {} uniform varying -> [Triangle attribute] -> uniform -> Model
81−model = Native.Graphics.WebGL.model
82−
83−{-| Render a WebGL scene with the given dimensions and models -}
84−webgl : (Int,Int) -> [Model] -> Element
85−webgl = Native.Graphics.WebGL.webgl
libraries/Math/Matrix4.elmdeleted−196
@@ -1,196 +0,0 @@
1−module Math.Matrix4 where
2−
3−{-| A high performance linear algebra library using native JS arrays. Geared
4−towards 3D graphics and use with `Graphics.WebGL`. All matrices are immutable.
5−
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.
9−
10−# Create
11−
12−@docs identity
13−
14−# Operations
15−
16−@docs inverseOrthonormal, mul, mulAffine, mulVec3, transpose, makeBasis
17−
18−# Projections
19−
20−@docs makeFrustrum, makePerspective, makeOrtho, makeOrtho2D, makeLookAt
21−
22−# Apply Transformations
23−
24−@docs rotate, scale, scale3, translate, translate3
25−
26−# Create Transformations
27−
28−@docs makeRotate, makeScale, makeScale3, makeTranslate, makeTranslate3
29−
30−-}
31−
32−import Native.MJS
33−import Math.Vector3 (Vec3)
34−
35−data Mat4 = Mat4
36−
37−{-| Multiply a vector by a 4x4 matrix: m * v
38−-}
39−mulVec3 : Mat4 -> Vec3 -> Vec3
40−mulVec3 = Native.MJS.v3mul4x4
41−
42−{-| A matrix with all 0s, except 1s on the diagonal.
43−-}
44−identity : Mat4
45−identity = Native.MJS.m4x4identity
46−
47−{-| Computes the inverse of the given matrix m, assuming that the matrix is
48−orthonormal.
49−-}
50−inverseOrthonormal : Mat4 -> Mat4
51−inverseOrthonormal = Native.MJS.m4x4inverseOrthonormal
52−
53−{-| Creates a matrix for a projection frustum with the given parameters.
54−
55−Parameters:
56−
57− * left - the left coordinate of the frustum
58− * right- the right coordinate of the frustum
59− * bottom - the bottom coordinate of the frustum
60− * top - the top coordinate of the frustum
61− * znear - the near z distance of the frustum
62− * zfar - the far z distance of the frustum
63−-}
64−makeFrustrum : Float -> Float -> Float -> Float -> Float -> Float -> Float -> Mat4
65−makeFrustrum = Native.MJS.m4x4makeFrustrum
66−
67−{-| Creates a matrix for a perspective projection with the given parameters.
68−
69−Parameters:
70−
71− * fovy - field of view in the y axis, in degrees
72− * aspect - aspect ratio
73− * znear - the near z distance of the projection
74− * zfar - the far z distance of the projection
75−-}
76−makePerspective : Float -> Float -> Float -> Float -> Mat4
77−makePerspective = Native.MJS.m4x4makePerspective
78−
79−{-|
80−Creates a matrix for an orthogonal frustum projection with the given parameters.
81−
82−Parameters:
83−
84− * left - the left coordinate of the frustum
85− * right- the right coordinate of the frustum
86− * bottom - the bottom coordinate of the frustum
87− * top - the top coordinate of the frustum
88− * znear - the near z distance of the frustum
89− * zfar - the far z distance of the frustum
90−-}
91−makeOrtho : Float -> Float -> Float -> Float -> Float -> Float -> Float -> Mat4
92−makeOrtho = Native.MJS.m4x4makeOrtho
93−
94−{-| Creates a matrix for a 2D orthogonal frustum projection with the given
95−parameters. `znear` and `zfar` are assumed to be -1 and 1, respectively.
96−
97−Parameters:
98−
99− * left - the left coordinate of the frustum
100− * right- the right coordinate of the frustum
101− * bottom - the bottom coordinate of the frustum
102− * top - the top coordinate of the frustum
103−-}
104−makeOrtho2D : Float -> Float -> Float -> Float -> Mat4
105−makeOrtho2D = Native.MJS.m4x4makeOrtho2D
106−
107−{-| Matrix multiplcation: a * b
108−-}
109−mul : Mat4 -> Mat4 -> Mat4
110−mul = Native.MJS.m4x4mul
111−
112−{-| Matrix multiplication, assuming a and b are affine: a * b
113−-}
114−mulAffine : Mat4 -> Mat4 -> Mat4
115−mulAffine = Native.MJS.m4x4mulAffine
116−
117−{-| Creates a transformation matrix for rotation in radians about the
118−3-element vector axis.
119−-}
120−makeRotate : Float -> Vec3 -> Mat4
121−makeRotate = Native.MJS.m4x4makeRotate
122−
123−{-| Concatenates a rotation in radians about an axis to the given matrix.
124−-}
125−rotate : Float -> Vec3 -> Mat4 -> Mat4
126−rotate = Native.MJS.m4x4rotate
127−
128−{-| Creates a transformation matrix for scaling by 3 scalar values, one for
129−each of the x, y, and z directions.
130−-}
131−makeScale3 : Float -> Float -> Float -> Mat4
132−makeScale3 = Native.MJS.m4x4makeScale3
133−
134−{-| Creates a transformation matrix for scaling each of the x, y, and z axes by
135−the amount given in the corresponding element of the 3-element vector.
136−-}
137−makeScale : Vec3 -> Mat4
138−makeScale = Native.MJS.m4x4makeScale
139−
140−{-| Concatenates a scaling to the given matrix.
141−-}
142−scale3 : Float -> Float -> Float -> Mat4 -> Mat4
143−scale3 = Native.MJS.m4x4scale3
144−
145−{-| Concatenates a scaling to the given matrix.
146−-}
147−scale : Vec3 -> Mat4 -> Mat4
148−scale = Native.MJS.m4x4scale
149−
150−{-|
151−Creates a transformation matrix for translating by 3 scalar values, one for
152−each of the x, y, and z directions.
153−-}
154−makeTranslate3 : Float -> Float -> Float -> Mat4
155−makeTranslate3 = Native.MJS.m4x4makeTranslate3
156−
157−{-| Creates a transformation matrix for translating each of the x, y, and z
158−axes by the amount given in the corresponding element of the 3-element vector.
159−-}
160−makeTranslate : Vec3 -> Mat4
161−makeTranslate = Native.MJS.m4x4makeTranslate
162−
163−{-|
164−Concatenates a translation to the given matrix.
165−-}
166−translate3 : Float -> Float -> Float -> Mat4 -> Mat4
167−translate3 = Native.MJS.m4x4translate3
168−
169−{-|
170−Concatenates a translation to the given matrix.
171−-}
172−translate : Vec3 -> Mat4 -> Mat4
173−translate = Native.MJS.m4x4translate
174−
175−{-|
176−Creates a transformation matrix for a camera.
177−
178−Parameters:
179−
180− * eye - The location of the camera
181− * center - The location of the focused object
182− * up - The "up" direction according to the camera
183−-}
184−makeLookAt : Vec3 -> Vec3 -> Vec3 -> Mat4
185−makeLookAt = Native.MJS.m4x4makeLookAt
186−
187−{-| "Flip" the matrix across the diagonal by swapping row index and column
188−index.
189−-}
190−transpose : Mat4 -> Mat4
191−transpose = Native.MJS.m4x4transpose
192−
193−{-| Creates a transform from a basis consisting of 3 linearly independent vectors.
194−-}
195−makeBasis : Vec3 -> Vec3 -> Vec3 -> Mat4
196−makeBasis = Native.MJS.m4x4makeBasis
libraries/Math/Vector2.elmdeleted−104
@@ -1,104 +0,0 @@
1−module Math.Vector2 where
2−{-| A high performance linear algebra library using native JS arrays. Geared
3−towards 3D graphics and use with `Graphics.WebGL`. All vectors are immutable.
4−
5−# Create
6−@docs v2
7−
8−# Get and Set
9−The set functions create a new copy of the vector, updating a single field.
10−
11−@docs getX, getY, setX, setY
12−
13−# Operations
14−@docs add, sub, negate, scale, dot, normalize, direction,
15− length, lengthSquared, distance, distanceSquared
16−
17−# Conversions
18−toTuple, fromTuple, toRecord, fromRecord
19−-}
20−
21−import Native.Math.Vector2
22−
23−data Vec2 = Vec2
24−
25−{-| Creates a new 2-element vector with the given values. -}
26−v2 : Float -> Float -> Vec2
27−v2 = Native.Math.Vector2.v2
28−
29−{-| Extract the x component of a vector. -}
30−getX : Vec2 -> Float
31−getX = Native.Math.Vector2.getX
32−
33−{-| Extract the y component of a vector. -}
34−getY : Vec2 -> Float
35−getY = Native.Math.Vector2.getY
36−
37−{-| Update the x component of a vector, returning a new vector. -}
38−setX : Float -> Vec2 -> Vec2
39−setX = Native.Math.Vector2.setX
40−
41−{-| Update the y component of a vector, returning a new vector. -}
42−setY : Float -> Vec2 -> Vec2
43−setY = Native.Math.Vector2.setY
44−
45−{-| Convert a vector to a tuple. -}
46−toTuple : Vec2 -> (Float,Float)
47−toTuple = Native.Math.Vector2.toTuple
48−
49−{-| Convert a vector to a record. -}
50−toRecord : Vec2 -> { x:Float, y:Float }
51−toRecord = Native.Math.Vector2.toRecord
52−
53−{-| Convert a tuple to a vector. -}
54−fromTuple : (Float,Float) -> Vec2
55−fromTuple = Native.Math.Vector2.fromTuple
56−
57−{-| Convert a record to a vector. -}
58−fromRecord : { x:Float, y:Float } -> Vec2
59−fromRecord = Native.Math.Vector2.fromRecord
60−
61−{-| Vector addition: a + b -}
62−add : Vec2 -> Vec2 -> Vec2
63−add = Native.Math.Vector2.add
64−
65−{-| Vector subtraction: a - b -}
66−sub : Vec2 -> Vec2 -> Vec2
67−sub = Native.Math.Vector2.sub
68−
69−{-| Vector negation: -a -}
70−negate : Vec2 -> Vec2
71−negate = Native.Math.Vector2.neg
72−
73−{-| The normalized direction from a to b: (a - b) / |a - b| -}
74−direction : Vec2 -> Vec2 -> Vec2
75−direction = Native.Math.Vector2.direction
76−
77−{-| The length of the given vector: |a| -}
78−length : Vec2 -> Float
79−length = Native.Math.Vector2.length
80−
81−{-| The square of the length of the given vector: |a| * |a| -}
82−lengthSquared : Vec2 -> Float
83−lengthSquared = Native.Math.Vector2.lengthSquared
84−
85−{-| The distance between two vectors. -}
86−distance : Vec2 -> Vec2 -> Float
87−distance = Native.Math.Vector2.distance
88−
89−{-| The square of the distance between two vectors. -}
90−distanceSquared : Vec2 -> Vec2 -> Float
91−distanceSquared = Native.Math.Vector2.distanceSquared
92−
93−{-| A unit vector with the same direction as the given vector: a / |a| -}
94−normalize : Vec2 -> Vec2
95−normalize = Native.Math.Vector2.normalize
96−
97−{-| Multiply the vector by a scalar: a * k -}
98−scale : Vec2 -> Float -> Vec2
99−scale = Native.Math.Vector2.scale
100−
101−{-| The dot product of a and b -}
102−dot : Vec2 -> Vec2 -> Float
103−dot = Native.Math.Vector2.dot
104−
libraries/Math/Vector3.elmdeleted−128
@@ -1,128 +0,0 @@
1−module Math.Vector3 where
2−{-| A high performance linear algebra library using native JS arrays. Geared
3−towards 3D graphics and use with `Graphics.WebGL`. All vectors are immutable.
4−
5−# Create
6−@docs v3, i, j, k
7−
8−# Get and Set
9−The set functions create a new copy of the vector, updating a single field.
10−
11−@docs getX, getY, getZ, setX, setY, setZ
12−
13−# Operations
14−@docs add, sub, negate, scale, dot, cross, normalize, direction,
15− length, lengthSquared, distance, distanceSquared
16−
17−# Conversions
18−@docs toTuple, fromTuple, toRecord, fromRecord
19−-}
20−
21−import Native.MJS
22−
23−data Vec3 = Vec3
24−
25−{-| Creates a new 3-element vector with the given values.
26−-}
27−v3 : Float -> Float -> Float -> Vec3
28−v3 = Native.MJS.v3
29−
30−{-| The unit vector &icirc; which points in the x direction: `v3 1 0 0` -}
31−i : Vec3
32−i = Native.MJS.v3 1 0 0
33−
34−{-| The unit vector &jcirc; which points in the y direction: `v3 0 1 0` -}
35−j : Vec3
36−j = Native.MJS.v3 0 1 0
37−
38−{-| The unit vector &kcirc; which points in the z direction: `v3 0 0 1` -}
39−k : Vec3
40−k = Native.MJS.v3 0 0 1
41−
42−{-| Extract the x component of a vector. -}
43−getX : Vec3 -> Float
44−getX = Native.MJS.v3getX
45−
46−{-| Extract the y component of a vector. -}
47−getY : Vec3 -> Float
48−getY = Native.MJS.v3getY
49−
50−{-| Extract the z component of a vector. -}
51−getZ : Vec3 -> Float
52−getZ = Native.MJS.v3getZ
53−
54−{-| Update the x component of a vector, returning a new vector. -}
55−setX : Float -> Vec3 -> Vec3
56−setX = Native.MJS.v3setX
57−
58−{-| Update the y component of a vector, returning a new vector. -}
59−setY : Float -> Vec3 -> Vec3
60−setY = Native.MJS.v3setY
61−
62−{-| Update the z component of a vector, returning a new vector. -}
63−setZ : Float -> Vec3 -> Vec3
64−setZ = Native.MJS.v3setZ
65−
66−{-| Convert a vector to a tuple. -}
67−toTuple : Vec3 -> (Float,Float,Float)
68−toTuple = Native.MJS.toTuple3
69−
70−{-| Convert a vector to a record. -}
71−toRecord : Vec3 -> { x:Float, y:Float, z:Float }
72−toRecord = Native.MJS.toRecord3
73−
74−{-| Convert a tuple to a vector. -}
75−fromTuple : (Float,Float,Float) -> Vec3
76−fromTuple = Native.MJS.fromTuple3
77−
78−{-| Convert a record to a vector. -}
79−fromRecord : { x:Float, y:Float, z:Float } -> Vec3
80−fromRecord = Native.MJS.fromRecord3
81−
82−{-| Vector addition: a + b -}
83−add : Vec3 -> Vec3 -> Vec3
84−add = Native.MJS.v3add
85−
86−{-| Vector subtraction: a - b -}
87−sub : Vec3 -> Vec3 -> Vec3
88−sub = Native.MJS.v3sub
89−
90−{-| Vector negation: -a -}
91−negate : Vec3 -> Vec3
92−negate = Native.MJS.v3neg
93−
94−{-| The normalized direction from a to b: (a - b) / |a - b| -}
95−direction : Vec3 -> Vec3 -> Vec3
96−direction = Native.MJS.v3direction
97−
98−{-| The length of the given vector: |a| -}
99−length : Vec3 -> Float
100−length = Native.MJS.v3length
101−
102−{-| The square of the length of the given vector: |a| * |a| -}
103−lengthSquared : Vec3 -> Float
104−lengthSquared = Native.MJS.v3lengthSquared
105−
106−{-| The distance between two vectors. -}
107−distance : Vec3 -> Vec3 -> Float
108−distance = Native.MJS.v3distance
109−
110−{-| The square of the distance between two vectors. -}
111−distanceSquared : Vec3 -> Vec3 -> Float
112−distanceSquared = Native.MJS.v3distanceSquared
113−
114−{-| A unit vector with the same direction as the given vector: a / |a| -}
115−normalize : Vec3 -> Vec3
116−normalize = Native.MJS.v3normalize
117−
118−{-| Multiply the vector by a scalar: a * k -}
119−scale : Vec3 -> Float -> Vec3
120−scale = Native.MJS.v3scale
121−
122−{-| The dot product of a and b -}
123−dot : Vec3 -> Vec3 -> Float
124−dot = Native.MJS.v3dot
125−
126−{-| The cross product of a and b -}
127−cross : Vec3 -> Vec3 -> Vec3
128−cross = Native.MJS.v3cross
libraries/Math/Vector4.elmdeleted−120
@@ -1,120 +0,0 @@
1−module Math.Vector4 where
2−{-| A high performance linear algebra library using native JS arrays. Geared
3−towards 3D graphics and use with `Graphics.WebGL`. All vectors are immutable.
4−
5−# Create
6−@docs v4
7−
8−# Get and Set
9−The set functions create a new copy of the vector, updating a single field.
10−
11−@docs getX, getY, setX, setY
12−
13−# Operations
14−@docs add, sub, negate, scale, dot, normalize, direction,
15− length, lengthSquared, distance, distanceSquared
16−
17−# Conversions
18−toTuple, fromTuple, toRecord, fromRecord
19−-}
20−
21−import Native.Math.Vector4
22−
23−data Vec4 = Vec4
24−
25−{-| Creates a new 4-element vector with the given x, y, z, and w values. -}
26−v4 : Float -> Float -> Float -> Float -> Vec4
27−v4 = Native.Math.Vector4.v4
28−
29−{-| Extract the x component of a vector. -}
30−getX : Vec4 -> Float
31−getX = Native.Math.Vector4.getX
32−
33−{-| Extract the y component of a vector. -}
34−getY : Vec4 -> Float
35−getY = Native.Math.Vector4.getY
36−
37−{-| Extract the z component of a vector. -}
38−getZ : Vec4 -> Float
39−getZ = Native.Math.Vector4.getZ
40−
41−{-| Extract the w component of a vector. -}
42−getW : Vec4 -> Float
43−getW = Native.Math.Vector4.getW
44−
45−{-| Update the x component of a vector, returning a new vector. -}
46−setX : Float -> Vec4 -> Vec4
47−setX = Native.Math.Vector4.setX
48−
49−{-| Update the y component of a vector, returning a new vector. -}
50−setY : Float -> Vec4 -> Vec4
51−setY = Native.Math.Vector4.setY
52−
53−{-| Update the z component of a vector, returning a new vector. -}
54−setZ : Float -> Vec4 -> Vec4
55−setZ = Native.Math.Vector4.setZ
56−
57−{-| Update the w component of a vector, returning a new vector. -}
58−setW : Float -> Vec4 -> Vec4
59−setW = Native.Math.Vector4.setW
60−
61−{-| Convert a vector to a tuple. -}
62−toTuple : Vec4 -> (Float,Float,Float,Float)
63−toTuple = Native.Math.Vector4.toTuple
64−
65−{-| Convert a vector to a record. -}
66−toRecord : Vec4 -> { x:Float, y:Float, z:Float, w:Float }
67−toRecord = Native.Math.Vector4.toRecord
68−
69−{-| Convert a tuple to a vector. -}
70−fromTuple : (Float,Float,Float,Float) -> Vec4
71−fromTuple = Native.Math.Vector4.fromTuple
72−
73−{-| Convert a record to a vector. -}
74−fromRecord : { x:Float, y:Float, z:Float, w:Float } -> Vec4
75−fromRecord = Native.Math.Vector4.fromRecord
76−
77−{-| Vector addition: a + b -}
78−add : Vec4 -> Vec4 -> Vec4
79−add = Native.Math.Vector4.add
80−
81−{-| Vector subtraction: a - b -}
82−sub : Vec4 -> Vec4 -> Vec4
83−sub = Native.Math.Vector4.sub
84−
85−{-| Vector negation: -a -}
86−negate : Vec4 -> Vec4
87−negate = Native.Math.Vector4.neg
88−
89−{-| The normalized direction from a to b: (a - b) / |a - b| -}
90−direction : Vec4 -> Vec4 -> Vec4
91−direction = Native.Math.Vector4.direction
92−
93−{-| The length of the given vector: |a| -}
94−length : Vec4 -> Float
95−length = Native.Math.Vector4.length
96−
97−{-| The square of the length of the given vector: |a| * |a| -}
98−lengthSquared : Vec4 -> Float
99−lengthSquared = Native.Math.Vector4.lengthSquared
100−
101−{-| The distance between two vectors. -}
102−distance : Vec4 -> Vec4 -> Float
103−distance = Native.Math.Vector4.distance
104−
105−{-| The square of the distance between two vectors. -}
106−distanceSquared : Vec4 -> Vec4 -> Float
107−distanceSquared = Native.Math.Vector4.distanceSquared
108−
109−{-| A unit vector with the same direction as the given vector: a / |a| -}
110−normalize : Vec4 -> Vec4
111−normalize = Native.Math.Vector4.normalize
112−
113−{-| Multiply the vector by a scalar: a * k -}
114−scale : Vec4 -> Float -> Vec4
115−scale = Native.Math.Vector4.scale
116−
117−{-| The dot product of a and b -}
118−dot : Vec4 -> Vec4 -> Float
119−dot = Native.Math.Vector4.dot
120−
libraries/Native/Graphics/WebGL.jsdeleted−365
@@ -1,365 +0,0 @@
1−Elm.Native.Graphics.WebGL = {};
2−Elm.Native.Graphics.WebGL.make = function(elm) {
3−
4− // LOG LEVEL
5−
6− elm.Native = elm.Native || {};
7− elm.Native.Graphics = elm.Native.Graphics || {};
8− elm.Native.Graphics.WebGL = elm.Native.Graphics.WebGL || {};
9− if (elm.Native.Graphics.WebGL.values) return elm.Native.Graphics.WebGL.values;
10−
11− var newNode = ElmRuntime.use(ElmRuntime.Render.Utils).newElement;
12− var newElement = Elm.Graphics.Element.make(elm).newElement;
13−
14− var List = Elm.Native.List.make(elm);
15− var MJS = Elm.Native.MJS.make(elm);
16− var Utils = Elm.Native.Utils.make(elm);
17− var Signal = Elm.Signal.make(elm);
18− var Tuple2 = Utils.Tuple2;
19−
20− function unsafeCoerceGLSL(src) {
21− return { src : src };
22− }
23−
24− function loadTex(source) {
25−
26− var response = Signal.constant(elm.Http.values.Waiting);
27−
28− var img = new Image();
29−
30− img.onload = function() {
31− var success = elm.Http.values.Success({img:img});
32− elm.notify(response.id, success);
33− }
34−
35− img.onerror = function(e) {
36− var failure = A2(elm.Http.values.Failure,0,"Failed");
37− elm.notify(response.id, failure);
38− }
39−
40− img.src = source;
41−
42− return response;
43−
44− }
45−
46− function model(vert, frag, buffer, uniforms) {
47−
48− return model = {
49− vert: vert,
50− frag: frag,
51− buffer: buffer,
52− uniforms: uniforms
53− };
54−
55− }
56−
57− function do_texture (gl, img) {
58−
59− var tex = gl.createTexture();
60− console.log("Created texture");
61− gl.bindTexture(gl.TEXTURE_2D, tex);
62− gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
63− gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
64− gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
65− gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
66− gl.generateMipmap(gl.TEXTURE_2D);
67− //gl.bindTexture(gl.TEXTURE0, null);
68− return tex;
69−
70− }
71−
72− function do_compile (gl, src, tipe) {
73−
74− var shader = gl.createShader(tipe);
75− console.log("Created shader");
76−
77− gl.shaderSource(shader, src);
78− gl.compileShader(shader);
79− var compile = gl.COMPILE_STATUS;
80− if (!gl.getShaderParameter(shader,compile)) {
81− throw gl.getShaderInfoLog(shader);
82− }
83−
84− return shader;
85−
86− }
87−
88− function do_link (gl, vshader, fshader) {
89−
90− var program = gl.createProgram();
91− console.log("Created program");
92−
93− gl.attachShader(program, vshader);
94− gl.attachShader(program, fshader);
95− gl.linkProgram(program);
96− if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
97− throw gl.getProgramInfoLog(program);
98− }
99−
100− return program;
101−
102− }
103−
104− function do_bind (gl, program, bufferElems) {
105−
106− var buffers = {};
107−
108− var attributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
109− for (var i = 0; i < attributes; i += 1) {
110− var attribute = gl.getActiveAttrib(program, i);
111− switch (attribute.type) {
112− case gl.FLOAT_VEC3:
113−
114− // Might want to invert the loop
115− // to build the array buffer first
116− // and then bind each one-at-a-time
117− var data = [];
118− List.each(function(elem){
119− data.push(elem._0[attribute.name][0]);
120− data.push(elem._0[attribute.name][1]);
121− data.push(elem._0[attribute.name][2]);
122− data.push(elem._1[attribute.name][0]);
123− data.push(elem._1[attribute.name][1]);
124− data.push(elem._1[attribute.name][2]);
125− data.push(elem._2[attribute.name][0]);
126− data.push(elem._2[attribute.name][1]);
127− data.push(elem._2[attribute.name][2]);
128− }, bufferElems);
129− var array = new Float32Array(data);
130−
131− var buffer = gl.createBuffer();
132− console.log("Created attribute buffer " + attribute.name);
133− gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
134− gl.bufferData(gl.ARRAY_BUFFER, array, gl.STATIC_DRAW);
135−
136− buffers[attribute.name] = buffer;
137−
138− break;
139−
140− default:
141− console.log("Bad buffer type");
142− break;
143− }
144−
145− }
146−
147− var numIndices = 3 * List.length(bufferElems);
148− var indices = List.toArray(List.range(0, numIndices - 1));
149− console.log("Created index buffer");
150− var indexBuffer = gl.createBuffer();
151− gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
152− gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);
153−
154− var bufferObject = {
155− numIndices: numIndices,
156− indexBuffer: indexBuffer,
157− buffers: buffers
158− };
159−
160− return bufferObject;
161−
162− }
163−
164− function drawGL(model) {
165−
166− var gl = model.cache.gl;
167−
168− gl.viewport(0, 0, model.w, model.h);
169− gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
170− console.log("Drawing");
171−
172− function drawModel(m) {
173−
174− var program;
175− if (m.vert.id && m.frag.id) {
176− var progid = m.vert.id + '#' + m.frag.id;
177− program = model.cache.programs[progid];
178− }
179−
180− if (!program) {
181−
182− var vshader = undefined;
183− if (m.vert.id) {
184− vshader = model.cache.shaders[m.vert.id];
185− } else {
186− m.vert.id = Utils.guid();
187− }
188−
189− if (!vshader) {
190− vshader = do_compile(gl, m.vert.src, gl.VERTEX_SHADER);
191− model.cache.shaders[m.vert.id] = vshader;
192− }
193−
194− var fshader = undefined;
195− if (m.frag.id) {
196− fshader = model.cache.shaders[m.frag.id];
197− } else {
198− m.frag.id = Utils.guid();
199− }
200−
201− if (!fshader) {
202− fshader = do_compile(gl, m.frag.src, gl.FRAGMENT_SHADER);
203− model.cache.shaders[m.frag.id] = fshader;
204− }
205−
206− program = do_link(gl, vshader, fshader);
207− var progid = m.vert.id + '#' + m.frag.id;
208− model.cache.programs[progid] = program;
209−
210− }
211−
212− gl.useProgram(program);
213−
214− var numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
215− var textureCounter = 0;
216− for (var i = 0; i < numUniforms; i += 1) {
217− var uniform = gl.getActiveUniform(program, i);
218− var uniformLocation = gl.getUniformLocation(program, uniform.name);
219− switch (uniform.type) {
220− case gl.INT:
221− gl.uniform1i(uniformLocation, m.uniforms[uniform.name]);
222− break;
223− case gl.FLOAT:
224− gl.uniform1f(uniformLocation, m.uniforms[uniform.name]);
225− break;
226− case gl.FLOAT_VEC3:
227− gl.uniform3fv(uniformLocation, m.uniforms[uniform.name]);
228− break;
229− case gl.FLOAT_MAT4:
230− gl.uniformMatrix4fv(uniformLocation, false, m.uniforms[uniform.name]);
231− break;
232− case gl.SAMPLER_2D:
233− var texture = m.uniforms[uniform.name];
234− var tex = undefined;
235− if (texture.id) {
236− tex = model.cache.textures[texture.id];
237− } else {
238− texture.id = Utils.guid();
239− }
240− if (!tex) {
241− tex = do_texture(gl, texture.img);
242− model.cache.textures[texture.id] = tex;
243− }
244− var activeName = 'TEXTURE' + textureCounter;
245− gl.activeTexture(gl[activeName]);
246− gl.bindTexture(gl.TEXTURE_2D,tex);
247− gl.uniform1i(uniformLocation, textureCounter);
248− textureCounter += 1;
249− break;
250− default:
251− console.log("Unsupported uniform type: " + uniform.type);
252− break;
253− }
254− }
255−
256− var buffer = model.cache.buffers[m.buffer.guid];
257− if (!buffer) {
258− buffer = do_bind(gl, program, m.buffer);
259− model.cache.buffers[m.buffer.guid] = buffer;
260− }
261−
262− var numIndices = buffer.numIndices;
263− var indexBuffer = buffer.indexBuffer;
264− gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
265−
266− var numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
267− for (var i = 0; i < numAttributes; i += 1) {
268− var attribute = gl.getActiveAttrib(program, i);
269− var attribLocation = gl.getAttribLocation(program, attribute.name);
270− gl.enableVertexAttribArray(attribLocation);
271− var attributeBuffer = buffer.buffers[attribute.name];
272−
273− switch (attribute.type) {
274− case gl.FLOAT_VEC3:
275− gl.bindBuffer(gl.ARRAY_BUFFER, attributeBuffer);
276− gl.vertexAttribPointer(attribLocation, 3, gl.FLOAT, false, 0, 0);
277− break;
278− default:
279− console.log("Unsupported attribute type: " + attribute.type);
280− break;
281− }
282− }
283−
284− gl.drawElements(gl.TRIANGLES, numIndices, gl.UNSIGNED_SHORT, 0);
285−
286− }
287−
288− List.each(drawModel, model.models);
289−
290− }
291−
292− function webgl(dimensions, models) {
293−
294− if (!window.WebGLRenderingContext) {
295− throw new Error("It appears your browser does not support WebGL! http://get.webgl.org/troubleshooting");
296− }
297−
298− var w = dimensions._0;
299− var h = dimensions._1;
300−
301− function render(model) {
302−
303− var div = newNode('div');
304− div.style.overflow = 'hidden';
305− var canvas = newNode('canvas');
306− var gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
307− gl.enable(gl.DEPTH_TEST);
308−
309− model.cache.gl = gl;
310− model.cache.canvas = canvas;
311− model.cache.shaders = [];
312− model.cache.programs = {};
313− model.cache.buffers = [];
314− model.cache.textures = [];
315−
316− update(div, model, model);
317−
318− return div;
319−
320− }
321−
322− function update(div, oldModel, newModel) {
323−
324− newModel.cache = oldModel.cache;
325−
326− var canvas = newModel.cache.canvas;
327−
328− canvas.style.width = oldModel.w + 'px';
329− canvas.style.height = oldModel.h + 'px';
330− canvas.style.display = "block";
331− canvas.style.position = "absolute";
332− canvas.width = oldModel.w;
333− canvas.height = oldModel.h;
334−
335− drawGL(newModel);
336−
337− div.appendChild(canvas);
338−
339− }
340−
341− var elem = {
342− ctor: 'Custom',
343− type: 'WebGL',
344− render: render,
345− update: update,
346− model: {
347− models: models,
348− cache: {},
349− w: w,
350− h: h
351− }
352− };
353−
354− return A3(newElement, w, h, elem);
355−
356− }
357−
358− return elm.Native.Graphics.WebGL.values = {
359− unsafeCoerceGLSL:unsafeCoerceGLSL,
360− loadTex:loadTex,
361− model:F4(model),
362− webgl:F2(webgl)
363− };
364−
365−};
libraries/Native/MJS.jsdeleted−1789
@@ -1,1789 +0,0 @@
1−
2−/*
3− * Copyright (c) 2010 Mozilla Corporation
4− * Copyright (c) 2010 Vladimir Vukicevic
5− * Copyright (c) 2013 John Mayer
6− *
7− * Permission is hereby granted, free of charge, to any person
8− * obtaining a copy of this software and associated documentation
9− * files (the "Software"), to deal in the Software without
10− * restriction, including without limitation the rights to use,
11− * copy, modify, merge, publish, distribute, sublicense, and/or sell
12− * copies of the Software, and to permit persons to whom the
13− * Software is furnished to do so, subject to the following
14− * conditions:
15− *
16− * The above copyright notice and this permission notice shall be
17− * included in all copies or substantial portions of the Software.
18− *
19− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20− * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21− * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22− * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23− * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24− * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25− * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26− * OTHER DEALINGS IN THE SOFTWARE.
27− */
28−
29−/*
30− * File: mjs
31− *
32− * Vector and Matrix math utilities for JavaScript, optimized for WebGL.
33− * Edited to work with the Elm Programming Language
34− */
35−
36−Elm.Native.MJS = {};
37−Elm.Native.MJS.make = function(elm) {
38−
39− elm.Native = elm.Native || {};
40− elm.Native.MJS = elm.Native.MJS || {};
41− if (elm.Native.MJS.values) return elm.Native.MJS.values;
42−
43− /*
44− * Constant: MJS_VERSION
45− *
46− * mjs version number aa.bb.cc, encoded as an integer of the form:
47− * 0xaabbcc.
48− */
49− var MJS_VERSION = 0x000000;
50−
51− /*
52− * Constant: MJS_DO_ASSERT
53− *
54− * Enables or disables runtime assertions.
55− *
56− * For potentially more performance, the assert methods can be
57− * commented out in each place where they are called.
58− */
59− // var MJS_DO_ASSERT = false;
60−
61− /*
62− * Constant: MJS_FLOAT_ARRAY_TYPE
63− *
64− * The base float array type. By default, WebGLFloatArray.
65− *
66− * mjs can work with any array-like elements, but if an array
67− * creation is requested, it will create an array of the type
68− * MJS_FLOAT_ARRAY_TYPE. Also, the builtin constants such as (M4x4.I)
69− * will be of this type.
70− */
71− //MJS_FLOAT_ARRAY_TYPE = WebGLFloatArray;
72− var MJS_FLOAT_ARRAY_TYPE = Float32Array;
73− //MJS_FLOAT_ARRAY_TYPE = Float64Array;
74− //MJS_FLOAT_ARRAY_TYPE = Array;
75−
76− /*
77− if (MJS_DO_ASSERT) {
78− function MathUtils_assert(cond, msg) {
79− if (!cond) {
80− throw "Assertion failed: " + msg;
81− }
82− }
83− } else {
84− */
85− function MathUtils_assert() { }
86− //}
87−
88− /*
89− * Class: V3
90− *
91− * Methods for working with 3-element vectors. A vector is represented by a 3-element array.
92− * Any valid JavaScript array type may be used, but if new
93− * vectors are created they are created using the configured MJS_FLOAT_ARRAY_TYPE.
94− */
95−
96− var V3 = { };
97−
98− V3._temp1 = new MJS_FLOAT_ARRAY_TYPE(3);
99− V3._temp2 = new MJS_FLOAT_ARRAY_TYPE(3);
100− V3._temp3 = new MJS_FLOAT_ARRAY_TYPE(3);
101−
102− if (MJS_FLOAT_ARRAY_TYPE == Array) {
103− V3.x = [1.0, 0.0, 0.0];
104− V3.y = [0.0, 1.0, 0.0];
105− V3.z = [0.0, 0.0, 1.0];
106−
107− V3.$ = function V3_$(x, y, z) {
108− return [x, y, z];
109− };
110− } else {
111− V3.x = new MJS_FLOAT_ARRAY_TYPE([1.0, 0.0, 0.0]);
112− V3.y = new MJS_FLOAT_ARRAY_TYPE([0.0, 1.0, 0.0]);
113− V3.z = new MJS_FLOAT_ARRAY_TYPE([0.0, 0.0, 1.0]);
114−
115− /*
116− * Function: V3.$
117− *
118− * Creates a new 3-element vector with the given values.
119− *
120− * Parameters:
121− *
122− * x,y,z - the 3 elements of the new vector.
123− *
124− * Returns:
125− *
126− * A new vector containing with the given argument values.
127− */
128−
129− V3.$ = function V3_$(x, y, z) {
130− return new MJS_FLOAT_ARRAY_TYPE([x, y, z]);
131− };
132− }
133−
134− V3.u = V3.x;
135− V3.v = V3.y;
136−
137− V3.getX = function V3_getX(a) {
138− return a[0];
139− }
140− V3.getY = function V3_getY(a) {
141− return a[1];
142− }
143− V3.getZ = function V3_getZ(a) {
144− return a[2];
145− }
146− V3.setX = function V3_setX(x, a) {
147− return new MJS_FLOAT_ARRAY_TYPE(x, a[1], a[2]);
148− }
149− V3.setY = function V3_setY(y, a) {
150− return new MJS_FLOAT_ARRAY_TYPE(a[0], y, a[2]);
151− }
152− V3.setZ = function V3_setZ(z, a) {
153− return new MJS_FLOAT_ARRAY_TYPE(a[0], a[1], z);
154− }
155−
156− V3.toTuple3 = function V3_toTuple3(a) {
157− return {
158− ctor:"_Tuple3",
159− _0:a[0],
160− _1:a[1],
161− _2:a[2]
162− };
163− };
164− V3.fromTuple3 = function V3_fromTuple3(t) {
165− return new MJS_FLOAT_ARRAY_TYPE([t._0, t._1, t._2]);
166− };
167−
168− V3.toRecord3 = function V3_toRecord3(a) {
169− return {
170− _:{},
171− x:a[0],
172− y:a[1],
173− z:a[2]
174− };
175− };
176− V3.fromRecord3 = function V3_fromRecord3(r) {
177− return new MJS_FLOAT_ARRAY_TYPE([r.x, r.y, r.z]);
178− };
179−
180− /*
181− * Function: V3.add
182− *
183− * Perform r = a + b.
184− *
185− * Parameters:
186− *
187− * a - the first vector operand
188− * b - the second vector operand
189− * r - optional vector to store the result in
190− *
191− * Returns:
192− *
193− * If r is specified, returns r after performing the operation.
194− * Otherwise, returns a new 3-element vector with the result.
195− */
196− V3.add = function V3_add(a, b, r) {
197− //MathUtils_assert(a.length == 3, "a.length == 3");
198− //MathUtils_assert(b.length == 3, "b.length == 3");
199− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
200−
201− if (r == undefined)
202− r = new MJS_FLOAT_ARRAY_TYPE(3);
203− r[0] = a[0] + b[0];
204− r[1] = a[1] + b[1];
205− r[2] = a[2] + b[2];
206− return r;
207− };
208−
209− /*
210− * Function: V3.sub
211− *
212− * Perform
213− * r = a - b.
214− *
215− * Parameters:
216− *
217− * a - the first vector operand
218− * b - the second vector operand
219− * r - optional vector to store the result in
220− *
221− * Returns:
222− *
223− * If r is specified, returns r after performing the operation.
224− * Otherwise, returns a new 3-element vector with the result.
225− */
226− V3.sub = function V3_sub(a, b, r) {
227− //MathUtils_assert(a.length == 3, "a.length == 3");
228− //MathUtils_assert(b.length == 3, "b.length == 3");
229− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
230−
231− if (r == undefined)
232− r = new MJS_FLOAT_ARRAY_TYPE(3);
233− r[0] = a[0] - b[0];
234− r[1] = a[1] - b[1];
235− r[2] = a[2] - b[2];
236− return r;
237− };
238−
239− /*
240− * Function: V3.neg
241− *
242− * Perform
243− * r = - a.
244− *
245− * Parameters:
246− *
247− * a - the vector operand
248− * r - optional vector to store the result in
249− *
250− * Returns:
251− *
252− * If r is specified, returns r after performing the operation.
253− * Otherwise, returns a new 3-element vector with the result.
254− */
255− V3.neg = function V3_neg(a, r) {
256− //MathUtils_assert(a.length == 3, "a.length == 3");
257− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
258−
259− if (r == undefined)
260− r = new MJS_FLOAT_ARRAY_TYPE(3);
261− r[0] = - a[0];
262− r[1] = - a[1];
263− r[2] = - a[2];
264− return r;
265− };
266−
267− /*
268− * Function: V3.direction
269− *
270− * Perform
271− * r = (a - b) / |a - b|. The result is the normalized
272− * direction from a to b.
273− *
274− * Parameters:
275− *
276− * a - the first vector operand
277− * b - the second vector operand
278− * r - optional vector to store the result in
279− *
280− * Returns:
281− *
282− * If r is specified, returns r after performing the operation.
283− * Otherwise, returns a new 3-element vector with the result.
284− */
285− V3.direction = function V3_direction(a, b, r) {
286− //MathUtils_assert(a.length == 3, "a.length == 3");
287− //MathUtils_assert(b.length == 3, "b.length == 3");
288− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
289−
290− if (r == undefined)
291− r = new MJS_FLOAT_ARRAY_TYPE(3);
292− return V3.normalize(V3.sub(a, b, r), r);
293− };
294−
295− /*
296− * Function: V3.length
297− *
298− * Perform r = |a|.
299− *
300− * Parameters:
301− *
302− * a - the vector operand
303− *
304− * Returns:
305− *
306− * The length of the given vector.
307− */
308− V3.length = function V3_length(a) {
309− //MathUtils_assert(a.length == 3, "a.length == 3");
310−
311− return Math.sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
312− };
313−
314− /*
315− * Function: V3.lengthSquard
316− *
317− * Perform r = |a|*|a|.
318− *
319− * Parameters:
320− *
321− * a - the vector operand
322− *
323− * Returns:
324− *
325− * The square of the length of the given vector.
326− */
327− V3.lengthSquared = function V3_lengthSquared(a) {
328− //MathUtils_assert(a.length == 3, "a.length == 3");
329−
330− return a[0]*a[0] + a[1]*a[1] + a[2]*a[2];
331− };
332−
333− V3.distance = function V3_distance(a, b) {
334− var dx = a[0] - b[0];
335− var dy = a[1] - b[1];
336− var dz = a[2] - b[2];
337− return Math.sqrt(dx * dx + dy * dy + dz * dz);
338− };
339−
340− V3.distanceSquared = function V3_distanceSquared(a) {
341− var dx = a[0] - b[0];
342− var dy = a[1] - b[1];
343− var dz = a[2] - b[2];
344− return dx * dx + dy * dy + dz * dz;
345− };
346−
347− /*
348− * Function: V3.normalize
349− *
350− * Perform r = a / |a|.
351− *
352− * Parameters:
353− *
354− * a - the vector operand
355− * r - optional vector to store the result in
356− *
357− * Returns:
358− *
359− * If r is specified, returns r after performing the operation.
360− * Otherwise, returns a new 3-element vector with the result.
361− */
362− V3.normalize = function V3_normalize(a, r) {
363− //MathUtils_assert(a.length == 3, "a.length == 3");
364− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
365−
366− if (r == undefined)
367− r = new MJS_FLOAT_ARRAY_TYPE(3);
368− var im = 1.0 / V3.length(a);
369− r[0] = a[0] * im;
370− r[1] = a[1] * im;
371− r[2] = a[2] * im;
372− return r;
373− };
374−
375− /*
376− * Function: V3.scale
377− *
378− * Perform r = a * k.
379− *
380− * Parameters:
381− *
382− * a - the vector operand
383− * k - a scalar value
384− * r - optional vector to store the result in
385− *
386− * Returns:
387− *
388− * If r is specified, returns r after performing the operation.
389− * Otherwise, returns a new 3-element vector with the result.
390− */
391− V3.scale = function V3_scale(a, k, r) {
392− //MathUtils_assert(a.length == 3, "a.length == 3");
393− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
394−
395− if (r == undefined)
396− r = new MJS_FLOAT_ARRAY_TYPE(3);
397− r[0] = a[0] * k;
398− r[1] = a[1] * k;
399− r[2] = a[2] * k;
400− return r;
401− };
402−
403− /*
404− * Function: V3.dot
405− *
406− * Perform
407− * r = dot(a, b).
408− *
409− * Parameters:
410− *
411− * a - the first vector operand
412− * b - the second vector operand
413− *
414− * Returns:
415− *
416− * The dot product of a and b.
417− */
418− V3.dot = function V3_dot(a, b) {
419− //MathUtils_assert(a.length == 3, "a.length == 3");
420− //MathUtils_assert(b.length == 3, "b.length == 3");
421−
422− return a[0] * b[0] +
423− a[1] * b[1] +
424− a[2] * b[2];
425− };
426−
427− /*
428− * Function: V3.cross
429− *
430− * Perform r = a x b.
431− *
432− * Parameters:
433− *
434− * a - the first vector operand
435− * b - the second vector operand
436− * r - optional vector to store the result in
437− *
438− * Returns:
439− *
440− * If r is specified, returns r after performing the operation.
441− * Otherwise, returns a new 3-element vector with the result.
442− */
443− V3.cross = function V3_cross(a, b, r) {
444− //MathUtils_assert(a.length == 3, "a.length == 3");
445− //MathUtils_assert(b.length == 3, "b.length == 3");
446− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
447−
448− if (r == undefined)
449− r = new MJS_FLOAT_ARRAY_TYPE(3);
450− r[0] = a[1]*b[2] - a[2]*b[1];
451− r[1] = a[2]*b[0] - a[0]*b[2];
452− r[2] = a[0]*b[1] - a[1]*b[0];
453− return r;
454− };
455−
456− /*
457− * Function: V3.mul4x4
458− *
459− * Perform
460− * r = m * v.
461− *
462− * Parameters:
463− *
464− * m - the 4x4 matrix operand
465− * v - the 3-element vector operand
466− * r - optional vector to store the result in
467− *
468− * Returns:
469− *
470− * If r is specified, returns r after performing the operation.
471− * Otherwise, returns a new 3-element vector with the result.
472− * The 4-element result vector is divided by the w component
473− * and returned as a 3-element vector.
474− */
475− V3.mul4x4 = function V3_mul4x4(m, v, r) {
476− //MathUtils_assert(m.length == 16, "m.length == 16");
477− //MathUtils_assert(v.length == 3, "v.length == 3");
478− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
479−
480− var w;
481− var tmp = V3._temp1;
482− if (r == undefined)
483− r = new MJS_FLOAT_ARRAY_TYPE(3);
484− tmp[0] = m[ 3];
485− tmp[1] = m[ 7];
486− tmp[2] = m[11];
487− w = V3.dot(v, tmp) + m[15];
488− tmp[0] = m[ 0];
489− tmp[1] = m[ 4];
490− tmp[2] = m[ 8];
491− r[0] = (V3.dot(v, tmp) + m[12])/w;
492− tmp[0] = m[ 1];
493− tmp[1] = m[ 5];
494− tmp[2] = m[ 9];
495− r[1] = (V3.dot(v, tmp) + m[13])/w;
496− tmp[0] = m[ 2];
497− tmp[1] = m[ 6];
498− tmp[2] = m[10];
499− r[2] = (V3.dot(v, tmp) + m[14])/w;
500− return r;
501− };
502−
503− /*
504− * Class: M4x4
505− *
506− * Methods for working with 4x4 matrices. A matrix is represented by a 16-element array
507− * in column-major order. Any valid JavaScript array type may be used, but if new
508− * matrices are created they are created using the configured MJS_FLOAT_ARRAY_TYPE.
509− */
510−
511− var M4x4 = { };
512−
513− M4x4._temp1 = new MJS_FLOAT_ARRAY_TYPE(16);
514− M4x4._temp2 = new MJS_FLOAT_ARRAY_TYPE(16);
515−
516− if (MJS_FLOAT_ARRAY_TYPE == Array) {
517− M4x4.I = [1.0, 0.0, 0.0, 0.0,
518− 0.0, 1.0, 0.0, 0.0,
519− 0.0, 0.0, 1.0, 0.0,
520− 0.0, 0.0, 0.0, 1.0];
521−
522− M4x4.$ = function M4x4_$(m00, m01, m02, m03,
523− m04, m05, m06, m07,
524− m08, m09, m10, m11,
525− m12, m13, m14, m15)
526− {
527− return [m00, m01, m02, m03,
528− m04, m05, m06, m07,
529− m08, m09, m10, m11,
530− m12, m13, m14, m15];
531− };
532− } else {
533− M4x4.I = new MJS_FLOAT_ARRAY_TYPE([1.0, 0.0, 0.0, 0.0,
534− 0.0, 1.0, 0.0, 0.0,
535− 0.0, 0.0, 1.0, 0.0,
536− 0.0, 0.0, 0.0, 1.0]);
537−
538− /*
539− * Function: M4x4.$
540− *
541− * Creates a new 4x4 matrix with the given values.
542− *
543− * Parameters:
544− *
545− * m00..m15 - the 16 elements of the new matrix.
546− *
547− * Returns:
548− *
549− * A new matrix filled with the given argument values.
550− */
551− M4x4.$ = function M4x4_$(m00, m01, m02, m03,
552− m04, m05, m06, m07,
553− m08, m09, m10, m11,
554− m12, m13, m14, m15)
555− {
556− return new MJS_FLOAT_ARRAY_TYPE([m00, m01, m02, m03,
557− m04, m05, m06, m07,
558− m08, m09, m10, m11,
559− m12, m13, m14, m15]);
560− };
561− }
562−
563− M4x4.identity = M4x4.I;
564−
565− /*
566− * Function: M4x4.topLeft3x3
567− *
568− * Return the top left 3x3 matrix from the given 4x4 matrix m.
569− *
570− * Parameters:
571− *
572− * m - the matrix
573− * r - optional 3x3 matrix to store the result in
574− *
575− * Returns:
576− *
577− * If r is specified, returns r after performing the operation.
578− * Otherwise, returns a new 3x3 matrix with the result.
579− */
580− M4x4.topLeft3x3 = function M4x4_topLeft3x3(m, r) {
581− //MathUtils_assert(m.length == 16, "m.length == 16");
582− //MathUtils_assert(r == undefined || r.length == 9, "r == undefined || r.length == 9");
583−
584− if (r == undefined)
585− r = new MJS_FLOAT_ARRAY_TYPE(9);
586− r[0] = m[0]; r[1] = m[1]; r[2] = m[2];
587− r[3] = m[4]; r[4] = m[5]; r[5] = m[6];
588− r[6] = m[8]; r[7] = m[9]; r[8] = m[10];
589− return r;
590− };
591−
592− /*
593− * Function: M4x4.inverseOrthonormal
594− *
595− * Computes the inverse of the given matrix m, assuming that
596− * the matrix is orthonormal.
597− *
598− * Parameters:
599− *
600− * m - the matrix
601− * r - optional 4x4 matrix to store the result in
602− *
603− * Returns:
604− *
605− * If r is specified, returns r after performing the operation.
606− * Otherwise, returns a new 4x4 matrix with the result.
607− */
608− M4x4.inverseOrthonormal = function M4x4_inverseOrthonormal(m, r) {
609− //MathUtils_assert(m.length == 16, "m.length == 16");
610− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
611− //MathUtils_assert(m != r, "m != r");
612−
613− if (r == undefined)
614− r = new MJS_FLOAT_ARRAY_TYPE(16);
615− M4x4.transpose(m, r);
616− var t = [m[12], m[13], m[14]];
617− r[3] = r[7] = r[11] = 0;
618− r[12] = -V3.dot([r[0], r[4], r[8]], t);
619− r[13] = -V3.dot([r[1], r[5], r[9]], t);
620− r[14] = -V3.dot([r[2], r[6], r[10]], t);
621− return r;
622− };
623−
624− /*
625− * Function: M4x4.inverseTo3x3
626− *
627− * Computes the inverse of the given matrix m, but calculates
628− * only the top left 3x3 values of the result.
629− *
630− * Parameters:
631− *
632− * m - the matrix
633− * r - optional 3x3 matrix to store the result in
634− *
635− * Returns:
636− *
637− * If r is specified, returns r after performing the operation.
638− * Otherwise, returns a new 3x3 matrix with the result.
639− */
640− M4x4.inverseTo3x3 = function M4x4_inverseTo3x3(m, r) {
641− //MathUtils_assert(m.length == 16, "m.length == 16");
642− //MathUtils_assert(r == undefined || r.length == 9, "r == undefined || r.length == 9");
643−
644− if (r == undefined)
645− r = new MJS_FLOAT_ARRAY_TYPE(9);
646−
647− var a11 = m[10]*m[5]-m[6]*m[9],
648− a21 = -m[10]*m[1]+m[2]*m[9],
649− a31 = m[6]*m[1]-m[2]*m[5],
650− a12 = -m[10]*m[4]+m[6]*m[8],
651− a22 = m[10]*m[0]-m[2]*m[8],
652− a32 = -m[6]*m[0]+m[2]*m[4],
653− a13 = m[9]*m[4]-m[5]*m[8],
654− a23 = -m[9]*m[0]+m[1]*m[8],
655− a33 = m[5]*m[0]-m[1]*m[4];
656− var det = m[0]*(a11) + m[1]*(a12) + m[2]*(a13);
657− if (det == 0) // no inverse
658− throw "matrix not invertible";
659− var idet = 1.0 / det;
660−
661− r[0] = idet*a11;
662− r[1] = idet*a21;
663− r[2] = idet*a31;
664− r[3] = idet*a12;
665− r[4] = idet*a22;
666− r[5] = idet*a32;
667− r[6] = idet*a13;
668− r[7] = idet*a23;
669− r[8] = idet*a33;
670−
671− return r;
672− };
673−
674− /*
675− * Function: M4x4.makeFrustum
676− *
677− * Creates a matrix for a projection frustum with the given parameters.
678− *
679− * Parameters:
680− *
681− * left - the left coordinate of the frustum
682− * right- the right coordinate of the frustum
683− * bottom - the bottom coordinate of the frustum
684− * top - the top coordinate of the frustum
685− * znear - the near z distance of the frustum
686− * zfar - the far z distance of the frustum
687− * r - optional 4x4 matrix to store the result in
688− *
689− * Returns:
690− *
691− * If r is specified, returns r after creating the projection matrix.
692− * Otherwise, returns a new 4x4 matrix.
693− */
694− M4x4.makeFrustum = function M4x4_makeFrustum(left, right, bottom, top, znear, zfar, r) {
695− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
696−
697− if (r == undefined)
698− r = new MJS_FLOAT_ARRAY_TYPE(16);
699−
700− var X = 2*znear/(right-left);
701− var Y = 2*znear/(top-bottom);
702− var A = (right+left)/(right-left);
703− var B = (top+bottom)/(top-bottom);
704− var C = -(zfar+znear)/(zfar-znear);
705− var D = -2*zfar*znear/(zfar-znear);
706−
707− r[0] = 2*znear/(right-left);
708− r[1] = 0;
709− r[2] = 0;
710− r[3] = 0;
711− r[4] = 0;
712− r[5] = 2*znear/(top-bottom);
713− r[6] = 0;
714− r[7] = 0;
715− r[8] = (right+left)/(right-left);
716− r[9] = (top+bottom)/(top-bottom);
717− r[10] = -(zfar+znear)/(zfar-znear);
718− r[11] = -1;
719− r[12] = 0;
720− r[13] = 0;
721− r[14] = -2*zfar*znear/(zfar-znear);
722− r[15] = 0;
723−
724− return r;
725− };
726−
727− /*
728− * Function: M4x4.makePerspective
729− *
730− * Creates a matrix for a perspective projection with the given parameters.
731− *
732− * Parameters:
733− *
734− * fovy - field of view in the y axis, in degrees
735− * aspect - aspect ratio
736− * znear - the near z distance of the projection
737− * zfar - the far z distance of the projection
738− * r - optional 4x4 matrix to store the result in
739− *
740− * Returns:
741− *
742− * If r is specified, returns r after creating the projection matrix.
743− * Otherwise, returns a new 4x4 matrix.
744− */
745− M4x4.makePerspective = function M4x4_makePerspective (fovy, aspect, znear, zfar, r) {
746− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
747−
748− var ymax = znear * Math.tan(fovy * Math.PI / 360.0);
749− var ymin = -ymax;
750− var xmin = ymin * aspect;
751− var xmax = ymax * aspect;
752−
753− return M4x4.makeFrustum(xmin, xmax, ymin, ymax, znear, zfar, r);
754− };
755−
756− /*
757− * Function: M4x4.makeOrtho
758− *
759− * Creates a matrix for an orthogonal frustum projection with the given parameters.
760− *
761− * Parameters:
762− *
763− * left - the left coordinate of the frustum
764− * right- the right coordinate of the frustum
765− * bottom - the bottom coordinate of the frustum
766− * top - the top coordinate of the frustum
767− * znear - the near z distance of the frustum
768− * zfar - the far z distance of the frustum
769− * r - optional 4x4 matrix to store the result in
770− *
771− * Returns:
772− *
773− * If r is specified, returns r after creating the projection matrix.
774− * Otherwise, returns a new 4x4 matrix.
775− */
776− M4x4.makeOrtho = function M4x4_makeOrtho (left, right, bottom, top, znear, zfar, r) {
777− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
778−
779− if (r == undefined)
780− r = new MJS_FLOAT_ARRAY_TYPE(16);
781−
782− var tX = -(right+left)/(right-left);
783− var tY = -(top+bottom)/(top-bottom);
784− var tZ = -(zfar+znear)/(zfar-znear);
785− var X = 2 / (right-left);
786− var Y = 2 / (top-bottom);
787− var Z = -2 / (zfar-znear);
788−
789− r[0] = 2 / (right-left);
790− r[1] = 0;
791− r[2] = 0;
792− r[3] = 0;
793− r[4] = 0;
794− r[5] = 2 / (top-bottom);
795− r[6] = 0;
796− r[7] = 0;
797− r[8] = 0;
798− r[9] = 0;
799− r[10] = -2 / (zfar-znear);
800− r[11] = 0;
801− r[12] = -(right+left)/(right-left);
802− r[13] = -(top+bottom)/(top-bottom);
803− r[14] = -(zfar+znear)/(zfar-znear);
804− r[15] = 1;
805−
806− return r;
807− };
808−
809− /*
810− * Function: M4x4.makeOrtho2D
811− *
812− * Creates a matrix for a 2D orthogonal frustum projection with the given parameters.
813− * znear and zfar are assumed to be -1 and 1, respectively.
814− *
815− * Parameters:
816− *
817− * left - the left coordinate of the frustum
818− * right- the right coordinate of the frustum
819− * bottom - the bottom coordinate of the frustum
820− * top - the top coordinate of the frustum
821− * r - optional 4x4 matrix to store the result in
822− *
823− * Returns:
824− *
825− * If r is specified, returns r after creating the projection matrix.
826− * Otherwise, returns a new 4x4 matrix.
827− */
828− M4x4.makeOrtho2D = function M4x4_makeOrtho2D (left, right, bottom, top, r) {
829− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
830−
831− return M4x4.makeOrtho(left, right, bottom, top, -1, 1, r);
832− };
833−
834− /*
835− * Function: M4x4.mul
836− *
837− * Performs r = a * b.
838− *
839− * Parameters:
840− *
841− * a - the first matrix operand
842− * b - the second matrix operand
843− * r - optional 4x4 matrix to store the result in
844− *
845− * Returns:
846− *
847− * If r is specified, returns r after performing the operation.
848− * Otherwise, returns a new 4x4 matrix with the result.
849− */
850− M4x4.mul = function M4x4_mul(a, b, r) {
851− //MathUtils_assert(a.length == 16, "a.length == 16");
852− //MathUtils_assert(b.length == 16, "b.length == 16");
853− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
854− //MathUtils_assert(a != r && b != r, "a != r && b != r");
855−
856− if (r == undefined)
857− r = new MJS_FLOAT_ARRAY_TYPE(16);
858−
859− var a11 = a[0];
860− var a21 = a[1];
861− var a31 = a[2];
862− var a41 = a[3];
863− var a12 = a[4];
864− var a22 = a[5];
865− var a32 = a[6];
866− var a42 = a[7];
867− var a13 = a[8];
868− var a23 = a[9];
869− var a33 = a[10];
870− var a43 = a[11];
871− var a14 = a[12];
872− var a24 = a[13];
873− var a34 = a[14];
874− var a44 = a[15];
875−
876− var b11 = b[0];
877− var b21 = b[1];
878− var b31 = b[2];
879− var b41 = b[3];
880− var b12 = b[4];
881− var b22 = b[5];
882− var b32 = b[6];
883− var b42 = b[7];
884− var b13 = b[8];
885− var b23 = b[9];
886− var b33 = b[10];
887− var b43 = b[11];
888− var b14 = b[12];
889− var b24 = b[13];
890− var b34 = b[14];
891− var b44 = b[15];
892−
893− r[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
894− r[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
895− r[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
896− r[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
897− r[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
898− r[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
899− r[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
900− r[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
901− r[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
902− r[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
903− r[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
904− r[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
905− r[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
906− r[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
907− r[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
908− r[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
909−
910− return r;
911− };
912−
913− /*
914− * Function: M4x4.mulAffine
915− *
916− * Performs r = a * b, assuming a and b are affine (elements 3,7,11,15 = 0,0,0,1)
917− *
918− * Parameters:
919− *
920− * a - the first matrix operand
921− * b - the second matrix operand
922− * r - optional 4x4 matrix to store the result in
923− *
924− * Returns:
925− *
926− * If r is specified, returns r after performing the operation.
927− * Otherwise, returns a new 4x4 matrix with the result.
928− */
929− M4x4.mulAffine = function M4x4_mulAffine(a, b, r) {
930− //MathUtils_assert(a.length == 16, "a.length == 16");
931− //MathUtils_assert(b.length == 16, "b.length == 16");
932− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
933− //MathUtils_assert(a != r && b != r, "a != r && b != r");
934−
935− if (r == undefined)
936− r = new MJS_FLOAT_ARRAY_TYPE(16);
937− var a11 = a[0];
938− var a21 = a[1];
939− var a31 = a[2];
940− var a12 = a[4];
941− var a22 = a[5];
942− var a32 = a[6];
943− var a13 = a[8];
944− var a23 = a[9];
945− var a33 = a[10];
946− var a14 = a[12];
947− var a24 = a[13];
948− var a34 = a[14];
949−
950− var b11 = b[0];
951− var b21 = b[1];
952− var b31 = b[2];
953− var b12 = b[4];
954− var b22 = b[5];
955− var b32 = b[6];
956− var b13 = b[8];
957− var b23 = b[9];
958− var b33 = b[10];
959− var b14 = b[12];
960− var b24 = b[13];
961− var b34 = b[14];
962−
963− r[0] = a11 * b11 + a12 * b21 + a13 * b31;
964− r[1] = a21 * b11 + a22 * b21 + a23 * b31;
965− r[2] = a31 * b11 + a32 * b21 + a33 * b31;
966− r[3] = 0;
967− r[4] = a11 * b12 + a12 * b22 + a13 * b32;
968− r[5] = a21 * b12 + a22 * b22 + a23 * b32;
969− r[6] = a31 * b12 + a32 * b22 + a33 * b32;
970− r[7] = 0;
971− r[8] = a11 * b13 + a12 * b23 + a13 * b33;
972− r[9] = a21 * b13 + a22 * b23 + a23 * b33;
973− r[10] = a31 * b13 + a32 * b23 + a33 * b33;
974− r[11] = 0;
975− r[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14;
976− r[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24;
977− r[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34;
978− r[15] = 1;
979−
980− return r;
981− };
982−
983− /*
984− * Function: M4x4.makeRotate
985− *
986− * Creates a transformation matrix for rotation by angle radians about the 3-element vector axis.
987− *
988− * Parameters:
989− *
990− * angle - the angle of rotation, in radians
991− * axis - the axis around which the rotation is performed, a 3-element vector
992− * r - optional 4x4 matrix to store the result in
993− *
994− * Returns:
995− *
996− * If r is specified, returns r after creating the matrix.
997− * Otherwise, returns a new 4x4 matrix with the result.
998− */
999− M4x4.makeRotate = function M4x4_makeRotate(angle, axis, r) {
1000− //MathUtils_assert(angle.length == 3, "angle.length == 3");
1001− //MathUtils_assert(axis.length == 3, "axis.length == 3");
1002− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1003−
1004− if (r == undefined)
1005− r = new MJS_FLOAT_ARRAY_TYPE(16);
1006−
1007− axis = V3.normalize(axis, V3._temp1);
1008− var x = axis[0], y = axis[1], z = axis[2];
1009− var c = Math.cos(angle);
1010− var c1 = 1-c;
1011− var s = Math.sin(angle);
1012−
1013− r[0] = x*x*c1+c;
1014− r[1] = y*x*c1+z*s;
1015− r[2] = z*x*c1-y*s;
1016− r[3] = 0;
1017− r[4] = x*y*c1-z*s;
1018− r[5] = y*y*c1+c;
1019− r[6] = y*z*c1+x*s;
1020− r[7] = 0;
1021− r[8] = x*z*c1+y*s;
1022− r[9] = y*z*c1-x*s;
1023− r[10] = z*z*c1+c;
1024− r[11] = 0;
1025− r[12] = 0;
1026− r[13] = 0;
1027− r[14] = 0;
1028− r[15] = 1;
1029−
1030− return r;
1031− };
1032−
1033− /*
1034− * Function: M4x4.rotate
1035− *
1036− * Concatenates a rotation of angle radians about the axis to the give matrix m.
1037− *
1038− * Parameters:
1039− *
1040− * angle - the angle of rotation, in radians
1041− * axis - the axis around which the rotation is performed, a 3-element vector
1042− * m - the matrix to concatenate the rotation to
1043− * r - optional 4x4 matrix to store the result in
1044− *
1045− * Returns:
1046− *
1047− * If r is specified, returns r after performing the operation.
1048− * Otherwise, returns a new 4x4 matrix with the result.
1049− */
1050− M4x4.rotate = function M4x4_rotate(angle, axis, m, r) {
1051− //MathUtils_assert(angle.length == 3, "angle.length == 3");
1052− //MathUtils_assert(axis.length == 3, "axis.length == 3");
1053− //MathUtils_assert(m.length == 16, "m.length == 16");
1054− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1055−
1056− if (r == undefined)
1057− r = new MJS_FLOAT_ARRAY_TYPE(16);
1058− var a0=axis [0], a1=axis [1], a2=axis [2];
1059− var l = Math.sqrt(a0*a0 + a1*a1 + a2*a2);
1060− var x = a0, y = a1, z = a2;
1061− if (l != 1.0) {
1062− var im = 1.0 / l;
1063− x *= im;
1064− y *= im;
1065− z *= im;
1066− }
1067− var c = Math.cos(angle);
1068− var c1 = 1-c;
1069− var s = Math.sin(angle);
1070− var xs = x*s;
1071− var ys = y*s;
1072− var zs = z*s;
1073− var xyc1 = x * y * c1;
1074− var xzc1 = x * z * c1;
1075− var yzc1 = y * z * c1;
1076−
1077− var m11 = m[0];
1078− var m21 = m[1];
1079− var m31 = m[2];
1080− var m41 = m[3];
1081− var m12 = m[4];
1082− var m22 = m[5];
1083− var m32 = m[6];
1084− var m42 = m[7];
1085− var m13 = m[8];
1086− var m23 = m[9];
1087− var m33 = m[10];
1088− var m43 = m[11];
1089−
1090− var t11 = x * x * c1 + c;
1091− var t21 = xyc1 + zs;
1092− var t31 = xzc1 - ys;
1093− var t12 = xyc1 - zs;
1094− var t22 = y * y * c1 + c;
1095− var t32 = yzc1 + xs;
1096− var t13 = xzc1 + ys;
1097− var t23 = yzc1 - xs;
1098− var t33 = z * z * c1 + c;
1099−
1100− r[0] = m11 * t11 + m12 * t21 + m13 * t31;
1101− r[1] = m21 * t11 + m22 * t21 + m23 * t31;
1102− r[2] = m31 * t11 + m32 * t21 + m33 * t31;
1103− r[3] = m41 * t11 + m42 * t21 + m43 * t31;
1104− r[4] = m11 * t12 + m12 * t22 + m13 * t32;
1105− r[5] = m21 * t12 + m22 * t22 + m23 * t32;
1106− r[6] = m31 * t12 + m32 * t22 + m33 * t32;
1107− r[7] = m41 * t12 + m42 * t22 + m43 * t32;
1108− r[8] = m11 * t13 + m12 * t23 + m13 * t33;
1109− r[9] = m21 * t13 + m22 * t23 + m23 * t33;
1110− r[10] = m31 * t13 + m32 * t23 + m33 * t33;
1111− r[11] = m41 * t13 + m42 * t23 + m43 * t33;
1112− if (r != m) {
1113− r[12] = m[12];
1114− r[13] = m[13];
1115− r[14] = m[14];
1116− r[15] = m[15];
1117− }
1118− return r;
1119− };
1120−
1121− /*
1122− * Function: M4x4.makeScale3
1123− *
1124− * Creates a transformation matrix for scaling by 3 scalar values, one for
1125− * each of the x, y, and z directions.
1126− *
1127− * Parameters:
1128− *
1129− * x - the scale for the x axis
1130− * y - the scale for the y axis
1131− * z - the scale for the z axis
1132− * r - optional 4x4 matrix to store the result in
1133− *
1134− * Returns:
1135− *
1136− * If r is specified, returns r after creating the matrix.
1137− * Otherwise, returns a new 4x4 matrix with the result.
1138− */
1139− M4x4.makeScale3 = function M4x4_makeScale3(x, y, z, r) {
1140− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1141−
1142− if (r == undefined)
1143− r = new MJS_FLOAT_ARRAY_TYPE(16);
1144−
1145− r[0] = x;
1146− r[1] = 0;
1147− r[2] = 0;
1148− r[3] = 0;
1149− r[4] = 0;
1150− r[5] = y;
1151− r[6] = 0;
1152− r[7] = 0;
1153− r[8] = 0;
1154− r[9] = 0;
1155− r[10] = z;
1156− r[11] = 0;
1157− r[12] = 0;
1158− r[13] = 0;
1159− r[14] = 0;
1160− r[15] = 1;
1161−
1162− return r;
1163− };
1164−
1165− /*
1166− * Function: M4x4.makeScale1
1167− *
1168− * Creates a transformation matrix for a uniform scale by a single scalar value.
1169− *
1170− * Parameters:
1171− *
1172− * k - the scale factor
1173− * r - optional 4x4 matrix to store the result in
1174− *
1175− * Returns:
1176− *
1177− * If r is specified, returns r after creating the matrix.
1178− * Otherwise, returns a new 4x4 matrix with the result.
1179− */
1180− M4x4.makeScale1 = function M4x4_makeScale1(k, r) {
1181− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1182−
1183− return M4x4.makeScale3(k, k, k, r);
1184− };
1185−
1186− /*
1187− * Function: M4x4.makeScale
1188− *
1189− * Creates a transformation matrix for scaling each of the x, y, and z axes by the amount
1190− * given in the corresponding element of the 3-element vector.
1191− *
1192− * Parameters:
1193− *
1194− * v - the 3-element vector containing the scale factors
1195− * r - optional 4x4 matrix to store the result in
1196− *
1197− * Returns:
1198− *
1199− * If r is specified, returns r after creating the matrix.
1200− * Otherwise, returns a new 4x4 matrix with the result.
1201− */
1202− M4x4.makeScale = function M4x4_makeScale(v, r) {
1203− //MathUtils_assert(v.length == 3, "v.length == 3");
1204− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1205−
1206− return M4x4.makeScale3(v[0], v[1], v[2], r);
1207− };
1208−
1209− /*
1210− * Function: M4x4.scale3
1211− */
1212− M4x4.scale3 = function M4x4_scale3(x, y, z, m, r) {
1213− //MathUtils_assert(m.length == 16, "m.length == 16");
1214− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1215−
1216− if (r == m) {
1217− m[0] *= x;
1218− m[1] *= x;
1219− m[2] *= x;
1220− m[3] *= x;
1221− m[4] *= y;
1222− m[5] *= y;
1223− m[6] *= y;
1224− m[7] *= y;
1225− m[8] *= z;
1226− m[9] *= z;
1227− m[10] *= z;
1228− m[11] *= z;
1229− return m;
1230− }
1231−
1232− if (r == undefined)
1233− r = new MJS_FLOAT_ARRAY_TYPE(16);
1234−
1235− r[0] = m[0] * x;
1236− r[1] = m[1] * x;
1237− r[2] = m[2] * x;
1238− r[3] = m[3] * x;
1239− r[4] = m[4] * y;
1240− r[5] = m[5] * y;
1241− r[6] = m[6] * y;
1242− r[7] = m[7] * y;
1243− r[8] = m[8] * z;
1244− r[9] = m[9] * z;
1245− r[10] = m[10] * z;
1246− r[11] = m[11] * z;
1247− r[12] = m[12];
1248− r[13] = m[13];
1249− r[14] = m[14];
1250− r[15] = m[15];
1251−
1252− return r;
1253− };
1254−
1255− /*
1256− * Function: M4x4.scale1
1257− */
1258− M4x4.scale1 = function M4x4_scale1(k, m, r) {
1259− //MathUtils_assert(m.length == 16, "m.length == 16");
1260− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1261− if (r == m) {
1262− m[0] *= k;
1263− m[1] *= k;
1264− m[2] *= k;
1265− m[3] *= k;
1266− m[4] *= k;
1267− m[5] *= k;
1268− m[6] *= k;
1269− m[7] *= k;
1270− m[8] *= k;
1271− m[9] *= k;
1272− m[10] *= k;
1273− m[11] *= k;
1274− return m;
1275− }
1276−
1277−
1278− if (r == undefined)
1279− r = new MJS_FLOAT_ARRAY_TYPE(16);
1280−
1281− r[0] = m[0] * k;
1282− r[1] = m[1] * k;
1283− r[2] = m[2] * k;
1284− r[3] = m[3] * k;
1285− r[4] = m[4] * k;
1286− r[5] = m[5] * k;
1287− r[6] = m[6] * k;
1288− r[7] = m[7] * k;
1289− r[8] = m[8] * k;
1290− r[9] = m[9] * k;
1291− r[10] = m[10] * k;
1292− r[11] = m[11] * k;
1293− r[12] = m[12];
1294− r[13] = m[13];
1295− r[14] = m[14];
1296− r[15] = m[15];
1297−
1298− return r;
1299− };
1300−
1301− /*
1302− * Function: M4x4.scale1
1303− */
1304− M4x4.scale = function M4x4_scale(v, m, r) {
1305− //MathUtils_assert(v.length == 3, "v.length == 3");
1306− //MathUtils_assert(m.length == 16, "m.length == 16");
1307− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1308− var x = v[0], y = v[1], z = v[2];
1309−
1310− if (r == m) {
1311− m[0] *= x;
1312− m[1] *= x;
1313− m[2] *= x;
1314− m[3] *= x;
1315− m[4] *= y;
1316− m[5] *= y;
1317− m[6] *= y;
1318− m[7] *= y;
1319− m[8] *= z;
1320− m[9] *= z;
1321− m[10] *= z;
1322− m[11] *= z;
1323− return m;
1324− }
1325−
1326− if (r == undefined)
1327− r = new MJS_FLOAT_ARRAY_TYPE(16);
1328−
1329−
1330− r[0] = m[0] * x;
1331− r[1] = m[1] * x;
1332− r[2] = m[2] * x;
1333− r[3] = m[3] * x;
1334− r[4] = m[4] * y;
1335− r[5] = m[5] * y;
1336− r[6] = m[6] * y;
1337− r[7] = m[7] * y;
1338− r[8] = m[8] * z;
1339− r[9] = m[9] * z;
1340− r[10] = m[10] * z;
1341− r[11] = m[11] * z;
1342− r[12] = m[12];
1343− r[13] = m[13];
1344− r[14] = m[14];
1345− r[15] = m[15];
1346−
1347− return r;
1348− };
1349−
1350− /*
1351− * Function: M4x4.makeTranslate3
1352− */
1353− M4x4.makeTranslate3 = function M4x4_makeTranslate3(x, y, z, r) {
1354− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1355−
1356− if (r == undefined)
1357− r = new MJS_FLOAT_ARRAY_TYPE(16);
1358−
1359− r[0] = 1;
1360− r[1] = 0;
1361− r[2] = 0;
1362− r[3] = 0;
1363− r[4] = 0;
1364− r[5] = 1;
1365− r[6] = 0;
1366− r[7] = 0;
1367− r[8] = 0;
1368− r[9] = 0;
1369− r[10] = 1;
1370− r[11] = 0;
1371− r[12] = x;
1372− r[13] = y;
1373− r[14] = z;
1374− r[15] = 1;
1375−
1376− return r;
1377− };
1378−
1379− /*
1380− * Function: M4x4.makeTranslate1
1381− */
1382− M4x4.makeTranslate1 = function M4x4_makeTranslate1 (k, r) {
1383− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1384−
1385− return M4x4.makeTranslate3(k, k, k, r);
1386− };
1387−
1388− /*
1389− * Function: M4x4.makeTranslate
1390− */
1391− M4x4.makeTranslate = function M4x4_makeTranslate (v, r) {
1392− //MathUtils_assert(v.length == 3, "v.length == 3");
1393− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1394−
1395− return M4x4.makeTranslate3(v[0], v[1], v[2], r);
1396− };
1397−
1398− /*
1399− * Function: M4x4.translate3Self
1400− */
1401− M4x4.translate3Self = function M4x4_translate3Self (x, y, z, m) {
1402− //MathUtils_assert(m.length == 16, "m.length == 16");
1403− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1404− m[12] += m[0] * x + m[4] * y + m[8] * z;
1405− m[13] += m[1] * x + m[5] * y + m[9] * z;
1406− m[14] += m[2] * x + m[6] * y + m[10] * z;
1407− m[15] += m[3] * x + m[7] * y + m[11] * z;
1408− return m;
1409− };
1410−
1411− /*
1412− * Function: M4x4.translate3
1413− */
1414− M4x4.translate3 = function M4x4_translate3 (x, y, z, m, r) {
1415− //MathUtils_assert(m.length == 16, "m.length == 16");
1416− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1417−
1418− if (r == m) {
1419− m[12] += m[0] * x + m[4] * y + m[8] * z;
1420− m[13] += m[1] * x + m[5] * y + m[9] * z;
1421− m[14] += m[2] * x + m[6] * y + m[10] * z;
1422− m[15] += m[3] * x + m[7] * y + m[11] * z;
1423− return m;
1424− }
1425−
1426− if (r == undefined)
1427− r = new MJS_FLOAT_ARRAY_TYPE(16);
1428−
1429− var m11 = m[0];
1430− var m21 = m[1];
1431− var m31 = m[2];
1432− var m41 = m[3];
1433− var m12 = m[4];
1434− var m22 = m[5];
1435− var m32 = m[6];
1436− var m42 = m[7];
1437− var m13 = m[8];
1438− var m23 = m[9];
1439− var m33 = m[10];
1440− var m43 = m[11];
1441−
1442−
1443− r[0] = m11;
1444− r[1] = m21;
1445− r[2] = m31;
1446− r[3] = m41;
1447− r[4] = m12;
1448− r[5] = m22;
1449− r[6] = m32;
1450− r[7] = m42;
1451− r[8] = m13;
1452− r[9] = m23;
1453− r[10] = m33;
1454− r[11] = m43;
1455− r[12] = m11 * x + m12 * y + m13 * z + m[12];
1456− r[13] = m21 * x + m22 * y + m23 * z + m[13];
1457− r[14] = m31 * x + m32 * y + m33 * z + m[14];
1458− r[15] = m41 * x + m42 * y + m43 * z + m[15];
1459−
1460− return r;
1461− };
1462−
1463− /*
1464− * Function: M4x4.translate1
1465− */
1466− M4x4.translate1 = function M4x4_translate1 (k, m, r) {
1467− //MathUtils_assert(m.length == 16, "m.length == 16");
1468− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1469−
1470− return M4x4.translate3(k, k, k, m, r);
1471− };
1472− /*
1473− * Function: M4x4.translateSelf
1474− */
1475− M4x4.translateSelf = function M4x4_translateSelf (v, m) {
1476− //MathUtils_assert(v.length == 3, "v.length == 3");
1477− //MathUtils_assert(m.length == 16, "m.length == 16");
1478− var x=v[0], y=v[1], z=v[2];
1479− m[12] += m[0] * x + m[4] * y + m[8] * z;
1480− m[13] += m[1] * x + m[5] * y + m[9] * z;
1481− m[14] += m[2] * x + m[6] * y + m[10] * z;
1482− m[15] += m[3] * x + m[7] * y + m[11] * z;
1483− return m;
1484− };
1485− /*
1486− * Function: M4x4.translate
1487− */
1488− M4x4.translate = function M4x4_translate (v, m, r) {
1489− //MathUtils_assert(v.length == 3, "v.length == 3");
1490− //MathUtils_assert(m.length == 16, "m.length == 16");
1491− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1492− var x=v[0], y=v[1], z=v[2];
1493− if (r == m) {
1494− m[12] += m[0] * x + m[4] * y + m[8] * z;
1495− m[13] += m[1] * x + m[5] * y + m[9] * z;
1496− m[14] += m[2] * x + m[6] * y + m[10] * z;
1497− m[15] += m[3] * x + m[7] * y + m[11] * z;
1498− return m;
1499− }
1500−
1501− if (r == undefined)
1502− r = new MJS_FLOAT_ARRAY_TYPE(16);
1503−
1504− var m11 = m[0];
1505− var m21 = m[1];
1506− var m31 = m[2];
1507− var m41 = m[3];
1508− var m12 = m[4];
1509− var m22 = m[5];
1510− var m32 = m[6];
1511− var m42 = m[7];
1512− var m13 = m[8];
1513− var m23 = m[9];
1514− var m33 = m[10];
1515− var m43 = m[11];
1516−
1517− r[0] = m11;
1518− r[1] = m21;
1519− r[2] = m31;
1520− r[3] = m41;
1521− r[4] = m12;
1522− r[5] = m22;
1523− r[6] = m32;
1524− r[7] = m42;
1525− r[8] = m13;
1526− r[9] = m23;
1527− r[10] = m33;
1528− r[11] = m43;
1529− r[12] = m11 * x + m12 * y + m13 * z + m[12];
1530− r[13] = m21 * x + m22 * y + m23 * z + m[13];
1531− r[14] = m31 * x + m32 * y + m33 * z + m[14];
1532− r[15] = m41 * x + m42 * y + m43 * z + m[15];
1533−
1534− return r;
1535− };
1536−
1537− /*
1538− * Function: M4x4.makeLookAt
1539− */
1540− M4x4.makeLookAt = function M4x4_makeLookAt (eye, center, up, r) {
1541− //MathUtils_assert(eye.length == 3, "eye.length == 3");
1542− //MathUtils_assert(center.length == 3, "center.length == 3");
1543− //MathUtils_assert(up.length == 3, "up.length == 3");
1544− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1545−
1546− var z = V3.direction(eye, center, V3._temp1);
1547− var x = V3.normalize(V3.cross(up, z, V3._temp2), V3._temp2);
1548− var y = V3.normalize(V3.cross(z, x, V3._temp3), V3._temp3);
1549−
1550− var tm1 = M4x4._temp1;
1551− var tm2 = M4x4._temp2;
1552−
1553− tm1[0] = x[0];
1554− tm1[1] = y[0];
1555− tm1[2] = z[0];
1556− tm1[3] = 0;
1557− tm1[4] = x[1];
1558− tm1[5] = y[1];
1559− tm1[6] = z[1];
1560− tm1[7] = 0;
1561− tm1[8] = x[2];
1562− tm1[9] = y[2];
1563− tm1[10] = z[2];
1564− tm1[11] = 0;
1565− tm1[12] = 0;
1566− tm1[13] = 0;
1567− tm1[14] = 0;
1568− tm1[15] = 1;
1569−
1570− tm2[0] = 1; tm2[1] = 0; tm2[2] = 0; tm2[3] = 0;
1571− tm2[4] = 0; tm2[5] = 1; tm2[6] = 0; tm2[7] = 0;
1572− tm2[8] = 0; tm2[9] = 0; tm2[10] = 1; tm2[11] = 0;
1573− tm2[12] = -eye[0]; tm2[13] = -eye[1]; tm2[14] = -eye[2]; tm2[15] = 1;
1574−
1575− if (r == undefined)
1576− r = new MJS_FLOAT_ARRAY_TYPE(16);
1577− return M4x4.mul(tm1, tm2, r);
1578− };
1579−
1580− /*
1581− * Function: M4x4.transposeSelf
1582− */
1583− M4x4.transposeSelf = function M4x4_transposeSelf (m) {
1584− //MathUtils_assert(m.length == 16, "m.length == 16");
1585− var tmp = m[1]; m[1] = m[4]; m[4] = tmp;
1586− tmp = m[2]; m[2] = m[8]; m[8] = tmp;
1587− tmp = m[3]; m[3] = m[12]; m[12] = tmp;
1588− tmp = m[6]; m[6] = m[9]; m[9] = tmp;
1589− tmp = m[7]; m[7] = m[13]; m[13] = tmp;
1590− tmp = m[11]; m[11] = m[14]; m[14] = tmp;
1591− return m;
1592− };
1593− /*
1594− * Function: M4x4.transpose
1595− */
1596− M4x4.transpose = function M4x4_transpose (m, r) {
1597− //MathUtils_assert(m.length == 16, "m.length == 16");
1598− //MathUtils_assert(r == undefined || r.length == 16, "r == undefined || r.length == 16");
1599−
1600− if (m == r) {
1601− var tmp = 0.0;
1602− tmp = m[1]; m[1] = m[4]; m[4] = tmp;
1603− tmp = m[2]; m[2] = m[8]; m[8] = tmp;
1604− tmp = m[3]; m[3] = m[12]; m[12] = tmp;
1605− tmp = m[6]; m[6] = m[9]; m[9] = tmp;
1606− tmp = m[7]; m[7] = m[13]; m[13] = tmp;
1607− tmp = m[11]; m[11] = m[14]; m[14] = tmp;
1608− return m;
1609− }
1610−
1611− if (r == undefined)
1612− r = new MJS_FLOAT_ARRAY_TYPE(16);
1613−
1614− r[0] = m[0]; r[1] = m[4]; r[2] = m[8]; r[3] = m[12];
1615− r[4] = m[1]; r[5] = m[5]; r[6] = m[9]; r[7] = m[13];
1616− r[8] = m[2]; r[9] = m[6]; r[10] = m[10]; r[11] = m[14];
1617− r[12] = m[3]; r[13] = m[7]; r[14] = m[11]; r[15] = m[15];
1618−
1619− return r;
1620− };
1621−
1622−
1623− /*
1624− * Function: M4x4.transformPoint
1625− */
1626− M4x4.transformPoint = function M4x4_transformPoint (m, v, r) {
1627− //MathUtils_assert(m.length == 16, "m.length == 16");
1628− //MathUtils_assert(v.length == 3, "v.length == 3");
1629− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
1630− if (r == undefined)
1631− r = new MJS_FLOAT_ARRAY_TYPE(3);
1632−
1633− var v0 = v[0], v1 = v[1], v2 = v[2];
1634−
1635− r[0] = m[0] * v0 + m[4] * v1 + m[8] * v2 + m[12];
1636− r[1] = m[1] * v0 + m[5] * v1 + m[9] * v2 + m[13];
1637− r[2] = m[2] * v0 + m[6] * v1 + m[10] * v2 + m[14];
1638− var w = m[3] * v0 + m[7] * v1 + m[11] * v2 + m[15];
1639−
1640− if (w != 1.0) {
1641− r[0] /= w;
1642− r[1] /= w;
1643− r[2] /= w;
1644− }
1645−
1646− return r;
1647− };
1648−
1649− /*
1650− * Function: M4x4.transformLine
1651− */
1652− M4x4.transformLine = function M4x4_transformLine(m, v, r) {
1653− //MathUtils_assert(m.length == 16, "m.length == 16");
1654− //MathUtils_assert(v.length == 3, "v.length == 3");
1655− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
1656− if (r == undefined)
1657− r = new MJS_FLOAT_ARRAY_TYPE(3);
1658−
1659− var v0 = v[0], v1 = v[1], v2 = v[2];
1660− r[0] = m[0] * v0 + m[4] * v1 + m[8] * v2;
1661− r[1] = m[1] * v0 + m[5] * v1 + m[9] * v2;
1662− r[2] = m[2] * v0 + m[6] * v1 + m[10] * v2;
1663− var w = m[3] * v0 + m[7] * v1 + m[11] * v2;
1664−
1665− if (w != 1.0) {
1666− r[0] /= w;
1667− r[1] /= w;
1668− r[2] /= w;
1669− }
1670−
1671− return r;
1672− };
1673−
1674−
1675− /*
1676− * Function: M4x4.transformPointAffine
1677− */
1678− M4x4.transformPointAffine = function M4x4_transformPointAffine (m, v, r) {
1679− //MathUtils_assert(m.length == 16, "m.length == 16");
1680− //MathUtils_assert(v.length == 3, "v.length == 3");
1681− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
1682− if (r == undefined)
1683− r = new MJS_FLOAT_ARRAY_TYPE(3);
1684−
1685− var v0 = v[0], v1 = v[1], v2 = v[2];
1686−
1687− r[0] = m[0] * v0 + m[4] * v1 + m[8] * v2 + m[12];
1688− r[1] = m[1] * v0 + m[5] * v1 + m[9] * v2 + m[13];
1689− r[2] = m[2] * v0 + m[6] * v1 + m[10] * v2 + m[14];
1690−
1691− return r;
1692− };
1693−
1694− /*
1695− * Function: M4x4.transformLineAffine
1696− */
1697− M4x4.transformLineAffine = function M4x4_transformLineAffine(m, v, r) {
1698− //MathUtils_assert(m.length == 16, "m.length == 16");
1699− //MathUtils_assert(v.length == 3, "v.length == 3");
1700− //MathUtils_assert(r == undefined || r.length == 3, "r == undefined || r.length == 3");
1701− if (r == undefined)
1702− r = new MJS_FLOAT_ARRAY_TYPE(3);
1703−
1704− var v0 = v[0], v1 = v[1], v2 = v[2];
1705− r[0] = m[0] * v0 + m[4] * v1 + m[8] * v2;
1706− r[1] = m[1] * v0 + m[5] * v1 + m[9] * v2;
1707− r[2] = m[2] * v0 + m[6] * v1 + m[10] * v2;
1708−
1709− return r;
1710− };
1711−
1712− M4x4.makeBasis = function M4x4_makeBasis(vx,vy,vz) {
1713−
1714− var r = new MJS_FLOAT_ARRAY_TYPE(16);
1715−
1716− r[0] = vx[0];
1717− r[1] = vx[1];
1718− r[2] = vx[2];
1719− r[3] = 0;
1720− r[4] = vy[0];
1721− r[5] = vy[1];
1722− r[6] = vy[2];
1723− r[7] = 0;
1724− r[8] = vz[0];
1725− r[9] = vz[1];
1726− r[10] = vz[2];
1727− r[11] = 0;
1728− r[12] = 0;
1729− r[13] = 0;
1730− r[14] = 0;
1731− r[15] = 1;
1732−
1733− return r;
1734−
1735− };
1736−
1737− return {
1738− v3: F3(V3.$),
1739− v3getX: V3.getX,
1740− v3getY: V3.getY,
1741− v3getZ: V3.getZ,
1742− v3setX: F2(V3.setX),
1743− v3setY: F2(V3.setY),
1744− v3setZ: F2(V3.setZ),
1745− toTuple3: V3.toTuple3,
1746− toRecord3: V3.toRecord3,
1747− fromTuple3: V3.fromTuple3,
1748− fromRecord3: V3.fromRecord3,
1749− v3add: F2(V3.add),
1750− v3sub: F2(V3.sub),
1751− v3neg: V3.neg,
1752− v3direction: F2(V3.direction),
1753− v3length: V3.length,
1754− v3lengthSquared: V3.lengthSquared,
1755− v3distance: F2(V3.distance),
1756− v3distanceSquared: F2(V3.distanceSquared),
1757− v3normalize: V3.normalize,
1758− v3scale: F2(V3.scale),
1759− v3dot: F2(V3.dot),
1760− v3cross: F2(V3.cross),
1761− v3mul4x4: F2(V3.mul4x4),
1762− m4x4identity: M4x4.identity,
1763− m4x4topLeft3x3: M4x4.topLeft3x3,
1764− m4x4inverseOrthonormal: M4x4.inverseOrthonormal,
1765− m4x4inverseTo3x3: M4x4.inverseTo3x3,
1766− m4x4makeFrustum: F6(M4x4.makeFrustum),
1767− m4x4makePerspective: F4(M4x4.makePerspective),
1768− m4x4makeOrtho: F6(M4x4.makeOrtho),
1769− m4x4makeOrtho2D: F4(M4x4.makeOrtho2D),
1770− m4x4mul: F2(M4x4.mul),
1771− m4x4Affine: F2(M4x4.mulAffine),
1772− m4x4makeRotate: F2(M4x4.makeRotate),
1773− m4x4rotate: F3(M4x4.rotate),
1774− m4x4makeScale3: F3(M4x4.makeScale3),
1775− m4x4makeScale1: M4x4.makeScale1,
1776− m4x4makeScale: M4x4.makeScale,
1777− m4x4scale3: F4(M4x4.scale3),
1778− m4x4scale: F2(M4x4.scale),
1779− m4x4makeTranslate3: F3(M4x4.makeTranslate3),
1780− m4x4makeTranslate: M4x4.makeTranslate,
1781− m4x4translate3: F4(M4x4.translate3),
1782− m4x4translate: F2(M4x4.translate),
1783− m4x4makeLookAt: F3(M4x4.makeLookAt),
1784− m4x4transpose: M4x4.transpose,
1785− m4x4transformPoint: F2(M4x4.transformPoint),
1786− m4x4makeBasis: F3(M4x4.makeBasis)
1787− };
1788−
1789−}
libraries/Native/Math/Vector2.jsdeleted−186
@@ -1,186 +0,0 @@
1−
2−/*
3− * Copyright (c) 2010 Mozilla Corporation
4− * Copyright (c) 2010 Vladimir Vukicevic
5− *
6− * Permission is hereby granted, free of charge, to any person
7− * obtaining a copy of this software and associated documentation
8− * files (the "Software"), to deal in the Software without
9− * restriction, including without limitation the rights to use,
10− * copy, modify, merge, publish, distribute, sublicense, and/or sell
11− * copies of the Software, and to permit persons to whom the
12− * Software is furnished to do so, subject to the following
13− * conditions:
14− *
15− * The above copyright notice and this permission notice shall be
16− * included in all copies or substantial portions of the Software.
17− *
18− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19− * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20− * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21− * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22− * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23− * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24− * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25− * OTHER DEALINGS IN THE SOFTWARE.
26− */
27−
28−/*
29− * File: mjs
30− *
31− * Vector and Matrix math utilities for JavaScript, optimized for WebGL.
32− * Edited to work with the Elm Programming Language
33− */
34−
35−Elm.Native.Math = Elm.Native.Math || {};
36−Elm.Native.Math.Vector2 = {};
37−Elm.Native.Math.Vector2.make = function(elm) {
38−
39− elm.Native = elm.Native || {};
40− elm.Native.Math = elm.Native.Math || {};
41− elm.Native.Math.Vector2 = elm.Native.Math.Vector2 || {};
42− if (elm.Native.Math.Vector2.values) return elm.Native.Math.Vector2.values;
43−
44− var MJS_FLOAT_ARRAY_TYPE = Float32Array;
45−
46− var V2 = { };
47−
48− if (MJS_FLOAT_ARRAY_TYPE == Array) {
49− V2.$ = function V2_$(x, y) {
50− return [x, y];
51− };
52− } else {
53− V2.$ = function V2_$(x, y) {
54− return new MJS_FLOAT_ARRAY_TYPE([x, y]);
55− };
56− }
57−
58− V2.getX = function V2_getX(a) {
59− return a[0];
60− }
61− V2.getY = function V2_getY(a) {
62− return a[1];
63− }
64− V2.setX = function V2_setX(x, a) {
65− return new MJS_FLOAT_ARRAY_TYPE(x, a[1]);
66− }
67− V2.setY = function V2_setY(y, a) {
68− return new MJS_FLOAT_ARRAY_TYPE(a[0], y);
69− }
70−
71− V2.toTuple = function V2_toTuple(a) {
72− return {
73− ctor:"_Tuple2",
74− _0:a[0],
75− _1:a[1]
76− };
77− };
78− V2.fromTuple = function V2_fromTuple(t) {
79− return new MJS_FLOAT_ARRAY_TYPE([t._0, t._1]);
80− };
81−
82− V2.toRecord = function V2_toRecord(a) {
83− return {
84− _:{},
85− x:a[0],
86− y:a[1]
87− };
88− };
89− V2.fromRecord = function V2_fromRecord(r) {
90− return new MJS_FLOAT_ARRAY_TYPE([r.x, r.y]);
91− };
92−
93− V2.add = function V2_add(a, b) {
94− var r = new MJS_FLOAT_ARRAY_TYPE(2);
95− r[0] = a[0] + b[0];
96− r[1] = a[1] + b[1];
97− return r;
98− };
99−
100− V2.sub = function V2_sub(a, b) {
101− var r = new MJS_FLOAT_ARRAY_TYPE(2);
102− r[0] = a[0] - b[0];
103− r[1] = a[1] - b[1];
104− return r;
105− };
106−
107− V2.neg = function V2_neg(a) {
108− var r = new MJS_FLOAT_ARRAY_TYPE(2);
109− r[0] = - a[0];
110− r[1] = - a[1];
111− return r;
112− };
113−
114− V2.direction = function V2_direction(a, b) {
115− var r = new MJS_FLOAT_ARRAY_TYPE(2);
116− r[0] = a[0] - b[0];
117− r[1] = a[1] - b[1];
118− var im = 1.0 / V2.length(r);
119− r[0] = r[0] * im;
120− r[1] = r[1] * im;
121− return r;
122− };
123−
124− V2.length = function V2_length(a) {
125− return Math.sqrt(a[0]*a[0] + a[1]*a[1]);
126− };
127−
128− V2.lengthSquared = function V2_lengthSquared(a) {
129− return a[0]*a[0] + a[1]*a[1];
130− };
131−
132− V2.distance = function V2_distance(a, b) {
133− var dx = a[0] - b[0];
134− var dy = a[1] - b[1];
135− return Math.sqrt(dx * dx + dy * dy);
136− };
137−
138− V2.distanceSquared = function V2_distanceSquared(a) {
139− var dx = a[0] - b[0];
140− var dy = a[1] - b[1];
141− return dx * dx + dy * dy;
142− };
143−
144− V2.normalize = function V2_normalize(a) {
145− var r = new MJS_FLOAT_ARRAY_TYPE(2);
146− var im = 1.0 / V2.length(a);
147− r[0] = a[0] * im;
148− r[1] = a[1] * im;
149− return r;
150− };
151−
152− V2.scale = function V2_scale(a, k) {
153− var r = new MJS_FLOAT_ARRAY_TYPE(2);
154− r[0] = a[0] * k;
155− r[1] = a[1] * k;
156− return r;
157− };
158−
159− V2.dot = function V2_dot(a, b) {
160− return a[0] * b[0] + a[1] * b[1];
161− };
162−
163− return {
164− v2: F2(V2.$),
165− getX: V2.getX,
166− getY: V2.getY,
167− setX: F2(V2.setX),
168− setY: F2(V2.setY),
169− toTuple: V2.toTuple,
170− toRecord: V2.toRecord,
171− fromTuple: V2.fromTuple,
172− fromRecord: V2.fromRecord,
173− add: F2(V2.add),
174− sub: F2(V2.sub),
175− neg: V2.neg,
176− direction: F2(V2.direction),
177− length: V2.length,
178− lengthSquared: V2.lengthSquared,
179− distance: F2(V2.distance),
180− distanceSquared: F2(V2.distanceSquared),
181− normalize: V2.normalize,
182− scale: F2(V2.scale),
183− dot: F2(V2.dot)
184− };
185−
186−}
libraries/Native/Math/Vector4.jsdeleted−224
@@ -1,224 +0,0 @@
1−
2−/*
3− * Copyright (c) 2010 Mozilla Corporation
4− * Copyright (c) 2010 Vladimir Vukicevic
5− *
6− * Permission is hereby granted, free of charge, to any person
7− * obtaining a copy of this software and associated documentation
8− * files (the "Software"), to deal in the Software without
9− * restriction, including without limitation the rights to use,
10− * copy, modify, merge, publish, distribute, sublicense, and/or sell
11− * copies of the Software, and to permit persons to whom the
12− * Software is furnished to do so, subject to the following
13− * conditions:
14− *
15− * The above copyright notice and this permission notice shall be
16− * included in all copies or substantial portions of the Software.
17− *
18− * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19− * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20− * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21− * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22− * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23− * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24− * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25− * OTHER DEALINGS IN THE SOFTWARE.
26− */
27−
28−/*
29− * File: mjs
30− *
31− * Vector and Matrix math utilities for JavaScript, optimized for WebGL.
32− * Edited to work with the Elm Programming Language
33− */
34−
35−Elm.Native.Math = Elm.Native.Math || {};
36−Elm.Native.Math.Vector4 = {};
37−Elm.Native.Math.Vector4.make = function(elm) {
38−
39− elm.Native = elm.Native || {};
40− elm.Native.Math = elm.Native.Math || {};
41− elm.Native.Math.Vector4 = elm.Native.Math.Vector4 || {};
42− if (elm.Native.Math.Vector4.values) return elm.Native.Math.Vector4.values;
43−
44− var MJS_FLOAT_ARRAY_TYPE = Float32Array;
45−
46− var V4 = { };
47−
48− if (MJS_FLOAT_ARRAY_TYPE == Array) {
49− V4.$ = function V4_$(x, y, z, w) {
50− return [x, y, z, w];
51− };
52− } else {
53− V4.$ = function V4_$(x, y, z, w) {
54− return new MJS_FLOAT_ARRAY_TYPE([x, y, z, w]);
55− };
56− }
57−
58− V4.getX = function V4_getX(a) {
59− return a[0];
60− }
61− V4.getY = function V4_getY(a) {
62− return a[1];
63− }
64− V4.getZ = function V4_getZ(a) {
65− return a[2];
66− }
67− V4.getW = function V4_getW(a) {
68− return a[3];
69− }
70− V4.setX = function V4_setX(x, a) {
71− return new MJS_FLOAT_ARRAY_TYPE(x, a[1], a[2], a[3]);
72− }
73− V4.setY = function V4_setY(y, a) {
74− return new MJS_FLOAT_ARRAY_TYPE(a[0], y, a[2], a[3]);
75− }
76− V4.setZ = function V4_setZ(z, a) {
77− return new MJS_FLOAT_ARRAY_TYPE(a[0], a[1], z, a[3]);
78− }
79− V4.setW = function V4_setW(w, a) {
80− return new MJS_FLOAT_ARRAY_TYPE(a[0], a[1], a[2], w);
81− }
82−
83− V4.toTuple = function V4_toTuple(a) {
84− return {
85− ctor:"_Tuple4",
86− _0:a[0],
87− _1:a[1],
88− _2:a[2],
89− _3:a[3]
90− };
91− };
92− V4.fromTuple = function V4_fromTuple(t) {
93− return new MJS_FLOAT_ARRAY_TYPE([t._0, t._1, t._2, t._3]);
94− };
95−
96− V4.toRecord = function V4_toRecord(a) {
97− return {
98− _:{},
99− x:a[0],
100− y:a[1],
101− z:a[2],
102− w:a[3]
103− };
104− };
105− V4.fromRecord = function V4_fromRecord(r) {
106− return new MJS_FLOAT_ARRAY_TYPE([r.x, r.y, r.z, r.w]);
107− };
108−
109− V4.add = function V4_add(a, b) {
110− var r = new MJS_FLOAT_ARRAY_TYPE(4);
111− r[0] = a[0] + b[0];
112− r[1] = a[1] + b[1];
113− r[2] = a[2] + b[2];
114− r[3] = a[3] + b[3];
115− return r;
116− };
117−
118− V4.sub = function V4_sub(a, b) {
119− var r = new MJS_FLOAT_ARRAY_TYPE(4);
120− r[0] = a[0] - b[0];
121− r[1] = a[1] - b[1];
122− r[2] = a[2] - b[2];
123− r[3] = a[3] - b[3];
124− return r;
125− };
126−
127− V4.neg = function V4_neg(a) {
128− var r = new MJS_FLOAT_ARRAY_TYPE(4);
129− r[0] = - a[0];
130− r[1] = - a[1];
131− r[2] = - a[2];
132− r[3] = - a[3];
133− return r;
134− };
135−
136− V4.direction = function V4_direction(a, b) {
137− var r = new MJS_FLOAT_ARRAY_TYPE(4);
138− r[0] = a[0] - b[0];
139− r[1] = a[1] - b[1];
140− r[2] = a[2] - b[2];
141− r[3] = a[3] - b[3];
142− var im = 1.0 / V4.length(r);
143− r[0] = r[0] * im;
144− r[1] = r[1] * im;
145− r[2] = r[2] * im;
146− r[3] = r[3] * im;
147− return r;
148− };
149−
150− V4.length = function V4_length(a) {
151− return Math.sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2] + a[3]*a[3]);
152− };
153−
154− V4.lengthSquared = function V4_lengthSquared(a) {
155− return a[0]*a[0] + a[1]*a[1] + a[2]*a[2] + a[3]*a[3];
156− };
157−
158− V4.distance = function V4_distance(a, b) {
159− var dx = a[0] - b[0];
160− var dy = a[1] - b[1];
161− var dz = a[2] - b[2];
162− var dw = a[3] - b[3];
163− return Math.sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
164− };
165−
166− V4.distanceSquared = function V4_distanceSquared(a) {
167− var dx = a[0] - b[0];
168− var dy = a[1] - b[1];
169− var dz = a[2] - b[2];
170− var dw = a[3] - b[3];
171− return dx * dx + dy * dy + dz * dz + dw * dw;
172− };
173−
174− V4.normalize = function V4_normalize(a) {
175− var r = new MJS_FLOAT_ARRAY_TYPE(4);
176− var im = 1.0 / V4.length(a);
177− r[0] = a[0] * im;
178− r[1] = a[1] * im;
179− r[2] = a[2] * im;
180− r[3] = a[3] * im;
181− return r;
182− };
183−
184− V4.scale = function V4_scale(a, k) {
185− var r = new MJS_FLOAT_ARRAY_TYPE(4);
186− r[0] = a[0] * k;
187− r[1] = a[1] * k;
188− r[2] = a[2] * k;
189− r[3] = a[3] * k;
190− return r;
191− };
192−
193− V4.dot = function V4_dot(a, b) {
194− return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
195− };
196−
197− return {
198− v4: F4(V4.$),
199− getX: V4.getX,
200− getY: V4.getY,
201− getZ: V4.getZ,
202− getW: V4.getW,
203− setX: F2(V4.setX),
204− setY: F2(V4.setY),
205− setZ: F2(V4.setZ),
206− setW: F2(V4.setW),
207− toTuple: V4.toTuple,
208− toRecord: V4.toRecord,
209− fromTuple: V4.fromTuple,
210− fromRecord: V4.fromRecord,
211− add: F2(V4.add),
212− sub: F2(V4.sub),
213− neg: V4.neg,
214− direction: F2(V4.direction),
215− length: V4.length,
216− lengthSquared: V4.lengthSquared,
217− distance: F2(V4.distance),
218− distanceSquared: F2(V4.distanceSquared),
219− normalize: V4.normalize,
220− scale: F2(V4.scale),
221− dot: F2(V4.dot)
222− };
223−
224−}
libraries/elm_dependencies.json−2
@@ -18,7 +18,6 @@
1818 , "Graphics.Element"
1919 , "Graphics.Collage"
2020 , "Graphics.Input"
21− , "Graphics.WebGL"
2221 , "Graphics.Input.Field"
2322 , "Http"
2423 , "JavaScript.Experimental"
@@ -26,7 +25,6 @@
2625 , "Keyboard"
2726 , "List"
2827 , "Maybe"
29− , "MJS"
3028 , "Mouse"
3129 , "Random"
3230 , "Regex"