[dali_1.9.21] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / math / angle-axis.h
1 #ifndef DALI_ANGLE_AXIS_H
2 #define DALI_ANGLE_AXIS_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <iosfwd>
23 #include <ostream>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/math/radian.h>
27 #include <dali/public-api/math/vector3.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_core_math
33  * @{
34  */
35
36 struct Radian;
37
38 /**
39  * @brief An angle & axis pair.
40  *
41  * This is slightly easier to understand than quaternions for handling rotations
42  * of objects. Both elements should be non-zero to correctly describe a rotation.
43  * @SINCE_1_0.0
44  */
45 struct AngleAxis
46 {
47   /**
48    * @brief Creates an angle-axis pair.
49    * @SINCE_1_0.0
50    */
51   AngleAxis()
52   : angle(0.0f),
53     axis(0.0f, 0.0f, 0.0f)
54   { }
55
56   /**
57    * @brief Creates an angle-axis pair.
58    *
59    * @SINCE_1_0.0
60    * @param[in] initialAngle The initial angle in radians
61    * @param[in] initialAxis The initial axis
62    */
63   AngleAxis( Radian initialAngle, const Vector3& initialAxis )
64   : angle( initialAngle ),
65     axis( initialAxis )
66   { }
67
68 public:
69
70   AngleAxis( const AngleAxis& ) = default; ///< Default copy constructor
71   AngleAxis( AngleAxis&& ) = default; ///< Default move constructor
72   AngleAxis& operator=( const AngleAxis& ) = default; ///< Default copy assignment operator
73   AngleAxis& operator=( AngleAxis&& ) = default; ///< Default move assignment operator
74
75 public:
76
77   Radian angle; ///< The angle in radians
78   Vector3 axis; ///< The axis
79
80 };
81
82 // Compiler generated destructor, copy constructor and assignment operators are ok as this class is POD
83
84 /**
85  * @brief Compares two angle axis for equality.
86  *
87  * @SINCE_1_0.0
88  * @param lhs angle axis
89  * @param rhs angle axis
90  * @return True if they are equal
91  */
92 inline bool operator==( const Dali::AngleAxis& lhs, const Dali::AngleAxis& rhs )
93 {
94   return (lhs.angle == rhs.angle) && (lhs.axis == rhs.axis);
95 }
96
97 /**
98  * @brief Prints an angle axis.
99  *
100  * @SINCE_1_1.33
101  * @param[in] o The output stream operator
102  * @param[in] angleAxis The angle axis to print
103  * @return The output stream operator
104  */
105 inline std::ostream& operator<< (std::ostream& o, const Dali::AngleAxis& angleAxis)
106 {
107   return o << "[ Axis: [" << angleAxis.axis.x << ", " << angleAxis.axis.y << ", " << angleAxis.axis.z << "], Angle: " << Degree( angleAxis.angle ).degree << " degrees ]";
108 }
109
110 /**
111  * @}
112  */
113 } // namespace Dali
114
115 #endif // DALI_ANGLE_AXIS_H