1 /**
2 * @author alteredq / http://alteredqualia.com/
3 *
4 * - shows frustum, line of sight and up of the camera
5 * - suitable for fast updates
6 * - based on frustum visualization in lightgl.js shadowmap example
7 * http://evanw.github.com/lightgl.js/tests/shadowmap.html
8 */
9
10 /**@constructor*/
11 THREE.CameraHelper = function ( camera ) {
12
13 THREE.Line.call( this );
14
15 var scope = this;
16
17 this.geometry = new THREE.Geometry();
18 this.material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
19 this.type = THREE.LinePieces;
20
21 this.matrixWorld = camera.matrixWorld;
22 this.matrixAutoUpdate = false;
23
24 this.pointMap = {};
25
26 // colors
27
28 var hexFrustum = 0xffaa00;
29 var hexCone = 0xff0000;
30 var hexUp = 0x00aaff;
31 var hexTarget = 0xffffff;
32 var hexCross = 0x333333;
33
34 // near
35
36 addLine( "n1", "n2", hexFrustum );
37 addLine( "n2", "n4", hexFrustum );
38 addLine( "n4", "n3", hexFrustum );
39 addLine( "n3", "n1", hexFrustum );
40
41 // far
42
43 addLine( "f1", "f2", hexFrustum );
44 addLine( "f2", "f4", hexFrustum );
45 addLine( "f4", "f3", hexFrustum );
46 addLine( "f3", "f1", hexFrustum );
47
48 // sides
49
50 addLine( "n1", "f1", hexFrustum );
51 addLine( "n2", "f2", hexFrustum );
52 addLine( "n3", "f3", hexFrustum );
53 addLine( "n4", "f4", hexFrustum );
54
55 // cone
56
57 addLine( "p", "n1", hexCone );
58 addLine( "p", "n2", hexCone );
59 addLine( "p", "n3", hexCone );
60 addLine( "p", "n4", hexCone );
61
62 // up
63
64 addLine( "u1", "u2", hexUp );
65 addLine( "u2", "u3", hexUp );
66 addLine( "u3", "u1", hexUp );
67
68 // target
69
70 addLine( "c", "t", hexTarget );
71 addLine( "p", "c", hexCross );
72
73 // cross
74
75 addLine( "cn1", "cn2", hexCross );
76 addLine( "cn3", "cn4", hexCross );
77
78 addLine( "cf1", "cf2", hexCross );
79 addLine( "cf3", "cf4", hexCross );
80
81 this.camera = camera;
82
83 function addLine( a, b, hex ) {
84
85 addPoint( a, hex );
86 addPoint( b, hex );
87
88 }
89
90 function addPoint( id, hex ) {
91
92 scope.geometry.vertices.push( new THREE.Vector3() );
93 scope.geometry.colors.push( new THREE.Color( hex ) );
94
95 if ( scope.pointMap[ id ] === undefined ) scope.pointMap[ id ] = [];
96
97 scope.pointMap[ id ].push( scope.geometry.vertices.length - 1 );
98
99 }
100
101 this.update( camera );
102
103 };
104
105 THREE.CameraHelper.prototype = Object.create( THREE.Line.prototype );
106
107 THREE.CameraHelper.prototype.update = function () {
108
109 var scope = this;
110
111 var w = 1, h = 1;
112
113 // we need just camera projection matrix
114 // world matrix must be identity
115
116 THREE.CameraHelper.__c.projectionMatrix.copy( this.camera.projectionMatrix );
117
118 // center / target
119
120 setPoint( "c", 0, 0, -1 );
121 setPoint( "t", 0, 0, 1 );
122
123 // near
124
125 setPoint( "n1", -w, -h, -1 );
126 setPoint( "n2", w, -h, -1 );
127 setPoint( "n3", -w, h, -1 );
128 setPoint( "n4", w, h, -1 );
129
130 // far
131
132 setPoint( "f1", -w, -h, 1 );
133 setPoint( "f2", w, -h, 1 );
134 setPoint( "f3", -w, h, 1 );
135 setPoint( "f4", w, h, 1 );
136
137 // up
138
139 setPoint( "u1", w * 0.7, h * 1.1, -1 );
140 setPoint( "u2", -w * 0.7, h * 1.1, -1 );
141 setPoint( "u3", 0, h * 2, -1 );
142
143 // cross
144
145 setPoint( "cf1", -w, 0, 1 );
146 setPoint( "cf2", w, 0, 1 );
147 setPoint( "cf3", 0, -h, 1 );
148 setPoint( "cf4", 0, h, 1 );
149
150 setPoint( "cn1", -w, 0, -1 );
151 setPoint( "cn2", w, 0, -1 );
152 setPoint( "cn3", 0, -h, -1 );
153 setPoint( "cn4", 0, h, -1 );
154
155 function setPoint( point, x, y, z ) {
156
157 THREE.CameraHelper.__v.set( x, y, z );
158 THREE.CameraHelper.__projector.unprojectVector( THREE.CameraHelper.__v, THREE.CameraHelper.__c );
159
160 var points = scope.pointMap[ point ];
161
162 if ( points !== undefined ) {
163
164 for ( var i = 0, il = points.length; i < il; i ++ ) {
165
166 scope.geometry.vertices[ points[ i ] ].copy( THREE.CameraHelper.__v );
167
168 }
169
170 }
171
172 }
173
174 this.geometry.verticesNeedUpdate = true;
175
176 };
177
178 THREE.CameraHelper.__projector = new THREE.Projector();
179 THREE.CameraHelper.__v = new THREE.Vector3();
180 THREE.CameraHelper.__c = new THREE.Camera();
181
182
nike free rn
new balance hombre baratas
cinturones gucci
ugg rebajas
cinturon gucci
ray ban baratas
nike cortez
peuterey mujer
christian louboutin madrid
mbt zapatos
gafas ray ban baratas
mbt ofertas
air max blancas
mbt barcelona
nike air max 90
woolrich barcelona
nike mujer
botas ugg
gafas de sol carrera aratas
air max 2016 baratas
oakley baratas
nike air max 2016