vsg 1.1.9
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/animation/time_value.h>
17#include <vsg/app/ViewMatrix.h>
18#include <vsg/maths/transform.h>
19
20namespace vsg
21{
22
23 using VectorKey = time_dvec3;
24 using QuatKey = time_dquat;
25
26 class VSG_DECLSPEC TransformKeyframes : public Inherit<Object, TransformKeyframes>
27 {
28 public:
29 TransformKeyframes();
30
32 std::string name;
33
35 std::vector<VectorKey> positions;
36
38 std::vector<QuatKey> rotations;
39
41 std::vector<VectorKey> scales;
42
43 void clear()
44 {
45 positions.clear();
46 rotations.clear();
47 scales.clear();
48 }
49
50 void add(double time, const dvec3& position, const dquat& rotation)
51 {
52 positions.push_back(VectorKey{time, position});
53 rotations.push_back(QuatKey{time, rotation});
54 }
55
56 void add(double time, const dvec3& position, const dquat& rotation, const dvec3& scale)
57 {
58 positions.push_back(VectorKey{time, position});
59 rotations.push_back(QuatKey{time, rotation});
60 scales.push_back(VectorKey{time, scale});
61 }
62
63 void read(Input& input) override;
64 void write(Output& output) const override;
65 };
66 VSG_type_name(vsg::TransformKeyframes);
67
69 class VSG_DECLSPEC TransformSampler : public Inherit<AnimationSampler, TransformSampler>
70 {
71 public:
72 TransformSampler();
73 TransformSampler(const TransformSampler& rhs, const CopyOp& copyop = {});
74
76 ref_ptr<Object> object;
77
78 // updated using keyFrames
79 dvec3 position;
80 dquat rotation;
81 dvec3 scale;
82
83 void update(double time) override;
84 double maxTime() const override;
85
86 inline dmat4 transform() const { return translate(position) * vsg::rotate(rotation) * vsg::scale(scale); }
87
88 public:
89 ref_ptr<Object> clone(const CopyOp& copyop = {}) const override { return TransformSampler::create(*this, copyop); }
90 int compare(const Object& rhs) const override;
91
92 void read(Input& input) override;
93 void write(Output& output) const override;
94
95 void apply(mat4Value& mat) override;
96 void apply(dmat4Value& mat) override;
97 void apply(MatrixTransform& mt) override;
98 void apply(Joint& joint) override;
99 void apply(LookAt& lookAt) override;
100 void apply(Camera& camera) override;
101 };
102 VSG_type_name(vsg::TransformSampler);
103
104} // namespace vsg
Definition Camera.h:27
Definition Object.h:42
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:53
Definition MatrixTransform.h:24
Definition Object.h:60
Definition Output.h:41
std::vector< QuatKey > rotations
rotation key frames
Definition TransformSampler.h:38
std::string name
name of node
Definition TransformSampler.h:32
std::vector< VectorKey > positions
position key frames
Definition TransformSampler.h:35
std::vector< VectorKey > scales
scale key frames
Definition TransformSampler.h:41
Animation sampler for sampling position, rotation and scale keyframes for setting transforms/joints.
Definition TransformSampler.h:70
ref_ptr< Object > clone(const CopyOp &copyop={}) const override
Definition TransformSampler.h:89
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