diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/math/vec4.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/vec4.js | 567 |
1 files changed, 284 insertions, 283 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/math/vec4.js b/js/helper-classes/RDGE/src/core/script/math/vec4.js index 53759d6e..1052d3a5 100755 --- a/js/helper-classes/RDGE/src/core/script/math/vec4.js +++ b/js/helper-classes/RDGE/src/core/script/math/vec4.js | |||
@@ -1,283 +1,284 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | |
5 | 5 | Redistribution and use in source and binary forms, with or without | |
6 | Redistribution and use in source and binary forms, with or without | 6 | modification, are permitted provided that the following conditions are met: |
7 | modification, are permitted provided that the following conditions are met: | 7 | |
8 | 8 | * Redistributions of source code must retain the above copyright notice, | |
9 | - Redistributions of source code must retain the above copyright notice, | 9 | this list of conditions and the following disclaimer. |
10 | this list of conditions and the following disclaimer. | 10 | |
11 | - Redistributions in binary form must reproduce the above copyright | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
12 | notice, this list of conditions and the following disclaimer in the | 12 | this list of conditions and the following disclaimer in the documentation |
13 | documentation and/or other materials provided with the distribution. | 13 | and/or other materials provided with the distribution. |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 14 | |
15 | may be used to endorse or promote products derived from this software | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | without specific prior written permission. | 16 | contributors may be used to endorse or promote products derived from this |
17 | 17 | software without specific prior written permission. | |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | </copyright> */ | 29 | POSSIBILITY OF SUCH DAMAGE. |
30 | 30 | </copyright> */ | |
31 | /** | 31 | |
32 | * RDGE.vec4 = {} | 32 | /** |
33 | * This library contains functions for operating on 4D vectors. Any JS array | 33 | * RDGE.vec4 = {} |
34 | * containing at least 4 numeric components can represent a 4D vector. | 34 | * This library contains functions for operating on 4D vectors. Any JS array |
35 | * | 35 | * containing at least 4 numeric components can represent a 4D vector. |
36 | * For example, all of these are valid RDGE.vec4 declarations: | 36 | * |
37 | * var a = [0, 0, 0, 1]; | 37 | * For example, all of these are valid RDGE.vec4 declarations: |
38 | * var b = RDGE.RDGE.vec4.identity(); | 38 | * var a = [0, 0, 0, 1]; |
39 | * var c = RDGE.RDGE.vec4.zero(); | 39 | * var b = RDGE.RDGE.vec4.identity(); |
40 | * | 40 | * var c = RDGE.RDGE.vec4.zero(); |
41 | */ | 41 | * |
42 | var RDGE = RDGE || {}; | 42 | */ |
43 | RDGE.vec4 = {}; | 43 | var RDGE = RDGE || {}; |
44 | 44 | RDGE.vec4 = {}; | |
45 | /** | 45 | |
46 | * RDGE.vec4.string | 46 | /** |
47 | */ | 47 | * RDGE.vec4.string |
48 | RDGE.vec4.string = function (v) { | 48 | */ |
49 | return "{ " + v[0] + ", " + v[1] + ", " + v[2] + ", " + v[3] + " }"; | 49 | RDGE.vec4.string = function (v) { |
50 | }; | 50 | return "{ " + v[0] + ", " + v[1] + ", " + v[2] + ", " + v[3] + " }"; |
51 | 51 | }; | |
52 | /** | 52 | |
53 | * RDGE.vec4.verify | 53 | /** |
54 | */ | 54 | * RDGE.vec4.verify |
55 | RDGE.vec4.verify = function (v) { | 55 | */ |
56 | if (v == undefined || v.length == undefined || v.length < 4) { | 56 | RDGE.vec4.verify = function (v) { |
57 | return false; | 57 | if (v == undefined || v.length == undefined || v.length < 4) { |
58 | } | 58 | return false; |
59 | 59 | } | |
60 | if (typeof (v[0]) != "number" || typeof (v[1]) != "number" || typeof (v[2]) != "number" || typeof (v[3]) != "number") { | 60 | |
61 | return false; | 61 | if (typeof (v[0]) != "number" || typeof (v[1]) != "number" || typeof (v[2]) != "number" || typeof (v[3]) != "number") { |
62 | } | 62 | return false; |
63 | 63 | } | |
64 | return true; | 64 | |
65 | }; | 65 | return true; |
66 | 66 | }; | |
67 | /** | 67 | |
68 | * RDGE.vec4.inplace_copy | 68 | /** |
69 | */ | 69 | * RDGE.vec4.inplace_copy |
70 | RDGE.vec4.inplace_copy = function (dst, src) { | 70 | */ |
71 | dst[0] = src[0]; | 71 | RDGE.vec4.inplace_copy = function (dst, src) { |
72 | dst[1] = src[1]; | 72 | dst[0] = src[0]; |
73 | dst[2] = src[2]; | 73 | dst[1] = src[1]; |
74 | dst[3] = src[3]; | 74 | dst[2] = src[2]; |
75 | }; | 75 | dst[3] = src[3]; |
76 | 76 | }; | |
77 | /** | 77 | |
78 | * RDGE.vec4.copy | 78 | /** |
79 | */ | 79 | * RDGE.vec4.copy |
80 | RDGE.vec4.copy = function (v) { | 80 | */ |
81 | if (v.length == undefined) { | 81 | RDGE.vec4.copy = function (v) { |
82 | return [v, v, v, v]; | 82 | if (v.length == undefined) { |
83 | } | 83 | return [v, v, v, v]; |
84 | 84 | } | |
85 | if (v.length == 3) { | 85 | |
86 | return [v[0], v[1], v[2], 1.0]; | 86 | if (v.length == 3) { |
87 | } | 87 | return [v[0], v[1], v[2], 1.0]; |
88 | 88 | } | |
89 | return [v[0], v[1], v[2], v[3]]; | 89 | |
90 | }; | 90 | return [v[0], v[1], v[2], v[3]]; |
91 | 91 | }; | |
92 | /** | 92 | |
93 | * RDGE.vec4.zero | 93 | /** |
94 | */ | 94 | * RDGE.vec4.zero |
95 | RDGE.vec4.zero = function () { | 95 | */ |
96 | return [0.0, 0.0, 0.0, 0.0]; | 96 | RDGE.vec4.zero = function () { |
97 | }; | 97 | return [0.0, 0.0, 0.0, 0.0]; |
98 | 98 | }; | |
99 | /** | 99 | |
100 | * RDGE.vec4.identity | 100 | /** |
101 | */ | 101 | * RDGE.vec4.identity |
102 | RDGE.vec4.identity = function () { | 102 | */ |
103 | return [0.0, 0.0, 0.0, 1.0]; | 103 | RDGE.vec4.identity = function () { |
104 | }; | 104 | return [0.0, 0.0, 0.0, 1.0]; |
105 | 105 | }; | |
106 | /** | 106 | |
107 | * RDGE.vec4.up | 107 | /** |
108 | */ | 108 | * RDGE.vec4.up |
109 | RDGE.vec4.up = function () { | 109 | */ |
110 | return [0.0, 1.0, 0.0, 0.0]; | 110 | RDGE.vec4.up = function () { |
111 | }; | 111 | return [0.0, 1.0, 0.0, 0.0]; |
112 | 112 | }; | |
113 | /** | 113 | |
114 | * RDGE.vec4.forward | 114 | /** |
115 | */ | 115 | * RDGE.vec4.forward |
116 | RDGE.vec4.forward = function () { | 116 | */ |
117 | return [0.0, 0.0, 1.0, 0.0]; | 117 | RDGE.vec4.forward = function () { |
118 | }; | 118 | return [0.0, 0.0, 1.0, 0.0]; |
119 | 119 | }; | |
120 | /** | 120 | |
121 | * RDGE.vec4.right | 121 | /** |
122 | */ | 122 | * RDGE.vec4.right |
123 | RDGE.vec4.right = function () { | 123 | */ |
124 | return [1.0, 0.0, 0.0, 0.0]; | 124 | RDGE.vec4.right = function () { |
125 | }; | 125 | return [1.0, 0.0, 0.0, 0.0]; |
126 | 126 | }; | |
127 | /** | 127 | |
128 | * RDGE.vec4.random | 128 | /** |
129 | */ | 129 | * RDGE.vec4.random |
130 | RDGE.vec4.random = function (min, max) { | 130 | */ |
131 | return [min[0] + (max[0] - min[0]) * Math.random(), | 131 | RDGE.vec4.random = function (min, max) { |
132 | min[1] + (max[1] - min[1]) * Math.random(), | 132 | return [min[0] + (max[0] - min[0]) * Math.random(), |
133 | min[2] + (max[2] - min[2]) * Math.random(), | 133 | min[1] + (max[1] - min[1]) * Math.random(), |
134 | min[3] + (max[3] - min[3]) * Math.random()]; | 134 | min[2] + (max[2] - min[2]) * Math.random(), |
135 | }; | 135 | min[3] + (max[3] - min[3]) * Math.random()]; |
136 | 136 | }; | |
137 | /** | 137 | |
138 | * RDGE.vec4.add | 138 | /** |
139 | */ |