Loading...
Searching...
No Matches
camera.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_BASE_GF_CAMERA_H
25#define PXR_BASE_GF_CAMERA_H
26
29
30#include "pxr/pxr.h"
32#include "pxr/base/gf/range1f.h"
33#include "pxr/base/gf/vec4f.h"
34#include "pxr/base/gf/api.h"
35
36#include <vector>
37
38PXR_NAMESPACE_OPEN_SCOPE
39
40class GfFrustum;
41
50{
51public:
54 Perspective = 0,
55 Orthographic,
56 };
57
60 FOVHorizontal = 0,
61 FOVVertical
62 };
63
67 GF_API static const double APERTURE_UNIT;
69 GF_API static const double FOCAL_LENGTH_UNIT;
70
74 GF_API static const double DEFAULT_HORIZONTAL_APERTURE;
75 GF_API static const double DEFAULT_VERTICAL_APERTURE;
76
77public:
78 GF_API GfCamera(
79 const GfMatrix4d &transform = GfMatrix4d(1.0),
80 Projection projection = Perspective,
81 float horizontalAperture = DEFAULT_HORIZONTAL_APERTURE,
82 float verticalAperture = DEFAULT_VERTICAL_APERTURE,
83 float horizontalApertureOffset = 0.0,
84 float verticalApertureOffset = 0.0,
85 float focalLength = 50.0,
86 const GfRange1f &clippingRange = GfRange1f(1, 1000000),
87 const std::vector<GfVec4f> &clippingPlanes = std::vector<GfVec4f>(),
88 float fStop = 0.0,
89 float focusDistance = 0.0);
90
92 GF_API void SetTransform(const GfMatrix4d &val);
93
95 GF_API void SetProjection(const Projection &val);
96
98
102
104
107 GF_API void SetFocalLength(const float val);
108
111 GF_API void SetHorizontalAperture(const float val);
112
115 GF_API void SetVerticalAperture(const float val);
116
119 GF_API void SetHorizontalApertureOffset(const float val);
120
123 GF_API void SetVerticalApertureOffset(const float val);
125
128
135
137 float aspectRatio,
138 float fieldOfView,
139 FOVDirection direction,
140 float horizontalAperture = DEFAULT_HORIZONTAL_APERTURE);
141
146
148 float aspectRatio, float orthographicSize, FOVDirection direction);
149
155
157 const GfMatrix4d &viewMatrix, const GfMatrix4d &projMatix,
158 const float focalLength = 50.0);
159
161
163 GF_API void SetClippingRange(const GfRange1f &val);
164
172 GF_API void SetClippingPlanes(const std::vector<GfVec4f> &val);
173
175 GF_API void SetFStop(const float val);
176
178 GF_API void SetFocusDistance(const float val);
179
182 GF_API GfMatrix4d GetTransform() const;
183
185 GF_API Projection GetProjection() const;
186
189 GF_API float GetHorizontalAperture() const;
190
193 GF_API float GetVerticalAperture() const;
194
199 GF_API float GetHorizontalApertureOffset() const;
200
203 GF_API float GetVerticalApertureOffset() const;
204
206 GF_API float GetAspectRatio() const;
207
210 GF_API float GetFocalLength() const;
211
213 GF_API float GetFieldOfView(FOVDirection direction) const;
214
217
219 GF_API const std::vector<GfVec4f> &GetClippingPlanes() const;
220
223 GF_API GfFrustum GetFrustum() const;
224
226 GF_API float GetFStop() const;
227
229 GF_API float GetFocusDistance() const;
230
232 GF_API bool operator==(const GfCamera& other) const;
233
234 // Inequality operator. true iff not equality.
235 GF_API bool operator!=(const GfCamera& other) const;
236
237private:
238 // frustum
239 GfMatrix4d _transform;
240 Projection _projection;
241 float _horizontalAperture;
242 float _verticalAperture;
243 float _horizontalApertureOffset;
244 float _verticalApertureOffset;
245 float _focalLength;
246 GfRange1f _clippingRange;
247 std::vector<GfVec4f> _clippingPlanes;
248
249 // focus
250 float _fStop;
251 float _focusDistance;
252};
253
254PXR_NAMESPACE_CLOSE_SCOPE
255
256#endif // PXR_BASE_GF_CAMERA_H
Object-based representation of a camera.
Definition: camera.h:50
GF_API void SetClippingRange(const GfRange1f &val)
Sets the clipping range in world units.
static GF_API const double APERTURE_UNIT
The unit for horizontal and vertical aperture is one tenth of the world unit.
Definition: camera.h:67
static GF_API const double FOCAL_LENGTH_UNIT
The unit for focal length. Similar to APERTURE_UNIT.
Definition: camera.h:69
GF_API void SetVerticalAperture(const float val)
Sets the height of the projector aperture in tenths of a world unit (e.g., mm if the world unit is as...
GF_API GfMatrix4d GetTransform() const
Returns the transform of the filmback in world space.
GF_API void SetVerticalApertureOffset(const float val)
Sets the vertical offset of the projector aperture in tenths of a world unit (e.g....
GF_API void SetClippingPlanes(const std::vector< GfVec4f > &val)
Sets additional arbitrarily oriented clipping planes.
GF_API float GetVerticalApertureOffset() const
Returns the vertical offset of the projector aperture in tenths of a world unit (e....
GF_API void SetFStop(const float val)
Sets the lens aperture, unitless.
GF_API void SetOrthographicFromAspectRatioAndSize(float aspectRatio, float orthographicSize, FOVDirection direction)
Sets the frustum to be orthographic such that it has the given aspectRatio and such that the orthogra...
GF_API float GetAspectRatio() const
Returns the projector aperture aspect ratio.
GF_API float GetFocalLength() const
Returns the focal length in tenths of a world unit (e.g., mm if the world unit is assumed to be cm).
GF_API float GetHorizontalAperture() const
Returns the width of the projector aperture in tenths of a world unit (e.g., mm if the world unit is ...
GF_API Projection GetProjection() const
Returns the projection type.
GF_API float GetFieldOfView(FOVDirection direction) const
Returns the horizontal or vertical field of view in degrees.
GF_API float GetVerticalAperture() const
Returns the height of the projector aperture in tenths of a world unit (e.g., mm if the world unit is...
GF_API float GetHorizontalApertureOffset() const
Returns the horizontal offset of the projector aperture in tenths of a world unit (e....
GF_API float GetFStop() const
Returns the lens aperture.
GF_API void SetHorizontalAperture(const float val)
Sets the width of the projector aperture in tenths of a world unit (e.g., mm if the world unit is ass...
GF_API bool operator==(const GfCamera &other) const
Equality operator. true iff all parts match.
GF_API GfRange1f GetClippingRange() const
Returns the clipping range in world units.
Projection
Projection type.
Definition: camera.h:53
GF_API GfFrustum GetFrustum() const
Returns the computed, world-space camera frustum.
GF_API void SetFromViewAndProjectionMatrix(const GfMatrix4d &viewMatrix, const GfMatrix4d &projMatix, const float focalLength=50.0)
Sets the camera from a view and projection matrix.
GF_API void SetProjection(const Projection &val)
Sets the projection type.
GF_API const std::vector< GfVec4f > & GetClippingPlanes() const
Returns additional clipping planes.
GF_API void SetFocalLength(const float val)
These are the values actually stored in the class and they correspond to measurements of an actual ph...
GF_API void SetFocusDistance(const float val)
Sets the focus distance in world units.
GF_API void SetHorizontalApertureOffset(const float val)
Sets the horizontal offset of the projector aperture in tenths of a world unit (e....
FOVDirection
Direction used for Field of View or orthographic size.
Definition: camera.h:59
GF_API void SetTransform(const GfMatrix4d &val)
Sets the transform of the filmback in world space to val.
GF_API float GetFocusDistance() const
Returns the focus distance in world units.
GF_API void SetPerspectiveFromAspectRatioAndFieldOfView(float aspectRatio, float fieldOfView, FOVDirection direction, float horizontalAperture=DEFAULT_HORIZONTAL_APERTURE)
Sets the frustum to be projective with the given aspectRatio and horizontal, respectively,...
static GF_API const double DEFAULT_HORIZONTAL_APERTURE
Default horizontal and vertical aperture, based on a 35mm (non-anamorphic) projector aperture (0....
Definition: camera.h:74
Basic type: View frustum.
Definition: frustum.h:88
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type: 1-dimensional floating point range.
Definition: range1f.h:62