OSVR-Core
ProjectionMatrixFromFOV.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_ProjectionMatrixFromFOV_h_GUID_880B5E97_076B_4AB7_2E6E_CC6297F3D85B
26 #define INCLUDED_ProjectionMatrixFromFOV_h_GUID_880B5E97_076B_4AB7_2E6E_CC6297F3D85B
27 
28 // Internal Includes
30 #include <osvr/Util/Angles.h>
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 // - none
37 
38 namespace osvr {
39 namespace util {
41  template <typename System>
43  AngleGeneric<System> vFov) {
44  // Scale the unit X and Y parameters based on the near
45  // plane to make the field of view match what we expect.
46  // The tangent of the view angle in either axis is the
47  // in-plane distance (left, right, top, or bottom) divided
48  // by the distance to the near clipping plane. We have
49  // the angle specified and for now we assume a unit distance
50  // to the window (corrected later either in the alternate
51  // computeSymmetricFOVRect signature or after caching but before
52  // passing to computeProjectionMatrix). Given this, we solve for
53  // the tangent of half the angle (each of left and right provide
54  // half, as do top and bottom).
55  Rectd ret;
56  ret[Rectd::RIGHT] = std::tan(getRadians(hFov / 2.));
57  ret[Rectd::LEFT] = -ret[Rectd::RIGHT];
58  ret[Rectd::TOP] = std::tan(getRadians(vFov / 2.));
59  ret[Rectd::BOTTOM] = -ret[Rectd::TOP];
60 
61  return ret;
62  }
65  template <typename System>
68  double near) {
69  // Get the rectangle at the unit distance
70  Rectd ret = computeSymmetricFOVRect(hFov, vFov);
71 
72  // Scale the in-plane positions based on the near plane to put
73  // the virtual viewing window on the near plane with the eye at the
74  // origin.
75  ret *= near;
76  return ret;
77  }
78 
79  template <typename System>
80  inline Eigen::Matrix4d
82  AngleGeneric<System> vFov, double near,
83  double far) {
89  return createProjectionMatrix(computeSymmetricFOVRect(hFov, vFov, near),
90  near, far);
91  }
92 } // namespace util
93 } // namespace osvr
94 #endif // INCLUDED_ProjectionMatrixFromFOV_h_GUID_880B5E97_076B_4AB7_2E6E_CC6297F3D85B
Definition: RunLoopManager.h:42
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
boost::units::quantity< boost::units::unit< boost::units::plane_angle_dimension, System >, Y > AngleGeneric
Convenience template alias for a plane_angle quantity in an arbitrary system with arbitrary scalar...
Definition: Angles.h:47
Eigen::Matrix4d createSymmetricProjectionMatrix(AngleGeneric< System > hFov, AngleGeneric< System > vFov, double near, double far)
Definition: ProjectionMatrixFromFOV.h:81
Rectd computeSymmetricFOVRect(AngleGeneric< System > hFov, AngleGeneric< System > vFov)
Compute a rectangle at unit distance for the given fov values.
Definition: ProjectionMatrixFromFOV.h:42
Definition: Rect.h:39
Eigen::Matrix4d createProjectionMatrix(Rectd const &bounds, double near, double far)
Takes in points at the near clipping plane, as well as the near and far clipping planes.
Definition: ProjectionMatrix.h:48
Y getRadians(AngleGeneric< System, Y > const angle)
Get the raw scalar value of your angle in radians.
Definition: Angles.h:67
Header.