Diligent Engine API Reference
interpolator.h
1 /*
2  * Copyright 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef INTERPOLATOR_H_
18 #define INTERPOLATOR_H_
19 
20 #include <jni.h>
21 #include <errno.h>
22 #include <time.h>
23 #include "JNIHelper.h"
24 #include "perfMonitor.h"
25 #include <list>
26 
27 namespace ndk_helper {
28 
29 enum INTERPOLATOR_TYPE {
30  INTERPOLATOR_TYPE_LINEAR,
31  INTERPOLATOR_TYPE_EASEINQUAD,
32  INTERPOLATOR_TYPE_EASEOUTQUAD,
33  INTERPOLATOR_TYPE_EASEINOUTQUAD,
34  INTERPOLATOR_TYPE_EASEINCUBIC,
35  INTERPOLATOR_TYPE_EASEOUTCUBIC,
36  INTERPOLATOR_TYPE_EASEINOUTCUBIC,
37  INTERPOLATOR_TYPE_EASEINQUART,
38  INTERPOLATOR_TYPE_EASEINEXPO,
39  INTERPOLATOR_TYPE_EASEOUTEXPO,
40 };
41 
42 struct InterpolatorParams {
43  float dest_value_;
44  INTERPOLATOR_TYPE type_;
45  double duration_;
46 };
47 
48 /******************************************************************
49  * Interpolates values with several interpolation methods
50  */
51 class Interpolator {
52  private:
53  double start_time_;
54  double dest_time_;
55  INTERPOLATOR_TYPE type_;
56 
57  float start_value_;
58  float dest_value_;
59  std::list<InterpolatorParams> list_params_;
60 
61  float GetFormula(const INTERPOLATOR_TYPE type, const float t, const float b,
62  const float d, const float c);
63 
64  public:
65  Interpolator();
66  ~Interpolator();
67 
68  Interpolator& Set(const float start, const float dest,
69  const INTERPOLATOR_TYPE type, double duration);
70 
71  Interpolator& Add(const float dest, const INTERPOLATOR_TYPE type,
72  const double duration);
73 
74  bool Update(const double currentTime, float& p);
75 
76  void Clear();
77 };
78 
79 } // namespace ndkHelper
80 #endif /* INTERPOLATOR_H_ */
Definition: gestureDetector.h:32