mirror of https://github.com/axmolengine/axmol.git
RotateTo action now uses Vec3() to keep track of the state
This commit is contained in:
parent
3d44439e2a
commit
98354e9f8e
|
@ -724,28 +724,28 @@ Spawn* Spawn::reverse() const
|
||||||
// RotateTo
|
// RotateTo
|
||||||
//
|
//
|
||||||
|
|
||||||
RotateTo* RotateTo::create(float duration, float deltaAngle)
|
RotateTo* RotateTo::create(float duration, float dstAngle)
|
||||||
{
|
{
|
||||||
RotateTo* rotateTo = new RotateTo();
|
RotateTo* rotateTo = new RotateTo();
|
||||||
rotateTo->initWithDuration(duration, deltaAngle);
|
rotateTo->initWithDuration(duration, dstAngle, dstAngle);
|
||||||
rotateTo->autorelease();
|
rotateTo->autorelease();
|
||||||
|
|
||||||
return rotateTo;
|
return rotateTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
RotateTo* RotateTo::create(float duration, float deltaAngleX, float deltaAngleY)
|
RotateTo* RotateTo::create(float duration, float dstAngleX, float dstAngleY)
|
||||||
{
|
{
|
||||||
RotateTo* rotateTo = new RotateTo();
|
RotateTo* rotateTo = new RotateTo();
|
||||||
rotateTo->initWithDuration(duration, deltaAngleX, deltaAngleY);
|
rotateTo->initWithDuration(duration, dstAngleX, dstAngleY);
|
||||||
rotateTo->autorelease();
|
rotateTo->autorelease();
|
||||||
|
|
||||||
return rotateTo;
|
return rotateTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
RotateTo* RotateTo::create(float duration, const Vec3& deltaAngle3D)
|
RotateTo* RotateTo::create(float duration, const Vec3& dstAngle3D)
|
||||||
{
|
{
|
||||||
RotateTo* rotateTo = new RotateTo();
|
RotateTo* rotateTo = new RotateTo();
|
||||||
rotateTo->initWithDuration(duration, deltaAngle3D);
|
rotateTo->initWithDuration(duration, dstAngle3D);
|
||||||
rotateTo->autorelease();
|
rotateTo->autorelease();
|
||||||
|
|
||||||
return rotateTo;
|
return rotateTo;
|
||||||
|
@ -756,23 +756,12 @@ RotateTo::RotateTo()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RotateTo::initWithDuration(float duration, float deltaAngle)
|
bool RotateTo::initWithDuration(float duration, float dstAngleX, float dstAngleY)
|
||||||
{
|
{
|
||||||
if (ActionInterval::initWithDuration(duration))
|
if (ActionInterval::initWithDuration(duration))
|
||||||
{
|
{
|
||||||
_dstAngleX = _dstAngleY = deltaAngle;
|
_dstAngle.x = dstAngleX;
|
||||||
return true;
|
_dstAngle.y = dstAngleY;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RotateTo::initWithDuration(float duration, float deltaAngleX, float deltaAngleY)
|
|
||||||
{
|
|
||||||
if (ActionInterval::initWithDuration(duration))
|
|
||||||
{
|
|
||||||
_dstAngleX = deltaAngleX;
|
|
||||||
_dstAngleY = deltaAngleY;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -780,11 +769,11 @@ bool RotateTo::initWithDuration(float duration, float deltaAngleX, float deltaAn
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RotateTo::initWithDuration(float duration, const Vec3& deltaAngle3D)
|
bool RotateTo::initWithDuration(float duration, const Vec3& dstAngle3D)
|
||||||
{
|
{
|
||||||
if (ActionInterval::initWithDuration(duration))
|
if (ActionInterval::initWithDuration(duration))
|
||||||
{
|
{
|
||||||
_dstAngle3D = deltaAngle3D;
|
_dstAngle = dstAngle3D;
|
||||||
_is3D = true;
|
_is3D = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -798,9 +787,9 @@ RotateTo* RotateTo::clone(void) const
|
||||||
// no copy constructor
|
// no copy constructor
|
||||||
auto a = new RotateTo();
|
auto a = new RotateTo();
|
||||||
if(_is3D)
|
if(_is3D)
|
||||||
a->initWithDuration(_duration, _dstAngle3D);
|
a->initWithDuration(_duration, _dstAngle);
|
||||||
else
|
else
|
||||||
a->initWithDuration(_duration, _dstAngleX, _dstAngleY);
|
a->initWithDuration(_duration, _dstAngle.x, _dstAngle.y);
|
||||||
a->autorelease();
|
a->autorelease();
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
@ -833,20 +822,17 @@ void RotateTo::startWithTarget(Node *target)
|
||||||
|
|
||||||
if (_is3D)
|
if (_is3D)
|
||||||
{
|
{
|
||||||
_startAngle3D = _target->getRotation3D();
|
_startAngle = _target->getRotation3D();
|
||||||
|
|
||||||
calculateAngles(_startAngle3D.x, _diffAngle3D.x, _dstAngle3D.x);
|
|
||||||
calculateAngles(_startAngle3D.y, _diffAngle3D.y, _dstAngle3D.y);
|
|
||||||
calculateAngles(_startAngle3D.z, _diffAngle3D.z, _dstAngle3D.z);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_startAngleX = _target->getRotationSkewX();
|
_startAngle.x = _target->getRotationSkewX();
|
||||||
_startAngleY = _target->getRotationSkewY();
|
_startAngle.y = _target->getRotationSkewY();
|
||||||
|
|
||||||
calculateAngles(_startAngleX, _diffAngleX, _dstAngleX);
|
|
||||||
calculateAngles(_startAngleY, _diffAngleY, _dstAngleY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calculateAngles(_startAngle.x, _diffAngle.x, _dstAngle.x);
|
||||||
|
calculateAngles(_startAngle.y, _diffAngle.y, _dstAngle.y);
|
||||||
|
calculateAngles(_startAngle.z, _diffAngle.z, _dstAngle.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RotateTo::update(float time)
|
void RotateTo::update(float time)
|
||||||
|
@ -856,32 +842,32 @@ void RotateTo::update(float time)
|
||||||
if(_is3D)
|
if(_is3D)
|
||||||
{
|
{
|
||||||
_target->setRotation3D(Vec3(
|
_target->setRotation3D(Vec3(
|
||||||
_startAngle3D.x + _diffAngle3D.x * time,
|
_startAngle.x + _diffAngle.x * time,
|
||||||
_startAngle3D.y + _diffAngle3D.y * time,
|
_startAngle.y + _diffAngle.y * time,
|
||||||
_startAngle3D.z + _diffAngle3D.z * time
|
_startAngle.z + _diffAngle.z * time
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if CC_USE_PHYSICS
|
#if CC_USE_PHYSICS
|
||||||
if (_startAngleX == _startAngleY && _diffAngleX == _diffAngleY)
|
if (_startAngle.x == _startAngle.y && _diffAngle.x == _diffAngle.y)
|
||||||
{
|
{
|
||||||
_target->setRotation(_startAngleX + _diffAngleX * time);
|
_target->setRotation(_startAngle.x + _diffAngle.x * time);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// _startAngleX != _startAngleY || _diffAngleX != _diffAngleY
|
// _startAngle.x != _startAngle.y || _diffAngle.x != _diffAngle.y
|
||||||
if (_target->getPhysicsBody() != nullptr)
|
if (_target->getPhysicsBody() != nullptr)
|
||||||
{
|
{
|
||||||
CCLOG("RotateTo WARNING: PhysicsBody doesn't support skew rotation");
|
CCLOG("RotateTo WARNING: PhysicsBody doesn't support skew rotation");
|
||||||
}
|
}
|
||||||
|
|
||||||
_target->setRotationSkewX(_startAngleX + _diffAngleX * time);
|
_target->setRotationSkewX(_startAngle.x + _diffAngle.x * time);
|
||||||
_target->setRotationSkewY(_startAngleY + _diffAngleY * time);
|
_target->setRotationSkewY(_startAngle.y + _diffAngle.y * time);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
_target->setRotationSkewX(_startAngleX + _diffAngleX * time);
|
_target->setRotationSkewX(_startAngle.x + _diffAngle.x * time);
|
||||||
_target->setRotationSkewY(_startAngleY + _diffAngleY * time);
|
_target->setRotationSkewY(_startAngle.y + _diffAngle.y * time);
|
||||||
#endif // CC_USE_PHYSICS
|
#endif // CC_USE_PHYSICS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -339,13 +339,13 @@ class CC_DLL RotateTo : public ActionInterval
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** creates the action with separate rotation angles */
|
/** creates the action with separate rotation angles */
|
||||||
static RotateTo* create(float duration, float deltaAngleX, float deltaAngleY);
|
static RotateTo* create(float duration, float dstAngleX, float dstAngleY);
|
||||||
|
|
||||||
/** creates the action */
|
/** creates the action */
|
||||||
static RotateTo* create(float duration, float deltaAngle);
|
static RotateTo* create(float duration, float dstAngle);
|
||||||
|
|
||||||
/** creates the action with 3D rotation angles */
|
/** creates the action with 3D rotation angles */
|
||||||
static RotateTo* create(float duration, const Vec3& deltaAngle3D);
|
static RotateTo* create(float duration, const Vec3& dstAngle3D);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Overrides
|
// Overrides
|
||||||
|
@ -360,26 +360,17 @@ CC_CONSTRUCTOR_ACCESS:
|
||||||
virtual ~RotateTo() {}
|
virtual ~RotateTo() {}
|
||||||
|
|
||||||
/** initializes the action */
|
/** initializes the action */
|
||||||
bool initWithDuration(float duration, float deltaAngle);
|
bool initWithDuration(float duration, float dstAngleX, float dstAngleY);
|
||||||
bool initWithDuration(float duration, float deltaAngleX, float deltaAngleY);
|
bool initWithDuration(float duration, const Vec3& dstAngle3D);
|
||||||
bool initWithDuration(float duration, const Vec3& deltaAngle3D);
|
|
||||||
|
|
||||||
/** calculates the start and diff angles */
|
/** calculates the start and diff angles */
|
||||||
void calculateAngles(float &startAngle, float &diffAngle, float dstAngle);
|
void calculateAngles(float &startAngle, float &diffAngle, float dstAngle);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float _dstAngleX;
|
|
||||||
float _startAngleX;
|
|
||||||
float _diffAngleX;
|
|
||||||
|
|
||||||
float _dstAngleY;
|
|
||||||
float _startAngleY;
|
|
||||||
float _diffAngleY;
|
|
||||||
|
|
||||||
bool _is3D;
|
bool _is3D;
|
||||||
Vec3 _dstAngle3D;
|
Vec3 _dstAngle;
|
||||||
Vec3 _startAngle3D;
|
Vec3 _startAngle;
|
||||||
Vec3 _diffAngle3D;
|
Vec3 _diffAngle;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(RotateTo);
|
CC_DISALLOW_COPY_AND_ASSIGN(RotateTo);
|
||||||
|
|
Loading…
Reference in New Issue