misc_camera_trackball.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - trackball camera</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. color: #000;
  10. font-family:Monospace;
  11. font-size:13px;
  12. text-align:center;
  13. font-weight: bold;
  14. background-color: #fff;
  15. margin: 0px;
  16. overflow: hidden;
  17. }
  18. #info {
  19. color:#000;
  20. position: absolute;
  21. top: 0px; width: 100%;
  22. padding: 5px;
  23. }
  24. a { color: red; }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="container"></div>
  29. <div id="info">
  30. <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - trackball camera example</br>
  31. MOVE mouse &amp; press LEFT/A: rotate, MIDDLE/S: zoom, RIGHT/D: pan
  32. </div>
  33. <script src="../build/Three.js"></script>
  34. <script src="js/Detector.js"></script>
  35. <script src="js/Stats.js"></script>
  36. <script>
  37. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  38. var container, stats;
  39. var camera, controls, scene, renderer;
  40. var cross;
  41. init();
  42. animate();
  43. function init() {
  44. // scene and camera
  45. scene = new THREE.Scene();
  46. scene.fog = new THREE.FogExp2( 0xffffff, 0.002 );
  47. camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
  48. camera.position.z = 500;
  49. scene.add( camera );
  50. controls = new THREE.TrackballControls( camera );
  51. controls.rotateSpeed = 1.0;
  52. controls.zoomSpeed = 1.2;
  53. controls.panSpeed = 0.8;
  54. controls.noZoom = false;
  55. controls.noPan = false;
  56. controls.staticMoving = true;
  57. controls.dynamicDampingFactor = 0.3;
  58. controls.keys = [ 65, 83, 68 ];
  59. // world
  60. var cube = new THREE.CubeGeometry( 20, 60, 20 );
  61. cube.vertices[ 0 ].position.multiplyScalar( 0.01 );
  62. cube.vertices[ 1 ].position.multiplyScalar( 0.01 );
  63. cube.vertices[ 4 ].position.multiplyScalar( 0.01 );
  64. cube.vertices[ 5 ].position.multiplyScalar( 0.01 );
  65. var material = new THREE.MeshLambertMaterial( { color: 0xffffff } );
  66. for( var i = 0; i < 500; i ++ ) {
  67. var mesh = new THREE.Mesh( cube, material );
  68. mesh.position.set(( Math.random() - 0.5 ) * 1000,
  69. ( Math.random() - 0.5 ) * 1000,
  70. ( Math.random() - 0.5 ) * 1000 );
  71. mesh.updateMatrix();
  72. mesh.matrixAutoUpdate = false;
  73. scene.add( mesh );
  74. }
  75. // lights
  76. light = new THREE.DirectionalLight( 0xffffff );
  77. light.position.set( 1, 1, 1 );
  78. scene.add( light );
  79. light = new THREE.DirectionalLight( 0x002288 );
  80. light.position.set( -1, -1, -1 );
  81. scene.add( light );
  82. light = new THREE.AmbientLight( 0x222222 );
  83. scene.add( light );
  84. // renderer
  85. renderer = new THREE.WebGLRenderer( { antialias: false } );
  86. renderer.setClearColorHex( 0xffffff, 1 );
  87. renderer.setSize( window.innerWidth, window.innerHeight );
  88. container = document.getElementById( 'container' );
  89. container.appendChild( renderer.domElement );
  90. stats = new Stats();
  91. stats.domElement.style.position = 'absolute';
  92. stats.domElement.style.top = '0px';
  93. stats.domElement.style.zIndex = 100;
  94. container.appendChild( stats.domElement );
  95. }
  96. function animate() {
  97. requestAnimationFrame( animate );
  98. render();
  99. stats.update();
  100. }
  101. function render() {
  102. controls.update();
  103. renderer.render( scene, camera );
  104. }
  105. </script>
  106. </body>
  107. </html>