aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/math/vec3.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/math/vec3.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/math/vec3.js423
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 */
19vec3 = {}; 19var RDGE = RDGE || {};
20RDGE.vec3 = {};
20 21
21/** 22/**
22* vec3.string 23* RDGE.vec3.string
23*/ 24*/
24vec3.string = function(v) { 25RDGE.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 */
33vec3.verify = function(v) { 34RDGE.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*/
46vec3.inplace_copy = function(dst, src) { 47RDGE.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*/
55vec3.copy = function(v) { 56RDGE.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*/
67vec3.translation = function(m) { 68RDGE.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*/
75vec3.basisX = function(m) { 76RDGE.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*/
83vec3.basisY = function(m) { 84RDGE.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*/
91vec3.basisZ = function(m) { 92RDGE.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*/
98vec3.zero = function() { 99RDGE.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*/
105vec3.up = function() { 106RDGE.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*/
112vec3.forward = function() { 113RDGE.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*/
119vec3.right = function() { 120RDGE.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*/
126vec3.random = function(min, max) { 127RDGE.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*/
135vec3.xy = function(v) { 136RDGE.vec3.xy = function (v) {
136 return [v[0], v[1]]; 137 return [v[0], v[1]];
137} 138};
138 139
139/** 140/**
140* vec3.xz 141* RDGE.vec3.xz
141*/ 142*/
142vec3.xz = function(v) { 143RDGE.vec3.xz = function (v) {
143 return [v[0], v[2]]; 144 return [v[0], v[2]];
144} 145};