2014-06-04 18:17:09 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2014-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
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:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CCANIMATIONCURVE_H__
|
|
|
|
#define __CCANIMATIONCURVE_H__
|
|
|
|
|
2016-07-12 03:13:56 +08:00
|
|
|
#include <cmath>
|
2014-06-04 18:17:09 +08:00
|
|
|
#include <functional>
|
|
|
|
|
2014-09-10 08:17:07 +08:00
|
|
|
#include "platform/CCPlatformMacros.h"
|
2014-06-04 18:17:09 +08:00
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "math/CCMath.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2014-06-04 18:17:09 +08:00
|
|
|
|
2015-03-27 14:10:41 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup _3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**
|
|
|
|
* Evaluate Type
|
|
|
|
*/
|
2014-06-17 19:18:56 +08:00
|
|
|
enum class EvaluateType
|
2014-06-04 18:17:09 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
INT_LINEAR,
|
2014-06-18 14:01:57 +08:00
|
|
|
INT_NEAR,
|
|
|
|
INT_QUAT_SLERP,
|
|
|
|
INT_USER_FUNCTION,
|
2014-06-04 18:17:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-03-27 14:10:41 +08:00
|
|
|
* @brief curve of bone's position, rotation or scale
|
2015-03-30 15:47:47 +08:00
|
|
|
*
|
|
|
|
* @lua NA
|
2014-06-04 18:17:09 +08:00
|
|
|
*/
|
|
|
|
template <int componentSize>
|
2021-12-25 10:04:45 +08:00
|
|
|
class AnimationCurve : public Ref
|
2014-06-04 18:17:09 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-06-19 14:11:14 +08:00
|
|
|
/**create animation curve*/
|
2014-06-09 18:37:58 +08:00
|
|
|
static AnimationCurve* create(float* keytime, float* value, int count);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**
|
2015-09-09 11:37:41 +08:00
|
|
|
* evaluate value of time
|
2014-06-19 14:11:14 +08:00
|
|
|
* @param time Time to be estimated
|
|
|
|
* @param dst Estimated value of that time
|
|
|
|
* @param type EvaluateType
|
|
|
|
*/
|
2014-06-04 18:17:09 +08:00
|
|
|
void evaluate(float time, float* dst, EvaluateType type) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**set evaluate function, allow the user use own function*/
|
2014-06-04 18:17:09 +08:00
|
|
|
void setEvaluateFun(std::function<void(float time, float* dst)> fun);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**get start time*/
|
2014-06-04 18:17:09 +08:00
|
|
|
float getStartTime() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**get end time*/
|
2014-06-04 18:17:09 +08:00
|
|
|
float getEndTime() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
AnimationCurve();
|
2014-06-04 18:17:09 +08:00
|
|
|
virtual ~AnimationCurve();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
/**
|
|
|
|
* Determine index by time.
|
|
|
|
*/
|
|
|
|
int determineIndex(float time) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-06-17 19:18:56 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
float* _value; //
|
|
|
|
float* _keytime; // key time(0 - 1), start time _keytime[0], end time _keytime[_count - 1]
|
2014-06-04 18:17:09 +08:00
|
|
|
int _count;
|
2021-12-25 10:04:45 +08:00
|
|
|
int _componentSizeByte; // component size in byte, position and scale 3 * sizeof(float), rotation 4 * sizeof(float)
|
|
|
|
|
|
|
|
std::function<void(float time, float* dst)> _evaluateFun; // user defined function
|
2014-06-04 18:17:09 +08:00
|
|
|
};
|
|
|
|
|
2015-04-01 10:23:53 +08:00
|
|
|
// end of 3d group
|
2015-03-27 14:10:41 +08:00
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2014-06-04 18:17:09 +08:00
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "3d/CCAnimationCurve.inl"
|
2014-06-04 18:17:09 +08:00
|
|
|
|
|
|
|
#endif
|