model_data_animation_data.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 */
28 
29 #pragma once
30 
31 #include "model_data_animation_timeline.h"
32 
33 namespace clan
34 {
35 
43 template<typename Type>
45 {
46 public:
47  std::vector<ModelDataAnimationTimeline<Type> > timelines;
48 
49  bool has_multiple_values() const
50  {
51  return (!timelines.empty() && timelines[0].values.size() > 1) || timelines.size() > 1;
52  }
53 
54  Type get_value(int animation_index, float timestamp) const
55  {
56  if (timelines.empty())
57  return Type();
58 
59  int timeline_index = min(animation_index, (int)timelines.size() - 1);
60  return timelines[timeline_index].get_value(timestamp);
61  }
62 
63  Type get_single_value() const
64  {
65  return get_value(0, 0.0f);
66  }
67 
68  void set_single_value(Type value)
69  {
70  timelines.resize(1);
71  timelines[0].timestamps.resize(1);
72  timelines[0].timestamps[0] = 0.0f;
73  timelines[0].values.resize(1);
74  timelines[0].values[0] = value;
75  }
76 };
77 
78 }
79 
std::vector< ModelDataAnimationTimeline< Type > > timelines
Definition: model_data_animation_data.h:47
Type get_single_value() const
Definition: model_data_animation_data.h:63
void set_single_value(Type value)
Definition: model_data_animation_data.h:68
A min(A a, B b)
Definition: cl_math.h:51
Type get_value(int animation_index, float timestamp) const
Definition: model_data_animation_data.h:54
bool has_multiple_values() const
Definition: model_data_animation_data.h:49
Stores different values for different animation timelines.
Definition: model_data_animation_data.h:44