2013-06-06 12:02:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCUtilMath.h"
|
|
|
|
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
NS_CC_EXT_ARMATURE_BEGIN
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
bool isSpriteContainPoint(Sprite *sprite, Point point, Point &outPoint)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
outPoint = sprite->convertToNodeSpace(point);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
Size s = sprite->getContentSize();
|
|
|
|
Rect r(0, 0, s.width, s.height);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
return r.containsPoint(outPoint);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
bool isSpriteContainPoint(Sprite *sprite, Point point)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
Point p = Point(0, 0);
|
|
|
|
return isSpriteContainPoint(sprite, point, p);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Point bezierTo(float t, Point &point1, Point &point2, Point &point3)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Point p;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
p.x = pow((1 - t), 2) * point1.x + 2 * t * (1 - t) * point2.x + pow(t, 2) * point3.x;
|
|
|
|
p.y = pow((1 - t), 2) * point1.y + 2 * t * (1 - t) * point2.y + pow(t, 2) * point3.y;
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Point bezierTo(float t, Point &point1, Point &point2, Point &point3, Point &point4)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Point p;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
p.x = point1.x * pow((1 - t), 3) + 3 * t * point2.x * pow((1 - t), 2) + 3 * point3.x * pow(t, 2) * (1 - t) + point4.x * pow(t, 3);
|
|
|
|
p.y = point1.y * pow((1 - t), 3) + 3 * t * point2.y * pow((1 - t), 2) + 3 * point3.y * pow(t, 2) * (1 - t) + point4.y * pow(t, 3);
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Point circleTo(float t, Point ¢er, float radius, float fromRadian, float radianDif)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Point p;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
p.x = center.x + radius * cos(fromRadian + radianDif * t);
|
|
|
|
p.y = center.y + radius * sin(fromRadian + radianDif * t);
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
NS_CC_EXT_ARMATURE_END
|