jax 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +18 -0
- data/Rakefile +2 -2
- data/lib/assets/javascripts/jax/{application.js.erb → application.js} +0 -4
- data/lib/assets/javascripts/jax/core.js +1 -1
- data/lib/assets/javascripts/jax/core/base.js.erb +4 -0
- data/lib/assets/javascripts/jax/core/glMatrix_ext/vec3.js +22 -0
- data/lib/assets/javascripts/jax/core/matrix_stack.js +1 -1
- data/lib/assets/javascripts/jax/mvc/model.js +18 -0
- data/lib/assets/javascripts/jax/vendor/{glMatrix.js → gl-matrix.js} +1 -1
- data/lib/assets/javascripts/jax/webgl.js +1 -1
- data/lib/assets/javascripts/jax/webgl/camera.js +24 -39
- data/lib/assets/javascripts/jax/webgl/scene/light_source.js +58 -29
- data/lib/jax/version.rb +1 -1
- data/spec/javascripts/jax/core/utils_spec.js +9 -0
- data/spec/javascripts/jax/webgl/camera_spec.js +25 -0
- data/spec/javascripts/jax/webgl/lighting_spec.js +17 -0
- data/spec/javascripts/vendor/gl_matrix_spec.js +90 -0
- data/vendor/assets/javascripts/gl-matrix-pdoc.js +705 -0
- data/vendor/assets/javascripts/gl-matrix.js +1924 -0
- metadata +48 -45
- data/vendor/assets/javascripts/glMatrix.js +0 -1772
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-02 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153721020 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153721020
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: jquery-rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153720420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.13
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153720420
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jasmine
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153719960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.0.2.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2153719960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rest-client
|
49
|
-
requirement: &
|
49
|
+
requirement: &2153719480 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.6.3
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2153719480
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &2153718920 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 2.6.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2153718920
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: coffee-rails
|
71
|
-
requirement: &
|
71
|
+
requirement: &2153718340 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 3.1.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2153718340
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: coderay
|
82
|
-
requirement: &
|
82
|
+
requirement: &2153717740 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 0.9.7
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2153717740
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: sqlite3
|
93
|
-
requirement: &
|
93
|
+
requirement: &2153717260 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 1.3.4
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2153717260
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: sass-rails
|
104
|
-
requirement: &
|
104
|
+
requirement: &2153716680 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 3.1.0
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *2153716680
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: uglifier
|
115
|
-
requirement: &
|
115
|
+
requirement: &2153716180 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ~>
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: 1.0.2
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *2153716180
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: genspec
|
126
|
-
requirement: &
|
126
|
+
requirement: &2153715720 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - ~>
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: 0.2.3
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *2153715720
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: selenium-webdriver
|
137
|
-
requirement: &
|
137
|
+
requirement: &2153715120 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ~>
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: 2.9.1
|
143
143
|
type: :development
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *2153715120
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: fakeweb
|
148
|
-
requirement: &
|
148
|
+
requirement: &2153714620 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ~>
|
@@ -153,10 +153,10 @@ dependencies:
|
|
153
153
|
version: 1.3.0
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *2153714620
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: ansi
|
159
|
-
requirement: &
|
159
|
+
requirement: &2153714240 !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|
162
162
|
- - ! '>='
|
@@ -164,10 +164,10 @@ dependencies:
|
|
164
164
|
version: '0'
|
165
165
|
type: :development
|
166
166
|
prerelease: false
|
167
|
-
version_requirements: *
|
167
|
+
version_requirements: *2153714240
|
168
168
|
- !ruby/object:Gem::Dependency
|
169
169
|
name: cucumber-rails
|
170
|
-
requirement: &
|
170
|
+
requirement: &2153713680 !ruby/object:Gem::Requirement
|
171
171
|
none: false
|
172
172
|
requirements:
|
173
173
|
- - ~>
|
@@ -175,10 +175,10 @@ dependencies:
|
|
175
175
|
version: 1.0.2
|
176
176
|
type: :development
|
177
177
|
prerelease: false
|
178
|
-
version_requirements: *
|
178
|
+
version_requirements: *2153713680
|
179
179
|
- !ruby/object:Gem::Dependency
|
180
180
|
name: RedCloth
|
181
|
-
requirement: &
|
181
|
+
requirement: &2153713040 !ruby/object:Gem::Requirement
|
182
182
|
none: false
|
183
183
|
requirements:
|
184
184
|
- - ~>
|
@@ -186,10 +186,10 @@ dependencies:
|
|
186
186
|
version: '4.2'
|
187
187
|
type: :development
|
188
188
|
prerelease: false
|
189
|
-
version_requirements: *
|
189
|
+
version_requirements: *2153713040
|
190
190
|
- !ruby/object:Gem::Dependency
|
191
191
|
name: w3c_validators
|
192
|
-
requirement: &
|
192
|
+
requirement: &2153712580 !ruby/object:Gem::Requirement
|
193
193
|
none: false
|
194
194
|
requirements:
|
195
195
|
- - ~>
|
@@ -197,10 +197,10 @@ dependencies:
|
|
197
197
|
version: '1.2'
|
198
198
|
type: :development
|
199
199
|
prerelease: false
|
200
|
-
version_requirements: *
|
200
|
+
version_requirements: *2153712580
|
201
201
|
- !ruby/object:Gem::Dependency
|
202
202
|
name: treetop
|
203
|
-
requirement: &
|
203
|
+
requirement: &2153712120 !ruby/object:Gem::Requirement
|
204
204
|
none: false
|
205
205
|
requirements:
|
206
206
|
- - ~>
|
@@ -208,10 +208,10 @@ dependencies:
|
|
208
208
|
version: 1.4.9
|
209
209
|
type: :development
|
210
210
|
prerelease: false
|
211
|
-
version_requirements: *
|
211
|
+
version_requirements: *2153712120
|
212
212
|
- !ruby/object:Gem::Dependency
|
213
213
|
name: bluecloth
|
214
|
-
requirement: &
|
214
|
+
requirement: &2153711500 !ruby/object:Gem::Requirement
|
215
215
|
none: false
|
216
216
|
requirements:
|
217
217
|
- - ~>
|
@@ -219,7 +219,7 @@ dependencies:
|
|
219
219
|
version: 2.0.11
|
220
220
|
type: :development
|
221
221
|
prerelease: false
|
222
|
-
version_requirements: *
|
222
|
+
version_requirements: *2153711500
|
223
223
|
description: ! "\n Framework for creating rich WebGL-enabled applications using
|
224
224
|
JavaScript and Ruby.\n Can be used stand-alone to create static JavaScript documents,
|
225
225
|
or integrated\n seamlessly with Ruby on Rails to build dynamic WebGL applications.\n
|
@@ -275,7 +275,7 @@ files:
|
|
275
275
|
- jax.gemspec
|
276
276
|
- lib/assets/javascripts/jax.js
|
277
277
|
- lib/assets/javascripts/jax/anim_frame.js
|
278
|
-
- lib/assets/javascripts/jax/application.js
|
278
|
+
- lib/assets/javascripts/jax/application.js
|
279
279
|
- lib/assets/javascripts/jax/builtin/all.js
|
280
280
|
- lib/assets/javascripts/jax/builtin/meshes/cube.js
|
281
281
|
- lib/assets/javascripts/jax/builtin/meshes/plane.js
|
@@ -316,7 +316,7 @@ files:
|
|
316
316
|
- lib/assets/javascripts/jax/prototype/core.js
|
317
317
|
- lib/assets/javascripts/jax/prototype/extensions.js
|
318
318
|
- lib/assets/javascripts/jax/vendor/ejs.js
|
319
|
-
- lib/assets/javascripts/jax/vendor/
|
319
|
+
- lib/assets/javascripts/jax/vendor/gl-matrix.js
|
320
320
|
- lib/assets/javascripts/jax/webgl.js
|
321
321
|
- lib/assets/javascripts/jax/webgl/camera.js
|
322
322
|
- lib/assets/javascripts/jax/webgl/cleanup.js
|
@@ -518,6 +518,7 @@ files:
|
|
518
518
|
- spec/javascripts/shaders/preprocessor_spec.js
|
519
519
|
- spec/javascripts/shaders/shadow_map_spec.js
|
520
520
|
- spec/javascripts/shaders/texture_spec.js
|
521
|
+
- spec/javascripts/vendor/gl_matrix_spec.js
|
521
522
|
- spec/lib/jax/commands/plugin_manager/credentials_spec.rb
|
522
523
|
- spec/lib/jax/commands/plugin_manager/push_spec.rb
|
523
524
|
- spec/lib/jax/commands/plugin_manager_spec.rb
|
@@ -576,7 +577,8 @@ files:
|
|
576
577
|
- templates/view.js.coffee.erb
|
577
578
|
- templates/view.js.erb
|
578
579
|
- vendor/assets/javascripts/ejs.js
|
579
|
-
- vendor/assets/javascripts/
|
580
|
+
- vendor/assets/javascripts/gl-matrix-pdoc.js
|
581
|
+
- vendor/assets/javascripts/gl-matrix.js
|
580
582
|
- vendor/assets/javascripts/jasmine.js
|
581
583
|
- vendor/assets/stylesheets/jasmine.css
|
582
584
|
- vendor/pdoc_template/html/assets/images/pdoc/alias.png
|
@@ -644,7 +646,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
644
646
|
version: '0'
|
645
647
|
segments:
|
646
648
|
- 0
|
647
|
-
hash:
|
649
|
+
hash: 2586210584584297927
|
648
650
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
649
651
|
none: false
|
650
652
|
requirements:
|
@@ -653,7 +655,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
653
655
|
version: '0'
|
654
656
|
segments:
|
655
657
|
- 0
|
656
|
-
hash:
|
658
|
+
hash: 2586210584584297927
|
657
659
|
requirements: []
|
658
660
|
rubyforge_project: jax
|
659
661
|
rubygems_version: 1.8.10
|
@@ -763,6 +765,7 @@ test_files:
|
|
763
765
|
- spec/javascripts/shaders/preprocessor_spec.js
|
764
766
|
- spec/javascripts/shaders/shadow_map_spec.js
|
765
767
|
- spec/javascripts/shaders/texture_spec.js
|
768
|
+
- spec/javascripts/vendor/gl_matrix_spec.js
|
766
769
|
- spec/lib/jax/commands/plugin_manager/credentials_spec.rb
|
767
770
|
- spec/lib/jax/commands/plugin_manager/push_spec.rb
|
768
771
|
- spec/lib/jax/commands/plugin_manager_spec.rb
|
@@ -1,1772 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* glMatrix.js - High performance matrix and vector operations for WebGL
|
3
|
-
* version 0.9.5
|
4
|
-
*/
|
5
|
-
|
6
|
-
/*
|
7
|
-
* Copyright (c) 2010 Brandon Jones
|
8
|
-
*
|
9
|
-
* This software is provided 'as-is', without any express or implied
|
10
|
-
* warranty. In no event will the authors be held liable for any damages
|
11
|
-
* arising from the use of this software.
|
12
|
-
*
|
13
|
-
* Permission is granted to anyone to use this software for any purpose,
|
14
|
-
* including commercial applications, and to alter it and redistribute it
|
15
|
-
* freely, subject to the following restrictions:
|
16
|
-
*
|
17
|
-
* 1. The origin of this software must not be misrepresented; you must not
|
18
|
-
* claim that you wrote the original software. If you use this software
|
19
|
-
* in a product, an acknowledgment in the product documentation would be
|
20
|
-
* appreciated but is not required.
|
21
|
-
*
|
22
|
-
* 2. Altered source versions must be plainly marked as such, and must not
|
23
|
-
* be misrepresented as being the original software.
|
24
|
-
*
|
25
|
-
* 3. This notice may not be removed or altered from any source
|
26
|
-
* distribution.
|
27
|
-
*/
|
28
|
-
|
29
|
-
// Fallback for systems that don't support WebGL
|
30
|
-
if(typeof Float32Array != 'undefined') {
|
31
|
-
glMatrixArrayType = Float32Array;
|
32
|
-
} else if(typeof WebGLFloatArray != 'undefined') {
|
33
|
-
glMatrixArrayType = WebGLFloatArray; // This is officially deprecated and should dissapear in future revisions.
|
34
|
-
} else {
|
35
|
-
glMatrixArrayType = Array;
|
36
|
-
}
|
37
|
-
|
38
|
-
/**
|
39
|
-
* vec3
|
40
|
-
* 3 Dimensional Vector
|
41
|
-
**/
|
42
|
-
var vec3 = {};
|
43
|
-
|
44
|
-
/**
|
45
|
-
* vec3.create([vec]) -> vec3
|
46
|
-
* - vec (vec3): optional vec3 containing values to initialize with
|
47
|
-
*
|
48
|
-
* Creates a new instance of a vec3 using the default array type
|
49
|
-
* Any javascript array containing at least 3 numeric elements can serve as a vec3
|
50
|
-
*
|
51
|
-
* Returns:
|
52
|
-
* New vec3
|
53
|
-
**/
|
54
|
-
vec3.create = function(vec) {
|
55
|
-
var dest = new glMatrixArrayType(3);
|
56
|
-
|
57
|
-
if(vec) {
|
58
|
-
dest[0] = vec[0];
|
59
|
-
dest[1] = vec[1];
|
60
|
-
dest[2] = vec[2];
|
61
|
-
}
|
62
|
-
|
63
|
-
return dest;
|
64
|
-
};
|
65
|
-
|
66
|
-
/**
|
67
|
-
* vec3.set(vec, dest) -> vec3
|
68
|
-
* - vec (vec3) : vec3 containing values to copy
|
69
|
-
* - dest (vec3) : vec3 receiving copied values
|
70
|
-
*
|
71
|
-
* Copies the values of one vec3 to another
|
72
|
-
*
|
73
|
-
* Returns:
|
74
|
-
* dest
|
75
|
-
**/
|
76
|
-
vec3.set = function(vec, dest) {
|
77
|
-
dest[0] = vec[0];
|
78
|
-
dest[1] = vec[1];
|
79
|
-
dest[2] = vec[2];
|
80
|
-
|
81
|
-
return dest;
|
82
|
-
};
|
83
|
-
|
84
|
-
/**
|
85
|
-
* vec3.add(vec, vec2[, dest]) -> vec3
|
86
|
-
* - vec (vec3) : first operand
|
87
|
-
* - vec2 (vec3) : second operand
|
88
|
-
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
89
|
-
*
|
90
|
-
* Performs a vector addition
|
91
|
-
*
|
92
|
-
* Returns:
|
93
|
-
* dest if specified, vec otherwise
|
94
|
-
**/
|
95
|
-
vec3.add = function(vec, vec2, dest) {
|
96
|
-
if(!dest || vec == dest) {
|
97
|
-
vec[0] += vec2[0];
|
98
|
-
vec[1] += vec2[1];
|
99
|
-
vec[2] += vec2[2];
|
100
|
-
return vec;
|
101
|
-
}
|
102
|
-
|
103
|
-
dest[0] = vec[0] + vec2[0];
|
104
|
-
dest[1] = vec[1] + vec2[1];
|
105
|
-
dest[2] = vec[2] + vec2[2];
|
106
|
-
return dest;
|
107
|
-
};
|
108
|
-
|
109
|
-
/**
|
110
|
-
* vec3.subtract(vec, vec2[, dest]) -> vec3
|
111
|
-
* - vec (vec3) : first operand
|
112
|
-
* - vec2 (vec3) : second operand
|
113
|
-
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
114
|
-
*
|
115
|
-
* Performs a vector subtraction
|
116
|
-
*
|
117
|
-
* Returns:
|
118
|
-
* dest if specified, vec otherwise
|
119
|
-
**/
|
120
|
-
vec3.subtract = function(vec, vec2, dest) {
|
121
|
-
if(!dest || vec == dest) {
|
122
|
-
vec[0] -= vec2[0];
|
123
|
-
vec[1] -= vec2[1];
|
124
|
-
vec[2] -= vec2[2];
|
125
|
-
return vec;
|
126
|
-
}
|
127
|
-
|
128
|
-
dest[0] = vec[0] - vec2[0];
|
129
|
-
dest[1] = vec[1] - vec2[1];
|
130
|
-
dest[2] = vec[2] - vec2[2];
|
131
|
-
return dest;
|
132
|
-
};
|
133
|
-
|
134
|
-
/**
|
135
|
-
* vec3.negate(vec[, dest]) -> vec3
|
136
|
-
* - vec (vec3) : vec3 to negate
|
137
|
-
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
138
|
-
*
|
139
|
-
* Negates the components of a vec3
|
140
|
-
*
|
141
|
-
* Returns:
|
142
|
-
* dest if specified, vec otherwise
|
143
|
-
**/
|
144
|
-
vec3.negate = function(vec, dest) {
|
145
|
-
if(!dest) { dest = vec; }
|
146
|
-
|
147
|
-
dest[0] = -vec[0];
|
148
|
-
dest[1] = -vec[1];
|
149
|
-
dest[2] = -vec[2];
|
150
|
-
return dest;
|
151
|
-
};
|
152
|
-
|
153
|
-
/**
|
154
|
-
* vec3.scale(vec, val[, dest]) -> vec3
|
155
|
-
* - vec (vec3) : vec3 to scale
|
156
|
-
* - val (Number) : numeric value to scale by
|
157
|
-
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
158
|
-
*
|
159
|
-
* Multiplies the components of a vec3 by a scalar value
|
160
|
-
*
|
161
|
-
* Returns:
|
162
|
-
* dest if specified, vec otherwise
|
163
|
-
**/
|
164
|
-
vec3.scale = function(vec, val, dest) {
|
165
|
-
if(!dest || vec == dest) {
|
166
|
-
vec[0] *= val;
|
167
|
-
vec[1] *= val;
|
168
|
-
vec[2] *= val;
|
169
|
-
return vec;
|
170
|
-
}
|
171
|
-
|
172
|
-
dest[0] = vec[0]*val;
|
173
|
-
dest[1] = vec[1]*val;
|
174
|
-
dest[2] = vec[2]*val;
|
175
|
-
return dest;
|
176
|
-
};
|
177
|
-
|
178
|
-
/**
|
179
|
-
* vec3.normalize(vec[, dest]) -> vec3
|
180
|
-
* - vec (vec3) : vec3 to normalize
|
181
|
-
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
182
|
-
*
|
183
|
-
* Generates a unit vector of the same direction as the provided vec3
|
184
|
-
* If vector length is 0, returns [0, 0, 0]
|
185
|
-
*
|
186
|
-
* Returns:
|
187
|
-
* dest if specified, vec otherwise
|
188
|
-
**/
|
189
|
-
vec3.normalize = function(vec, dest) {
|
190
|
-
if(!dest) { dest = vec; }
|
191
|
-
|
192
|
-
var x = vec[0], y = vec[1], z = vec[2];
|
193
|
-
var len = Math.sqrt(x*x + y*y + z*z);
|
194
|
-
|
195
|
-
if (!len) {
|
196
|
-
dest[0] = 0;
|
197
|
-
dest[1] = 0;
|
198
|
-
dest[2] = 0;
|
199
|
-
return dest;
|
200
|
-
} else if (len == 1) {
|
201
|
-
dest[0] = x;
|
202
|
-
dest[1] = y;
|
203
|
-
dest[2] = z;
|
204
|
-
return dest;
|
205
|
-
}
|
206
|
-
|
207
|
-
len = 1 / len;
|
208
|
-
dest[0] = x*len;
|
209
|
-
dest[1] = y*len;
|
210
|
-
dest[2] = z*len;
|
211
|
-
return dest;
|
212
|
-
};
|
213
|
-
|
214
|
-
/**
|
215
|
-
* vec3.cross(vec, vec2[, dest]) -> vec3
|
216
|
-
* - vec (vec3) : first operand
|
217
|
-
* - vec2 (vec3) : second operand
|
218
|
-
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
219
|
-
*
|
220
|
-
* Generates the cross product of two vec3s
|
221
|
-
*
|
222
|
-
* Returns:
|
223
|
-
* dest if specified, vec otherwise
|
224
|
-
**/
|
225
|
-
vec3.cross = function(vec, vec2, dest){
|
226
|
-
if(!dest) { dest = vec; }
|
227
|
-
|
228
|
-
var x = vec[0], y = vec[1], z = vec[2];
|
229
|
-
var x2 = vec2[0], y2 = vec2[1], z2 = vec2[2];
|
230
|
-
|
231
|
-
dest[0] = y*z2 - z*y2;
|
232
|
-
dest[1] = z*x2 - x*z2;
|
233
|
-
dest[2] = x*y2 - y*x2;
|
234
|
-
return dest;
|
235
|
-
};
|
236
|
-
|
237
|
-
/**
|
238
|
-
* vec3.length(vec) -> Number
|
239
|
-
* - vec (vec3) : vec3 to calculate length of
|
240
|
-
*
|
241
|
-
* Caclulates the length of a vec3
|
242
|
-
*
|
243
|
-
* Returns:
|
244
|
-
* Length of vec
|
245
|
-
**/
|
246
|
-
vec3.length = function(vec){
|
247
|
-
var x = vec[0], y = vec[1], z = vec[2];
|
248
|
-
return Math.sqrt(x*x + y*y + z*z);
|
249
|
-
};
|
250
|
-
|
251
|
-
/**
|
252
|
-
* vec3.dot(vec, vec2) -> Number
|
253
|
-
* - vec (vec3) : first operand
|
254
|
-
* - vec2 (vec3) : second operand
|
255
|
-
*
|
256
|
-
* Caclulates the dot product of two vec3s
|
257
|
-
*
|
258
|
-
* Returns:
|
259
|
-
* Dot product of vec and vec2
|
260
|
-
**/
|
261
|
-
vec3.dot = function(vec, vec2){
|
262
|
-
return vec[0]*vec2[0] + vec[1]*vec2[1] + vec[2]*vec2[2];
|
263
|
-
};
|
264
|
-
|
265
|
-
/**
|
266
|
-
* vec3.direction(vec, vec2[, dest]) -> vec3
|
267
|
-
* - vec (vec3) : origin vec3
|
268
|
-
* - vec2 (vec3) : vec3 to point to
|
269
|
-
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
270
|
-
*
|
271
|
-
* Generates a unit vector pointing from one vector to another
|
272
|
-
*
|
273
|
-
* Returns:
|
274
|
-
* dest if specified, vec otherwise
|
275
|
-
**/
|
276
|
-
vec3.direction = function(vec, vec2, dest) {
|
277
|
-
if(!dest) { dest = vec; }
|
278
|
-
|
279
|
-
var x = vec[0] - vec2[0];
|
280
|
-
var y = vec[1] - vec2[1];
|
281
|
-
var z = vec[2] - vec2[2];
|
282
|
-
|
283
|
-
var len = Math.sqrt(x*x + y*y + z*z);
|
284
|
-
if (!len) {
|
285
|
-
dest[0] = 0;
|
286
|
-
dest[1] = 0;
|
287
|
-
dest[2] = 0;
|
288
|
-
return dest;
|
289
|
-
}
|
290
|
-
|
291
|
-
len = 1 / len;
|
292
|
-
dest[0] = x * len;
|
293
|
-
dest[1] = y * len;
|
294
|
-
dest[2] = z * len;
|
295
|
-
return dest;
|
296
|
-
};
|
297
|
-
|
298
|
-
/**
|
299
|
-
* vec3.lerp(vec, vec2, lerp[, dest]) -> vec3
|
300
|
-
* - vec (vec3) : first vector
|
301
|
-
* - vec2 (vec3) : second vector
|
302
|
-
* - lerp (Number) : interpolation amount between the two inputs
|
303
|
-
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
304
|
-
*
|
305
|
-
* Performs a linear interpolation between two vec3
|
306
|
-
*
|
307
|
-
* Returns:
|
308
|
-
* dest if specified, vec otherwise
|
309
|
-
**/
|
310
|
-
vec3.lerp = function(vec, vec2, lerp, dest){
|
311
|
-
if(!dest) { dest = vec; }
|
312
|
-
|
313
|
-
dest[0] = vec[0] + lerp * (vec2[0] - vec[0]);
|
314
|
-
dest[1] = vec[1] + lerp * (vec2[1] - vec[1]);
|
315
|
-
dest[2] = vec[2] + lerp * (vec2[2] - vec[2]);
|
316
|
-
|
317
|
-
return dest;
|
318
|
-
}
|
319
|
-
|
320
|
-
/**
|
321
|
-
* vec3.str(vec) -> String
|
322
|
-
* - vec (vec3) : vec3 to represent as a string
|
323
|
-
*
|
324
|
-
* Returns a string representation of a vector
|
325
|
-
*
|
326
|
-
* Returns:
|
327
|
-
* string representation of vec
|
328
|
-
**/
|
329
|
-
vec3.str = function(vec) {
|
330
|
-
return '[' + vec[0] + ', ' + vec[1] + ', ' + vec[2] + ']';
|
331
|
-
};
|
332
|
-
|
333
|
-
/**
|
334
|
-
* mat3
|
335
|
-
* 3x3 Matrix
|
336
|
-
**/
|
337
|
-
var mat3 = {};
|
338
|
-
|
339
|
-
/**
|
340
|
-
* mat3.create([mat]) -> mat3
|
341
|
-
* - mat (mat3) : optional mat3 containing values to initialize with
|
342
|
-
*
|
343
|
-
* Creates a new instance of a mat3 using the default array type
|
344
|
-
* Any javascript array containing at least 9 numeric elements can serve as a mat3
|
345
|
-
*
|
346
|
-
* Returns:
|
347
|
-
* New mat3
|
348
|
-
**/
|
349
|
-
mat3.create = function(mat) {
|
350
|
-
var dest = new glMatrixArrayType(9);
|
351
|
-
|
352
|
-
if(mat) {
|
353
|
-
dest[0] = mat[0];
|
354
|
-
dest[1] = mat[1];
|
355
|
-
dest[2] = mat[2];
|
356
|
-
dest[3] = mat[3];
|
357
|
-
dest[4] = mat[4];
|
358
|
-
dest[5] = mat[5];
|
359
|
-
dest[6] = mat[6];
|
360
|
-
dest[7] = mat[7];
|
361
|
-
dest[8] = mat[8];
|
362
|
-
dest[9] = mat[9];
|
363
|
-
}
|
364
|
-
|
365
|
-
return dest;
|
366
|
-
};
|
367
|
-
|
368
|
-
/**
|
369
|
-
* mat3.set(mat, dest) -> mat3
|
370
|
-
* - mat (mat3) : mat3 containing values to copy
|
371
|
-
* - dest (mat3) : mat3 receiving copied values
|
372
|
-
*
|
373
|
-
* Copies the values of one mat3 to another
|
374
|
-
*
|
375
|
-
* Returns:
|
376
|
-
* dest
|
377
|
-
**/
|
378
|
-
mat3.set = function(mat, dest) {
|
379
|
-
dest[0] = mat[0];
|
380
|
-
dest[1] = mat[1];
|
381
|
-
dest[2] = mat[2];
|
382
|
-
dest[3] = mat[3];
|
383
|
-
dest[4] = mat[4];
|
384
|
-
dest[5] = mat[5];
|
385
|
-
dest[6] = mat[6];
|
386
|
-
dest[7] = mat[7];
|
387
|
-
dest[8] = mat[8];
|
388
|
-
return dest;
|
389
|
-
};
|
390
|
-
|
391
|
-
/**
|
392
|
-
* mat3.identity(dest) -> mat3
|
393
|
-
* - dest (mat3) : mat3 to set
|
394
|
-
*
|
395
|
-
* Sets a mat3 to an identity matrix
|
396
|
-
*
|
397
|
-
* Returns:
|
398
|
-
* dest
|
399
|
-
**/
|
400
|
-
mat3.identity = function(dest) {
|
401
|
-
dest[0] = 1;
|
402
|
-
dest[1] = 0;
|
403
|
-
dest[2] = 0;
|
404
|
-
dest[3] = 0;
|
405
|
-
dest[4] = 1;
|
406
|
-
dest[5] = 0;
|
407
|
-
dest[6] = 0;
|
408
|
-
dest[7] = 0;
|
409
|
-
dest[8] = 1;
|
410
|
-
return dest;
|
411
|
-
};
|
412
|
-
|
413
|
-
/**
|
414
|
-
* mat3.transpose(mat[, dest]) -> mat3
|
415
|
-
* - mat (mat3) : mat3 to transpose
|
416
|
-
* - dest (mat3) : optional mat3 receiving operation result. If not specified, result is written to +mat+.
|
417
|
-
*
|
418
|
-
* Transposes a mat3 (flips the values over the diagonal)
|
419
|
-
*
|
420
|
-
* Returns:
|
421
|
-
* dest if specified, mat otherwise
|
422
|
-
**/
|
423
|
-
mat3.transpose = function(mat, dest) {
|
424
|
-
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
425
|
-
if(!dest || mat == dest) {
|
426
|
-
var a01 = mat[1], a02 = mat[2];
|
427
|
-
var a12 = mat[5];
|
428
|
-
|
429
|
-
mat[1] = mat[3];
|
430
|
-
mat[2] = mat[6];
|
431
|
-
mat[3] = a01;
|
432
|
-
mat[5] = mat[7];
|
433
|
-
mat[6] = a02;
|
434
|
-
mat[7] = a12;
|
435
|
-
return mat;
|
436
|
-
}
|
437
|
-
|
438
|
-
dest[0] = mat[0];
|
439
|
-
dest[1] = mat[3];
|
440
|
-
dest[2] = mat[6];
|
441
|
-
dest[3] = mat[1];
|
442
|
-
dest[4] = mat[4];
|
443
|
-
dest[5] = mat[7];
|
444
|
-
dest[6] = mat[2];
|
445
|
-
dest[7] = mat[5];
|
446
|
-
dest[8] = mat[8];
|
447
|
-
return dest;
|
448
|
-
};
|
449
|
-
|
450
|
-
/**
|
451
|
-
* mat3.toMat4(mat[, dest]) -> mat4
|
452
|
-
* - mat (mat3) : mat3 containing values to copy
|
453
|
-
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to a new mat4.
|
454
|
-
*
|
455
|
-
* Copies the elements of a mat3 into the upper 3x3 elements of a mat4
|
456
|
-
*
|
457
|
-
* Returns:
|
458
|
-
* dest if specified, a new mat4 otherwise
|
459
|
-
**/
|
460
|
-
mat3.toMat4 = function(mat, dest) {
|
461
|
-
if(!dest) { dest = mat4.create(); }
|
462
|
-
|
463
|
-
dest[0] = mat[0];
|
464
|
-
dest[1] = mat[1];
|
465
|
-
dest[2] = mat[2];
|
466
|
-
dest[3] = 0;
|
467
|
-
|
468
|
-
dest[4] = mat[3];
|
469
|
-
dest[5] = mat[4];
|
470
|
-
dest[6] = mat[5];
|
471
|
-
dest[7] = 0;
|
472
|
-
|
473
|
-
dest[8] = mat[6];
|
474
|
-
dest[9] = mat[7];
|
475
|
-
dest[10] = mat[8];
|
476
|
-
dest[11] = 0;
|
477
|
-
|
478
|
-
dest[12] = 0;
|
479
|
-
dest[13] = 0;
|
480
|
-
dest[14] = 0;
|
481
|
-
dest[15] = 1;
|
482
|
-
|
483
|
-
return dest;
|
484
|
-
}
|
485
|
-
|
486
|
-
/**
|
487
|
-
* mat3.str(mat) -> String
|
488
|
-
* - mat (mat3) : mat3 to represent as a string
|
489
|
-
*
|
490
|
-
* Returns a string representation of a mat3
|
491
|
-
*
|
492
|
-
* Returns:
|
493
|
-
* string representation of mat
|
494
|
-
**/
|
495
|
-
mat3.str = function(mat) {
|
496
|
-
return '[' + mat[0] + ', ' + mat[1] + ', ' + mat[2] +
|
497
|
-
', ' + mat[3] + ', '+ mat[4] + ', ' + mat[5] +
|
498
|
-
', ' + mat[6] + ', ' + mat[7] + ', '+ mat[8] + ']';
|
499
|
-
};
|
500
|
-
|
501
|
-
/**
|
502
|
-
* mat4
|
503
|
-
* 4x4 Matrix
|
504
|
-
**/
|
505
|
-
var mat4 = {};
|
506
|
-
|
507
|
-
/**
|
508
|
-
* mat4.create([mat]) -> mat4
|
509
|
-
* - mat (mat4) : optional mat4 containing values to initialize with
|
510
|
-
*
|
511
|
-
* Creates a new instance of a mat4 using the default array type
|
512
|
-
* Any javascript array containing at least 16 numeric elements can serve as a mat4
|
513
|
-
*
|
514
|
-
* Returns:
|
515
|
-
* New mat4
|
516
|
-
**/
|
517
|
-
mat4.create = function(mat) {
|
518
|
-
var dest = new glMatrixArrayType(16);
|
519
|
-
|
520
|
-
if(mat) {
|
521
|
-
dest[0] = mat[0];
|
522
|
-
dest[1] = mat[1];
|
523
|
-
dest[2] = mat[2];
|
524
|
-
dest[3] = mat[3];
|
525
|
-
dest[4] = mat[4];
|
526
|
-
dest[5] = mat[5];
|
527
|
-
dest[6] = mat[6];
|
528
|
-
dest[7] = mat[7];
|
529
|
-
dest[8] = mat[8];
|
530
|
-
dest[9] = mat[9];
|
531
|
-
dest[10] = mat[10];
|
532
|
-
dest[11] = mat[11];
|
533
|
-
dest[12] = mat[12];
|
534
|
-
dest[13] = mat[13];
|
535
|
-
dest[14] = mat[14];
|
536
|
-
dest[15] = mat[15];
|
537
|
-
}
|
538
|
-
|
539
|
-
return dest;
|
540
|
-
};
|
541
|
-
|
542
|
-
/**
|
543
|
-
* mat4.set(mat, dest) -> mat4
|
544
|
-
* - mat (mat4) : mat4 containing values to copy
|
545
|
-
* - dest (mat4) : mat4 receiving copied values
|
546
|
-
*
|
547
|
-
* Copies the values of one mat4 to another
|
548
|
-
*
|
549
|
-
* Returns:
|
550
|
-
* dest
|
551
|
-
**/
|
552
|
-
mat4.set = function(mat, dest) {
|
553
|
-
dest[0] = mat[0];
|
554
|
-
dest[1] = mat[1];
|
555
|
-
dest[2] = mat[2];
|
556
|
-
dest[3] = mat[3];
|
557
|
-
dest[4] = mat[4];
|
558
|
-
dest[5] = mat[5];
|
559
|
-
dest[6] = mat[6];
|
560
|
-
dest[7] = mat[7];
|
561
|
-
dest[8] = mat[8];
|
562
|
-
dest[9] = mat[9];
|
563
|
-
dest[10] = mat[10];
|
564
|
-
dest[11] = mat[11];
|
565
|
-
dest[12] = mat[12];
|
566
|
-
dest[13] = mat[13];
|
567
|
-
dest[14] = mat[14];
|
568
|
-
dest[15] = mat[15];
|
569
|
-
return dest;
|
570
|
-
};
|
571
|
-
|
572
|
-
/**
|
573
|
-
* mat4.identity(dest) -> mat4
|
574
|
-
* - dest (mat4) : mat4 to set
|
575
|
-
*
|
576
|
-
* Sets a mat4 to an identity matrix
|
577
|
-
*
|
578
|
-
* Returns:
|
579
|
-
* dest
|
580
|
-
**/
|
581
|
-
mat4.identity = function(dest) {
|
582
|
-
dest[0] = 1;
|
583
|
-
dest[1] = 0;
|
584
|
-
dest[2] = 0;
|
585
|
-
dest[3] = 0;
|
586
|
-
dest[4] = 0;
|
587
|
-
dest[5] = 1;
|
588
|
-
dest[6] = 0;
|
589
|
-
dest[7] = 0;
|
590
|
-
dest[8] = 0;
|
591
|
-
dest[9] = 0;
|
592
|
-
dest[10] = 1;
|
593
|
-
dest[11] = 0;
|
594
|
-
dest[12] = 0;
|
595
|
-
dest[13] = 0;
|
596
|
-
dest[14] = 0;
|
597
|
-
dest[15] = 1;
|
598
|
-
return dest;
|
599
|
-
};
|
600
|
-
|
601
|
-
/**
|
602
|
-
* mat4.transpose(mat[, dest]) -> mat4
|
603
|
-
* - mat (mat4) : mat4 to transpose
|
604
|
-
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
605
|
-
*
|
606
|
-
* Transposes a mat4 (flips the values over the diagonal)
|
607
|
-
*
|
608
|
-
* Returns:
|
609
|
-
* dest is specified, mat otherwise
|
610
|
-
**/
|
611
|
-
mat4.transpose = function(mat, dest) {
|
612
|
-
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
613
|
-
if(!dest || mat == dest) {
|
614
|
-
var a01 = mat[1], a02 = mat[2], a03 = mat[3];
|
615
|
-
var a12 = mat[6], a13 = mat[7];
|
616
|
-
var a23 = mat[11];
|
617
|
-
|
618
|
-
mat[1] = mat[4];
|
619
|
-
mat[2] = mat[8];
|
620
|
-
mat[3] = mat[12];
|
621
|
-
mat[4] = a01;
|
622
|
-
mat[6] = mat[9];
|
623
|
-
mat[7] = mat[13];
|
624
|
-
mat[8] = a02;
|
625
|
-
mat[9] = a12;
|
626
|
-
mat[11] = mat[14];
|
627
|
-
mat[12] = a03;
|
628
|
-
mat[13] = a13;
|
629
|
-
mat[14] = a23;
|
630
|
-
return mat;
|
631
|
-
}
|
632
|
-
|
633
|
-
dest[0] = mat[0];
|
634
|
-
dest[1] = mat[4];
|
635
|
-
dest[2] = mat[8];
|
636
|
-
dest[3] = mat[12];
|
637
|
-
dest[4] = mat[1];
|
638
|
-
dest[5] = mat[5];
|
639
|
-
dest[6] = mat[9];
|
640
|
-
dest[7] = mat[13];
|
641
|
-
dest[8] = mat[2];
|
642
|
-
dest[9] = mat[6];
|
643
|
-
dest[10] = mat[10];
|
644
|
-
dest[11] = mat[14];
|
645
|
-
dest[12] = mat[3];
|
646
|
-
dest[13] = mat[7];
|
647
|
-
dest[14] = mat[11];
|
648
|
-
dest[15] = mat[15];
|
649
|
-
return dest;
|
650
|
-
};
|
651
|
-
|
652
|
-
/**
|
653
|
-
* mat4.determinant(mat) -> mat4
|
654
|
-
* - mat (mat4) : mat4 to calculate determinant of
|
655
|
-
*
|
656
|
-
* Calculates the determinant of a mat4
|
657
|
-
*
|
658
|
-
* Returns:
|
659
|
-
* determinant of mat
|
660
|
-
**/
|
661
|
-
mat4.determinant = function(mat) {
|
662
|
-
// Cache the matrix values (makes for huge speed increases!)
|
663
|
-
var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
|
664
|
-
var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
|
665
|
-
var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
|
666
|
-
var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
|
667
|
-
|
668
|
-
return a30*a21*a12*a03 - a20*a31*a12*a03 - a30*a11*a22*a03 + a10*a31*a22*a03 +
|
669
|
-
a20*a11*a32*a03 - a10*a21*a32*a03 - a30*a21*a02*a13 + a20*a31*a02*a13 +
|
670
|
-
a30*a01*a22*a13 - a00*a31*a22*a13 - a20*a01*a32*a13 + a00*a21*a32*a13 +
|
671
|
-
a30*a11*a02*a23 - a10*a31*a02*a23 - a30*a01*a12*a23 + a00*a31*a12*a23 +
|
672
|
-
a10*a01*a32*a23 - a00*a11*a32*a23 - a20*a11*a02*a33 + a10*a21*a02*a33 +
|
673
|
-
a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
|
674
|
-
};
|
675
|
-
|
676
|
-
/**
|
677
|
-
* mat4.inverse(mat[, dest]) -> mat4
|
678
|
-
* - mat (mat4) : mat4 to calculate inverse of
|
679
|
-
* - dest (mat4) : optional mat4 receiving inverse matrix. If not specified, result is written to +mat+.
|
680
|
-
*
|
681
|
-
* Calculates the inverse matrix of a mat4
|
682
|
-
*
|
683
|
-
* Returns:
|
684
|
-
* dest is specified, mat otherwise
|
685
|
-
**/
|
686
|
-
mat4.inverse = function(mat, dest) {
|
687
|
-
if(!dest) { dest = mat; }
|
688
|
-
|
689
|
-
// Cache the matrix values (makes for huge speed increases!)
|
690
|
-
var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
|
691
|
-
var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
|
692
|
-
var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
|
693
|
-
var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
|
694
|
-
|
695
|
-
var b00 = a00*a11 - a01*a10;
|
696
|
-
var b01 = a00*a12 - a02*a10;
|
697
|
-
var b02 = a00*a13 - a03*a10;
|
698
|
-
var b03 = a01*a12 - a02*a11;
|
699
|
-
var b04 = a01*a13 - a03*a11;
|
700
|
-
var b05 = a02*a13 - a03*a12;
|
701
|
-
var b06 = a20*a31 - a21*a30;
|
702
|
-
var b07 = a20*a32 - a22*a30;
|
703
|
-
var b08 = a20*a33 - a23*a30;
|
704
|
-
var b09 = a21*a32 - a22*a31;
|
705
|
-
var b10 = a21*a33 - a23*a31;
|
706
|
-
var b11 = a22*a33 - a23*a32;
|
707
|
-
|
708
|
-
// Calculate the determinant (inlined to avoid double-caching)
|
709
|
-
var invDet = 1/(b00*b11 - b01*b10 + b02*b09 + b03*b08 - b04*b07 + b05*b06);
|
710
|
-
|
711
|
-
dest[0] = (a11*b11 - a12*b10 + a13*b09)*invDet;
|
712
|
-
dest[1] = (-a01*b11 + a02*b10 - a03*b09)*invDet;
|
713
|
-
dest[2] = (a31*b05 - a32*b04 + a33*b03)*invDet;
|
714
|
-
dest[3] = (-a21*b05 + a22*b04 - a23*b03)*invDet;
|
715
|
-
dest[4] = (-a10*b11 + a12*b08 - a13*b07)*invDet;
|
716
|
-
dest[5] = (a00*b11 - a02*b08 + a03*b07)*invDet;
|
717
|
-
dest[6] = (-a30*b05 + a32*b02 - a33*b01)*invDet;
|
718
|
-
dest[7] = (a20*b05 - a22*b02 + a23*b01)*invDet;
|
719
|
-
dest[8] = (a10*b10 - a11*b08 + a13*b06)*invDet;
|
720
|
-
dest[9] = (-a00*b10 + a01*b08 - a03*b06)*invDet;
|
721
|
-
dest[10] = (a30*b04 - a31*b02 + a33*b00)*invDet;
|
722
|
-
dest[11] = (-a20*b04 + a21*b02 - a23*b00)*invDet;
|
723
|
-
dest[12] = (-a10*b09 + a11*b07 - a12*b06)*invDet;
|
724
|
-
dest[13] = (a00*b09 - a01*b07 + a02*b06)*invDet;
|
725
|
-
dest[14] = (-a30*b03 + a31*b01 - a32*b00)*invDet;
|
726
|
-
dest[15] = (a20*b03 - a21*b01 + a22*b00)*invDet;
|
727
|
-
|
728
|
-
return dest;
|
729
|
-
};
|
730
|
-
|
731
|
-
/**
|
732
|
-
* mat4.toRotationMat(mat[, dest]) -> mat4
|
733
|
-
* - mat (mat4) : mat4 containing values to copy
|
734
|
-
* - dest (mat4) : optional mat4 receiving copied values. If not specified, result is written to +mat+.
|
735
|
-
*
|
736
|
-
* Copies the upper 3x3 elements of a mat4 into another mat4
|
737
|
-
*
|
738
|
-
* Returns:
|
739
|
-
* dest is specified, a new mat4 otherwise
|
740
|
-
**/
|
741
|
-
mat4.toRotationMat = function(mat, dest) {
|
742
|
-
if(!dest) { dest = mat4.create(); }
|
743
|
-
|
744
|
-
dest[0] = mat[0];
|
745
|
-
dest[1] = mat[1];
|
746
|
-
dest[2] = mat[2];
|
747
|
-
dest[3] = mat[3];
|
748
|
-
dest[4] = mat[4];
|
749
|
-
dest[5] = mat[5];
|
750
|
-
dest[6] = mat[6];
|
751
|
-
dest[7] = mat[7];
|
752
|
-
dest[8] = mat[8];
|
753
|
-
dest[9] = mat[9];
|
754
|
-
dest[10] = mat[10];
|
755
|
-
dest[11] = mat[11];
|
756
|
-
dest[12] = 0;
|
757
|
-
dest[13] = 0;
|
758
|
-
dest[14] = 0;
|
759
|
-
dest[15] = 1;
|
760
|
-
|
761
|
-
return dest;
|
762
|
-
};
|
763
|
-
|
764
|
-
/**
|
765
|
-
* mat4.toMat3(mat[, dest]) -> mat3
|
766
|
-
* - mat (mat4) : mat4 containing values to copy
|
767
|
-
* - dest (mat3) : optional mat3 receiving copied values. If not specified, a new mat3 is created.
|
768
|
-
*
|
769
|
-
* Copies the upper 3x3 elements of a mat4 into a mat3
|
770
|
-
*
|
771
|
-
* Returns:
|
772
|
-
* dest is specified, a new mat3 otherwise
|
773
|
-
**/
|
774
|
-
mat4.toMat3 = function(mat, dest) {
|
775
|
-
if(!dest) { dest = mat3.create(); }
|
776
|
-
|
777
|
-
dest[0] = mat[0];
|
778
|
-
dest[1] = mat[1];
|
779
|
-
dest[2] = mat[2];
|
780
|
-
dest[3] = mat[4];
|
781
|
-
dest[4] = mat[5];
|
782
|
-
dest[5] = mat[6];
|
783
|
-
dest[6] = mat[8];
|
784
|
-
dest[7] = mat[9];
|
785
|
-
dest[8] = mat[10];
|
786
|
-
|
787
|
-
return dest;
|
788
|
-
};
|
789
|
-
|
790
|
-
/**
|
791
|
-
* mat4.toInverseMat3(mat[, dest]) -> mat3
|
792
|
-
* - mat (mat4) : mat4 containing values to invert and copy
|
793
|
-
* - dest (mat3) : optional mat3 receiving values
|
794
|
-
*
|
795
|
-
* Calculates the inverse of the upper 3x3 elements of a mat4 and copies the result into a mat3
|
796
|
-
* The resulting matrix is useful for calculating transformed normals
|
797
|
-
*
|
798
|
-
* Returns:
|
799
|
-
* dest is specified, a new mat3 otherwise
|
800
|
-
**/
|
801
|
-
mat4.toInverseMat3 = function(mat, dest) {
|
802
|
-
// Cache the matrix values (makes for huge speed increases!)
|
803
|
-
var a00 = mat[0], a01 = mat[1], a02 = mat[2];
|
804
|
-
var a10 = mat[4], a11 = mat[5], a12 = mat[6];
|
805
|
-
var a20 = mat[8], a21 = mat[9], a22 = mat[10];
|
806
|
-
|
807
|
-
var b01 = a22*a11-a12*a21;
|
808
|
-
var b11 = -a22*a10+a12*a20;
|
809
|
-
var b21 = a21*a10-a11*a20;
|
810
|
-
|
811
|
-
var d = a00*b01 + a01*b11 + a02*b21;
|
812
|
-
if (!d) { return null; }
|
813
|
-
var id = 1/d;
|
814
|
-
|
815
|
-
if(!dest) { dest = mat3.create(); }
|
816
|
-
|
817
|
-
dest[0] = b01*id;
|
818
|
-
dest[1] = (-a22*a01 + a02*a21)*id;
|
819
|
-
dest[2] = (a12*a01 - a02*a11)*id;
|
820
|
-
dest[3] = b11*id;
|
821
|
-
dest[4] = (a22*a00 - a02*a20)*id;
|
822
|
-
dest[5] = (-a12*a00 + a02*a10)*id;
|
823
|
-
dest[6] = b21*id;
|
824
|
-
dest[7] = (-a21*a00 + a01*a20)*id;
|
825
|
-
dest[8] = (a11*a00 - a01*a10)*id;
|
826
|
-
|
827
|
-
return dest;
|
828
|
-
};
|
829
|
-
|
830
|
-
/**
|
831
|
-
* mat4.multiply(mat, mat2[, dest]) -> mat4
|
832
|
-
* - mat (mat4) : first operand
|
833
|
-
* - mat2 (mat4) : second operand
|
834
|
-
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
835
|
-
*
|
836
|
-
* Performs a matrix multiplication
|
837
|
-
*
|
838
|
-
* Returns:
|
839
|
-
* dest if specified, mat otherwise
|
840
|
-
**/
|
841
|
-
mat4.multiply = function(mat, mat2, dest) {
|
842
|
-
if(!dest) { dest = mat }
|
843
|
-
|
844
|
-
// Cache the matrix values (makes for huge speed increases!)
|
845
|
-
var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
|
846
|
-
var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
|
847
|
-
var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
|
848
|
-
var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
|
849
|
-
|
850
|
-
var b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], b03 = mat2[3];
|
851
|
-
var b10 = mat2[4], b11 = mat2[5], b12 = mat2[6], b13 = mat2[7];
|
852
|
-
var b20 = mat2[8], b21 = mat2[9], b22 = mat2[10], b23 = mat2[11];
|
853
|
-
var b30 = mat2[12], b31 = mat2[13], b32 = mat2[14], b33 = mat2[15];
|
854
|
-
|
855
|
-
dest[0] = b00*a00 + b01*a10 + b02*a20 + b03*a30;
|
856
|
-
dest[1] = b00*a01 + b01*a11 + b02*a21 + b03*a31;
|
857
|
-
dest[2] = b00*a02 + b01*a12 + b02*a22 + b03*a32;
|
858
|
-
dest[3] = b00*a03 + b01*a13 + b02*a23 + b03*a33;
|
859
|
-
dest[4] = b10*a00 + b11*a10 + b12*a20 + b13*a30;
|
860
|
-
dest[5] = b10*a01 + b11*a11 + b12*a21 + b13*a31;
|
861
|
-
dest[6] = b10*a02 + b11*a12 + b12*a22 + b13*a32;
|
862
|
-
dest[7] = b10*a03 + b11*a13 + b12*a23 + b13*a33;
|
863
|
-
dest[8] = b20*a00 + b21*a10 + b22*a20 + b23*a30;
|
864
|
-
dest[9] = b20*a01 + b21*a11 + b22*a21 + b23*a31;
|
865
|
-
dest[10] = b20*a02 + b21*a12 + b22*a22 + b23*a32;
|
866
|
-
dest[11] = b20*a03 + b21*a13 + b22*a23 + b23*a33;
|
867
|
-
dest[12] = b30*a00 + b31*a10 + b32*a20 + b33*a30;
|
868
|
-
dest[13] = b30*a01 + b31*a11 + b32*a21 + b33*a31;
|
869
|
-
dest[14] = b30*a02 + b31*a12 + b32*a22 + b33*a32;
|
870
|
-
dest[15] = b30*a03 + b31*a13 + b32*a23 + b33*a33;
|
871
|
-
|
872
|
-
return dest;
|
873
|
-
};
|
874
|
-
|
875
|
-
/**
|
876
|
-
* mat4.multiplyVec3(mat, vec[, dest]) -> vec3
|
877
|
-
* - mat (mat4) : mat4 to transform the vector with
|
878
|
-
* - vec (vec3) : vec3 to transform
|
879
|
-
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
880
|
-
*
|
881
|
-
* Transforms a vec3 with the given matrix
|
882
|
-
* 4th vector component is implicitly '1'
|
883
|
-
*
|
884
|
-
* Returns:
|
885
|
-
* dest if specified, vec3 otherwise
|
886
|
-
**/
|
887
|
-
mat4.multiplyVec3 = function(mat, vec, dest) {
|
888
|
-
if(!dest) { dest = vec }
|
889
|
-
|
890
|
-
var x = vec[0], y = vec[1], z = vec[2];
|
891
|
-
|
892
|
-
dest[0] = mat[0]*x + mat[4]*y + mat[8]*z + mat[12];
|
893
|
-
dest[1] = mat[1]*x + mat[5]*y + mat[9]*z + mat[13];
|
894
|
-
dest[2] = mat[2]*x + mat[6]*y + mat[10]*z + mat[14];
|
895
|
-
|
896
|
-
return dest;
|
897
|
-
};
|
898
|
-
|
899
|
-
/**
|
900
|
-
* mat4.multiplyVec4(mat, vec[, dest]) -> vec4
|
901
|
-
* - mat (mat4) : mat4 to transform the vector with
|
902
|
-
* - vec (vec4) : vec4 to transform
|
903
|
-
* - dest (vec4) : optional vec4 receiving operation result. If not specified, result is written to +vec+.
|
904
|
-
*
|
905
|
-
* Transforms a vec4 with the given matrix
|
906
|
-
*
|
907
|
-
* Returns:
|
908
|
-
* dest if specified, vec otherwise
|
909
|
-
**/
|
910
|
-
mat4.multiplyVec4 = function(mat, vec, dest) {
|
911
|
-
if(!dest) { dest = vec }
|
912
|
-
|
913
|
-
var x = vec[0], y = vec[1], z = vec[2], w = vec[3];
|
914
|
-
|
915
|
-
dest[0] = mat[0]*x + mat[4]*y + mat[8]*z + mat[12]*w;
|
916
|
-
dest[1] = mat[1]*x + mat[5]*y + mat[9]*z + mat[13]*w;
|
917
|
-
dest[2] = mat[2]*x + mat[6]*y + mat[10]*z + mat[14]*w;
|
918
|
-
dest[3] = mat[3]*x + mat[7]*y + mat[11]*z + mat[15]*w;
|
919
|
-
|
920
|
-
return dest;
|
921
|
-
};
|
922
|
-
|
923
|
-
/**
|
924
|
-
* mat4.translate(mat, vec[, dest]) -> mat4
|
925
|
-
* - mat (mat4) : mat4 to translate
|
926
|
-
* - vec (vec3) : vec3 specifying the translation
|
927
|
-
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
928
|
-
*
|
929
|
-
* Translates a matrix by the given vector
|
930
|
-
*
|
931
|
-
* Returns:
|
932
|
-
* dest if specified, mat otherwise
|
933
|
-
**/
|
934
|
-
mat4.translate = function(mat, vec, dest) {
|
935
|
-
var x = vec[0], y = vec[1], z = vec[2];
|
936
|
-
|
937
|
-
if(!dest || mat == dest) {
|
938
|
-
mat[12] = mat[0]*x + mat[4]*y + mat[8]*z + mat[12];
|
939
|
-
mat[13] = mat[1]*x + mat[5]*y + mat[9]*z + mat[13];
|
940
|
-
mat[14] = mat[2]*x + mat[6]*y + mat[10]*z + mat[14];
|
941
|
-
mat[15] = mat[3]*x + mat[7]*y + mat[11]*z + mat[15];
|
942
|
-
return mat;
|
943
|
-
}
|
944
|
-
|
945
|
-
var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
|
946
|
-
var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
|
947
|
-
var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
|
948
|
-
|
949
|
-
dest[0] = a00;
|
950
|
-
dest[1] = a01;
|
951
|
-
dest[2] = a02;
|
952
|
-
dest[3] = a03;
|
953
|
-
dest[4] = a10;
|
954
|
-
dest[5] = a11;
|
955
|
-
dest[6] = a12;
|
956
|
-
dest[7] = a13;
|
957
|
-
dest[8] = a20;
|
958
|
-
dest[9] = a21;
|
959
|
-
dest[10] = a22;
|
960
|
-
dest[11] = a23;
|
961
|
-
|
962
|
-
dest[12] = a00*x + a10*y + a20*z + mat[12];
|
963
|
-
dest[13] = a01*x + a11*y + a21*z + mat[13];
|
964
|
-
dest[14] = a02*x + a12*y + a22*z + mat[14];
|
965
|
-
dest[15] = a03*x + a13*y + a23*z + mat[15];
|
966
|
-
return dest;
|
967
|
-
};
|
968
|
-
|
969
|
-
/**
|
970
|
-
* mat4.scale(mat, vec[, dest]) -> mat4
|
971
|
-
* - mat (mat4) : mat4 to scale
|
972
|
-
* - vec (vec3) : vec3 specifying the scale for each axis
|
973
|
-
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
974
|
-
*
|
975
|
-
* Scales a matrix by the given vector
|
976
|
-
*
|
977
|
-
* Returns:
|
978
|
-
* dest if specified, mat otherwise
|
979
|
-
**/
|
980
|
-
mat4.scale = function(mat, vec, dest) {
|
981
|
-
var x = vec[0], y = vec[1], z = vec[2];
|
982
|
-
|
983
|
-
if(!dest || mat == dest) {
|
984
|
-
mat[0] *= x;
|
985
|
-
mat[1] *= x;
|
986
|
-
mat[2] *= x;
|
987
|
-
mat[3] *= x;
|
988
|
-
mat[4] *= y;
|
989
|
-
mat[5] *= y;
|
990
|
-
mat[6] *= y;
|
991
|
-
mat[7] *= y;
|
992
|
-
mat[8] *= z;
|
993
|
-
mat[9] *= z;
|
994
|
-
mat[10] *= z;
|
995
|
-
mat[11] *= z;
|
996
|
-
return mat;
|
997
|
-
}
|
998
|
-
|
999
|
-
dest[0] = mat[0]*x;
|
1000
|
-
dest[1] = mat[1]*x;
|
1001
|
-
dest[2] = mat[2]*x;
|
1002
|
-
dest[3] = mat[3]*x;
|
1003
|
-
dest[4] = mat[4]*y;
|
1004
|
-
dest[5] = mat[5]*y;
|
1005
|
-
dest[6] = mat[6]*y;
|
1006
|
-
dest[7] = mat[7]*y;
|
1007
|
-
dest[8] = mat[8]*z;
|
1008
|
-
dest[9] = mat[9]*z;
|
1009
|
-
dest[10] = mat[10]*z;
|
1010
|
-
dest[11] = mat[11]*z;
|
1011
|
-
dest[12] = mat[12];
|
1012
|
-
dest[13] = mat[13];
|
1013
|
-
dest[14] = mat[14];
|
1014
|
-
dest[15] = mat[15];
|
1015
|
-
return dest;
|
1016
|
-
};
|
1017
|
-
|
1018
|
-
/**
|
1019
|
-
* mat4.rotate(mat, angle, axis[, dest]) -> mat4
|
1020
|
-
* - mat (mat4) : mat4 to rotate
|
1021
|
-
* - angle (Number) : angle (in radians) to rotate
|
1022
|
-
* - axis (vec3) : vec3 representing the axis to rotate around
|
1023
|
-
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
1024
|
-
*
|
1025
|
-
* Rotates a matrix by the given angle around the specified axis
|
1026
|
-
* If rotating around a primary axis (X,Y,Z) one of the specialized rotation functions should be used instead for performance
|
1027
|
-
*
|
1028
|
-
* Returns:
|
1029
|
-
* dest if specified, mat otherwise
|
1030
|
-
**/
|
1031
|
-
mat4.rotate = function(mat, angle, axis, dest) {
|
1032
|
-
var x = axis[0], y = axis[1], z = axis[2];
|
1033
|
-
var len = Math.sqrt(x*x + y*y + z*z);
|
1034
|
-
if (!len) { return null; }
|
1035
|
-
if (len != 1) {
|
1036
|
-
len = 1 / len;
|
1037
|
-
x *= len;
|
1038
|
-
y *= len;
|
1039
|
-
z *= len;
|
1040
|
-
}
|
1041
|
-
|
1042
|
-
var s = Math.sin(angle);
|
1043
|
-
var c = Math.cos(angle);
|
1044
|
-
var t = 1-c;
|
1045
|
-
|
1046
|
-
// Cache the matrix values (makes for huge speed increases!)
|
1047
|
-
var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
|
1048
|
-
var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
|
1049
|
-
var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
|
1050
|
-
|
1051
|
-
// Construct the elements of the rotation matrix
|
1052
|
-
var b00 = x*x*t + c, b01 = y*x*t + z*s, b02 = z*x*t - y*s;
|
1053
|
-
var b10 = x*y*t - z*s, b11 = y*y*t + c, b12 = z*y*t + x*s;
|
1054
|
-
var b20 = x*z*t + y*s, b21 = y*z*t - x*s, b22 = z*z*t + c;
|
1055
|
-
|
1056
|
-
if(!dest) {
|
1057
|
-
dest = mat
|
1058
|
-
} else if(mat != dest) { // If the source and destination differ, copy the unchanged last row
|
1059
|
-
dest[12] = mat[12];
|
1060
|
-
dest[13] = mat[13];
|
1061
|
-
dest[14] = mat[14];
|
1062
|
-
dest[15] = mat[15];
|
1063
|
-
}
|
1064
|
-
|
1065
|
-
// Perform rotation-specific matrix multiplication
|
1066
|
-
dest[0] = a00*b00 + a10*b01 + a20*b02;
|
1067
|
-
dest[1] = a01*b00 + a11*b01 + a21*b02;
|
1068
|
-
dest[2] = a02*b00 + a12*b01 + a22*b02;
|
1069
|
-
dest[3] = a03*b00 + a13*b01 + a23*b02;
|
1070
|
-
|
1071
|
-
dest[4] = a00*b10 + a10*b11 + a20*b12;
|
1072
|
-
dest[5] = a01*b10 + a11*b11 + a21*b12;
|
1073
|
-
dest[6] = a02*b10 + a12*b11 + a22*b12;
|
1074
|
-
dest[7] = a03*b10 + a13*b11 + a23*b12;
|
1075
|
-
|
1076
|
-
dest[8] = a00*b20 + a10*b21 + a20*b22;
|
1077
|
-
dest[9] = a01*b20 + a11*b21 + a21*b22;
|
1078
|
-
dest[10] = a02*b20 + a12*b21 + a22*b22;
|
1079
|
-
dest[11] = a03*b20 + a13*b21 + a23*b22;
|
1080
|
-
return dest;
|
1081
|
-
};
|
1082
|
-
|
1083
|
-
/**
|
1084
|
-
* mat4.rotateX(mat, angle[, dest]) -> mat4
|
1085
|
-
* - mat (mat4) : mat4 to rotate
|
1086
|
-
* - angle (Number) : angle (in radians) to rotate
|
1087
|
-
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
1088
|
-
*
|
1089
|
-
* Rotates a matrix by the given angle around the X axis
|
1090
|
-
*
|
1091
|
-
* Returns:
|
1092
|
-
* dest if specified, mat otherwise
|
1093
|
-
**/
|
1094
|
-
mat4.rotateX = function(mat, angle, dest) {
|
1095
|
-
var s = Math.sin(angle);
|
1096
|
-
var c = Math.cos(angle);
|
1097
|
-
|
1098
|
-
// Cache the matrix values (makes for huge speed increases!)
|
1099
|
-
var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
|
1100
|
-
var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
|
1101
|
-
|
1102
|
-
if(!dest) {
|
1103
|
-
dest = mat
|
1104
|
-
} else if(mat != dest) { // If the source and destination differ, copy the unchanged rows
|
1105
|
-
dest[0] = mat[0];
|
1106
|
-
dest[1] = mat[1];
|
1107
|
-
dest[2] = mat[2];
|
1108
|
-
dest[3] = mat[3];
|
1109
|
-
|
1110
|
-
dest[12] = mat[12];
|
1111
|
-
dest[13] = mat[13];
|
1112
|
-
dest[14] = mat[14];
|
1113
|
-
dest[15] = mat[15];
|
1114
|
-
}
|
1115
|
-
|
1116
|
-
// Perform axis-specific matrix multiplication
|
1117
|
-
dest[4] = a10*c + a20*s;
|
1118
|
-
dest[5] = a11*c + a21*s;
|
1119
|
-
dest[6] = a12*c + a22*s;
|
1120
|
-
dest[7] = a13*c + a23*s;
|
1121
|
-
|
1122
|
-
dest[8] = a10*-s + a20*c;
|
1123
|
-
dest[9] = a11*-s + a21*c;
|
1124
|
-
dest[10] = a12*-s + a22*c;
|
1125
|
-
dest[11] = a13*-s + a23*c;
|
1126
|
-
return dest;
|
1127
|
-
};
|
1128
|
-
|
1129
|
-
/**
|
1130
|
-
* mat4.rotateY(mat, angle[, dest]) -> mat4
|
1131
|
-
* - mat (mat4) : mat4 to rotate
|
1132
|
-
* - angle (Number) : angle (in radians) to rotate
|
1133
|
-
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
1134
|
-
*
|
1135
|
-
* Rotates a matrix by the given angle around the Y axis
|
1136
|
-
*
|
1137
|
-
* Returns:
|
1138
|
-
* dest if specified, mat otherwise
|
1139
|
-
**/
|
1140
|
-
mat4.rotateY = function(mat, angle, dest) {
|
1141
|
-
var s = Math.sin(angle);
|
1142
|
-
var c = Math.cos(angle);
|
1143
|
-
|
1144
|
-
// Cache the matrix values (makes for huge speed increases!)
|
1145
|
-
var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
|
1146
|
-
var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
|
1147
|
-
|
1148
|
-
if(!dest) {
|
1149
|
-
dest = mat
|
1150
|
-
} else if(mat != dest) { // If the source and destination differ, copy the unchanged rows
|
1151
|
-
dest[4] = mat[4];
|
1152
|
-
dest[5] = mat[5];
|
1153
|
-
dest[6] = mat[6];
|
1154
|
-
dest[7] = mat[7];
|
1155
|
-
|
1156
|
-
dest[12] = mat[12];
|
1157
|
-
dest[13] = mat[13];
|
1158
|
-
dest[14] = mat[14];
|
1159
|
-
dest[15] = mat[15];
|
1160
|
-
}
|
1161
|
-
|
1162
|
-
// Perform axis-specific matrix multiplication
|
1163
|
-
dest[0] = a00*c + a20*-s;
|
1164
|
-
dest[1] = a01*c + a21*-s;
|
1165
|
-
dest[2] = a02*c + a22*-s;
|
1166
|
-
dest[3] = a03*c + a23*-s;
|
1167
|
-
|
1168
|
-
dest[8] = a00*s + a20*c;
|
1169
|
-
dest[9] = a01*s + a21*c;
|
1170
|
-
dest[10] = a02*s + a22*c;
|
1171
|
-
dest[11] = a03*s + a23*c;
|
1172
|
-
return dest;
|
1173
|
-
};
|
1174
|
-
|
1175
|
-
/**
|
1176
|
-
* mat4.rotateZ(mat, angle[, dest]) -> mat4
|
1177
|
-
* - mat (mat4) : mat4 to rotate
|
1178
|
-
* - angle (Number) : angle (in radians) to rotate
|
1179
|
-
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
1180
|
-
*
|
1181
|
-
* Rotates a matrix by the given angle around the Z axis
|
1182
|
-
*
|
1183
|
-
* Returns:
|
1184
|
-
* dest if specified, mat otherwise
|
1185
|
-
**/
|
1186
|
-
mat4.rotateZ = function(mat, angle, dest) {
|
1187
|
-
var s = Math.sin(angle);
|
1188
|
-
var c = Math.cos(angle);
|
1189
|
-
|
1190
|
-
// Cache the matrix values (makes for huge speed increases!)
|
1191
|
-
var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
|
1192
|
-
var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
|
1193
|
-
|
1194
|
-
if(!dest) {
|
1195
|
-
dest = mat
|
1196
|
-
} else if(mat != dest) { // If the source and destination differ, copy the unchanged last row
|
1197
|
-
dest[8] = mat[8];
|
1198
|
-
dest[9] = mat[9];
|
1199
|
-
dest[10] = mat[10];
|
1200
|
-
dest[11] = mat[11];
|
1201
|
-
|
1202
|
-
dest[12] = mat[12];
|
1203
|
-
dest[13] = mat[13];
|
1204
|
-
dest[14] = mat[14];
|
1205
|
-
dest[15] = mat[15];
|
1206
|
-
}
|
1207
|
-
|
1208
|
-
// Perform axis-specific matrix multiplication
|
1209
|
-
dest[0] = a00*c + a10*s;
|
1210
|
-
dest[1] = a01*c + a11*s;
|
1211
|
-
dest[2] = a02*c + a12*s;
|
1212
|
-
dest[3] = a03*c + a13*s;
|
1213
|
-
|
1214
|
-
dest[4] = a00*-s + a10*c;
|
1215
|
-
dest[5] = a01*-s + a11*c;
|
1216
|
-
dest[6] = a02*-s + a12*c;
|
1217
|
-
dest[7] = a03*-s + a13*c;
|
1218
|
-
|
1219
|
-
return dest;
|
1220
|
-
};
|
1221
|
-
|
1222
|
-
/**
|
1223
|
-
* mat4.frustum(left, right, bottom, top, near, far[, dest]) -> mat4
|
1224
|
-
* - left (Number) : scalar, left bounds of the frustum
|
1225
|
-
* - right (Number) : scalar, right bounds of the frustum
|
1226
|
-
* - bottom (Number) : scalar, bottom bounds of the frustum
|
1227
|
-
* - top (Number) : scalar, top bounds of the frustum
|
1228
|
-
* - near (Number) : scalar, near bounds of the frustum
|
1229
|
-
* - far (Number) : scalar, far bounds of the frustum
|
1230
|
-
* - dest (mat4) : optional mat4 frustum matrix will be written into. If not specified, a new mat4 is created.
|
1231
|
-
*
|
1232
|
-
* Generates a frustum matrix with the given bounds
|
1233
|
-
*
|
1234
|
-
* Returns:
|
1235
|
-
* dest if specified, a new mat4 otherwise
|
1236
|
-
**/
|
1237
|
-
mat4.frustum = function(left, right, bottom, top, near, far, dest) {
|
1238
|
-
if(!dest) { dest = mat4.create(); }
|
1239
|
-
var rl = (right - left);
|
1240
|
-
var tb = (top - bottom);
|
1241
|
-
var fn = (far - near);
|
1242
|
-
dest[0] = (near*2) / rl;
|
1243
|
-
dest[1] = 0;
|
1244
|
-
dest[2] = 0;
|
1245
|
-
dest[3] = 0;
|
1246
|
-
dest[4] = 0;
|
1247
|
-
dest[5] = (near*2) / tb;
|
1248
|
-
dest[6] = 0;
|
1249
|
-
dest[7] = 0;
|
1250
|
-
dest[8] = (right + left) / rl;
|
1251
|
-
dest[9] = (top + bottom) / tb;
|
1252
|
-
dest[10] = -(far + near) / fn;
|
1253
|
-
dest[11] = -1;
|
1254
|
-
dest[12] = 0;
|
1255
|
-
dest[13] = 0;
|
1256
|
-
dest[14] = -(far*near*2) / fn;
|
1257
|
-
dest[15] = 0;
|
1258
|
-
return dest;
|
1259
|
-
};
|
1260
|
-
|
1261
|
-
/**
|
1262
|
-
* mat4.perspective(fovy, aspect, near, far[, dest]) -> mat4
|
1263
|
-
* - fovy (Number) : scalar, vertical field of view
|
1264
|
-
* - aspect (Number) : scalar, aspect ratio. Typically viewport width/height
|
1265
|
-
* - near (Number) : scalar, near bounds of the frustum
|
1266
|
-
* - far (Number) : scalar, far bounds of the frustum
|
1267
|
-
* - dest (mat4) : optional mat4 the frustum matrix will be written into. If not specified, a new mat4 is created.
|
1268
|
-
*
|
1269
|
-
* Generates a perspective projection matrix with the given bounds
|
1270
|
-
*
|
1271
|
-
* Returns:
|
1272
|
-
* dest if specified, a new mat4 otherwise
|
1273
|
-
**/
|
1274
|
-
mat4.perspective = function(fovy, aspect, near, far, dest) {
|
1275
|
-
var top = near*Math.tan(fovy*Math.PI / 360.0);
|
1276
|
-
var right = top*aspect;
|
1277
|
-
return mat4.frustum(-right, right, -top, top, near, far, dest);
|
1278
|
-
};
|
1279
|
-
|
1280
|
-
/**
|
1281
|
-
* mat4.ortho(left, right, bottom, top, near, far[, dest]) -> mat4
|
1282
|
-
* - left (Number) : scalar, left bounds of the frustum
|
1283
|
-
* - right (Number) : scalar, right bounds of the frustum
|
1284
|
-
* - bottom (Number) : scalar, bottom bounds of the frustum
|
1285
|
-
* - top (Number) : scalar, top bounds of the frustum
|
1286
|
-
* - near (Number) : scalar, near bounds of the frustum
|
1287
|
-
* - far (Number) : scalar, far bounds of the frustum
|
1288
|
-
* - dest (mat4) : optional mat4 the frustum matrix will be written into. If not specified, a new mat4 is created.
|
1289
|
-
*
|
1290
|
-
* Generates a orthogonal projection matrix with the given bounds
|
1291
|
-
*
|
1292
|
-
* Returns:
|
1293
|
-
* dest if specified, a new mat4 otherwise
|
1294
|
-
**/
|
1295
|
-
mat4.ortho = function(left, right, bottom, top, near, far, dest) {
|
1296
|
-
if(!dest) { dest = mat4.create(); }
|
1297
|
-
var rl = (right - left);
|
1298
|
-
var tb = (top - bottom);
|
1299
|
-
var fn = (far - near);
|
1300
|
-
dest[0] = 2 / rl;
|
1301
|
-
dest[1] = 0;
|
1302
|
-
dest[2] = 0;
|
1303
|
-
dest[3] = 0;
|
1304
|
-
dest[4] = 0;
|
1305
|
-
dest[5] = 2 / tb;
|
1306
|
-
dest[6] = 0;
|
1307
|
-
dest[7] = 0;
|
1308
|
-
dest[8] = 0;
|
1309
|
-
dest[9] = 0;
|
1310
|
-
dest[10] = -2 / fn;
|
1311
|
-
dest[11] = 0;
|
1312
|
-
dest[12] = -(left + right) / rl;
|
1313
|
-
dest[13] = -(top + bottom) / tb;
|
1314
|
-
dest[14] = -(far + near) / fn;
|
1315
|
-
dest[15] = 1;
|
1316
|
-
return dest;
|
1317
|
-
};
|
1318
|
-
|
1319
|
-
/**
|
1320
|
-
* mat4.lookAt(eye, center, up[, dest]) -> mat4
|
1321
|
-
* - eye (vec3) : position of the viewer
|
1322
|
-
* - center (vec3) : the point the viewer is looking at
|
1323
|
-
* - up (vec3) : vec3 pointing "up"
|
1324
|
-
* - dest (mat4) : optional mat4 the frustum matrix will be written into. If not specified, a new mat4 is created.
|
1325
|
-
*
|
1326
|
-
* Generates a look-at matrix with the given eye position, focal point, and up axis
|
1327
|
-
*
|
1328
|
-
* Returns:
|
1329
|
-
* dest if specified, a new mat4 otherwise
|
1330
|
-
**/
|
1331
|
-
mat4.lookAt = function(eye, center, up, dest) {
|
1332
|
-
if(!dest) { dest = mat4.create(); }
|
1333
|
-
|
1334
|
-
var eyex = eye[0],
|
1335
|
-
eyey = eye[1],
|
1336
|
-
eyez = eye[2],
|
1337
|
-
upx = up[0],
|
1338
|
-
upy = up[1],
|
1339
|
-
upz = up[2],
|
1340
|
-
centerx = center[0],
|
1341
|
-
centery = center[1],
|
1342
|
-
centerz = center[2];
|
1343
|
-
|
1344
|
-
if (eyex == centerx && eyey == centery && eyez == centerz) {
|
1345
|
-
return mat4.identity(dest);
|
1346
|
-
}
|
1347
|
-
|
1348
|
-
var z0,z1,z2,x0,x1,x2,y0,y1,y2,len;
|
1349
|
-
|
1350
|
-
//vec3.direction(eye, center, z);
|
1351
|
-
z0 = eyex - center[0];
|
1352
|
-
z1 = eyey - center[1];
|
1353
|
-
z2 = eyez - center[2];
|
1354
|
-
|
1355
|
-
// normalize (no check needed for 0 because of early return)
|
1356
|
-
len = 1/Math.sqrt(z0*z0 + z1*z1 + z2*z2);
|
1357
|
-
z0 *= len;
|
1358
|
-
z1 *= len;
|
1359
|
-
z2 *= len;
|
1360
|
-
|
1361
|
-
//vec3.normalize(vec3.cross(up, z, x));
|
1362
|
-
x0 = upy*z2 - upz*z1;
|
1363
|
-
x1 = upz*z0 - upx*z2;
|
1364
|
-
x2 = upx*z1 - upy*z0;
|
1365
|
-
len = Math.sqrt(x0*x0 + x1*x1 + x2*x2);
|
1366
|
-
if (!len) {
|
1367
|
-
x0 = 0;
|
1368
|
-
x1 = 0;
|
1369
|
-
x2 = 0;
|
1370
|
-
} else {
|
1371
|
-
len = 1/len;
|
1372
|
-
x0 *= len;
|
1373
|
-
x1 *= len;
|
1374
|
-
x2 *= len;
|
1375
|
-
};
|
1376
|
-
|
1377
|
-
//vec3.normalize(vec3.cross(z, x, y));
|
1378
|
-
y0 = z1*x2 - z2*x1;
|
1379
|
-
y1 = z2*x0 - z0*x2;
|
1380
|
-
y2 = z0*x1 - z1*x0;
|
1381
|
-
|
1382
|
-
len = Math.sqrt(y0*y0 + y1*y1 + y2*y2);
|
1383
|
-
if (!len) {
|
1384
|
-
y0 = 0;
|
1385
|
-
y1 = 0;
|
1386
|
-
y2 = 0;
|
1387
|
-
} else {
|
1388
|
-
len = 1/len;
|
1389
|
-
y0 *= len;
|
1390
|
-
y1 *= len;
|
1391
|
-
y2 *= len;
|
1392
|
-
}
|
1393
|
-
|
1394
|
-
dest[0] = x0;
|
1395
|
-
dest[1] = y0;
|
1396
|
-
dest[2] = z0;
|
1397
|
-
dest[3] = 0;
|
1398
|
-
dest[4] = x1;
|
1399
|
-
dest[5] = y1;
|
1400
|
-
dest[6] = z1;
|
1401
|
-
dest[7] = 0;
|
1402
|
-
dest[8] = x2;
|
1403
|
-
dest[9] = y2;
|
1404
|
-
dest[10] = z2;
|
1405
|
-
dest[11] = 0;
|
1406
|
-
dest[12] = -(x0*eyex + x1*eyey + x2*eyez);
|
1407
|
-
dest[13] = -(y0*eyex + y1*eyey + y2*eyez);
|
1408
|
-
dest[14] = -(z0*eyex + z1*eyey + z2*eyez);
|
1409
|
-
dest[15] = 1;
|
1410
|
-
|
1411
|
-
return dest;
|
1412
|
-
};
|
1413
|
-
|
1414
|
-
/**
|
1415
|
-
* mat4.str(mat) -> String
|
1416
|
-
* - mat (mat4) : mat4 to represent as a string
|
1417
|
-
*
|
1418
|
-
* Returns a string representation of a mat4
|
1419
|
-
*
|
1420
|
-
* Returns:
|
1421
|
-
* string representation of mat
|
1422
|
-
**/
|
1423
|
-
mat4.str = function(mat) {
|
1424
|
-
return '[' + mat[0] + ', ' + mat[1] + ', ' + mat[2] + ', ' + mat[3] +
|
1425
|
-
', '+ mat[4] + ', ' + mat[5] + ', ' + mat[6] + ', ' + mat[7] +
|
1426
|
-
', '+ mat[8] + ', ' + mat[9] + ', ' + mat[10] + ', ' + mat[11] +
|
1427
|
-
', '+ mat[12] + ', ' + mat[13] + ', ' + mat[14] + ', ' + mat[15] + ']';
|
1428
|
-
};
|
1429
|
-
|
1430
|
-
/**
|
1431
|
-
* quat4
|
1432
|
-
* Quaternions
|
1433
|
-
**/
|
1434
|
-
quat4 = {};
|
1435
|
-
|
1436
|
-
/**
|
1437
|
-
* quat4.create([quat]) -> quat4
|
1438
|
-
* - quat (quat4) : optional quat4 containing values to initialize with
|
1439
|
-
*
|
1440
|
-
* Creates a new instance of a quat4 using the default array type
|
1441
|
-
* Any javascript array containing at least 4 numeric elements can serve as a quat4
|
1442
|
-
*
|
1443
|
-
* Returns:
|
1444
|
-
* New quat4
|
1445
|
-
**/
|
1446
|
-
quat4.create = function(quat) {
|
1447
|
-
var dest = new glMatrixArrayType(4);
|
1448
|
-
|
1449
|
-
if(quat) {
|
1450
|
-
dest[0] = quat[0];
|
1451
|
-
dest[1] = quat[1];
|
1452
|
-
dest[2] = quat[2];
|
1453
|
-
dest[3] = quat[3];
|
1454
|
-
}
|
1455
|
-
|
1456
|
-
return dest;
|
1457
|
-
};
|
1458
|
-
|
1459
|
-
/**
|
1460
|
-
* quat4.set(quat, dest) -> quat4
|
1461
|
-
* - quat (quat4) : quat4 containing values to copy
|
1462
|
-
* - dest (quat4) : quat4 receiving copied values
|
1463
|
-
*
|
1464
|
-
* Copies the values of one quat4 to another
|
1465
|
-
*
|
1466
|
-
* Returns:
|
1467
|
-
* dest
|
1468
|
-
**/
|
1469
|
-
quat4.set = function(quat, dest) {
|
1470
|
-
dest[0] = quat[0];
|
1471
|
-
dest[1] = quat[1];
|
1472
|
-
dest[2] = quat[2];
|
1473
|
-
dest[3] = quat[3];
|
1474
|
-
|
1475
|
-
return dest;
|
1476
|
-
};
|
1477
|
-
|
1478
|
-
/**
|
1479
|
-
* quat4.calculateW(quat[, dest]) -> quat4
|
1480
|
-
* - quat (quat4) : quat4 to calculate W component of
|
1481
|
-
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
|
1482
|
-
*
|
1483
|
-
* Calculates the W component of a quat4 from the X, Y, and Z components.
|
1484
|
-
* Assumes that quaternion is 1 unit in length.
|
1485
|
-
* Any existing W component will be ignored.
|
1486
|
-
*
|
1487
|
-
* Returns:
|
1488
|
-
* dest if specified, quat otherwise
|
1489
|
-
**/
|
1490
|
-
quat4.calculateW = function(quat, dest) {
|
1491
|
-
var x = quat[0], y = quat[1], z = quat[2];
|
1492
|
-
|
1493
|
-
if(!dest || quat == dest) {
|
1494
|
-
quat[3] = -Math.sqrt(Math.abs(1.0 - x*x - y*y - z*z));
|
1495
|
-
return quat;
|
1496
|
-
}
|
1497
|
-
dest[0] = x;
|
1498
|
-
dest[1] = y;
|
1499
|
-
dest[2] = z;
|
1500
|
-
dest[3] = -Math.sqrt(Math.abs(1.0 - x*x - y*y - z*z));
|
1501
|
-
return dest;
|
1502
|
-
}
|
1503
|
-
|
1504
|
-
/**
|
1505
|
-
* quat4.inverse(quat[, dest]) -> quat4
|
1506
|
-
* - quat (quat4) : quat4 to calculate inverse of
|
1507
|
-
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
|
1508
|
-
*
|
1509
|
-
* Calculates the inverse of a quat4
|
1510
|
-
*
|
1511
|
-
* Returns:
|
1512
|
-
* dest if specified, quat otherwise
|
1513
|
-
**/
|
1514
|
-
quat4.inverse = function(quat, dest) {
|
1515
|
-
if(!dest || quat == dest) {
|
1516
|
-
quat[0] *= 1;
|
1517
|
-
quat[1] *= 1;
|
1518
|
-
quat[2] *= 1;
|
1519
|
-
return quat;
|
1520
|
-
}
|
1521
|
-
dest[0] = -quat[0];
|
1522
|
-
dest[1] = -quat[1];
|
1523
|
-
dest[2] = -quat[2];
|
1524
|
-
dest[3] = quat[3];
|
1525
|
-
return dest;
|
1526
|
-
}
|
1527
|
-
|
1528
|
-
/**
|
1529
|
-
* quat4.length(quat) -> quat4
|
1530
|
-
* - quat (quat4) : quat4 to calculate length of
|
1531
|
-
*
|
1532
|
-
* Calculates the length of a quat4
|
1533
|
-
*
|
1534
|
-
* Returns:
|
1535
|
-
* Length of quat
|
1536
|
-
**/
|
1537
|
-
quat4.length = function(quat) {
|
1538
|
-
var x = quat[0], y = quat[1], z = quat[2], w = quat[3];
|
1539
|
-
return Math.sqrt(x*x + y*y + z*z + w*w);
|
1540
|
-
}
|
1541
|
-
|
1542
|
-
/**
|
1543
|
-
* quat4.normalize(quat[, dest]) -> quat4
|
1544
|
-
* - quat (quat4) : quat4 to normalize
|
1545
|
-
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
|
1546
|
-
*
|
1547
|
-
* Generates a unit quaternion of the same direction as the provided quat4
|
1548
|
-
* If quaternion length is 0, returns [0, 0, 0, 0]
|
1549
|
-
*
|
1550
|
-
* Returns:
|
1551
|
-
* dest if specified, quat otherwise
|
1552
|
-
**/
|
1553
|
-
quat4.normalize = function(quat, dest) {
|
1554
|
-
if(!dest) { dest = quat; }
|
1555
|
-
|
1556
|
-
var x = quat[0], y = quat[1], z = quat[2], w = quat[3];
|
1557
|
-
var len = Math.sqrt(x*x + y*y + z*z + w*w);
|
1558
|
-
if(len == 0) {
|
1559
|
-
dest[0] = 0;
|
1560
|
-
dest[1] = 0;
|
1561
|
-
dest[2] = 0;
|
1562
|
-
dest[3] = 0;
|
1563
|
-
return dest;
|
1564
|
-
}
|
1565
|
-
len = 1/len;
|
1566
|
-
dest[0] = x * len;
|
1567
|
-
dest[1] = y * len;
|
1568
|
-
dest[2] = z * len;
|
1569
|
-
dest[3] = w * len;
|
1570
|
-
|
1571
|
-
return dest;
|
1572
|
-
}
|
1573
|
-
|
1574
|
-
/**
|
1575
|
-
* quat4.multiply(quat, quat2[, dest]) -> quat4
|
1576
|
-
* - quat (quat4) : first operand
|
1577
|
-
* - quat2 (quat4) : second operand
|
1578
|
-
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
|
1579
|
-
*
|
1580
|
-
* Performs a quaternion multiplication
|
1581
|
-
*
|
1582
|
-
* Returns:
|
1583
|
-
* dest if specified, quat otherwise
|
1584
|
-
**/
|
1585
|
-
quat4.multiply = function(quat, quat2, dest) {
|
1586
|
-
if(!dest) { dest = quat; }
|
1587
|
-
|
1588
|
-
var qax = quat[0], qay = quat[1], qaz = quat[2], qaw = quat[3];
|
1589
|
-
var qbx = quat2[0], qby = quat2[1], qbz = quat2[2], qbw = quat2[3];
|
1590
|
-
|
1591
|
-
dest[0] = qax*qbw + qaw*qbx + qay*qbz - qaz*qby;
|
1592
|
-
dest[1] = qay*qbw + qaw*qby + qaz*qbx - qax*qbz;
|
1593
|
-
dest[2] = qaz*qbw + qaw*qbz + qax*qby - qay*qbx;
|
1594
|
-
dest[3] = qaw*qbw - qax*qbx - qay*qby - qaz*qbz;
|
1595
|
-
|
1596
|
-
return dest;
|
1597
|
-
}
|
1598
|
-
|
1599
|
-
/**
|
1600
|
-
* quat4.multiplyVec3(quat, vec[, dest]) -> vec3
|
1601
|
-
* - quat (quat4) : quat4 to transform the vector with
|
1602
|
-
* - vec (vec3) : vec3 to transform
|
1603
|
-
* - dest (vec3) : optional vec3 receiving calculated values. If not specified, result is written to +vec+.
|
1604
|
-
*
|
1605
|
-
* Transforms a vec3 with the given quaternion
|
1606
|
-
*
|
1607
|
-
* Returns:
|
1608
|
-
* dest if specified, vec otherwise
|
1609
|
-
**/
|
1610
|
-
quat4.multiplyVec3 = function(quat, vec, dest) {
|
1611
|
-
if(!dest) { dest = vec; }
|
1612
|
-
|
1613
|
-
var x = vec[0], y = vec[1], z = vec[2];
|
1614
|
-
var qx = quat[0], qy = quat[1], qz = quat[2], qw = quat[3];
|
1615
|
-
|
1616
|
-
// calculate quat * vec
|
1617
|
-
var ix = qw*x + qy*z - qz*y;
|
1618
|
-
var iy = qw*y + qz*x - qx*z;
|
1619
|
-
var iz = qw*z + qx*y - qy*x;
|
1620
|
-
var iw = -qx*x - qy*y - qz*z;
|
1621
|
-
|
1622
|
-
// calculate result * inverse quat
|
1623
|
-
dest[0] = ix*qw + iw*-qx + iy*-qz - iz*-qy;
|
1624
|
-
dest[1] = iy*qw + iw*-qy + iz*-qx - ix*-qz;
|
1625
|
-
dest[2] = iz*qw + iw*-qz + ix*-qy - iy*-qx;
|
1626
|
-
|
1627
|
-
return dest;
|
1628
|
-
}
|
1629
|
-
|
1630
|
-
/**
|
1631
|
-
* quat4.toMat3(quat[, dest]) -> mat3
|
1632
|
-
* - quat (quat4) : quat4 to create matrix from
|
1633
|
-
* - dest (mat3) : optional mat3 receiving operation result. If not specified, a new mat3 is created.
|
1634
|
-
*
|
1635
|
-
* Calculates a 3x3 matrix from the given quat4
|
1636
|
-
*
|
1637
|
-
* Returns:
|
1638
|
-
* dest if specified, a new mat3 otherwise
|
1639
|
-
**/
|
1640
|
-
quat4.toMat3 = function(quat, dest) {
|
1641
|
-
if(!dest) { dest = mat3.create(); }
|
1642
|
-
|
1643
|
-
var x = quat[0], y = quat[1], z = quat[2], w = quat[3];
|
1644
|
-
|
1645
|
-
var x2 = x + x;
|
1646
|
-
var y2 = y + y;
|
1647
|
-
var z2 = z + z;
|
1648
|
-
|
1649
|
-
var xx = x*x2;
|
1650
|
-
var xy = x*y2;
|
1651
|
-
var xz = x*z2;
|
1652
|
-
|
1653
|
-
var yy = y*y2;
|
1654
|
-
var yz = y*z2;
|
1655
|
-
var zz = z*z2;
|
1656
|
-
|
1657
|
-
var wx = w*x2;
|
1658
|
-
var wy = w*y2;
|
1659
|
-
var wz = w*z2;
|
1660
|
-
|
1661
|
-
dest[0] = 1 - (yy + zz);
|
1662
|
-
dest[1] = xy - wz;
|
1663
|
-
dest[2] = xz + wy;
|
1664
|
-
|
1665
|
-
dest[3] = xy + wz;
|
1666
|
-
dest[4] = 1 - (xx + zz);
|
1667
|
-
dest[5] = yz - wx;
|
1668
|
-
|
1669
|
-
dest[6] = xz - wy;
|
1670
|
-
dest[7] = yz + wx;
|
1671
|
-
dest[8] = 1 - (xx + yy);
|
1672
|
-
|
1673
|
-
return dest;
|
1674
|
-
}
|
1675
|
-
|
1676
|
-
/**
|
1677
|
-
* quat4.toMat4(quat[, dest]) -> mat4
|
1678
|
-
* - quat (quat4) : quat4 to create matrix from
|
1679
|
-
* - dest (mat4) : optional mat4 receiving calculated values. If not specified, a new mat4 is created.
|
1680
|
-
*
|
1681
|
-
* Calculates a 4x4 matrix from the given quat4
|
1682
|
-
*
|
1683
|
-
* Returns:
|
1684
|
-
* dest if specified, a new mat4 otherwise
|
1685
|
-
**/
|
1686
|
-
quat4.toMat4 = function(quat, dest) {
|
1687
|
-
if(!dest) { dest = mat4.create(); }
|
1688
|
-
|
1689
|
-
var x = quat[0], y = quat[1], z = quat[2], w = quat[3];
|
1690
|
-
|
1691
|
-
var x2 = x + x;
|
1692
|
-
var y2 = y + y;
|
1693
|
-
var z2 = z + z;
|
1694
|
-
|
1695
|
-
var xx = x*x2;
|
1696
|
-
var xy = x*y2;
|
1697
|
-
var xz = x*z2;
|
1698
|
-
|
1699
|
-
var yy = y*y2;
|
1700
|
-
var yz = y*z2;
|
1701
|
-
var zz = z*z2;
|
1702
|
-
|
1703
|
-
var wx = w*x2;
|
1704
|
-
var wy = w*y2;
|
1705
|
-
var wz = w*z2;
|
1706
|
-
|
1707
|
-
dest[0] = 1 - (yy + zz);
|
1708
|
-
dest[1] = xy - wz;
|
1709
|
-
dest[2] = xz + wy;
|
1710
|
-
dest[3] = 0;
|
1711
|
-
|
1712
|
-
dest[4] = xy + wz;
|
1713
|
-
dest[5] = 1 - (xx + zz);
|
1714
|
-
dest[6] = yz - wx;
|
1715
|
-
dest[7] = 0;
|
1716
|
-
|
1717
|
-
dest[8] = xz - wy;
|
1718
|
-
dest[9] = yz + wx;
|
1719
|
-
dest[10] = 1 - (xx + yy);
|
1720
|
-
dest[11] = 0;
|
1721
|
-
|
1722
|
-
dest[12] = 0;
|
1723
|
-
dest[13] = 0;
|
1724
|
-
dest[14] = 0;
|
1725
|
-
dest[15] = 1;
|
1726
|
-
|
1727
|
-
return dest;
|
1728
|
-
}
|
1729
|
-
|
1730
|
-
/**
|
1731
|
-
* quat4.slerp(quat, quat2, lerp[, dest]) -> quat4
|
1732
|
-
* - quat (quat4) : first quarternion
|
1733
|
-
* - quat2 (quat4) : second quaternion
|
1734
|
-
* - lerp (Number) : interpolation amount between the two inputs
|
1735
|
-
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to +quat+.
|
1736
|
-
*
|
1737
|
-
* Performs a spherical linear interpolation between two quat4
|
1738
|
-
*
|
1739
|
-
* Returns:
|
1740
|
-
* dest if specified, quat otherwise
|
1741
|
-
**/
|
1742
|
-
quat4.slerp = function(quat, quat2, lerp, dest) {
|
1743
|
-
if(!dest) { dest = quat; }
|
1744
|
-
|
1745
|
-
var eps_lerp = lerp;
|
1746
|
-
|
1747
|
-
var dot = quat[0]*quat2[0] + quat[1]*quat2[1] + quat[2]*quat2[2] + quat[3]*quat2[3];
|
1748
|
-
if (dot < 0.0) {
|
1749
|
-
eps_lerp = -1.0 * lerp;
|
1750
|
-
}
|
1751
|
-
|
1752
|
-
dest[0] = 1.0 - lerp * quat[0] + eps_lerp * quat2[0];
|
1753
|
-
dest[1] = 1.0 - lerp * quat[1] + eps_lerp * quat2[1];
|
1754
|
-
dest[2] = 1.0 - lerp * quat[2] + eps_lerp * quat2[2];
|
1755
|
-
dest[3] = 1.0 - lerp * quat[3] + eps_lerp * quat2[3];
|
1756
|
-
|
1757
|
-
return dest;
|
1758
|
-
}
|
1759
|
-
|
1760
|
-
/**
|
1761
|
-
* quat4.str(quat) -> String
|
1762
|
-
* - quat (quat4) : quat4 to represent as a string
|
1763
|
-
*
|
1764
|
-
* Returns a string representation of a quaternion
|
1765
|
-
*
|
1766
|
-
* Returns:
|
1767
|
-
* string representation of quat
|
1768
|
-
**/
|
1769
|
-
quat4.str = function(quat) {
|
1770
|
-
return '[' + quat[0] + ', ' + quat[1] + ', ' + quat[2] + ', ' + quat[3] + ']';
|
1771
|
-
}
|
1772
|
-
|