2019-11-23 20:27:39 +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.
|
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2019-11-23 20:27:39 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __MATH_CCAFFINETRANSFORM_H__
|
|
|
|
#define __MATH_CCAFFINETRANSFORM_H__
|
|
|
|
|
|
|
|
#include "platform/CCPlatformMacros.h"
|
|
|
|
|
|
|
|
#include "math/CCMath.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup base
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**@{
|
|
|
|
Affine transform
|
|
|
|
a b 0
|
|
|
|
c d 0
|
|
|
|
tx ty 1
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Identity
|
|
|
|
1 0 0
|
|
|
|
0 1 0
|
|
|
|
0 0 1
|
|
|
|
*/
|
2022-07-16 10:43:05 +08:00
|
|
|
struct AX_DLL AffineTransform
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
float a, b, c, d;
|
|
|
|
float tx, ty;
|
|
|
|
|
|
|
|
static const AffineTransform IDENTITY;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/**Make affine transform.*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL AffineTransform __CCAffineTransformMake(float a, float b, float c, float d, float tx, float ty);
|
2019-11-23 20:27:39 +08:00
|
|
|
#define AffineTransformMake __CCAffineTransformMake
|
|
|
|
|
|
|
|
/**Multiply point (x,y,1) by a affine transform.*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL Vec2 __CCPointApplyAffineTransform(const Vec2& point, const AffineTransform& t);
|
2019-11-23 20:27:39 +08:00
|
|
|
#define PointApplyAffineTransform __CCPointApplyAffineTransform
|
|
|
|
|
|
|
|
/**Multiply size (width,height,0) by a affine transform.*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL Vec2 __CCSizeApplyAffineTransform(const Vec2& size, const AffineTransform& t);
|
2019-11-23 20:27:39 +08:00
|
|
|
#define SizeApplyAffineTransform __CCSizeApplyAffineTransform
|
|
|
|
/**Make identity affine transform.*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL AffineTransform AffineTransformMakeIdentity();
|
2019-11-23 20:27:39 +08:00
|
|
|
/**Transform Rect, which will transform the four vertices of the point.*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL Rect RectApplyAffineTransform(const Rect& rect, const AffineTransform& anAffineTransform);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**@{
|
|
|
|
Transform vec2 and Rect by Mat4.
|
|
|
|
*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL Rect RectApplyTransform(const Rect& rect, const Mat4& transform);
|
|
|
|
AX_DLL Vec2 PointApplyTransform(const Vec2& point, const Mat4& transform);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**@}*/
|
|
|
|
/**
|
|
|
|
Translation, equals
|
|
|
|
1 0 1
|
|
|
|
0 1 0 * affine transform
|
|
|
|
tx ty 1
|
|
|
|
*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL AffineTransform AffineTransformTranslate(const AffineTransform& t, float tx, float ty);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
Rotation, equals
|
|
|
|
cos(angle) sin(angle) 0
|
|
|
|
-sin(angle) cos(angle) 0 * AffineTransform
|
|
|
|
0 0 1
|
|
|
|
*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL AffineTransform AffineTransformRotate(const AffineTransform& aTransform, float anAngle);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
Scale, equals
|
|
|
|
sx 0 0
|
|
|
|
0 sy 0 * affineTransform
|
|
|
|
0 0 1
|
|
|
|
*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL AffineTransform AffineTransformScale(const AffineTransform& t, float sx, float sy);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**Concat two affine transform, t1 * t2*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL AffineTransform AffineTransformConcat(const AffineTransform& t1, const AffineTransform& t2);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**Compare affine transform.*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL bool AffineTransformEqualToTransform(const AffineTransform& t1, const AffineTransform& t2);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**Get the inverse of affine transform.*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL AffineTransform AffineTransformInvert(const AffineTransform& t);
|
2019-11-23 20:27:39 +08:00
|
|
|
/**Concat Mat4, return t1 * t2.*/
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DLL Mat4 TransformConcat(const Mat4& t1, const Mat4& t2);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
extern AX_DLL const AffineTransform AffineTransformIdentity;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// end of base transform
|
|
|
|
/// @}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __MATH_CCAFFINETRANSFORM_H__
|