axmol/cocos/3d/CCAnimate3D.h

176 lines
5.7 KiB
C
Raw Normal View History

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 __CCANIMATE3D_H__
#define __CCANIMATE3D_H__
#include <map>
2014-08-28 18:53:15 +08:00
#include <unordered_map>
2014-06-04 18:17:09 +08:00
2014-06-17 10:49:52 +08:00
#include "3d/CCAnimation3D.h"
2014-06-04 18:17:09 +08:00
#include "base/ccMacros.h"
#include "base/CCRef.h"
#include "2d/CCActionInterval.h"
NS_CC_BEGIN
2014-07-11 10:17:36 +08:00
class Bone3D;
2014-08-28 18:53:15 +08:00
class Sprite3D;
2015-03-27 14:10:41 +08:00
2015-04-24 11:49:28 +08:00
enum class Animate3DQuality
{
QUALITY_NONE = 0, // it'll not to be calculate the animate.
QUALITY_LOW, // low animation quality, it'll be more efficient.
QUALITY_HIGH, // high animation quality.
};
2014-06-04 18:17:09 +08:00
/**
2015-03-27 14:10:41 +08:00
* @addtogroup _3d
* @{
*/
/**
* @brief Animate3D, Animates a Sprite3D given with an Animation3D
2014-06-04 18:17:09 +08:00
*/
2014-10-09 09:30:23 +08:00
class CC_DLL Animate3D: public ActionInterval
2014-06-04 18:17:09 +08:00
{
public:
2014-06-19 14:11:14 +08:00
/**create Animate3D using Animation.*/
2014-06-09 18:37:58 +08:00
static Animate3D* create(Animation3D* animation);
2014-06-04 18:17:09 +08:00
2014-06-20 12:01:54 +08:00
/**
2014-06-20 18:54:09 +08:00
* create Animate3D
* @param animation used to generate animate3D
2014-06-20 12:01:54 +08:00
* @param formTime
* @param duration Time the Animate3D lasts
* @return Animate3D created using animate
*/
2014-06-20 18:54:09 +08:00
static Animate3D* create(Animation3D* animation, float fromTime, float duration);
2014-10-10 17:44:45 +08:00
/**
2014-10-14 10:50:54 +08:00
* create Animate3D by frame section, [startFrame, endFrame)
2014-10-10 17:44:45 +08:00
* @param animation used to generate animate3D
* @param startFrame
* @param endFrame
2014-10-10 17:48:54 +08:00
* @param frameRate default is 30 per second
2014-10-10 17:44:45 +08:00
* @return Animate3D created using animate
*/
2014-10-17 11:16:07 +08:00
static Animate3D* createWithFrames(Animation3D* animation, int startFrame, int endFrame, float frameRate = 30.f);
2014-10-10 17:44:45 +08:00
2014-06-04 18:17:09 +08:00
//
// Overrides
//
2014-08-28 18:53:15 +08:00
virtual void stop() override;
2014-06-04 18:17:09 +08:00
virtual void step(float dt) override;
virtual void startWithTarget(Node *target) override;
virtual Animate3D* reverse() const override;
2014-06-17 19:18:56 +08:00
virtual Animate3D *clone() const override;
2014-06-04 18:17:09 +08:00
virtual void update(float t) override;
2014-07-09 09:53:15 +08:00
/**get & set speed, negative speed means playing reverse */
float getSpeed() const;
void setSpeed(float speed);
2014-07-09 09:53:15 +08:00
/**get & set blend weight, weight must positive*/
2014-06-20 17:55:25 +08:00
float getWeight() const { return _weight; }
2014-07-09 09:53:15 +08:00
void setWeight(float weight);
2014-06-17 19:18:56 +08:00
/**get & set origin interval*/
void setOriginInterval(float interval);
float getOriginInterval() const {return _originInterval; }
2015-02-28 17:40:25 +08:00
/** get animate transition time between 3d animations */
2014-08-29 18:25:42 +08:00
static float getTransitionTime() { return _transTime; }
2015-02-28 17:40:25 +08:00
/** set animate transition time between 3d animations */
2015-03-03 11:04:34 +08:00
static void setTransitionTime(float transTime) { if (transTime >= 0.f) _transTime = transTime; }
2015-02-28 17:40:25 +08:00
2014-07-10 11:05:48 +08:00
/**get & set play reverse, these are deprecated, use set negative speed instead*/
2014-07-09 14:07:33 +08:00
CC_DEPRECATED_ATTRIBUTE bool getPlayBack() const { return _playReverse; }
CC_DEPRECATED_ATTRIBUTE void setPlayBack(bool reverse) { _playReverse = reverse; }
2015-04-24 11:49:28 +08:00
/**set animate quality*/
void setQuality(Animate3DQuality quality);
2015-04-24 11:49:28 +08:00
/**get animate quality*/
Animate3DQuality getQuality() const;
2015-03-26 11:30:22 +08:00
2014-06-17 19:18:56 +08:00
CC_CONSTRUCTOR_ACCESS:
2014-06-04 18:17:09 +08:00
Animate3D();
virtual ~Animate3D();
2014-09-02 10:40:29 +08:00
void removeFromMap();
2015-03-09 16:29:57 +08:00
/** init method */
bool init(Animation3D* animation);
bool init(Animation3D* animation, float fromTime, float duration);
bool initWithFrames(Animation3D* animation, int startFrame, int endFrame, float frameRate);
2014-06-19 14:11:14 +08:00
protected:
2015-03-09 16:29:57 +08:00
2014-08-28 18:53:15 +08:00
enum class Animate3DState
{
FadeIn,
FadeOut,
Running,
};
Animate3DState _state; //animation state
2014-06-19 14:11:14 +08:00
Animation3D* _animation; //animation data
2014-06-04 18:17:09 +08:00
2014-07-09 09:53:15 +08:00
float _absSpeed; //playing speed
2014-06-19 14:11:14 +08:00
float _weight; //blend weight
2014-06-20 12:01:54 +08:00
float _start; //start time 0 - 1, used to generate sub Animate3D
float _last; //last time 0 - 1, used to generate sub Animate3D
2014-07-09 09:53:15 +08:00
bool _playReverse; // is playing reverse
2014-08-29 18:25:42 +08:00
static float _transTime; //transition time from one animate3d to another
2014-08-28 18:53:15 +08:00
float _accTransTime; // acculate transition time
float _lastTime; // last t (0 - 1)
float _originInterval;// save origin interval time
2015-03-26 11:30:22 +08:00
// animation quality
EvaluateType _translateEvaluate;
EvaluateType _roteEvaluate;
EvaluateType _scaleEvaluate;
2015-04-24 11:49:28 +08:00
Animate3DQuality _quality;
2015-03-26 11:30:22 +08:00
2014-08-28 18:53:15 +08:00
std::unordered_map<Bone3D*, Animation3D::Curve*> _boneCurves; //weak ref
2015-03-26 09:12:05 +08:00
std::unordered_map<Node*, Animation3D::Curve*> _nodeCurves;
2014-08-28 18:53:15 +08:00
//sprite animates
2015-03-26 09:12:05 +08:00
static std::unordered_map<Node*, Animate3D*> s_fadeInAnimates;
static std::unordered_map<Node*, Animate3D*> s_fadeOutAnimates;
static std::unordered_map<Node*, Animate3D*> s_runningAnimates;
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
#endif // __CCANIMATE3D_H__