2014-06-04 18:17:09 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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__
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
2014-06-18 00:27:19 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
|
|
|
#undef NEAR
|
|
|
|
#endif
|
2014-06-04 18:17:09 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
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
|
|
|
{
|
2014-06-19 14:11:14 +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>
|
|
|
|
class AnimationCurve: public Ref
|
|
|
|
{
|
|
|
|
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);
|
2014-06-04 18:17:09 +08:00
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**
|
|
|
|
* evalute value of time
|
|
|
|
* @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;
|
|
|
|
|
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);
|
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**get start time*/
|
2014-06-04 18:17:09 +08:00
|
|
|
float getStartTime() const;
|
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
/**get end time*/
|
2014-06-04 18:17:09 +08:00
|
|
|
float getEndTime() const;
|
|
|
|
|
2014-06-17 19:18:56 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2014-06-04 18:17:09 +08:00
|
|
|
|
|
|
|
AnimationCurve();
|
|
|
|
virtual ~AnimationCurve();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine index by time.
|
|
|
|
*/
|
|
|
|
int determineIndex(float time) const;
|
|
|
|
|
2014-06-17 19:18:56 +08:00
|
|
|
protected:
|
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
float* _value; //
|
2014-06-05 16:36:01 +08:00
|
|
|
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;
|
|
|
|
int _componentSizeByte; //component size in byte, position and scale 3 * sizeof(float), rotation 4 * sizeof(float)
|
|
|
|
|
2014-06-19 14:11:14 +08:00
|
|
|
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
|
|
|
/// @}
|
|
|
|
|
2014-06-04 18:17:09 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#include "CCAnimationCurve.inl"
|
|
|
|
|
|
|
|
#endif
|