aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/camera.js
diff options
context:
space:
mode:
authorKris Kowal2012-07-06 12:34:53 -0700
committerKris Kowal2012-07-06 15:01:48 -0700
commit3644cb6def4f681c99959e5729e78ea353441fad (patch)
treef8a886f4829e507cc4956db37cff2580cae6003d /js/helper-classes/RDGE/src/core/script/camera.js
parent04343eda8c2f870b0da55cfdc8003c99fe1cc4de (diff)
downloadninja-3644cb6def4f681c99959e5729e78ea353441fad.tar.gz
Normalize to unix line terminators
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/camera.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/camera.js550
1 files changed, 275 insertions, 275 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/camera.js b/js/helper-classes/RDGE/src/core/script/camera.js
index 28d307ae..abcd8d42 100755
--- a/js/helper-classes/RDGE/src/core/script/camera.js
+++ b/js/helper-classes/RDGE/src/core/script/camera.js
@@ -1,275 +1,275 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility, Inc
3All Rights Reserved. 3All Rights Reserved.
4BSD License. 4BSD License.
5 5
6Redistribution and use in source and binary forms, with or without 6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 7modification, are permitted provided that the following conditions are met:
8 8
9 - Redistributions of source code must retain the above copyright notice, 9 - Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 10 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the 12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution. 13 documentation and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors 14 - Neither the name of Motorola Mobility nor the names of its contributors
15 may be used to endorse or promote products derived from this software 15 may be used to endorse or promote products derived from this software
16 without specific prior written permission. 16 without specific prior written permission.
17 17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE. 28POSSIBILITY OF SUCH DAMAGE.
29</copyright> */ 29</copyright> */
30/* 30/*
31 * camera class 31 * camera class
32 */ 32 */
33var RDGE = RDGE || {}; 33var RDGE = RDGE || {};
34 34
35RDGE.camera = function () { 35RDGE.camera = function () {
36 this.proj = RDGE.mat4.identity(); 36 this.proj = RDGE.mat4.identity();
37 this.view = RDGE.mat4.identity(); 37 this.view = RDGE.mat4.identity();
38 this.world = RDGE.mat4.identity(); 38 this.world = RDGE.mat4.identity();
39 this.viewProj = RDGE.mat4.identity(); 39 this.viewProj = RDGE.mat4.identity();
40 this.invViewProj = RDGE.mat4.identity(); 40 this.invViewProj = RDGE.mat4.identity();
41 this.frustum = []; 41 this.frustum = [];
42 this.frustumPts = []; 42 this.frustumPts = [];
43 this.controller = null; 43 this.controller = null;
44 44
45 this.setPerspective = function (fov, aratio, near, far) { 45 this.setPerspective = function (fov, aratio, near, far) {
46 this.ortho = null; 46 this.ortho = null;
47 this.persp = {}; 47 this.persp = {};
48 this.persp.fov = fov; 48 this.persp.fov = fov;
49 this.persp.aratio = aratio; 49 this.persp.aratio = aratio;
50 this.persp.near = near; 50 this.persp.near = near;
51 this.persp.far = far; 51 this.persp.far = far;
52 this.proj = RDGE.mat4.perspective(fov, aratio, near, far); 52 this.proj = RDGE.mat4.perspective(fov, aratio, near, far);
53 this.recalc(); 53 this.recalc();
54 }; 54 };
55 55
56 this.reset = function () { 56 this.reset = function () {
57 this.world = RDGE.mat4.identity(); 57 this.world = RDGE.mat4.identity();
58 this.recalc(); 58 this.recalc();
59 }; 59 };
60 60
61 this.copy = function (cam) { 61 this.copy = function (cam) {
62 RDGE.mat4.inplace_copy(this.view, cam.view); 62 RDGE.mat4.inplace_copy(this.view, cam.view);
63 RDGE.mat4.inplace_copy(this.world, cam.world); 63 RDGE.mat4.inplace_copy(this.world, cam.world);
64 RDGE.mat4.inplace_copy(this.proj, cam.proj); 64 RDGE.mat4.inplace_copy(this.proj, cam.proj);
65 RDGE.mat4.inplace_copy(this.viewProj, cam.viewProj); 65 RDGE.mat4.inplace_copy(this.viewProj, cam.viewProj);
66 RDGE.mat4.inplace_copy(this.invViewProj, cam.invViewProj); 66 RDGE.mat4.inplace_copy(this.invViewProj, cam.invViewProj);
67 this.frustum = cam.frustum.slice(); 67 this.frustum = cam.frustum.slice();
68 this.frustumPts = cam.frustumPts.slice(); 68 this.frustumPts = cam.frustumPts.slice();
69 }; 69 };
70 70
71 this.recalc = function () { 71 this.recalc = function () {
72 // update frustum planes 72 // update frustum planes
73 this.frustum = []; 73 this.frustum = [];
74 var vp = this.viewProj; 74 var vp = this.viewProj;
75 75
76 normalizePlane = function (p) { 76 normalizePlane = function (p) {
77 var len = RDGE.vec3.length(p); 77 var len = RDGE.vec3.length(p);
78 if (Math.abs(1.0 - len) > 0.001) { 78 if (Math.abs(1.0 - len) > 0.001) {
79 p[0] /= len; 79 p[0] /= len;
80 p[1] /= len; 80 p[1] /= len;
81 p[2] /= len; 81 p[2] /= len;
82 p[3] /= len; 82 p[3] /= len;
83 } 83 }
84 return p; 84 return p;
85 }; 85 };
86 86
87 /* This is the old way 87 /* This is the old way
88 var t = this.persp.near * Math.tan(0.017453292519943295769236 * this.persp.fov * 0.5); 88 var t = this.persp.near * Math.tan(0.017453292519943295769236 * this.persp.fov * 0.5);
89 var r = t * this.persp.aratio; 89 var r = t * this.persp.aratio;
90 var u = t; 90 var u = t;
91 var l = -r; 91 var l = -r;
92 var b = -u; 92 var b = -u;
93 93
94 tview = RDGE.mat4.transpose(this.view); 94 tview = RDGE.mat4.transpose(this.view);
95 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [this.persp.near, 0.0, l, 0.0] ) ) ); // left 95 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [this.persp.near, 0.0, l, 0.0] ) ) ); // left
96 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [-this.persp.near, 0.0, -r, 0.0] ) ) ); // right 96 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [-this.persp.near, 0.0, -r, 0.0] ) ) ); // right
97 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [0.0, this.persp.near, b, 0.0] ) ) ); // bottom 97 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [0.0, this.persp.near, b, 0.0] ) ) ); // bottom
98 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [0.0, -this.persp.near, -u, 0.0] ) ) ); // top 98 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [0.0, -this.persp.near, -u, 0.0] ) ) ); // top
99 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [0.0, 0.0, -1.0, -this.persp.near] ) ) ); // near 99 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [0.0, 0.0, -1.0, -this.persp.near] ) ) ); // near
100 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [0.0, 0.0, 1.0, this.persp.far] ) ) ); // far 100 this.frustum.push( normalizePlane( RDGE.mat4.transformPoint(tview, [0.0, 0.0, 1.0, this.persp.far] ) ) ); // far
101 */ 101 */
102 var l = normalizePlane([vp[3] + vp[0], vp[7] + vp[4], vp[11] + vp[8], vp[15] + vp[12]]); 102 var l = normalizePlane([vp[3] + vp[0], vp[7] + vp[4], vp[11] + vp[8], vp[15] + vp[12]]);
103 var r = normalizePlane([vp[3] - vp[0], vp[7] - vp[4], vp[11] - vp[8], vp[15] - vp[12]]); 103 var r = normalizePlane([vp[3] - vp[0], vp[7] - vp[4], vp[11] - vp[8], vp[15] - vp[12]]);
104 var t = normalizePlane([vp[3] - vp[1], vp[7] - vp[5], vp[11] - vp[9], vp[15] - vp[13]]); 104 var t = normalizePlane([vp[3] - vp[1], vp[7] - vp[5], vp[11] - vp[9], vp[15] - vp[13]]);
105 var b = normalizePlane([vp[3] + vp[1], vp[7] + vp[5], vp[11] + vp[9], vp[15] + vp[13]]); 105 var b = normalizePlane([vp[3] + vp[1], vp[7] + vp[5], vp[11] + vp[9], vp[15] + vp[13]]);
106 var n = normalizePlane([vp[3] + vp[2], vp[7] + vp[6], vp[11] + vp[10], vp[15] + vp[14]]); 106 var n = normalizePlane([vp[3] + vp[2], vp[7] + vp[6], vp[11] + vp[10], vp[15] + vp[14]]);
107 var f = normalizePlane([vp[3] - vp[2], vp[7] - vp[6], vp[11] - vp[10], vp[15] - vp[14]]); 107 var f = normalizePlane([vp[3] - vp[2], vp[7] - vp[6], vp[11] - vp[10], vp[15] - vp[14]]);
108 108
109 this.frustum.push(l); 109 this.frustum.push(l);
110 this.frustum.push(r); 110 this.frustum.push(r);
111 this.frustum.push(t); 111 this.frustum.push(t);
112 this.frustum.push(b); 112 this.frustum.push(b);
113 this.frustum.push(n); 113 this.frustum.push(n);
114 this.frustum.push(f); 114 this.frustum.push(f);
115 115
116 // update frustum points 116 // update frustum points
117 this.frustumPts = []; 117 this.frustumPts = [];
118 var invvp = this.viewProj; 118 var invvp = this.viewProj;
119 this.frustumPts.push(RDGE.mat4.transformPoint(invvp, [-1, -1, -1])); 119 this.frustumPts.push(RDGE.mat4.transformPoint(invvp, [-1, -1, -1]));
120 this.frustumPts.push(RDGE.mat4.transformPoint(invvp, [-1, 1, -1])); 120 this.frustumPts.push(RDGE.mat4.transformPoint(invvp, [-1, 1, -1]));
121 this.frustumPts.push(RDGE.mat4.transformPoint(invvp, [1, 1, -1])); 121 this.frustumPts.push(RDGE.mat4.transformPoint(invvp, [1, 1, -1]));