diff options
author | Valerio Virgillito | 2012-04-04 15:53:29 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-04-04 15:53:29 -0700 |
commit | e721a7c1009f298a1bd8fea583da14535e039880 (patch) | |
tree | 9415f5ba25ad643df678e561719d2708fd3ead5a /js/helper-classes/RDGE/src/core/script/math/vec3.js | |
parent | 8482e23cd9b8c4700b5130f2588e5eb24d376536 (diff) | |
parent | 7249d6377c8897b2f9d8115be99717be971a0981 (diff) | |
download | ninja-e721a7c1009f298a1bd8fea583da14535e039880.tar.gz |
Merge pull request #156 from mayhewinator/WorkingBranch
Namespace and code cleanup for RDGE and related files
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/math/vec3.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/vec3.js | 423 |
1 files changed, 211 insertions, 212 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/math/vec3.js b/js/helper-classes/RDGE/src/core/script/math/vec3.js index 143fc352..aa76b958 100755 --- a/js/helper-classes/RDGE/src/core/script/math/vec3.js +++ b/js/helper-classes/RDGE/src/core/script/math/vec3.js | |||
@@ -6,346 +6,345 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | 7 | ||
8 | /** | 8 | /** |
9 | * vec3 = {} | 9 | * RDGE.vec3 = {} |
10 | * This library contains functions for operating on 3D vectors. Any JS array | 10 | * This library contains functions for operating on 3D vectors. Any JS array |
11 | * containing at least 3 numeric components can represent a 3D vector. | 11 | * containing at least 3 numeric components can represent a 3D vector. |
12 | * | 12 | * |
13 | * For example, all of these are valid vec3 declarations: | 13 | * For example, all of these are valid RDGE.vec3 declarations: |
14 | * var a = [0, 0, 1]; | 14 | * var a = [0, 0, 1]; |
15 | * var b = vec3.zero(); | 15 | * var b = RDGE.vec3.zero(); |
16 | * var c = vec3.up(); | 16 | * var c = RDGE.vec3.up(); |
17 | * | 17 | * |
18 | */ | 18 | */ |
19 | vec3 = {}; | 19 | var RDGE = RDGE || {}; |
20 | RDGE.vec3 = {}; | ||
20 | 21 | ||
21 | /** | 22 | /** |
22 | * vec3.string | 23 | * RDGE.vec3.string |
23 | */ | 24 | */ |
24 | vec3.string = function(v) { | 25 | RDGE.vec3.string = function (v) { |
25 | return "{ " + v[0] + ", " + v[1] + ", " + v[2] + " }"; | 26 | return "{ " + v[0] + ", " + v[1] + ", " + v[2] + " }"; |
26 | } | 27 | }; |
27 | 28 | ||
28 | /** | 29 | /** |
29 | * vec3.verify | 30 | * RDGE.vec3.verify |
30 | * This function is provided for debugging purposes only. It is not recommended | 31 | * This function is provided for debugging purposes only. It is not recommended |
31 | * to be used in performance critical areas of the code. | 32 | * to be used in performance critical areas of the code. |
32 | */ | 33 | */ |
33 | vec3.verify = function(v) { | 34 | RDGE.vec3.verify = function (v) { |
34 | if (v == undefined || v.length == undefined || v.length < 3) { | 35 | if (v == undefined || v.length == undefined || v.length < 3) { |
35 | return false; | 36 | return false; |
36 | } | 37 | } |
37 | if (typeof (v[0]) != "number" || typeof (v[1]) != "number" || typeof (v[2]) != "number" ) { | 38 | if (typeof (v[0]) != "number" || typeof (v[1]) != "number" || typeof (v[2]) != "number") { |
38 | return false; | 39 | return false; |
39 | } | 40 | } |
40 | return true; | 41 | return true; |
41 | } | 42 | }; |
42 | 43 | ||
43 | /** | 44 | /** |
44 | * vec3.inplace_copy | 45 | * RDGE.vec3.inplace_copy |
45 | */ | 46 | */ |
46 | vec3.inplace_copy = function(dst, src) { | 47 | RDGE.vec3.inplace_copy = function (dst, src) { |
47 | dst[0] = src[0]; | 48 | dst[0] = src[0]; |
48 | dst[1] = src[1]; | 49 | dst[1] = src[1]; |
49 | dst[2] = src[2]; | 50 | dst[2] = src[2]; |
50 | } | 51 | }; |
51 | 52 | ||
52 | /** | 53 | /** |
53 | * vec3.copy | 54 | * RDGE.vec3.copy |
54 | */ | 55 | */ |
55 | vec3.copy = function(v) { | 56 | RDGE.vec3.copy = function (v) { |
56 | if( v.length == undefined ) { | 57 | if (v.length == undefined) { |
57 | return [ v, v, v ]; | 58 | return [v, v, v]; |
58 | } | 59 | } |
59 | 60 | ||
60 | return [v[0], v[1], v[2]]; | 61 | return [v[0], v[1], v[2]]; |
61 | } | 62 | }; |
62 | 63 | ||
63 | /** | 64 | /** |
64 | * vec3.translation | 65 | * RDGE.vec3.translation |
65 | * description : returns a vector containing the translation vector of m. | 66 | * description : returns a vector containing the translation vector of m. |
66 | */ | 67 | */ |
67 | vec3.translation = function(m) { | 68 | RDGE.vec3.translation = function (m) { |
68 | return [ m[12], m[13], m[14] ]; | 69 | return [m[12], m[13], m[14]]; |
69 | } | 70 | }; |
70 | 71 | ||
71 | /** | 72 | /** |
72 | * vec3.basisX = function( m ) | 73 | * RDGE.vec3.basisX = function( m ) |
73 | * description : returns a vector containing the translation vector of m. | 74 | * description : returns a vector containing the translation vector of m. |
74 | */ | 75 | */ |
75 | vec3.basisX = function(m) { | 76 | RDGE.vec3.basisX = function (m) { |
76 | return [ m[0], m[1], m[2] ]; | 77 | return [m[0], m[1], m[2]]; |
77 | } | 78 | }; |
78 | 79 | ||
79 | /** | 80 | /** |
80 | * vec3.basisY = function( m ) | 81 | * RDGE.vec3.basisY = function( m ) |
81 | * description : returns a vector containing the translation vector of m. | 82 | * description : returns a vector containing the translation vector of m. |
82 | */ | 83 | */ |
83 | vec3.basisY = function(m) { | 84 | RDGE.vec3.basisY = function (m) { |
84 | return [ m[4], m[5], m[6] ]; | 85 | return [m[4], m[5], m[6]]; |
85 | } | 86 | }; |
86 | 87 | ||
87 | /** | 88 | /** |
88 | * vec3.basisZ = function( m ) | 89 | * RDGE.vec3.basisZ = function( m ) |
89 | * description : returns a vector containing the translation vector of m. | 90 | * description : returns a vector containing the translation vector of m. |
90 | */ | 91 | */ |
91 | vec3.basisZ = function(m) { | 92 | RDGE.vec3.basisZ = function (m) { |
92 | return [ m[8], m[9], m[10] ]; | 93 | return [m[8], m[9], m[10]]; |
93 | } | 94 | }; |
94 | 95 | ||
95 | /** | 96 | /** |
96 | * vec3.zero | 97 | * RDGE.vec3.zero |
97 | */ | 98 | */ |
98 | vec3.zero = function() { | 99 | RDGE.vec3.zero = function () { |
99 | return [0.0, 0.0, 0.0]; | 100 | return [0.0, 0.0, 0.0]; |
100 | } | 101 | }; |
101 | 102 | ||
102 | /** | 103 | /** |
103 | * vec3.up | 104 | * RDGE.vec3.up |
104 | */ | 105 | */ |
105 | vec3.up = function() { | 106 | RDGE.vec3.up = function () { |
106 | return [ 0.0, 1.0, 0.0 ]; | 107 | return [0.0, 1.0, 0.0]; |
107 | } | 108 | }; |
108 | 109 | ||
109 | /** | 110 | /** |
110 | * vec3.forward | 111 | * RDGE.vec3.forward |
111 | */ | 112 | */ |
112 | vec3.forward = function() { | 113 | RDGE.vec3.forward = function () { |
113 | return [ 0.0, 0.0, 1.0 ]; | 114 | return [0.0, 0.0, 1.0]; |
114 | } | 115 | }; |
115 | 116 | ||
116 | /** | 117 | /** |
117 | * vec3.right | 118 | * RDGE.vec3.right |
118 | */ | 119 | */ |
119 | vec3.right = function() { | 120 | RDGE.vec3.right = function () { |
120 | return [ 1.0, 0.0, 0.0 ]; | 121 | return [1.0, 0.0, 0.0]; |
121 | } | 122 | }; |
122 | 123 | ||
123 | /** | 124 | /** |
124 | * vec3.random | 125 | * RDGE.vec3.random |
125 | */ | 126 | */ |
126 | vec3.random = function(min, max) { | 127 | RDGE.vec3.random = function (min, max) { |
127 | return [ min[0] + (max[0] - min[0]) * Math.random(), | 128 | return [min[0] + (max[0] - min[0]) * Math.random(), |
128 | min[1] + (max[1] - min[1]) * Math.random(), | 129 | min[1] + (max[1] - min[1]) * Math.random(), |
129 | min[2] + (max[2] - min[2]) * Math.random() ]; | 130 | min[2] + (max[2] - min[2]) * Math.random()]; |
130 | } | 131 | }; |
131 | 132 | ||
132 | /** | 133 | /** |
133 | * vec3.xy | 134 | * RDGE.vec3.xy |
134 | */ | 135 | */ |
135 | vec3.xy = function(v) { | 136 | RDGE.vec3.xy = function (v) { |
136 | return [v[0], v[1]]; | 137 | return [v[0], v[1]]; |
137 | } | 138 | }; |
138 |