vsg 1.1.3
VulkanSceneGraph library
Loading...
Searching...
No Matches
TransformSampler.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/Animation.h>
16#include <vsg/app/ViewMatrix.h>
17#include <vsg/maths/transform.h>
18
19namespace vsg
20{
21
22 struct VectorKey
23 {
24 double time;
25 dvec3 value;
26
27 bool operator<(const VectorKey& rhs) const { return time < rhs.time; }
28 };
29
30 struct QuatKey
31 {
32 double time;
33 dquat value;
34
35 bool operator<(const QuatKey& rhs) const { return time < rhs.time; }
36 };
37
38 class VSG_DECLSPEC TransformKeyframes : public Inherit<Object, TransformKeyframes>
39 {
40 public:
42
44 std::string name;
45
47 std::vector<VectorKey> positions;
48
50 std::vector<QuatKey> rotations;
51
53 std::vector<VectorKey> scales;
54
55 void clear()
56 {
57 positions.clear();
58 rotations.clear();
59 scales.clear();
60 }
61
62 void add(double time, const dvec3& position, const dquat& rotation)
63 {
64 positions.push_back(VectorKey{time, position});
65 rotations.push_back(QuatKey{time, rotation});
66 }
67
68 void add(double time, const dvec3& position, const dquat& rotation, const dvec3& scale)
69 {
70 positions.push_back(VectorKey{time, position});
71 rotations.push_back(QuatKey{time, rotation});
72 scales.push_back(VectorKey{time, scale});
73 }
74
75 void read(Input& input) override;
76 void write(Output& output) const override;
77 };
78 VSG_type_name(vsg::TransformKeyframes);
79
81 class VSG_DECLSPEC TransformSampler : public Inherit<AnimationSampler, TransformSampler>
82 {
83 public:
85 TransformSampler(const TransformSampler& rhs, const CopyOp& copyop = {});
86
88 ref_ptr<Object> object;
89
90 // updated using keyFrames
91 dvec3 position;
92 dquat rotation;
93 dvec3 scale;
94
95 void update(double time) override;
96 double maxTime() const override;
97
98 inline dmat4 transform() const { return translate(position) * vsg::rotate(rotation) * vsg::scale(scale); }
99
100 public:
101 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return TransformSampler::create(*this, copyop); }
102 int compare(const Object& rhs) const override;
103
104 void read(Input& input) override;
105 void write(Output& output) const override;
106
107 void apply(mat4Value& mat) override;
108 void apply(dmat4Value& mat) override;
109 void apply(MatrixTransform& mt) override;
110 void apply(Joint& joint) override;
111 void apply(LookAt& lookAt) override;
112 void apply(Camera& camera) override;
113 };
114 VSG_type_name(vsg::TransformSampler);
115
116} // namespace vsg
Definition Camera.h:27
Definition Object.h:42
Definition Inherit.h:28
Definition Input.h:44
Definition Joint.h:22
LookAt is a ViewMatrix that implements the gluLookAt model for specifying the view matrix.
Definition ViewMatrix.h:36
Definition MatrixTransform.h:24
Definition Object.h:60
Definition Output.h:41
Definition TransformSampler.h:39
std::vector< QuatKey > rotations
rotation key frames
Definition TransformSampler.h:50
std::string name
name of node
Definition TransformSampler.h:44
std::vector< VectorKey > positions
position key frames
Definition TransformSampler.h:47
std::vector< VectorKey > scales
scale key frames
Definition TransformSampler.h:53
Animation sampler for sampling position, rotation and scale keyframes for setting transforms/joints.
Definition TransformSampler.h:82
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition TransformSampler.h:101
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,...
Definition ref_ptr.h:22
Definition TransformSampler.h:31
Definition TransformSampler.h:23