Release 4.0.0-preview1-00301
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Matrix.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 namespace Tizen.NUI
19 {
20
21     internal class Matrix : global::System.IDisposable
22     {
23         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
24         protected bool swigCMemOwn;
25
26         internal Matrix(global::System.IntPtr cPtr, bool cMemoryOwn)
27         {
28             swigCMemOwn = cMemoryOwn;
29             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
30         }
31
32         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Matrix obj)
33         {
34             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
35         }
36
37
38         //A Flag to check who called Dispose(). (By User or DisposeQueue)
39         private bool isDisposeQueued = false;
40         //A Flat to check if it is already disposed.
41         protected bool disposed = false;
42
43
44         ~Matrix()
45         {
46             if (!isDisposeQueued)
47             {
48                 isDisposeQueued = true;
49                 DisposeQueue.Instance.Add(this);
50             }
51         }
52
53         public void Dispose()
54         {
55             //Throw excpetion if Dispose() is called in separate thread.
56             if (!Window.IsInstalled())
57             {
58                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
59             }
60
61             if (isDisposeQueued)
62             {
63                 Dispose(DisposeTypes.Implicit);
64             }
65             else
66             {
67                 Dispose(DisposeTypes.Explicit);
68                 System.GC.SuppressFinalize(this);
69             }
70         }
71
72         protected virtual void Dispose(DisposeTypes type)
73         {
74             if (disposed)
75             {
76                 return;
77             }
78
79             if (type == DisposeTypes.Explicit)
80             {
81                 //Called by User
82                 //Release your own managed resources here.
83                 //You should release all of your own disposable objects here.
84
85             }
86
87             //Release your own unmanaged resources here.
88             //You should not access any managed member here except static instance.
89             //because the execution order of Finalizes is non-deterministic.
90
91             if (swigCPtr.Handle != global::System.IntPtr.Zero)
92             {
93                 if (swigCMemOwn)
94                 {
95                     swigCMemOwn = false;
96                     NDalicPINVOKE.delete_Matrix(swigCPtr);
97                 }
98                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
99             }
100
101             disposed = true;
102         }
103
104
105         public static Vector4 operator *(Matrix arg1, Vector4 arg2)
106         {
107             return arg1.Multiply(arg2);
108         }
109
110         public Matrix() : this(NDalicPINVOKE.new_Matrix__SWIG_0(), true)
111         {
112             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113         }
114
115         public Matrix(bool initialize) : this(NDalicPINVOKE.new_Matrix__SWIG_1(initialize), true)
116         {
117             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
118         }
119
120         public Matrix(float[] array) : this(NDalicPINVOKE.new_Matrix__SWIG_2(array), true)
121         {
122             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123         }
124
125         public Matrix(Rotation rotation) : this(NDalicPINVOKE.new_Matrix__SWIG_3(Rotation.getCPtr(rotation)), true)
126         {
127             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128         }
129
130         public Matrix(Matrix matrix) : this(NDalicPINVOKE.new_Matrix__SWIG_4(Matrix.getCPtr(matrix)), true)
131         {
132             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133         }
134
135         public Matrix Assign(Matrix matrix)
136         {
137             Matrix ret = new Matrix(NDalicPINVOKE.Matrix_Assign(swigCPtr, Matrix.getCPtr(matrix)), false);
138             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
139             return ret;
140         }
141
142         public static Matrix IDENTITY
143         {
144             get
145             {
146                 global::System.IntPtr cPtr = NDalicPINVOKE.Matrix_IDENTITY_get();
147                 Matrix ret = (cPtr == global::System.IntPtr.Zero) ? null : new Matrix(cPtr, false);
148                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149                 return ret;
150             }
151         }
152
153         public void SetIdentity()
154         {
155             NDalicPINVOKE.Matrix_SetIdentity(swigCPtr);
156             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157         }
158
159         public void SetIdentityAndScale(Vector3 scale)
160         {
161             NDalicPINVOKE.Matrix_SetIdentityAndScale(swigCPtr, Vector3.getCPtr(scale));
162             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163         }
164
165         public void InvertTransform(Matrix result)
166         {
167             NDalicPINVOKE.Matrix_InvertTransform(swigCPtr, Matrix.getCPtr(result));
168             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169         }
170
171         public bool Invert()
172         {
173             bool ret = NDalicPINVOKE.Matrix_Invert(swigCPtr);
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175             return ret;
176         }
177
178         public void Transpose()
179         {
180             NDalicPINVOKE.Matrix_Transpose(swigCPtr);
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182         }
183
184         public Vector3 GetXAxis()
185         {
186             Vector3 ret = new Vector3(NDalicPINVOKE.Matrix_GetXAxis(swigCPtr), true);
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188             return ret;
189         }
190
191         public Vector3 GetYAxis()
192         {
193             Vector3 ret = new Vector3(NDalicPINVOKE.Matrix_GetYAxis(swigCPtr), true);
194             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195             return ret;
196         }
197
198         public Vector3 GetZAxis()
199         {
200             Vector3 ret = new Vector3(NDalicPINVOKE.Matrix_GetZAxis(swigCPtr), true);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202             return ret;
203         }
204
205         public void SetXAxis(Vector3 axis)
206         {
207             NDalicPINVOKE.Matrix_SetXAxis(swigCPtr, Vector3.getCPtr(axis));
208             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209         }
210
211         public void SetYAxis(Vector3 axis)
212         {
213             NDalicPINVOKE.Matrix_SetYAxis(swigCPtr, Vector3.getCPtr(axis));
214             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215         }
216
217         public void SetZAxis(Vector3 axis)
218         {
219             NDalicPINVOKE.Matrix_SetZAxis(swigCPtr, Vector3.getCPtr(axis));
220             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221         }
222
223         public Vector4 GetTranslation()
224         {
225             Vector4 ret = new Vector4(NDalicPINVOKE.Matrix_GetTranslation(swigCPtr), false);
226             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227             return ret;
228         }
229
230         public Vector3 GetTranslation3()
231         {
232             Vector3 ret = new Vector3(NDalicPINVOKE.Matrix_GetTranslation3(swigCPtr), false);
233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234             return ret;
235         }
236
237         public void SetTranslation(Vector4 translation)
238         {
239             NDalicPINVOKE.Matrix_SetTranslation__SWIG_0(swigCPtr, Vector4.getCPtr(translation));
240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241         }
242
243         public void SetTranslation(Vector3 translation)
244         {
245             NDalicPINVOKE.Matrix_SetTranslation__SWIG_1(swigCPtr, Vector3.getCPtr(translation));
246             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247         }
248
249         public void OrthoNormalize()
250         {
251             NDalicPINVOKE.Matrix_OrthoNormalize(swigCPtr);
252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253         }
254
255         public SWIGTYPE_p_float AsFloat()
256         {
257             global::System.IntPtr cPtr = NDalicPINVOKE.Matrix_AsFloat__SWIG_0(swigCPtr);
258             SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260             return ret;
261         }
262
263         public static void Multiply(Matrix result, Matrix lhs, Matrix rhs)
264         {
265             NDalicPINVOKE.Matrix_Multiply__SWIG_0(Matrix.getCPtr(result), Matrix.getCPtr(lhs), Matrix.getCPtr(rhs));
266             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
267         }
268
269         public static void Multiply(Matrix result, Matrix lhs, Rotation rhs)
270         {
271             NDalicPINVOKE.Matrix_Multiply__SWIG_1(Matrix.getCPtr(result), Matrix.getCPtr(lhs), Rotation.getCPtr(rhs));
272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273         }
274
275         public Vector4 Multiply(Vector4 rhs)
276         {
277             Vector4 ret = new Vector4(NDalicPINVOKE.Matrix_Multiply__SWIG_2(swigCPtr, Vector4.getCPtr(rhs)), true);
278             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279             return ret;
280         }
281
282         public bool EqualTo(Matrix rhs)
283         {
284             bool ret = NDalicPINVOKE.Matrix_EqualTo(swigCPtr, Matrix.getCPtr(rhs));
285             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286             return ret;
287         }
288
289         public bool NotEqualTo(Matrix rhs)
290         {
291             bool ret = NDalicPINVOKE.Matrix_NotEqualTo(swigCPtr, Matrix.getCPtr(rhs));
292             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293             return ret;
294         }
295
296         public void SetTransformComponents(Vector3 scale, Rotation rotation, Vector3 translation)
297         {
298             NDalicPINVOKE.Matrix_SetTransformComponents(swigCPtr, Vector3.getCPtr(scale), Rotation.getCPtr(rotation), Vector3.getCPtr(translation));
299             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300         }
301
302         public void SetInverseTransformComponents(Vector3 scale, Rotation rotation, Vector3 translation)
303         {
304             NDalicPINVOKE.Matrix_SetInverseTransformComponents__SWIG_0(swigCPtr, Vector3.getCPtr(scale), Rotation.getCPtr(rotation), Vector3.getCPtr(translation));
305             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306         }
307
308         public void SetInverseTransformComponents(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis, Vector3 translation)
309         {
310             NDalicPINVOKE.Matrix_SetInverseTransformComponents__SWIG_1(swigCPtr, Vector3.getCPtr(xAxis), Vector3.getCPtr(yAxis), Vector3.getCPtr(zAxis), Vector3.getCPtr(translation));
311             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312         }
313
314         public void GetTransformComponents(Vector3 position, Rotation rotation, Vector3 scale)
315         {
316             NDalicPINVOKE.Matrix_GetTransformComponents(swigCPtr, Vector3.getCPtr(position), Rotation.getCPtr(rotation), Vector3.getCPtr(scale));
317             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318         }
319
320     }
321
322 }