1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 /// A three dimensional vector.
23 public class Vector3 : global::System.IDisposable
25 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26 protected bool swigCMemOwn;
28 internal Vector3(global::System.IntPtr cPtr, bool cMemoryOwn)
30 swigCMemOwn = cMemoryOwn;
31 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Vector3 obj)
36 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39 //A Flag to check who called Dispose(). (By User or DisposeQueue)
40 private bool isDisposeQueued = false;
41 //A Flat to check if it is already disposed.
42 protected bool disposed = false;
48 isDisposeQueued = true;
49 DisposeQueue.Instance.Add(this);
55 //Throw excpetion if Dispose() is called in separate thread.
56 if (!Window.IsInstalled())
58 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
63 Dispose(DisposeTypes.Implicit);
67 Dispose(DisposeTypes.Explicit);
68 System.GC.SuppressFinalize(this);
72 protected virtual void Dispose(DisposeTypes type)
79 if(type == DisposeTypes.Explicit)
82 //Release your own managed resources here.
83 //You should release all of your own disposable objects here.
86 //Release your own unmanaged resources here.
87 //You should not access any managed member here except static instance.
88 //because the execution order of Finalizes is non-deterministic.
90 if (swigCPtr.Handle != global::System.IntPtr.Zero)
95 NDalicPINVOKE.delete_Vector3(swigCPtr);
97 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
103 /// Addition operator.
105 /// <param name="arg1">First Value</param>
106 /// <param name="arg2">Second Value</param>
107 /// <returns>A vector containing the result of the addition</returns>
108 public static Vector3 operator +(Vector3 arg1, Vector3 arg2)
110 return arg1.Add(arg2);
114 /// Subtraction operator.
116 /// <param name="arg1">First Value</param>
117 /// <param name="arg2">Second Value</param>
118 /// <returns>A vector containing the result of the subtraction</returns>
119 public static Vector3 operator -(Vector3 arg1, Vector3 arg2)
121 return arg1.Subtract(arg2);
125 /// Unary negation operator.
127 /// <param name="arg1">Target Value</param>
128 /// <returns>A vector containg the negation</returns>
129 public static Vector3 operator -(Vector3 arg1)
131 return arg1.Subtract();
135 /// Multiplication operator.
137 /// <param name="arg1">First Value</param>
138 /// <param name="arg2">Second Value</param>
139 /// <returns>A vector containing the result of the multiplication</returns>
140 public static Vector3 operator *(Vector3 arg1, Vector3 arg2)
142 return arg1.Multiply(arg2);
146 /// Multiplication operator.
148 /// <param name="arg1">First Value</param>
149 /// <param name="arg2">The float value to scale the vector</param>
150 /// <returns>A vector containing the result of the scaling</returns>
151 public static Vector3 operator *(Vector3 arg1, float arg2)
153 return arg1.Multiply(arg2);
157 /// Division operator.
159 /// <param name="arg1">First Value</param>
160 /// <param name="arg2">Second Value</param>
161 /// <returns>A vector containing the result of the division</returns>
162 public static Vector3 operator /(Vector3 arg1, Vector3 arg2)
164 return arg1.Divide(arg2);
168 /// Division operator.
170 /// <param name="arg1">First Value</param>
171 /// <param name="arg2">The float value to scale the vector by</param>
172 /// <returns>A vector containing the result of the scaling</returns>
173 public static Vector3 operator /(Vector3 arg1, float arg2)
175 return arg1.Divide(arg2);
179 /// Array subscript operator overload.
181 /// <param name="index">Subscript index</param>
182 /// <returns>The float at the given index</returns>
183 public float this[uint index]
187 return ValueOfIndex(index);
191 internal static Vector3 GetVector3FromPtr(global::System.IntPtr cPtr)
193 Vector3 ret = new Vector3(cPtr, false);
194 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201 public Vector3() : this(NDalicPINVOKE.new_Vector3__SWIG_0(), true)
203 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 /// Default constructor, initializes the vector to 0.
209 /// <param name="x">x (or width) component</param>
210 /// <param name="y">y (or height) component</param>
211 /// <param name="z">z (or depth) component</param>
212 public Vector3(float x, float y, float z) : this(NDalicPINVOKE.new_Vector3__SWIG_1(x, y, z), true)
214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218 /// Conversion constructor from an array of three floats.
220 /// <param name="array">Array of xyz</param>
221 public Vector3(float[] array) : this(NDalicPINVOKE.new_Vector3__SWIG_2(array), true)
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 /// <param name="vec2">Vector2 to create this vector from</param>
230 public Vector3(Vector2 vec2) : this(NDalicPINVOKE.new_Vector3__SWIG_3(Vector2.getCPtr(vec2)), true)
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// <param name="vec4">Vector4 to create this vector from</param>
239 public Vector3(Vector4 vec4) : this(NDalicPINVOKE.new_Vector3__SWIG_4(Vector4.getCPtr(vec4)), true)
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 public static Vector3 One
251 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_ONE_get();
252 Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false);
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 /// Vector representing the X axis
261 public static Vector3 XAxis
265 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_XAXIS_get();
266 Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false);
267 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 /// Vector representing the Y axis
275 public static Vector3 YAxis
279 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_YAXIS_get();
280 Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287 /// Vector representing the Z axis
289 public static Vector3 ZAxis
293 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_ZAXIS_get();
294 Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false);
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 /// Vector representing the negative X axis
303 public static Vector3 NegativeXAxis
307 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_NEGATIVE_XAXIS_get();
308 Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false);
309 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315 /// Vector representing the negative Y axis
317 public static Vector3 NegativeYAxis
321 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_NEGATIVE_YAXIS_get();
322 Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false);
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329 /// Vector representing the negative Z axis
331 public static Vector3 NegativeZAxis
335 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_NEGATIVE_ZAXIS_get();
336 Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 /// (0.0f, 0.0f, 0.0f)
345 public static Vector3 Zero
349 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_ZERO_get();
350 Vector3 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector3(cPtr, false);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356 private Vector3 Add(Vector3 rhs)
358 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_Add(swigCPtr, Vector3.getCPtr(rhs)), true);
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
363 private Vector3 AddAssign(Vector3 rhs)
365 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_AddAssign(swigCPtr, Vector3.getCPtr(rhs)), false);
366 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 private Vector3 Subtract(Vector3 rhs)
372 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_Subtract__SWIG_0(swigCPtr, Vector3.getCPtr(rhs)), true);
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 private Vector3 SubtractAssign(Vector3 rhs)
379 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_SubtractAssign(swigCPtr, Vector3.getCPtr(rhs)), false);
380 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 private Vector3 Multiply(Vector3 rhs)
386 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_Multiply__SWIG_0(swigCPtr, Vector3.getCPtr(rhs)), true);
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 private Vector3 Multiply(float rhs)
393 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_Multiply__SWIG_1(swigCPtr, rhs), true);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398 private Vector3 MultiplyAssign(Vector3 rhs)
400 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_MultiplyAssign__SWIG_0(swigCPtr, Vector3.getCPtr(rhs)), false);
401 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405 private Vector3 MultiplyAssign(float rhs)
407 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_MultiplyAssign__SWIG_1(swigCPtr, rhs), false);
408 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
412 private Vector3 MultiplyAssign(Rotation rhs)
414 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_MultiplyAssign__SWIG_2(swigCPtr, Rotation.getCPtr(rhs)), false);
415 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
419 private Vector3 Divide(Vector3 rhs)
421 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_Divide__SWIG_0(swigCPtr, Vector3.getCPtr(rhs)), true);
422 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
426 private Vector3 Divide(float rhs)
428 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_Divide__SWIG_1(swigCPtr, rhs), true);
429 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
433 private Vector3 DivideAssign(Vector3 rhs)
435 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_DivideAssign__SWIG_0(swigCPtr, Vector3.getCPtr(rhs)), false);
436 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
440 private Vector3 DivideAssign(float rhs)
442 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_DivideAssign__SWIG_1(swigCPtr, rhs), false);
443 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
447 private Vector3 Subtract()
449 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_Subtract__SWIG_1(swigCPtr), true);
450 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
454 private bool EqualTo(Vector3 rhs)
456 bool ret = NDalicPINVOKE.Vector3_EqualTo(swigCPtr, Vector3.getCPtr(rhs));
457 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461 private bool NotEqualTo(Vector3 rhs)
463 bool ret = NDalicPINVOKE.Vector3_NotEqualTo(swigCPtr, Vector3.getCPtr(rhs));
464 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 private float ValueOfIndex(uint index)
470 float ret = NDalicPINVOKE.Vector3_ValueOfIndex__SWIG_0(swigCPtr, index);
471 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
475 internal float Dot(Vector3 other)
477 float ret = NDalicPINVOKE.Vector3_Dot(swigCPtr, Vector3.getCPtr(other));
478 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
482 internal Vector3 Cross(Vector3 other)
484 Vector3 ret = new Vector3(NDalicPINVOKE.Vector3_Cross(swigCPtr, Vector3.getCPtr(other)), true);
485 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490 /// Returns the length of the vector.
492 /// <returns>The length of the vector</returns>
493 public float Length()
495 float ret = NDalicPINVOKE.Vector3_Length(swigCPtr);
496 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
501 /// Returns the length of the vector squared.<br>
502 /// This is more efficient than Length() for threshold
503 /// testing as it avoids the use of a square root.<br>
505 /// <returns>The length of the vector squared</returns>
506 public float LengthSquared()
508 float ret = NDalicPINVOKE.Vector3_LengthSquared(swigCPtr);
509 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
514 /// Sets the vector to be unit length, whilst maintaining its direction.
516 public void Normalize()
518 NDalicPINVOKE.Vector3_Normalize(swigCPtr);
519 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
523 /// Clamps the vector between minimum and maximum vectors.
525 /// <param name="min">The minimum vector</param>
526 /// <param name="max">The maximum vector</param>
527 public void Clamp(Vector3 min, Vector3 max)
529 NDalicPINVOKE.Vector3_Clamp(swigCPtr, Vector3.getCPtr(min), Vector3.getCPtr(max));
530 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
533 internal SWIGTYPE_p_float AsFloat()
535 global::System.IntPtr cPtr = NDalicPINVOKE.Vector3_AsFloat__SWIG_0(swigCPtr);
536 SWIGTYPE_p_float ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_float(cPtr, false);
537 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
542 /// Returns the x & y components (or width & height, or r & g) as a Vector2.
544 /// <returns>The partial vector contents as Vector2 (x,y)</returns>
545 public Vector2 GetVectorXY()
547 Vector2 ret = new Vector2(NDalicPINVOKE.Vector3_GetVectorXY__SWIG_0(swigCPtr), false);
548 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
553 /// Returns the y & z components (or height & depth, or g & b) as a Vector2.
555 /// <returns>The partial vector contents as Vector2 (y,z)</returns>
556 public Vector2 GetVectorYZ()
558 Vector2 ret = new Vector2(NDalicPINVOKE.Vector3_GetVectorYZ__SWIG_0(swigCPtr), false);
559 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
570 NDalicPINVOKE.Vector3_X_set(swigCPtr, value);
571 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
575 float ret = NDalicPINVOKE.Vector3_X_get(swigCPtr);
576 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
588 NDalicPINVOKE.Vector3_Width_set(swigCPtr, value);
589 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
593 float ret = NDalicPINVOKE.Vector3_Width_get(swigCPtr);
594 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
606 NDalicPINVOKE.Vector3_r_set(swigCPtr, value);
607 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
611 float ret = NDalicPINVOKE.Vector3_r_get(swigCPtr);
612 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
624 NDalicPINVOKE.Vector3_Y_set(swigCPtr, value);
625 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
629 float ret = NDalicPINVOKE.Vector3_Y_get(swigCPtr);
630 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
642 NDalicPINVOKE.Vector3_Height_set(swigCPtr, value);
643 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
647 float ret = NDalicPINVOKE.Vector3_Height_get(swigCPtr);
648 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
660 NDalicPINVOKE.Vector3_g_set(swigCPtr, value);
661 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
665 float ret = NDalicPINVOKE.Vector3_g_get(swigCPtr);
666 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
678 NDalicPINVOKE.Vector3_Z_set(swigCPtr, value);
679 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
683 float ret = NDalicPINVOKE.Vector3_Z_get(swigCPtr);
684 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
696 NDalicPINVOKE.Vector3_Depth_set(swigCPtr, value);
697 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
701 float ret = NDalicPINVOKE.Vector3_Depth_get(swigCPtr);
702 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
714 NDalicPINVOKE.Vector3_b_set(swigCPtr, value);
715 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
719 float ret = NDalicPINVOKE.Vector3_b_get(swigCPtr);
720 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();