[NUI] Move Matrix API as public (hidden)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Common / Matrix.cs
1 /*
2  * Copyright(c) 2021 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 using System;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {    /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
23     [EditorBrowsable(EditorBrowsableState.Never)]
24     public class Matrix : Disposable
25     {
26         internal Matrix(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
27         {
28         }
29
30         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
31         {
32             Interop.Matrix.DeleteMatrix(swigCPtr);
33         }
34
35         public Matrix() : this(Interop.Matrix.NewMatrix(), true)
36         {
37             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38         }
39
40         public Matrix(bool initialize) : this(Interop.Matrix.NewMatrix(initialize), true)
41         {
42             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43         }
44
45         public Matrix(float[] array) : this(Interop.Matrix.NewMatrix(array), true)
46         {
47             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
48         }
49
50         public Matrix(Rotation rotation) : this(Interop.Matrix.NewMatrixQuaternion(Rotation.getCPtr(rotation)), true)
51         {
52             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53         }
54
55         public Matrix(Matrix matrix) : this(Interop.Matrix.NewMatrix(Matrix.getCPtr(matrix)), true)
56         {
57             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
58         }
59
60         public Matrix Assign(Matrix matrix)
61         {
62             Matrix ret = new Matrix(Interop.Matrix.Assign(SwigCPtr, Matrix.getCPtr(matrix)), false);
63             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
64             return ret;
65         }
66
67         public static Matrix IDENTITY
68         {
69             get
70             {
71                 global::System.IntPtr cPtr = Interop.Matrix.IdentityGet();
72                 Matrix ret = (cPtr == global::System.IntPtr.Zero) ? null : new Matrix(cPtr, false);
73                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74                 return ret;
75             }
76         }
77
78         public float this[uint index]
79         {
80             set
81             {
82                 SetValueAtIndex(index, value);
83             }
84             get
85             {
86                 return ValueOfIndex(index);
87             }
88         }
89
90         public static Vector4 operator *(Matrix arg1, Vector4 arg2)
91         {
92             return arg1?.Multiply(arg2);
93         }
94
95         public static Matrix operator *(Matrix arg1, Rotation arg2)
96         {
97             Matrix ret = new Matrix(false);
98             Matrix.Multiply(ret, arg1, arg2);
99             return ret;
100         }
101
102         public static Matrix operator *(Matrix arg1, Matrix arg2)
103         {
104             return arg1?.Multiply(arg2);
105         }
106
107         public void SetIdentity()
108         {
109             Interop.Matrix.SetIdentity(SwigCPtr);
110             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111         }
112
113         public void SetIdentityAndScale(Vector3 scale)
114         {
115             Interop.Matrix.SetIdentityAndScale(SwigCPtr, Vector3.getCPtr(scale));
116             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117         }
118
119         public void InvertTransform(Matrix result)
120         {
121             Interop.Matrix.InvertTransform(SwigCPtr, Matrix.getCPtr(result));
122             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123         }
124
125         public bool Invert()
126         {
127             bool ret = Interop.Matrix.Invert(SwigCPtr);
128             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
129             return ret;
130         }
131
132         public void Transpose()
133         {
134             Interop.Matrix.Transpose(SwigCPtr);
135             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136         }
137
138         public Vector3 GetXAxis()
139         {
140             Vector3 ret = new Vector3(Interop.Matrix.GetXAxis(SwigCPtr), true);
141             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142             return ret;
143         }
144
145         public Vector3 GetYAxis()
146         {
147             Vector3 ret = new Vector3(Interop.Matrix.GetYAxis(SwigCPtr), true);
148             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149             return ret;
150         }
151
152         public Vector3 GetZAxis()
153         {
154             Vector3 ret = new Vector3(Interop.Matrix.GetZAxis(SwigCPtr), true);
155             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156             return ret;
157         }
158
159         public void SetXAxis(Vector3 axis)
160         {
161             Interop.Matrix.SetXAxis(SwigCPtr, Vector3.getCPtr(axis));
162             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163         }
164
165         public void SetYAxis(Vector3 axis)
166         {
167             Interop.Matrix.SetYAxis(SwigCPtr, Vector3.getCPtr(axis));
168             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169         }
170
171         public void SetZAxis(Vector3 axis)
172         {
173             Interop.Matrix.SetZAxis(SwigCPtr, Vector3.getCPtr(axis));
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175         }
176
177         public Vector4 GetTranslation()
178         {
179             Vector4 ret = new Vector4(Interop.Matrix.GetTranslation(SwigCPtr), false);
180             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181             return ret;
182         }
183
184         public Vector3 GetTranslation3()
185         {
186             Vector3 ret = new Vector3(Interop.Matrix.GetTranslation3(SwigCPtr), false);
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188             return ret;
189         }
190
191         public void SetTranslation(Vector4 translation)
192         {
193             Interop.Matrix.SetTranslationVector4(SwigCPtr, Vector4.getCPtr(translation));
194             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195         }
196
197         public void SetTranslation(Vector3 translation)
198         {
199             Interop.Matrix.SetTranslationVector3(SwigCPtr, Vector3.getCPtr(translation));
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201         }
202
203         public void OrthoNormalize()
204         {
205             Interop.Matrix.OrthoNormalize(SwigCPtr);
206             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207         }
208
209         public static void Multiply(Matrix result, Matrix lhs, Matrix rhs)
210         {
211             Interop.Matrix.Multiply(Matrix.getCPtr(result), Matrix.getCPtr(lhs), Matrix.getCPtr(rhs));
212             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213         }
214
215         public static void Multiply(Matrix result, Matrix lhs, Rotation rhs)
216         {
217             Interop.Matrix.MultiplyQuaternion(Matrix.getCPtr(result), Matrix.getCPtr(lhs), Rotation.getCPtr(rhs));
218             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219         }
220
221         public Vector4 Multiply(Vector4 rhs)
222         {
223             Vector4 ret = new Vector4(Interop.Matrix.MultiplyVector4(SwigCPtr, Vector4.getCPtr(rhs)), true);
224             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225             return ret;
226         }
227
228         public Matrix Multiply(Matrix rhs)
229         {
230             Matrix ret = new Matrix(Interop.Matrix.Multiply(SwigCPtr, Matrix.getCPtr(rhs)), true);
231             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232             return ret;
233         }
234
235         public void MultiplyAssign(Matrix rhs)
236         {
237             Interop.Matrix.MultiplyAssign(SwigCPtr, Matrix.getCPtr(rhs));
238             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239         }
240
241         public override int GetHashCode()
242         {
243             return SwigCPtr.Handle.GetHashCode();
244         }
245
246         public bool EqualTo(Matrix rhs)
247         {
248             bool ret = Interop.Matrix.EqualTo(SwigCPtr, Matrix.getCPtr(rhs));
249             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250             return ret;
251         }
252
253         public bool NotEqualTo(Matrix rhs)
254         {
255             bool ret = Interop.Matrix.NotEqualTo(SwigCPtr, Matrix.getCPtr(rhs));
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257             return ret;
258         }
259
260         public void SetTransformComponents(Vector3 scale, Rotation rotation, Vector3 translation)
261         {
262             Interop.Matrix.SetTransformComponents(SwigCPtr, Vector3.getCPtr(scale), Rotation.getCPtr(rotation), Vector3.getCPtr(translation));
263             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264         }
265
266         public void SetInverseTransformComponents(Vector3 scale, Rotation rotation, Vector3 translation)
267         {
268             Interop.Matrix.SetInverseTransformComponents(SwigCPtr, Vector3.getCPtr(scale), Rotation.getCPtr(rotation), Vector3.getCPtr(translation));
269             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270         }
271
272         public void SetInverseTransformComponents(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis, Vector3 translation)
273         {
274             Interop.Matrix.SetInverseTransformComponents(SwigCPtr, Vector3.getCPtr(xAxis), Vector3.getCPtr(yAxis), Vector3.getCPtr(zAxis), Vector3.getCPtr(translation));
275             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276         }
277
278         public void GetTransformComponents(Vector3 position, Rotation rotation, Vector3 scale)
279         {
280             Interop.Matrix.GetTransformComponents(SwigCPtr, Vector3.getCPtr(position), Rotation.getCPtr(rotation), Vector3.getCPtr(scale));
281             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282         }
283
284         public float ValueOfIndex(uint index)
285         {
286             float ret = Interop.Matrix.ValueOfIndex(SwigCPtr, index);
287             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288             return ret;
289         }
290
291         public float ValueOfIndex(uint indexRow, uint indexColumn)
292         {
293             float ret = Interop.Matrix.ValueOfIndex(SwigCPtr, indexRow, indexColumn);
294             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295             return ret;
296         }
297
298         public void SetValueAtIndex(uint index, float val)
299         {
300             Interop.Matrix.SetValueAtIndex(SwigCPtr, index, val);
301             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302         }
303
304         public void SetValueAtIndex(uint indexRow, uint indexColumn, float val)
305         {
306             Interop.Matrix.SetValueAtIndex(SwigCPtr, indexRow, indexColumn, val);
307             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308         }
309     }
310 }