Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /**
  2. * @author qiao / https://github.com/qiao
  3. * @author mrdoob / http://mrdoob.com
  4. * @author alteredq / http://alteredqualia.com/
  5. * @author WestLangley / http://github.com/WestLangley
  6. * @author erich666 / http://erichaines.com
  7. */
  8. /*global THREE, console */
  9. ( function () {
  10. function OrbitConstraint ( object ) {
  11. this.object = object;
  12. // "target" sets the location of focus, where the object orbits around
  13. // and where it pans with respect to.
  14. this.target = new THREE.Vector3();
  15. // Limits to how far you can dolly in and out ( PerspectiveCamera only )
  16. this.minDistance = 0;
  17. this.maxDistance = Infinity;
  18. // Limits to how far you can zoom in and out ( OrthographicCamera only )
  19. this.minZoom = 0;
  20. this.maxZoom = Infinity;
  21. // How far you can orbit vertically, upper and lower limits.
  22. // Range is 0 to Math.PI radians.
  23. this.minPolarAngle = 0; // radians
  24. this.maxPolarAngle = Math.PI; // radians
  25. // How far you can orbit horizontally, upper and lower limits.
  26. // If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
  27. this.minAzimuthAngle = - Infinity; // radians
  28. this.maxAzimuthAngle = Infinity; // radians
  29. // Set to true to disable damping (inertia)
  30. this.staticMoving = false;
  31. this.dynamicDampingFactor = 0.2;
  32. ////////////
  33. // internals
  34. var scope = this;
  35. var EPS = 0.000001;
  36. // Current position in spherical coordinate system.
  37. var theta;
  38. var phi;
  39. // Pending changes
  40. var phiDelta = 0;
  41. var thetaDelta = 0;
  42. var scale = 1;
  43. var panOffset = new THREE.Vector3();
  44. var zoomChanged = false;
  45. // API
  46. this.getPolarAngle = function () {
  47. return phi;
  48. };
  49. this.getAzimuthalAngle = function () {
  50. return theta;
  51. };
  52. this.rotateLeft = function ( angle ) {
  53. thetaDelta -= angle;
  54. };
  55. this.rotateUp = function ( angle ) {
  56. phiDelta -= angle;
  57. };
  58. // pass in distance in world space to move left
  59. this.panLeft = function() {
  60. var v = new THREE.Vector3();
  61. return function panLeft ( distance ) {
  62. var te = this.object.matrix.elements;
  63. // get X column of matrix
  64. v.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  65. v.multiplyScalar( - distance );
  66. panOffset.add( v );
  67. };
  68. }();
  69. // pass in distance in world space to move up
  70. this.panUp = function() {
  71. var v = new THREE.Vector3();
  72. return function panUp ( distance ) {
  73. var te = this.object.matrix.elements;
  74. // get Y column of matrix
  75. v.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  76. v.multiplyScalar( distance );
  77. panOffset.add( v );
  78. };
  79. }();
  80. // pass in x,y of change desired in pixel space,
  81. // right and down are positive
  82. this.pan = function ( deltaX, deltaY, screenWidth, screenHeight ) {
  83. if ( scope.object instanceof THREE.PerspectiveCamera ) {
  84. // perspective
  85. var position = scope.object.position;
  86. var offset = position.clone().sub( scope.target );
  87. var targetDistance = offset.length();
  88. // half of the fov is center to top of screen
  89. targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
  90. // we actually don't use screenWidth, since perspective camera is fixed to screen height
  91. scope.panLeft( 2 * deltaX * targetDistance / screenHeight );
  92. scope.panUp( 2 * deltaY * targetDistance / screenHeight );
  93. } else if ( scope.object instanceof THREE.OrthographicCamera ) {
  94. // orthographic
  95. scope.panLeft( deltaX * ( scope.object.right - scope.object.left ) / screenWidth );
  96. scope.panUp( deltaY * ( scope.object.top - scope.object.bottom ) / screenHeight );
  97. } else {
  98. // camera neither orthographic or perspective
  99. console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
  100. }
  101. };
  102. this.dollyIn = function ( dollyScale ) {
  103. if ( scope.object instanceof THREE.PerspectiveCamera ) {
  104. scale /= dollyScale;
  105. } else if ( scope.object instanceof THREE.OrthographicCamera ) {
  106. scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom * dollyScale ) );
  107. scope.object.updateProjectionMatrix();
  108. zoomChanged = true;
  109. } else {
  110. console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
  111. }
  112. };
  113. this.dollyOut = function ( dollyScale ) {
  114. if ( scope.object instanceof THREE.PerspectiveCamera ) {
  115. scale *= dollyScale;
  116. } else if ( scope.object instanceof THREE.OrthographicCamera ) {
  117. scope.object.zoom = Math.max( this.minZoom, Math.min( this.maxZoom, this.object.zoom / dollyScale ) );
  118. scope.object.updateProjectionMatrix();
  119. zoomChanged = true;
  120. } else {
  121. console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
  122. }
  123. };
  124. this.update = function() {
  125. var offset = new THREE.Vector3();
  126. // so camera.up is the orbit axis
  127. var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
  128. var quatInverse = quat.clone().inverse();
  129. var lastPosition = new THREE.Vector3();
  130. var lastQuaternion = new THREE.Quaternion();
  131. return function () {
  132. var position = this.object.position;
  133. offset.copy( position ).sub( this.target );
  134. // rotate offset to "y-axis-is-up" space
  135. offset.applyQuaternion( quat );
  136. // angle from z-axis around y-axis
  137. theta = Math.atan2( offset.x, offset.z );
  138. // angle from y-axis
  139. phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
  140. theta += thetaDelta;
  141. phi += phiDelta;
  142. // restrict theta to be between desired limits
  143. theta = Math.max( this.minAzimuthAngle, Math.min( this.maxAzimuthAngle, theta ) );
  144. // restrict phi to be between desired limits
  145. phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
  146. // restrict phi to be betwee EPS and PI-EPS
  147. phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
  148. var radius = offset.length() * scale;
  149. // restrict radius to be between desired limits
  150. radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
  151. // move target to panned location
  152. this.target.add( panOffset );
  153. offset.x = radius * Math.sin( phi ) * Math.sin( theta );
  154. offset.y = radius * Math.cos( phi );
  155. offset.z = radius * Math.sin( phi ) * Math.cos( theta );
  156. // rotate offset back to "camera-up-vector-is-up" space
  157. offset.applyQuaternion( quatInverse );
  158. position.copy( this.target ).add( offset );
  159. this.object.lookAt( this.target );
  160. if ( this.staticMoving ) {
  161. thetaDelta = 0;
  162. phiDelta = 0;
  163. } else {
  164. thetaDelta *= ( 1 - this.dynamicDampingFactor );
  165. phiDelta *= ( 1 - this.dynamicDampingFactor );
  166. }
  167. scale = 1;
  168. panOffset.set( 0, 0, 0 );
  169. // update condition is:
  170. // min(camera displacement, camera rotation in radians)^2 > EPS
  171. // using small-angle approximation cos(x/2) = 1 - x^2 / 8
  172. if ( zoomChanged ||
  173. lastPosition.distanceToSquared( this.object.position ) > EPS ||
  174. 8 * ( 1 - lastQuaternion.dot( this.object.quaternion ) ) > EPS ) {
  175. lastPosition.copy( this.object.position );
  176. lastQuaternion.copy( this.object.quaternion );
  177. zoomChanged = false;
  178. return true;
  179. }
  180. return false;
  181. };
  182. }();
  183. };
  184. // This set of controls performs orbiting, dollying (zooming), and panning. It maintains
  185. // the "up" direction as +Y, unlike the TrackballControls. Touch on tablet and phones is
  186. // supported.
  187. //
  188. // Orbit - left mouse / touch: one finger move
  189. // Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
  190. // Pan - right mouse, or arrow keys / touch: three finter swipe
  191. THREE.OrbitControls = function ( object, domElement ) {
  192. var constraint = new OrbitConstraint( object );
  193. this.domElement = ( domElement !== undefined ) ? domElement : document;
  194. // API
  195. Object.defineProperty( this, 'constraint', {
  196. get: function() {
  197. return constraint;
  198. }
  199. } );
  200. this.getPolarAngle = function () {
  201. return constraint.phi;
  202. };
  203. this.getAzimuthalAngle = function () {
  204. return constraint.theta;
  205. };
  206. // Set to false to disable this control
  207. this.enabled = true;
  208. // center is old, deprecated; use "target" instead
  209. this.center = this.target;
  210. // This option actually enables dollying in and out; left as "zoom" for
  211. // backwards compatibility
  212. this.noZoom = false;
  213. this.zoomSpeed = 1.0;
  214. // Set to true to disable this control
  215. this.noRotate = false;
  216. this.rotateSpeed = 1.0;
  217. // Set to true to disable this control
  218. this.noPan = false;
  219. this.keyPanSpeed = 7.0; // pixels moved per arrow key push
  220. // Set to true to automatically rotate around the target
  221. this.autoRotate = false;
  222. this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
  223. // Set to true to disable use of the keys
  224. this.noKeys = false;
  225. // The four arrow keys
  226. this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
  227. // Mouse buttons
  228. this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
  229. ////////////
  230. // internals
  231. var scope = this;
  232. var rotateStart = new THREE.Vector2();
  233. var rotateEnd = new THREE.Vector2();
  234. var rotateDelta = new THREE.Vector2();
  235. var panStart = new THREE.Vector2();
  236. var panEnd = new THREE.Vector2();
  237. var panDelta = new THREE.Vector2();
  238. var dollyStart = new THREE.Vector2();
  239. var dollyEnd = new THREE.Vector2();
  240. var dollyDelta = new THREE.Vector2();
  241. var STATE = { NONE : - 1, ROTATE : 0, DOLLY : 1, PAN : 2, TOUCH_ROTATE : 3, TOUCH_DOLLY : 4, TOUCH_PAN : 5 };
  242. var state = STATE.NONE;
  243. // for reset
  244. this.target0 = this.target.clone();
  245. this.position0 = this.object.position.clone();
  246. this.zoom0 = this.object.zoom;
  247. // events
  248. var changeEvent = { type: 'change' };
  249. var startEvent = { type: 'start' };
  250. var endEvent = { type: 'end' };
  251. // pass in x,y of change desired in pixel space,
  252. // right and down are positive
  253. function pan( deltaX, deltaY ) {
  254. var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
  255. constraint.pan( deltaX, deltaY, element.clientWidth, element.clientHeight );
  256. }
  257. this.update = function () {
  258. if ( this.autoRotate && state === STATE.NONE ) {
  259. constraint.rotateLeft( getAutoRotationAngle() );
  260. }
  261. if ( constraint.update() === true ) {
  262. this.dispatchEvent( changeEvent );
  263. }
  264. };
  265. this.reset = function () {
  266. state = STATE.NONE;
  267. this.target.copy( this.target0 );
  268. this.object.position.copy( this.position0 );
  269. this.object.zoom = this.zoom0;
  270. this.object.updateProjectionMatrix();
  271. this.dispatchEvent( changeEvent );
  272. this.update();
  273. };
  274. function getAutoRotationAngle() {
  275. return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
  276. }
  277. function getZoomScale() {
  278. return Math.pow( 0.95, scope.zoomSpeed );
  279. }
  280. function onMouseDown( event ) {
  281. if ( scope.enabled === false ) return;
  282. event.preventDefault();
  283. if ( event.button === scope.mouseButtons.ORBIT ) {
  284. if ( scope.noRotate === true ) return;
  285. state = STATE.ROTATE;
  286. rotateStart.set( event.clientX, event.clientY );
  287. } else if ( event.button === scope.mouseButtons.ZOOM ) {
  288. if ( scope.noZoom === true ) return;
  289. state = STATE.DOLLY;
  290. dollyStart.set( event.clientX, event.clientY );
  291. } else if ( event.button === scope.mouseButtons.PAN ) {
  292. if ( scope.noPan === true ) return;
  293. state = STATE.PAN;
  294. panStart.set( event.clientX, event.clientY );
  295. }
  296. if ( state !== STATE.NONE ) {
  297. document.addEventListener( 'mousemove', onMouseMove, false );
  298. document.addEventListener( 'mouseup', onMouseUp, false );
  299. scope.dispatchEvent( startEvent );
  300. }
  301. }
  302. function onMouseMove( event ) {
  303. if ( scope.enabled === false ) return;
  304. event.preventDefault();
  305. var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
  306. if ( state === STATE.ROTATE ) {
  307. if ( scope.noRotate === true ) return;
  308. rotateEnd.set( event.clientX, event.clientY );
  309. rotateDelta.subVectors( rotateEnd, rotateStart );
  310. // rotating across whole screen goes 360 degrees around
  311. constraint.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
  312. // rotating up and down along whole screen attempts to go 360, but limited to 180
  313. constraint.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
  314. rotateStart.copy( rotateEnd );
  315. } else if ( state === STATE.DOLLY ) {
  316. if ( scope.noZoom === true ) return;
  317. dollyEnd.set( event.clientX, event.clientY );
  318. dollyDelta.subVectors( dollyEnd, dollyStart );
  319. if ( dollyDelta.y > 0 ) {
  320. constraint.dollyIn( getZoomScale() );
  321. } else if ( dollyDelta.y < 0 ) {
  322. constraint.dollyOut( getZoomScale() );
  323. }
  324. dollyStart.copy( dollyEnd );
  325. } else if ( state === STATE.PAN ) {
  326. if ( scope.noPan === true ) return;
  327. panEnd.set( event.clientX, event.clientY );
  328. panDelta.subVectors( panEnd, panStart );
  329. pan( panDelta.x, panDelta.y );
  330. panStart.copy( panEnd );
  331. }
  332. if ( state !== STATE.NONE ) scope.update();
  333. }
  334. function onMouseUp( /* event */ ) {
  335. if ( scope.enabled === false ) return;
  336. document.removeEventListener( 'mousemove', onMouseMove, false );
  337. document.removeEventListener( 'mouseup', onMouseUp, false );
  338. scope.dispatchEvent( endEvent );
  339. state = STATE.NONE;
  340. }
  341. function onMouseWheel( event ) {
  342. if ( scope.enabled === false || scope.noZoom === true || state !== STATE.NONE ) return;
  343. event.preventDefault();
  344. event.stopPropagation();
  345. var delta = 0;
  346. if ( event.wheelDelta !== undefined ) {
  347. // WebKit / Opera / Explorer 9
  348. delta = event.wheelDelta;
  349. } else if ( event.detail !== undefined ) {
  350. // Firefox
  351. delta = - event.detail;
  352. }
  353. if ( delta > 0 ) {
  354. constraint.dollyOut( getZoomScale() );
  355. } else if ( delta < 0 ) {
  356. constraint.dollyIn( getZoomScale() );
  357. }
  358. scope.update();
  359. scope.dispatchEvent( startEvent );
  360. scope.dispatchEvent( endEvent );
  361. }
  362. function onKeyDown( event ) {
  363. if ( scope.enabled === false || scope.noKeys === true || scope.noPan === true ) return;
  364. switch ( event.keyCode ) {
  365. case scope.keys.UP:
  366. pan( 0, scope.keyPanSpeed );
  367. scope.update();
  368. break;
  369. case scope.keys.BOTTOM:
  370. pan( 0, - scope.keyPanSpeed );
  371. scope.update();
  372. break;
  373. case scope.keys.LEFT:
  374. pan( scope.keyPanSpeed, 0 );
  375. scope.update();
  376. break;
  377. case scope.keys.RIGHT:
  378. pan( - scope.keyPanSpeed, 0 );
  379. scope.update();
  380. break;
  381. }
  382. }
  383. function touchstart( event ) {
  384. if ( scope.enabled === false ) return;
  385. switch ( event.touches.length ) {
  386. case 1: // one-fingered touch: rotate
  387. if ( scope.noRotate === true ) return;
  388. state = STATE.TOUCH_ROTATE;
  389. rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  390. break;
  391. case 2: // two-fingered touch: dolly
  392. if ( scope.noZoom === true ) return;
  393. state = STATE.TOUCH_DOLLY;
  394. var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
  395. var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
  396. var distance = Math.sqrt( dx * dx + dy * dy );
  397. dollyStart.set( 0, distance );
  398. break;
  399. case 3: // three-fingered touch: pan
  400. if ( scope.noPan === true ) return;
  401. state = STATE.TOUCH_PAN;
  402. panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  403. break;
  404. default:
  405. state = STATE.NONE;
  406. }
  407. if ( state !== STATE.NONE ) scope.dispatchEvent( startEvent );
  408. }
  409. function touchmove( event ) {
  410. if ( scope.enabled === false ) return;
  411. event.preventDefault();
  412. event.stopPropagation();
  413. var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
  414. switch ( event.touches.length ) {
  415. case 1: // one-fingered touch: rotate
  416. if ( scope.noRotate === true ) return;
  417. if ( state !== STATE.TOUCH_ROTATE ) return;
  418. rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  419. rotateDelta.subVectors( rotateEnd, rotateStart );
  420. // rotating across whole screen goes 360 degrees around
  421. constraint.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
  422. // rotating up and down along whole screen attempts to go 360, but limited to 180
  423. constraint.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
  424. rotateStart.copy( rotateEnd );
  425. scope.update();
  426. break;
  427. case 2: // two-fingered touch: dolly
  428. if ( scope.noZoom === true ) return;
  429. if ( state !== STATE.TOUCH_DOLLY ) return;
  430. var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
  431. var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
  432. var distance = Math.sqrt( dx * dx + dy * dy );
  433. dollyEnd.set( 0, distance );
  434. dollyDelta.subVectors( dollyEnd, dollyStart );
  435. if ( dollyDelta.y > 0 ) {
  436. constraint.dollyOut( getZoomScale() );
  437. } else if ( dollyDelta.y < 0 ) {
  438. constraint.dollyIn( getZoomScale() );
  439. }
  440. dollyStart.copy( dollyEnd );
  441. scope.update();
  442. break;
  443. case 3: // three-fingered touch: pan
  444. if ( scope.noPan === true ) return;
  445. if ( state !== STATE.TOUCH_PAN ) return;
  446. panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
  447. panDelta.subVectors( panEnd, panStart );
  448. pan( panDelta.x, panDelta.y );
  449. panStart.copy( panEnd );
  450. scope.update();
  451. break;
  452. default:
  453. state = STATE.NONE;
  454. }
  455. }
  456. function touchend( /* event */ ) {
  457. if ( scope.enabled === false ) return;
  458. scope.dispatchEvent( endEvent );
  459. state = STATE.NONE;
  460. }
  461. function contextmenu( event ) {
  462. event.preventDefault();
  463. }
  464. this.dispose = function() {
  465. this.domElement.removeEventListener( 'contextmenu', contextmenu, false );
  466. this.domElement.removeEventListener( 'mousedown', onMouseDown, false );
  467. this.domElement.removeEventListener( 'mousewheel', onMouseWheel, false );
  468. this.domElement.removeEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
  469. this.domElement.removeEventListener( 'touchstart', touchstart, false );
  470. this.domElement.removeEventListener( 'touchend', touchend, false );
  471. this.domElement.removeEventListener( 'touchmove', touchmove, false );
  472. document.removeEventListener( 'mousemove', onMouseMove, false );
  473. document.removeEventListener( 'mouseup', onMouseUp, false );
  474. window.removeEventListener( 'keydown', onKeyDown, false );
  475. }
  476. this.domElement.addEventListener( 'contextmenu', contextmenu, false );
  477. this.domElement.addEventListener( 'mousedown', onMouseDown, false );
  478. this.domElement.addEventListener( 'mousewheel', onMouseWheel, false );
  479. this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
  480. this.domElement.addEventListener( 'touchstart', touchstart, false );
  481. this.domElement.addEventListener( 'touchend', touchend, false );
  482. this.domElement.addEventListener( 'touchmove', touchmove, false );
  483. window.addEventListener( 'keydown', onKeyDown, false );
  484. // force an update at start
  485. this.update();
  486. };
  487. THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
  488. THREE.OrbitControls.prototype.constructor = THREE.OrbitControls;
  489. Object.defineProperties( THREE.OrbitControls.prototype, {
  490. object: {
  491. get: function () {
  492. return this.constraint.object;
  493. }
  494. },
  495. target: {
  496. get: function () {
  497. return this.constraint.target;
  498. },
  499. set: function ( value ) {
  500. console.warn( 'THREE.OrbitControls: target is now immutable. Use target.set() instead.' );
  501. this.constraint.target.copy( value );
  502. }
  503. },
  504. minDistance : {
  505. get: function () {
  506. return this.constraint.minDistance;
  507. },
  508. set: function ( value ) {
  509. this.constraint.minDistance = value;
  510. }
  511. },
  512. maxDistance : {
  513. get: function () {
  514. return this.constraint.maxDistance;
  515. },
  516. set: function ( value ) {
  517. this.constraint.maxDistance = value;
  518. }
  519. },
  520. minZoom : {
  521. get: function () {
  522. return this.constraint.minZoom;
  523. },
  524. set: function ( value ) {
  525. this.constraint.minZoom = value;
  526. }
  527. },
  528. maxZoom : {
  529. get: function () {
  530. return this.constraint.maxZoom;
  531. },
  532. set: function ( value ) {
  533. this.constraint.maxZoom = value;
  534. }
  535. },
  536. minPolarAngle : {
  537. get: function () {
  538. return this.constraint.minPolarAngle;
  539. },
  540. set: function ( value ) {
  541. this.constraint.minPolarAngle = value;
  542. }
  543. },
  544. maxPolarAngle : {
  545. get: function () {
  546. return this.constraint.maxPolarAngle;
  547. },
  548. set: function ( value ) {
  549. this.constraint.maxPolarAngle = value;
  550. }
  551. },
  552. minAzimuthAngle : {
  553. get: function () {
  554. return this.constraint.minAzimuthAngle;
  555. },
  556. set: function ( value ) {
  557. this.constraint.minAzimuthAngle = value;
  558. }
  559. },
  560. maxAzimuthAngle : {
  561. get: function () {
  562. return this.constraint.maxAzimuthAngle;
  563. },
  564. set: function ( value ) {
  565. this.constraint.maxAzimuthAngle = value;
  566. }
  567. },
  568. staticMoving : {
  569. get: function () {
  570. return this.constraint.staticMoving;
  571. },
  572. set: function ( value ) {
  573. this.constraint.staticMoving = value;
  574. }
  575. },
  576. dynamicDampingFactor : {
  577. get: function () {
  578. return this.constraint.dynamicDampingFactor;
  579. },
  580. set: function ( value ) {
  581. this.constraint.dynamicDampingFactor = value;
  582. }
  583. }
  584. } );
  585. }() );