diff options
author | hwc487 | 2012-07-09 16:08:02 -0700 |
---|---|---|
committer | hwc487 | 2012-07-09 16:08:02 -0700 |
commit | 5085d0f67df89a21715308956004164597a6ba79 (patch) | |
tree | 2c896163143a66331205a39b0a3b1b45d51bf12a /js/helper-classes/RDGE/src/core/script/camera.js | |
parent | 51f1691f792dbda9b740ded8aa0457c9406db156 (diff) | |
parent | 84b3327bd92faafab7954b5eb64c7abe24a3fe13 (diff) | |
download | ninja-5085d0f67df89a21715308956004164597a6ba79.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into GridFixes
Conflicts:
js/helper-classes/3D/StageLine.js
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/camera.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/camera.js | 550 |
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 da9aff3d..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> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | BSD License. |
5 | 5 | ||
6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 7 | modification, 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 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | POSSIBILITY OF SUCH DAMAGE. |
29 | </copyright> */ | 29 | </copyright> */ |
30 | /* | 30 | /* |
31 | * camera class | 31 | * camera class |
32 | */ | 32 | */ |
33 | var RDGE = RDGE || {}; | 33 | var RDGE = RDGE || {}; |
34 | 34 | ||
35 | RDGE.camera = function () { | 35 | RDGE.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])); |