vsg  1.1.0
VulkanSceneGraph library
AnimationPath.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2021 Robert Osfield
6 
7 Permission 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 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE 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/core/Inherit.h>
16 #include <vsg/maths/quat.h>
17 #include <vsg/ui/KeyEvent.h>
18 
19 #include <map>
20 
21 namespace vsg
22 {
23 
26  class VSG_DECLSPEC AnimationPath : public Inherit<Object, AnimationPath>
27  {
28  public:
29  enum Mode
30  {
31  ONCE,
32  REPEAT,
33  FORWARD_AND_BACK
34  };
35 
36  struct Location
37  {
38  dvec3 position;
39  dquat orientation;
40  dvec3 scale = {1.0, 1.0, 1.0};
41  };
42 
43  Mode mode = ONCE;
44  std::map<double, Location> locations;
45 
46  void add(double time, const dvec3& position, const dquat& orientation = {}, const dvec3& scale = {1.0, 1.0, 1.0})
47  {
48  locations[time] = Location{position, orientation, scale};
49  }
50 
51  double period() const;
52 
53  Location computeLocation(double time) const;
54  dmat4 computeMatrix(double time) const;
55 
56  void read(Input& input) override;
57  void write(Output& output) const override;
58  };
59  VSG_type_name(vsg::AnimationPath);
60 
63  class VSG_DECLSPEC AnimationPathHandler : public Inherit<Visitor, AnimationPathHandler>
64  {
65  public:
66  AnimationPathHandler(ref_ptr<Object> in_object, ref_ptr<AnimationPath> in_path, clock::time_point in_start_point);
67 
68  ref_ptr<Object> object;
70 
71  KeySymbol resetKey = KEY_Space;
72 
73  clock::time_point startPoint;
74  double time = 0.0;
75 
76  bool printFrameStatsToConsole = false;
77  clock::time_point statsStartPoint;
78  double frameCount = 0.0;
79 
80  void apply(Camera& camera) override;
81  void apply(MatrixTransform& transform) override;
82 
83  void apply(KeyPressEvent& keyPress) override;
84  void apply(FrameEvent& frame) override;
85 
86  protected:
87  };
88  VSG_type_name(vsg::AnimationPathHandler);
89 
91  class VSG_DECLSPEC RecordAnimationPathHandler : public Inherit<Visitor, RecordAnimationPathHandler>
92  {
93  public:
94  explicit RecordAnimationPathHandler(ref_ptr<Object> in_object, const Path& in_filename = "saved_animation.vsgt", ref_ptr<Options> in_options = {});
95 
96  ref_ptr<Object> object;
97  Path filename;
98  ref_ptr<Options> options;
99 
101  KeySymbol toggleRecordingKey = KEY_r;
102  KeySymbol togglePlaybackKey = KEY_p;
103 
104  bool recording = false;
105  bool playing = false;
106  clock::time_point startPoint;
107  double time = 0.0;
108 
109  bool printFrameStatsToConsole = false;
110  clock::time_point statsStartPoint;
111  double frameCount = 0.0;
112 
113  void apply(Camera& camera) override;
114  void apply(MatrixTransform& transform) override;
115 
116  void apply(KeyPressEvent& keyPress) override;
117  void apply(FrameEvent& frame) override;
118 
119  protected:
120  };
121  VSG_type_name(vsg::RecordAnimationPathHandler);
122 
123 } // namespace vsg
Definition: AnimationPath.h:64
Definition: AnimationPath.h:27
Definition: Camera.h:27
Definition: ApplicationEvent.h:37
Definition: Inherit.h:28
KeyPressEvent represents a key press event.
Definition: KeyEvent.h:309
Definition: MatrixTransform.h:24
Definition: Path.h:32
RecordAnimationPathHandler event handler records the camera.
Definition: AnimationPath.h:92
Definition: ref_ptr.h:22
Definition: AnimationPath.h:37