vsg: include/vsg/animation/CameraSampler.h Source File

vsg 1.1.13 VulkanSceneGraph library

Loading...
Searching...
No Matches
CameraSampler.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2024 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <vsg/animation/TransformSampler.h>
16#include <vsg/app/ViewMatrix.h>
17#include <vsg/maths/transform.h>
18
19namespace vsg
20{
21
22 using time_path = time_value<RefObjectPath>;
23
24 class VSG_DECLSPEC CameraKeyframes : public Inherit<Object, CameraKeyframes>
25 {
26 public:
27 CameraKeyframes();
28
30 std::string name;
31
32 // object tracking key frames
33 std::vector<time_path> tracking;
34
36 std::vector<time_dvec3> origins;
37
39 std::vector<time_dvec3> positions;
40
42 std::vector<time_dquat> rotations;
43
45 std::vector<time_double> fieldOfViews;
46
48 std::vector<time_dvec2> nearFars;
49
50 void clear()
51 {
52 origins.clear();
53 positions.clear();
54 rotations.clear();
55 fieldOfViews.clear();
56 nearFars.clear();
57 }
58
59 void add(double time, const dvec3& origin, const dvec3& position, const dquat& rotation, double fov, const dvec2& nearFar)
60 {
61 origins.push_back(VectorKey{time, origin});
62 positions.push_back(VectorKey{time, position});
63 rotations.push_back(QuatKey{time, rotation});
64 fieldOfViews.push_back(time_double{time, fov});
65 nearFars.push_back(time_dvec2{time, nearFar});
66 }
67
68 void add(double time, const dvec3& origin, const dvec3& position, const dquat& rotation, double fov)
69 {
70 origins.push_back(VectorKey{time, origin});
71 positions.push_back(VectorKey{time, position});
72 rotations.push_back(QuatKey{time, rotation});
73 fieldOfViews.push_back(time_double{time, fov});
74 }
75
76 void add(double time, const dvec3& position, const dquat& rotation, double fov, const dvec2& nearFar)
77 {
78 positions.push_back(VectorKey{time, position});
79 rotations.push_back(QuatKey{time, rotation});
80 fieldOfViews.push_back(time_double{time, fov});
81 nearFars.push_back(time_dvec2{time, nearFar});
82 }
83
84 void add(double time, const dvec3& position, const dquat& rotation, double fov)
85 {
86 positions.push_back(VectorKey{time, position});
87 rotations.push_back(QuatKey{time, rotation});
88 fieldOfViews.push_back(time_double{time, fov});
89 }
90
91 void add(double time, const dvec3& origin, const dvec3& position, const dquat& rotation)
92 {
93 origins.push_back(VectorKey{time, origin});
94 positions.push_back(VectorKey{time, position});
95 rotations.push_back(QuatKey{time, rotation});
96 }
97
98 void add(double time, const dvec3& position, const dquat& rotation)
99 {
100 positions.push_back(VectorKey{time, position});
101 rotations.push_back(QuatKey{time, rotation});
102 }
103
104 void read(Input& input) override;
105 void write(Output& output) const override;
106 };
107 VSG_type_name(vsg::CameraKeyframes);
108
110 class VSG_DECLSPEC CameraSampler : public Inherit<AnimationSampler, CameraSampler>
111 {
112 public:
113 CameraSampler();
114 CameraSampler(const CameraSampler& rhs, const CopyOp& copyop = {});
115
116 ref_ptr<CameraKeyframes> keyframes;
117 ref_ptr<Object> object;
118
119 // updated using keyFrames
120 dvec3 origin;
121 dvec3 position;
122 dquat rotation;
123 double fieldOfView;
124 dvec2 nearFar;
125
126 void update(double time) override;
127 double maxTime() const override;
128
129 inline dmat4 transform() const { return translate(position) * vsg::rotate(rotation); }
130
131 public:
132 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return CameraSampler::create(*this, copyop); }
133 int compare(const Object& rhs) const override;
134
135 void read(Input& input) override;
136 void write(Output& output) const override;
137
138 void apply(mat4Value& mat) override;
139 void apply(dmat4Value& mat) override;
140 void apply(LookAt& lookAt) override;
141 void apply(LookDirection& lookDirection) override;
142 void apply(Perspective& perspective) override;
143 void apply(Camera& camera) override;
144 };
145 VSG_type_name(vsg::CameraSampler);
146
147} // namespace vsg
vsg::Camera
Definition Camera.h:27
vsg::CameraKeyframes::name
std::string name
name of node
Definition CameraSampler.h:30
vsg::CameraKeyframes::fieldOfViews
std::vector< time_double > fieldOfViews
field of view key frames
Definition CameraSampler.h:45
vsg::CameraKeyframes::origins
std::vector< time_dvec3 > origins
position key frames
Definition CameraSampler.h:36
vsg::CameraKeyframes::rotations
std::vector< time_dquat > rotations
rotation key frames
Definition CameraSampler.h:42
vsg::CameraKeyframes::nearFars
std::vector< time_dvec2 > nearFars
near/far key frames
Definition CameraSampler.h:48
vsg::CameraKeyframes::positions
std::vector< time_dvec3 > positions
position key frames
Definition CameraSampler.h:39
vsg::CameraSampler
Animation sampler for sampling position, rotation and scale keyframes for setting camera view and pro...
Definition CameraSampler.h:111
vsg::CameraSampler::clone
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition CameraSampler.h:132
vsg::CameraSampler::compare
int compare(const Object &rhs) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
vsg::CopyOp
Definition Object.h:42
vsg::Input
Definition Input.h:44
vsg::LookAt
LookAt is a ViewMatrix that implements the gluLookAt model for specifying the view matrix.
Definition ViewMatrix.h:54
vsg::LookDirection
LookDirection is a ViewMatrix that uses a position and rotation to set the view matrix.
Definition ViewMatrix.h:108
vsg::Object
Definition Object.h:60
vsg::Output
Definition Output.h:41
vsg::Perspective
Perspective is a ProjectionMatrix that implements the gluPerspective model for setting the projection...
Definition ProjectionMatrix.h:50
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::time_value
Definition time_value.h:24