babylon.vrCameraMetrics.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. module BABYLON {
  2. export class VRCameraMetrics {
  3. public hResolution: number;
  4. public vResolution: number;
  5. public hScreenSize: number;
  6. public vScreenSize: number;
  7. public vScreenCenter: number;
  8. public eyeToScreenDistance: number;
  9. public lensSeparationDistance: number;
  10. public interpupillaryDistance: number;
  11. public distortionK: number[];
  12. public chromaAbCorrection: number[];
  13. public postProcessScaleFactor: number;
  14. public lensCenterOffset: number;
  15. public compensateDistortion = true;
  16. public get aspectRatio(): number {
  17. return this.hResolution / (2 * this.vResolution);
  18. }
  19. public get aspectRatioFov(): number {
  20. return (2 * Math.atan((this.postProcessScaleFactor * this.vScreenSize) / (2 * this.eyeToScreenDistance)));
  21. }
  22. public get leftHMatrix(): Matrix {
  23. var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
  24. var h = (4 * meters) / this.hScreenSize;
  25. return Matrix.Translation(h, 0, 0);
  26. }
  27. public get rightHMatrix(): Matrix {
  28. var meters = (this.hScreenSize / 4) - (this.lensSeparationDistance / 2);
  29. var h = (4 * meters) / this.hScreenSize;
  30. return Matrix.Translation(-h, 0, 0);
  31. }
  32. public get leftPreViewMatrix(): Matrix {
  33. return Matrix.Translation(0.5 * this.interpupillaryDistance, 0, 0);
  34. }
  35. public get rightPreViewMatrix(): Matrix {
  36. return Matrix.Translation(-0.5 * this.interpupillaryDistance, 0, 0);
  37. }
  38. public static GetDefault(): VRCameraMetrics {
  39. var result = new VRCameraMetrics();
  40. result.hResolution = 1280;
  41. result.vResolution = 800;
  42. result.hScreenSize = 0.149759993;
  43. result.vScreenSize = 0.0935999975;
  44. result.vScreenCenter = 0.0467999987;
  45. result.eyeToScreenDistance = 0.0410000011;
  46. result.lensSeparationDistance = 0.0635000020;
  47. result.interpupillaryDistance = 0.0640000030;
  48. result.distortionK = [1.0, 0.219999999, 0.239999995, 0.0];
  49. result.chromaAbCorrection = [0.995999992, -0.00400000019, 1.01400006, 0.0];
  50. result.postProcessScaleFactor = 1.714605507808412;
  51. result.lensCenterOffset = 0.151976421;
  52. return result;
  53. }
  54. }
  55. }