This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
camera.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_GF_CAMERA_H
8#define PXR_BASE_GF_CAMERA_H
9
12
13#include "pxr/pxr.h"
15#include "pxr/base/gf/range1f.h"
16#include "pxr/base/gf/vec4f.h"
17#include "pxr/base/gf/api.h"
18
19#include <vector>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23class GfFrustum;
24
33{
34public:
37 Perspective = 0,
38 Orthographic,
39 };
40
43 FOVHorizontal = 0,
44 FOVVertical
45 };
46
50 GF_API static const double APERTURE_UNIT;
52 GF_API static const double FOCAL_LENGTH_UNIT;
53
57 GF_API static const double DEFAULT_HORIZONTAL_APERTURE;
58 GF_API static const double DEFAULT_VERTICAL_APERTURE;
59
60public:
61 GF_API GfCamera(
62 const GfMatrix4d &transform = GfMatrix4d(1.0),
63 Projection projection = Perspective,
64 float horizontalAperture = DEFAULT_HORIZONTAL_APERTURE,
65 float verticalAperture = DEFAULT_VERTICAL_APERTURE,
66 float horizontalApertureOffset = 0.0,
67 float verticalApertureOffset = 0.0,
68 float focalLength = 50.0,
69 const GfRange1f &clippingRange = GfRange1f(1, 1000000),
70 const std::vector<GfVec4f> &clippingPlanes = std::vector<GfVec4f>(),
71 float fStop = 0.0,
72 float focusDistance = 0.0);
73
75 GF_API void SetTransform(const GfMatrix4d &val);
76
78 GF_API void SetProjection(const Projection &val);
79
81
85
87
90 GF_API void SetFocalLength(const float val);
91
94 GF_API void SetHorizontalAperture(const float val);
95
98 GF_API void SetVerticalAperture(const float val);
99
102 GF_API void SetHorizontalApertureOffset(const float val);
103
106 GF_API void SetVerticalApertureOffset(const float val);
108
111
118
120 float aspectRatio,
121 float fieldOfView,
122 FOVDirection direction,
123 float horizontalAperture = DEFAULT_HORIZONTAL_APERTURE);
124
129
131 float aspectRatio, float orthographicSize, FOVDirection direction);
132
138
140 const GfMatrix4d &viewMatrix, const GfMatrix4d &projMatix,
141 const float focalLength = 50.0);
142
144
146 GF_API void SetClippingRange(const GfRange1f &val);
147
155 GF_API void SetClippingPlanes(const std::vector<GfVec4f> &val);
156
158 GF_API void SetFStop(const float val);
159
161 GF_API void SetFocusDistance(const float val);
162
165 GF_API GfMatrix4d GetTransform() const;
166
168 GF_API Projection GetProjection() const;
169
172 GF_API float GetHorizontalAperture() const;
173
176 GF_API float GetVerticalAperture() const;
177
182 GF_API float GetHorizontalApertureOffset() const;
183
186 GF_API float GetVerticalApertureOffset() const;
187
189 GF_API float GetAspectRatio() const;
190
193 GF_API float GetFocalLength() const;
194
196 GF_API float GetFieldOfView(FOVDirection direction) const;
197
200
202 GF_API const std::vector<GfVec4f> &GetClippingPlanes() const;
203
206 GF_API GfFrustum GetFrustum() const;
207
209 GF_API float GetFStop() const;
210
212 GF_API float GetFocusDistance() const;
213
215 GF_API bool operator==(const GfCamera& other) const;
216
217 // Inequality operator. true iff not equality.
218 GF_API bool operator!=(const GfCamera& other) const;
219
220private:
221 // frustum
222 GfMatrix4d _transform;
223 Projection _projection;
224 float _horizontalAperture;
225 float _verticalAperture;
226 float _horizontalApertureOffset;
227 float _verticalApertureOffset;
228 float _focalLength;
229 GfRange1f _clippingRange;
230 std::vector<GfVec4f> _clippingPlanes;
231
232 // focus
233 float _fStop;
234 float _focusDistance;
235};
236
237PXR_NAMESPACE_CLOSE_SCOPE
238
239#endif // PXR_BASE_GF_CAMERA_H
Object-based representation of a camera.
Definition: camera.h:33
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:50
static GF_API const double FOCAL_LENGTH_UNIT
The unit for focal length. Similar to APERTURE_UNIT.
Definition: camera.h:52
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:36
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:42
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:57
Basic type: View frustum.
Definition: frustum.h:71
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type: 1-dimensional floating point range.
Definition: range1f.h:45