Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / effects / inc / renderer / math / FUiEffects_RendererMathVector3Traits.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file       FUiEffects_RendererMathVector3Traits.h
20  * @brief      The Vector3Traits class
21  *
22  */
23
24 #ifndef _FUI_EFFECTS_INTERNAL_RENDERER_MATH_VECTOR3_TRAITS_H_
25 #define _FUI_EFFECTS_INTERNAL_RENDERER_MATH_VECTOR3_TRAITS_H_
26
27 #include <renderer/math/FUiEffects_RendererMathVectorTraits.h>
28
29 namespace Tizen { namespace Ui { namespace Effects { namespace _Renderer { namespace Math
30 {
31
32 template<typename T>
33 class VectorTraits<T, 3> :
34         public VectorTraitsBase<T, 3>
35 {
36 public:
37         typedef Vector<T, 3> VectorType;
38         typedef VectorTraitsBase<T, 3> VectorTraitsBaseType;
39         typedef typename VectorTraitsBaseType::TypeReference TypeReference;
40
41         using VectorTraitsBaseType::data;
42
43         inline T& X(void);
44         inline const TypeReference X(void) const;
45
46         inline T& Y(void);
47         inline const TypeReference Y(void) const;
48
49         inline T& Z(void);
50         inline const TypeReference Z(void) const;
51
52         inline VectorType& Set(const TypeReference x, const TypeReference y, const TypeReference z);
53
54         inline VectorType& Cross(const VectorType& other);
55         inline VectorType GetCrossed(const VectorType& other) const;
56         inline VectorType& MakeCrossed(const VectorType& first, const VectorType& second);
57         static inline VectorType CreateCrossed(const VectorType& first, const VectorType& second);
58 };
59
60 template<typename T>
61 T& VectorTraits<T, 3>::X(void)
62 {
63         return data[0];
64 }
65
66 template<typename T>
67 const typename VectorTraits<T, 3>::TypeReference VectorTraits<T, 3>::X(void) const
68 {
69         return data[0];
70 }
71
72 template<typename T>
73 T& VectorTraits<T, 3>::Y(void)
74 {
75         return data[1];
76 }
77
78 template<typename T>
79 const typename VectorTraits<T, 3>::TypeReference VectorTraits<T, 3>::Y(void) const
80 {
81         return data[1];
82 }
83
84 template<typename T>
85 T& VectorTraits<T, 3>::Z(void)
86 {
87         return data[2];
88 }
89
90 template<typename T>
91 const typename VectorTraits<T, 3>::TypeReference VectorTraits<T, 3>::Z(void) const
92 {
93         return data[2];
94 }
95
96 template<typename T>
97 typename VectorTraits<T, 3>::VectorType& VectorTraits<T, 3>::Set(const TypeReference x, const TypeReference y, const TypeReference z)
98 {
99         data[0] = x;
100         data[1] = y;
101         data[2] = z;
102         return *(static_cast<VectorType*>(this));
103 }
104
105 template<typename T>
106 typename VectorTraits<T, 3>::VectorType& VectorTraits<T, 3>::Cross(const VectorType& other)
107 {
108         return Set((Y() * other.Z() - Z() * other.Y()), (Z() * other.X() - X() * other.Z()), (X() * other.Y() - Y() * other.X()));
109 }
110
111 template<typename T>
112 typename VectorTraits<T, 3>::VectorType VectorTraits<T, 3>::GetCrossed(const VectorType& other) const
113 {
114         VectorType result(X(), Y(), Z());
115         return result.Cross(other);
116 }
117
118 template<typename T>
119 typename VectorTraits<T, 3>::VectorType& VectorTraits<T, 3>::MakeCrossed(const VectorType& first, const VectorType& second)
120 {
121         *this = first;
122         return Cross(second);
123 }
124
125 template<typename T>
126 typename VectorTraits<T, 3>::VectorType VectorTraits<T, 3>::CreateCrossed(const VectorType& first, const VectorType& second)
127 {
128         return VectorTraits<T, 3>().MakeCrossed(first, second);
129 }
130
131 }}}}} //Tizen::Ui::Effects::_Renderer::Math
132
133 #endif //_FUI_EFFECTS_INTERNAL_RENDERER_MATH_VECTOR3_TRAITS_H_