4fce86913a822f6511c2d67a6c927deb7d173e8e
[platform/core/uifw/dali-core.git] / dali / internal / common / math.h
1 #ifndef __DALI_INTERNAL_MATH_H__
2 #define __DALI_INTERNAL_MATH_H__
3
4 /*
5  * Copyright (c) 2016 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 namespace Dali
22 {
23
24 namespace Internal
25 {
26
27 typedef float Vec2[2];
28 typedef float Vec3[3];
29 typedef float Vec4[4];
30 typedef float Mat4[16];
31 typedef Vec3  Size3;
32
33 /**
34  * @brief Applies a transformation matrix to a vector
35  *
36  * @param[out] result The transformed vector
37  * @param[in] m The transformation matrix
38  * @param[in] v The vector to transform
39  */
40 void TransformVector3( Vec3 result, const Mat4 m, const Vec3 v );
41
42 /**
43  * @brief Computes the length of a vector3
44  *
45  * @param[in] v The vector
46  * @return The lenght of the vector
47  */
48 float Length( const Vec3 v );
49
50 /**
51  * @brief Transforms 2D vector by the Size3 and stores value in Vec2
52  *
53  * @param[out] result Vec2 type to store final value
54  * @param[in] v Vector to transform
55  * @param[in] s Size to transform with
56  */
57 void MultiplyVectorBySize( Vec2& result, const Vec2 v, const Size3 s );
58
59 /**
60  * @brief Transforms 3D vector by the Size3 and stores value in Vec3
61  *
62  * @param[out] result Vec3 type to store final value
63  * @param[in] v Vector to transform
64  * @param[in] s Size to transform with
65  */
66 void MultiplyVectorBySize( Vec3& result, const Vec3 v, const Size3 s );
67
68 /**
69  * @brief Transforms 4D vector by the Size3 and stores value in Vec4
70  *
71  * @param[out] result Vec4 type to store final value
72  * @param[in] v Vector to transform
73  * @param[in] s Size to transform with
74  */
75 void MultiplyVectorBySize( Vec4& result, const Vec4 v, const Size3 s );
76
77 /**
78  * @brief Multiplies 2D vector by the matrix
79  *
80  * @param[out] result Result of the multiplication
81  * @param[in] m Matrix to use
82  * @param[in] v Vector to multiply
83  */
84 void MultiplyVectorByMatrix4( Vec2& result, const Mat4 m, const Vec2 v );
85
86 /**
87  * @brief Multiplies 3D vector by the matrix
88  *
89  * @param[out] result Result of the multiplication
90  * @param[in] m Matrix to use
91  * @param[in] v Vector to multiply
92  */
93 void MultiplyVectorByMatrix4( Vec3& result, const Mat4 m, const Vec3 v );
94
95 /**
96  * @brief Multiplies 4D vector by the matrix
97  *
98  * @param[out] result Result of the multiplication
99  * @param[in] m Matrix to use
100  * @param[in] v Vector to multiply
101  */
102 void MultiplyVectorByMatrix4( Vec4& result, const Mat4 m, const Vec4 v );
103
104 /**
105  * @brief Multiplies two Mat4 matrices
106  *
107  * @param[out] result Result of multiplication
108  * @param[in] lhs Left-hand-side matrix to use
109  * @param[in] rhs Right-hand-side matrix to use
110  */
111 void MultiplyMatrices( float* result, const Mat4 lhs, const Mat4 rhs );
112
113
114 } // namespace Internal
115
116 } // namespace Dali
117
118 #endif  //__DALI_INTERNAL_MATH_H__