PerspectiveCamera.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @author simonThiele / https://github.com/simonThiele
  3. */
  4. module( "PerspectiveCamera" );
  5. test( "updateProjectionMatrix", function() {
  6. var cam = new THREE.PerspectiveCamera( 75, 16 / 9, 0.1, 300.0 );
  7. // updateProjectionMatrix is called in contructor
  8. var m = cam.projectionMatrix;
  9. // perspective projection is given my the 4x4 Matrix
  10. // 2n/r-l 0 l+r/r-l 0
  11. // 0 2n/t-b t+b/t-b 0
  12. // 0 0 -(f+n/f-n) -(2fn/f-n)
  13. // 0 0 -1 0
  14. // this matrix was calculated by hand via glMatrix.perspective(75, 16 / 9, 0.1, 300.0, pMatrix)
  15. // to get a reference matrix from plain WebGL
  16. var reference = new THREE.Matrix4().set(
  17. 0.7330642938613892, 0, 0, 0,
  18. 0, 1.3032253980636597, 0, 0,
  19. 0, 0, -1.000666856765747, -0.2000666856765747,
  20. 0, 0, -1, 0
  21. );
  22. ok( reference.equals(m) );
  23. });
  24. test( "clone", function() {
  25. var near = 1,
  26. far = 3,
  27. bottom = -1,
  28. top = 1,
  29. aspect = 16 / 9,
  30. fov = 90;
  31. var cam = new THREE.PerspectiveCamera( fov, aspect, near, far );
  32. var clonedCam = cam.clone();
  33. ok( cam.fov === clonedCam.fov , "fov is equal" );
  34. ok( cam.aspect === clonedCam.aspect , "aspect is equal" );
  35. ok( cam.near === clonedCam.near , "near is equal" );
  36. ok( cam.far === clonedCam.far , "far is equal" );
  37. ok( cam.zoom === clonedCam.zoom , "zoom is equal" );
  38. ok( cam.projectionMatrix.equals(clonedCam.projectionMatrix) , "projectionMatrix is equal" );
  39. });