StereoEffect.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. * @authod mrdoob / http://mrdoob.com/
  4. * @authod arodic / http://aleksandarrodic.com/
  5. */
  6. THREE.StereoEffect = function ( renderer ) {
  7. // API
  8. this.separation = 3;
  9. // internals
  10. var _width, _height;
  11. var _position = new THREE.Vector3();
  12. var _quaternion = new THREE.Quaternion();
  13. var _scale = new THREE.Vector3();
  14. var _cameraL = new THREE.PerspectiveCamera();
  15. var _cameraR = new THREE.PerspectiveCamera();
  16. // initialization
  17. renderer.autoClear = false;
  18. this.setSize = function ( width, height ) {
  19. _width = width / 2;
  20. _height = height;
  21. renderer.setSize( width, height );
  22. };
  23. this.render = function ( scene, camera ) {
  24. scene.updateMatrixWorld();
  25. if ( camera.parent === undefined ) camera.updateMatrixWorld();
  26. camera.matrixWorld.decompose( _position, _quaternion, _scale );
  27. // left
  28. _cameraL.fov = camera.fov;
  29. _cameraL.aspect = 0.5 * camera.aspect;
  30. _cameraL.near = camera.near;
  31. _cameraL.far = camera.far;
  32. _cameraL.updateProjectionMatrix();
  33. _cameraL.position.copy( _position );
  34. _cameraL.quaternion.copy( _quaternion );
  35. _cameraL.translateX( - this.separation );
  36. // right
  37. _cameraR.near = camera.near;
  38. _cameraR.far = camera.far;
  39. _cameraR.projectionMatrix = _cameraL.projectionMatrix;
  40. _cameraR.position.copy( _position );
  41. _cameraR.quaternion.copy( _quaternion );
  42. _cameraR.translateX( this.separation );
  43. //
  44. renderer.setViewport( 0, 0, _width * 2, _height );
  45. renderer.clear();
  46. renderer.setViewport( 0, 0, _width, _height );
  47. renderer.render( scene, _cameraL );
  48. renderer.setViewport( _width, 0, _width, _height );
  49. renderer.render( scene, _cameraR );
  50. };
  51. };