Allolib  1.0
C++ Components For Interactive Multimedia
al_Lens.hpp
1 #ifndef INCLUDE_AL_LENS_HPP
2 #define INCLUDE_AL_LENS_HPP
3 
4 /* Allocore --
5  Multimedia / virtual environment application class library
6 
7  Copyright (C) 2009. AlloSphere Research Group, Media Arts & Technology, UCSB.
8  Copyright (C) 2012. The Regents of the University of California.
9  All rights reserved.
10 
11  Redistribution and use in source and binary forms, with or without
12  modification, are permitted provided that the following conditions are met:
13 
14  Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16 
17  Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20 
21  Neither the name of the University of California nor the names of its
22  contributors may be used to endorse or promote products derived from
23  this software without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  POSSIBILITY OF SUCH DAMAGE.
36 
37 
38  File description:
39  Optical properties for scene rendering
40 
41  File author(s):
42  Lance Putnam, 2010, putnam.lance@gmail.com
43  Graham Wakefield, 2010, grrrwaaa@gmail.com
44  Wesley Smith, 2010, wesley.hoke@gmail.com
45 */
46 
47 #include "al/math/al_Matrix4.hpp"
48 #include "al/math/al_Vec.hpp"
49 #include "al/spatial/al_Pose.hpp"
50 
51 #ifdef AL_WINDOWS
52 #undef near
53 #undef far
54 #endif
55 
56 namespace al {
57 
60 class Lens {
61  public:
67  Lens(double fovy = 30, double nearClip = 0.1, double farClip = 100,
68  double focalLength = 6, double eyeSep = 0.02);
69 
70  // setters
71  Lens& fovy(double v);
72  Lens& fovx(double v,
73  double aspect);
74  Lens& near(double v) {
75  mNear = v;
76  return *this;
77  }
78  Lens& far(double v) {
79  mFar = v;
80  return *this;
81  }
82  Lens& focalLength(double v) {
83  mFocalLength = v;
84  return *this;
85  }
86  Lens& eyeSep(double v) {
87  mEyeSep = v;
88  return *this;
89  }
90 
91  double fovy() const {
92  return mFovy;
93  }
94  double near() const { return mNear; }
95  double far() const { return mFar; }
96  double focalLength() const { return mFocalLength; }
97  double eyeSep() const { return mEyeSep; }
98  double eyeSepAuto() const {
99  return focalLength() / 30.0;
100  }
101 
103 
106  double heightAtDepth(double depth) const { return depth * mTanFOV; }
107 
109  double heightAtNear() const { return heightAtDepth(near()); }
110 
113  static double getFovyForHeight(double height, double depth);
114 
116 
120  static double getFovyForFovX(double fovx, double aspect);
121 
122  protected:
123  double mFovy; // Lens aperture (degrees)
124  double mTanFOV; // Cached factor for computing frustum dimensions
125  double mNear, mFar; // Cutting plane distances
126  double mFocalLength; // Focal length along vd
127  double mEyeSep; // Eye separation
128  // Vec3d mStereoOffset; // eye offset vector (right eye; left eye is
129  // inverse), usually (1, 0, 0)
130 };
131 
132 } // namespace al
133 
134 #endif
Lens & near(double v)
Set frustum near plane distance.
Definition: al_Lens.hpp:74
double heightAtNear() const
Returns half the height of the frustum at the near plane.
Definition: al_Lens.hpp:109
double near() const
Get frustum near plane distance.
Definition: al_Lens.hpp:94
double eyeSepAuto() const
Get automatic inter-ocular distance.
Definition: al_Lens.hpp:98
Lens & fovx(double v, double aspect)
Set horizontal field of view, in degrees.
Lens & focalLength(double v)
Set focal length.
Definition: al_Lens.hpp:82
double fovy() const
Get vertical field of view, in degrees.
Definition: al_Lens.hpp:91
Lens & far(double v)
Set frustum far plane distance.
Definition: al_Lens.hpp:78
double eyeSep() const
Get eye separation.
Definition: al_Lens.hpp:97
Lens & eyeSep(double v)
Set eye separation.
Definition: al_Lens.hpp:86
double focalLength() const
Get focal length.
Definition: al_Lens.hpp:96
static double getFovyForFovX(double fovx, double aspect)
Calculate required fovy to produce a specific fovx.
Lens(double fovy=30, double nearClip=0.1, double farClip=100, double focalLength=6, double eyeSep=0.02)
Lens & fovy(double v)
Set vertical field of view, in degrees.
static double getFovyForHeight(double height, double depth)
double heightAtDepth(double depth) const
Returns half the height of the frustum at a given depth.
Definition: al_Lens.hpp:106
double far() const
Get frustum far plane distance.
Definition: al_Lens.hpp:95
Definition: al_App.hpp:23