axmol/core/math/CCAffineTransform.h

121 lines
3.9 KiB
C
Raw Normal View History

2013-10-12 15:25:45 +08:00
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2013-10-12 15:25:45 +08:00
2022-08-08 18:02:17 +08:00
https://axys1.github.io/
2013-10-12 15:25:45 +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:
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.
****************************************************************************/
2014-04-30 08:37:36 +08:00
#ifndef __MATH_CCAFFINETRANSFORM_H__
#define __MATH_CCAFFINETRANSFORM_H__
2013-10-12 15:25:45 +08:00
#include "platform/CCPlatformMacros.h"
2014-04-30 08:37:36 +08:00
2014-04-26 13:03:25 +08:00
#include "math/CCMath.h"
2013-10-12 15:25:45 +08:00
/**
* @addtogroup base
* @{
*/
NS_AX_BEGIN
2013-10-12 15:25:45 +08:00
/**@{
Affine transform
a b 0
c d 0
tx ty 1
2021-12-25 10:04:45 +08:00
Identity
1 0 0
0 1 0
0 0 1
*/
2022-07-15 19:17:01 +08:00
struct AX_DLL AffineTransform
2021-12-25 10:04:45 +08:00
{
2013-10-12 15:25:45 +08:00
float a, b, c, d;
float tx, ty;
static const AffineTransform IDENTITY;
};
/**@}*/
/**Make affine transform.*/
2022-07-15 19:17:01 +08:00
AX_DLL AffineTransform __CCAffineTransformMake(float a, float b, float c, float d, float tx, float ty);
2013-10-12 15:25:45 +08:00
#define AffineTransformMake __CCAffineTransformMake
/**Multiply point (x,y,1) by a affine transform.*/
2022-07-15 19:17:01 +08:00
AX_DLL Vec2 __CCPointApplyAffineTransform(const Vec2& point, const AffineTransform& t);
2013-10-12 15:25:45 +08:00
#define PointApplyAffineTransform __CCPointApplyAffineTransform
/**Multiply size (width,height,0) by a affine transform.*/
2022-07-15 19:17:01 +08:00
AX_DLL Vec2 __CCSizeApplyAffineTransform(const Vec2& size, const AffineTransform& t);
2013-10-12 15:25:45 +08:00
#define SizeApplyAffineTransform __CCSizeApplyAffineTransform
/**Make identity affine transform.*/
2022-07-15 19:17:01 +08:00
AX_DLL AffineTransform AffineTransformMakeIdentity();
/**Transform Rect, which will transform the four vertices of the point.*/
2022-07-15 19:17:01 +08:00
AX_DLL Rect RectApplyAffineTransform(const Rect& rect, const AffineTransform& anAffineTransform);
/**@{
Transform vec2 and Rect by Mat4.
*/
2022-07-15 19:17:01 +08:00
AX_DLL Rect RectApplyTransform(const Rect& rect, const Mat4& transform);
AX_DLL Vec2 PointApplyTransform(const Vec2& point, const Mat4& transform);
/**@}*/
/**
Translation, equals
1 0 1
0 1 0 * affine transform
tx ty 1
*/
2022-07-15 19:17:01 +08:00
AX_DLL AffineTransform AffineTransformTranslate(const AffineTransform& t, float tx, float ty);
/**
Rotation, equals
cos(angle) sin(angle) 0
-sin(angle) cos(angle) 0 * AffineTransform
0 0 1
*/
2022-07-15 19:17:01 +08:00
AX_DLL AffineTransform AffineTransformRotate(const AffineTransform& aTransform, float anAngle);
/**
Scale, equals
sx 0 0
0 sy 0 * affineTransform
0 0 1
*/
2022-07-15 19:17:01 +08:00
AX_DLL AffineTransform AffineTransformScale(const AffineTransform& t, float sx, float sy);
/**Concat two affine transform, t1 * t2*/
2022-07-15 19:17:01 +08:00
AX_DLL AffineTransform AffineTransformConcat(const AffineTransform& t1, const AffineTransform& t2);
/**Compare affine transform.*/
2022-07-15 19:17:01 +08:00
AX_DLL bool AffineTransformEqualToTransform(const AffineTransform& t1, const AffineTransform& t2);
/**Get the inverse of affine transform.*/
2022-07-15 19:17:01 +08:00
AX_DLL AffineTransform AffineTransformInvert(const AffineTransform& t);
/**Concat Mat4, return t1 * t2.*/
2022-07-15 19:17:01 +08:00
AX_DLL Mat4 TransformConcat(const Mat4& t1, const Mat4& t2);
2013-12-11 03:07:15 +08:00
2022-07-15 19:17:01 +08:00
extern AX_DLL const AffineTransform AffineTransformIdentity;
2013-10-12 15:25:45 +08:00
NS_AX_END
2013-10-12 15:25:45 +08:00
// end of base transform
/// @}
2021-12-25 10:04:45 +08:00
#endif // __MATH_CCAFFINETRANSFORM_H__