RavEngine
Loading...
Searching...
No Matches
raw_animation_utils.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_UTILS_H_
29#define OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_UTILS_H_
30
31#include "ozz/animation/offline/export.h"
32#include "ozz/animation/offline/raw_animation.h"
33
34#include "ozz/base/maths/transform.h"
35#include "ozz/base/span.h"
36
37namespace ozz {
38namespace animation {
39namespace offline {
40
41// Translation interpolation method.
42OZZ_ANIMOFFLINE_DLL math::Float3 LerpTranslation(const math::Float3& _a,
43 const math::Float3& _b,
44 float _alpha);
45
46// Rotation interpolation method.
47OZZ_ANIMOFFLINE_DLL math::Quaternion LerpRotation(const math::Quaternion& _a,
48 const math::Quaternion& _b, float _alpha);
49
50// Scale interpolation method.
51OZZ_ANIMOFFLINE_DLL math::Float3 LerpScale(const math::Float3& _a,
52 const math::Float3& _b,
53 float _alpha);
54
55// Samples a RawAnimation track. This function shall be used for offline
56// purpose. Use ozz::animation::Animation and ozz::animation::SamplingJob for
57// runtime purpose.
58// Returns false if track is invalid.
59OZZ_ANIMOFFLINE_DLL bool SampleTrack(const RawAnimation::JointTrack& _track,
60 float _time,
61 ozz::math::Transform* _transform);
62
63// Samples a RawAnimation. This function shall be used for offline
64// purpose. Use ozz::animation::Animation and ozz::animation::SamplingJob for
65// runtime purpose.
66// _animation must be valid.
67// Returns false output range is too small or animation is invalid.
68OZZ_ANIMOFFLINE_DLL bool SampleAnimation(
69 const RawAnimation& _animation, float _time,
70 const span<ozz::math::Transform>& _transforms);
71
72// Implement fixed rate keyframe time iteration. This utility purpose is to
73// ensure that sampling goes strictly from 0 to duration, and that period
74// between consecutive time samples have a fixed period.
75// This sounds trivial, but floating point error could occur if keyframe time
76// was accumulated for a long duration.
77class OZZ_ANIMOFFLINE_DLL FixedRateSamplingTime {
78 public:
79 FixedRateSamplingTime(float _duration, float _frequency);
80
81 float time(size_t _key) const {
82 assert(_key < num_keys_);
83 return ozz::math::Min(_key * period_, duration_);
84 }
85
86 size_t num_keys() const { return num_keys_; }
87
88 private:
89 float duration_;
90 float period_;
91 size_t num_keys_;
92};
93} // namespace offline
94} // namespace animation
95} // namespace ozz
96#endif // OZZ_OZZ_ANIMATION_OFFLINE_RAW_ANIMATION_UTILS_H_
Definition raw_animation_utils.h:77
Definition transform.h:40