Kiwano Engine v1.3.x
Transform.hpp
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/math/Vec2.hpp>
23#include <kiwano/math/Matrix.hpp>
24
25namespace kiwano
26{
27namespace math
28{
29
34template <typename _Ty>
36{
37public:
38 using ValueType = _Ty;
39
40 float rotation;
44
45public:
46 TransformT();
47
51
52 bool IsFast() const;
53
54 bool operator==(const TransformT& rhs) const;
55};
56
57template <typename _Ty>
59 : position()
60 , rotation(0.f)
61 , scale(1.f, 1.f)
62 , skew(0.f, 0.f)
63{
64}
65
66template <typename _Ty>
68{
69 if (!skew.IsOrigin())
70 {
71 return Matrix3x2T<_Ty>::Skewing(skew) * Matrix3x2T<_Ty>::SRT(position, scale, rotation);
72 }
73 return Matrix3x2T<_Ty>::SRT(position, scale, rotation);
74}
75
76template <typename _Ty>
77inline bool TransformT<_Ty>::IsFast() const
78{
79 return skew.x == 0.f && skew.y == 0.f && scale.x == 1.f && scale.y == 1.f && rotation == 0.f;
80}
81
82template <typename _Ty>
83bool TransformT<_Ty>::operator==(const TransformT& rhs) const
84{
85 return position == rhs.position && rotation == rhs.rotation && scale == rhs.scale && skew == rhs.skew;
86}
87
88} // namespace math
89} // namespace kiwano
二维放射变换
Definition: Transform.hpp:36
float rotation
旋转
Definition: Transform.hpp:40
Matrix3x2T< ValueType > ToMatrix() const
将二维放射变换转换为矩阵
Definition: Transform.hpp:67
Vec2T< ValueType > skew
错切角度
Definition: Transform.hpp:43
Vec2T< ValueType > position
坐标
Definition: Transform.hpp:41
Vec2T< ValueType > scale
缩放
Definition: Transform.hpp:42
Definition: Matrix.hpp:35