2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
21 namespace Tizen.NUI.Scene3D
24 /// Camera class controls a camera in 3D space.
26 /// Camera can be added on the SceneView and displays SceneView's virtual 3D world to the screen.
27 /// Camera can be translated and rotated in the space.
30 /// Transform inheritance cannot be guaranteed when adding children to a camera.
32 /// <since_tizen> 10 </since_tizen>
33 public partial class Camera : View
35 internal Camera(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
40 /// Creates an uninitialized Camera.
42 /// <since_tizen> 10 </since_tizen>
43 public Camera() : this(Interop.Camera.New(), true)
45 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51 /// <param name="camera">The Camera object to be copied.</param>
52 /// <since_tizen> 10 </since_tizen>
53 public Camera(Camera camera) : this(Interop.Camera.NewCamera(Camera.getCPtr(camera)), true)
55 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
61 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
62 [EditorBrowsable(EditorBrowsableState.Never)]
63 public Camera Assign(Camera rhs)
65 Camera ret = new Camera(Interop.Camera.Assign(SwigCPtr, Camera.getCPtr(rhs)), false);
66 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71 /// Creates a CameraActor object.
72 /// Sets the default camera perspective projection for the given canvas size..
74 internal Camera(Vector2 size) : this(Interop.Camera.New(Vector2.getCPtr(size)), true)
76 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
79 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 internal static Camera DownCast(BaseHandle handle)
85 throw new global::System.ArgumentNullException(nameof(handle));
87 Camera ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Camera;
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93 /// Enumeration for the projectionMode.
94 /// ProjectionMode defines how the camera shows 3D objects or scene on a 2D plane with projection.
96 /// <since_tizen> 10 </since_tizen>
97 public enum ProjectionModeType
100 /// Distance causes foreshortening; objects further from the camera appear smaller.
104 /// Relative distance from the camera does not affect the size of objects.
110 /// Enumeration for the projectionDirection.
112 /// This will be released at Tizen.NET API Level 10, so currently this would be used as inhouse API.
113 [EditorBrowsable(EditorBrowsableState.Never)]
114 public enum ProjectionDirectionType
117 /// Distance causes foreshortening; objects further from the camera appear smaller.
121 /// Relative distance from the camera does not affect the size of objects.
127 /// Sets/Gets the projection mode.
128 /// The default is Perspective
130 /// <since_tizen> 10 </since_tizen>
131 public ProjectionModeType ProjectionMode
135 return (ProjectionModeType)GetValue(ProjectionProperty);
139 SetValue(ProjectionProperty, value);
140 NotifyPropertyChanged();
146 /// Sets/Gets the projection direction.
147 /// Projection direction determine basic direction of projection relative properties.
148 /// It will be used when we need to calculate some values relative with aspect ratio.
149 /// <see cref="FieldOfView"/>, and <see cref="OrthographicSize"/>
152 /// For example, if aspect ratio is 4:3 and set fieldOfView as 60 degree.
153 /// If ProjectionDirectionType.Vertical, basic direction is vertical. so, FoV of horizontal direction become ~75.2 degree
154 /// If ProjectionDirectionType.Horizontal, basic direction is horizontal. so, FoV of vertical direction become ~46.8 degree
157 /// This property doesn't change <see cref="FieldOfView"/> and <see cref="OrthographicSize"/> value automatically.
158 /// So result scene might be changed.
160 /// <para>The default is Vertical.</para>
162 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
163 [EditorBrowsable(EditorBrowsableState.Never)]
164 public ProjectionDirectionType ProjectionDirection
168 return (ProjectionDirectionType)GetValue(ProjectionDirectionProperty);
172 SetValue(ProjectionDirectionProperty, value);
173 NotifyPropertyChanged();
178 /// Sets/Gets the field of view in Radians.
179 /// FieldOfView depends on <see cref="ProjectionDirection"/> value.
180 /// The default field of view is 45 degrees.
182 /// <since_tizen> 10 </since_tizen>
183 public Radian FieldOfView
187 return new Radian((float)GetValue(FieldOfViewProperty));
191 SetValue(FieldOfViewProperty, value?.ConvertToFloat() ?? 0.0f);
192 NotifyPropertyChanged();
197 /// Sets/Gets Orthographic Size of this camera.
198 /// OrthographicSize depends on <see cref="ProjectionDirection"/> value.
199 /// If ProjectoinDirection is Vertical, OrthographicSize is height/2 of viewing cube of Orthographic projection.
200 /// If ProjectoinDirection is Horizontal, OrthographicSize is width/2 of viewing cube of Orthographic projection.
201 /// Remained Width or Height of viewing cube is internally computed by using aspect ratio of Viewport.
203 /// <since_tizen> 10 </since_tizen>
204 public float OrthographicSize
208 return InternalOrthographicSize;
212 SetValue(OrthographicSizeProperty, value);
213 NotifyPropertyChanged();
218 /// Gets the aspect ratio of the camera.
220 /// <since_tizen> 10 </since_tizen>
221 public float AspectRatio
225 return (float)GetValue(AspectRatioProperty);
230 /// Sets/Gets the near clipping plane distance.
232 /// <since_tizen> 10 </since_tizen>
233 public float NearPlaneDistance
237 return (float)GetValue(NearPlaneDistanceProperty);
241 SetValue(NearPlaneDistanceProperty, value);
242 NotifyPropertyChanged();
247 /// Sets/Gets the far clipping plane distance.
249 /// <since_tizen> 10 </since_tizen>
250 public float FarPlaneDistance
254 return (float)GetValue(FarPlaneDistanceProperty);
258 SetValue(FarPlaneDistanceProperty, value);
259 NotifyPropertyChanged();
264 /// Gets the left clipping plane distance.
266 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
267 [EditorBrowsable(EditorBrowsableState.Never)]
268 public float LeftPlaneDistance
272 return (float)GetValue(LeftPlaneDistanceProperty);
277 /// Gets the right clipping plane distance.
279 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
280 [EditorBrowsable(EditorBrowsableState.Never)]
281 public float RightPlaneDistance
285 return (float)GetValue(RightPlaneDistanceProperty);
290 /// Gets the top clipping plane distance.
292 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
293 [EditorBrowsable(EditorBrowsableState.Never)]
294 public float TopPlaneDistance
298 return (float)GetValue(TopPlaneDistanceProperty);
303 /// Gets the bottom clipping plane distance.
305 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
306 [EditorBrowsable(EditorBrowsableState.Never)]
307 public float BottomPlaneDistance
311 return (float)GetValue(BottomPlaneDistanceProperty);
316 /// Requests for an inversion on the Y axis on the projection calculation.
317 /// or gets whether the Y axis is inverted.
319 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
320 [EditorBrowsable(EditorBrowsableState.Never)]
321 public bool InvertYAxis
325 return (bool)GetValue(InvertYAxisProperty);
329 SetValue(InvertYAxisProperty, value);
330 NotifyPropertyChanged();
335 /// Gets ProjectionMatrix of this Camera
336 /// TODO : Open Matrix
338 internal Matrix ProjectionMatrix
342 Matrix returnValue = new Matrix();
343 PropertyValue projectionMatrix = GetProperty(Interop.Camera.ProjectionMatrixGet());
344 projectionMatrix?.Get(returnValue);
345 projectionMatrix?.Dispose();
351 /// Gets ViewMatrix of this Camera
352 /// TODO : Open Matrix
354 internal Matrix ViewMatrix
358 Matrix returnValue = new Matrix();
359 PropertyValue viewMatrix = GetProperty(Interop.Camera.ViewMatrixGet());
360 viewMatrix.Get(returnValue);
361 viewMatrix.Dispose();
366 private ProjectionModeType InternalProjectionMode
370 int returnValue = (int)ProjectionModeType.Perspective;
371 PropertyValue projectionMode = GetProperty(Interop.Camera.ProjectionModeGet());
372 projectionMode?.Get(out returnValue);
373 projectionMode?.Dispose();
374 return (ProjectionModeType)returnValue;
378 PropertyValue setValue = new Tizen.NUI.PropertyValue((int)value);
379 SetProperty(Interop.Camera.ProjectionModeGet(), setValue);
384 private ProjectionDirectionType InternalProjectionDirection
388 int returnValue = (int)ProjectionDirectionType.Vertical;
389 PropertyValue projectionDirection = GetProperty(Interop.Camera.ProjectionDirectionGet());
390 projectionDirection?.Get(out returnValue);
391 projectionDirection?.Dispose();
392 return (ProjectionDirectionType)returnValue;
396 PropertyValue setValue = new Tizen.NUI.PropertyValue((int)value);
397 SetProperty(Interop.Camera.ProjectionDirectionGet(), setValue);
402 private float InternalFieldOfView
406 float returnValue = 0.0f;
407 PropertyValue fieldView = GetProperty(Interop.Camera.FieldOfViewGet());
408 fieldView?.Get(out returnValue);
409 fieldView?.Dispose();
414 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
415 SetProperty(Interop.Camera.FieldOfViewGet(), setValue);
420 private float InternalOrthographicSize
424 float returnValue = 0.0f;
425 PropertyValue orthographicSize = GetProperty(Interop.Camera.OrthographicSizeGet());
426 orthographicSize?.Get(out returnValue);
427 orthographicSize?.Dispose();
432 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
433 SetProperty(Interop.Camera.OrthographicSizeGet(), setValue);
438 private float InternalAspectRatio
442 float returnValue = 0.0f;
443 PropertyValue aspectRatio = GetProperty(Interop.Camera.AspectRatioGet());
444 aspectRatio?.Get(out returnValue);
445 aspectRatio?.Dispose();
450 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
451 SetProperty(Interop.Camera.AspectRatioGet(), setValue);
456 private float InternalNearPlaneDistance
460 float returnValue = 0.0f;
461 PropertyValue nearPlaneDistance = GetProperty(Interop.Camera.NearPlaneDistanceGet());
462 nearPlaneDistance?.Get(out returnValue);
463 nearPlaneDistance?.Dispose();
468 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
469 SetProperty(Interop.Camera.NearPlaneDistanceGet(), setValue);
474 private float InternalFarPlaneDistance
478 float returnValue = 0.0f;
479 PropertyValue farPlaneDistance = GetProperty(Interop.Camera.FarPlaneDistanceGet());
480 farPlaneDistance?.Get(out returnValue);
481 farPlaneDistance?.Dispose();
486 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
487 SetProperty(Interop.Camera.FarPlaneDistanceGet(), setValue);
492 private float InternalLeftPlaneDistance
496 float returnValue = 0.0f;
497 PropertyValue leftPlaneDistance = GetProperty(Interop.Camera.LeftPlaneDistanceGet());
498 leftPlaneDistance?.Get(out returnValue);
499 leftPlaneDistance?.Dispose();
504 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
505 SetProperty(Interop.Camera.LeftPlaneDistanceGet(), setValue);
510 private float InternalRightPlaneDistance
514 float returnValue = 0.0f;
515 PropertyValue rightPlaneDistance = GetProperty(Interop.Camera.RightPlaneDistanceGet());
516 rightPlaneDistance?.Get(out returnValue);
517 rightPlaneDistance?.Dispose();
522 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
523 SetProperty(Interop.Camera.RightPlaneDistanceGet(), setValue);
528 private float InternalTopPlaneDistance
532 float returnValue = 0.0f;
533 PropertyValue topPlaneDistance = GetProperty(Interop.Camera.TopPlaneDistanceGet());
534 topPlaneDistance?.Get(out returnValue);
535 topPlaneDistance?.Dispose();
540 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
541 SetProperty(Interop.Camera.TopPlaneDistanceGet(), setValue);
546 private float InternalBottomPlaneDistance
550 float returnValue = 0.0f;
551 PropertyValue bottomPlaneDistance = GetProperty(Interop.Camera.BottomPlaneDistanceGet());
552 bottomPlaneDistance?.Get(out returnValue);
553 bottomPlaneDistance?.Dispose();
558 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
559 SetProperty(Interop.Camera.BottomPlaneDistanceGet(), setValue);
564 private bool InternalInvertYAxis
568 bool returnValue = false;
569 PropertyValue invertYAxis = GetProperty(Interop.Camera.InvertYAxisGet());
570 invertYAxis?.Get(out returnValue);
571 invertYAxis?.Dispose();
576 PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
577 SetProperty(Interop.Camera.InvertYAxisGet(), setValue);
582 internal void SetProjection(ProjectionModeType mode)
584 Interop.Camera.SetProjectionMode(SwigCPtr, (int)mode);
585 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
588 internal ProjectionModeType GetProjection()
590 ProjectionModeType ret = (ProjectionModeType)Interop.Camera.GetProjectionMode(SwigCPtr);
591 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
595 internal void SetFieldOfView(float fieldOfView)
597 Interop.Camera.SetFieldOfView(SwigCPtr, fieldOfView);
598 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
601 internal float GetFieldOfView()
603 float ret = Interop.Camera.GetFieldOfView(SwigCPtr);
604 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
608 internal void SetAspectRatio(float aspectRatio)
610 Interop.Camera.SetAspectRatio(SwigCPtr, aspectRatio);
611 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
614 internal float GetAspectRatio()
616 float ret = Interop.Camera.GetAspectRatio(SwigCPtr);
617 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
621 internal void SetNearClippingPlane(float nearClippingPlane)
623 Interop.Camera.SetNearClippingPlane(SwigCPtr, nearClippingPlane);
624 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
627 internal float GetNearClippingPlane()
629 float ret = Interop.Camera.GetNearClippingPlane(SwigCPtr);
630 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
634 internal void SetFarClippingPlane(float farClippingPlane)
636 Interop.Camera.SetFarClippingPlane(SwigCPtr, farClippingPlane);
637 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
640 internal float GetFarClippingPlane()
642 float ret = Interop.Camera.GetFarClippingPlane(SwigCPtr);
643 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
647 internal void SetInvertYAxis(bool invertYAxis)
649 Interop.Camera.SetInvertYAxis(SwigCPtr, invertYAxis);
650 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
653 internal bool GetInvertYAxis()
655 bool ret = Interop.Camera.GetInvertYAxis(SwigCPtr);
656 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
661 /// Convert from vertical fov to horizontal fov consider with camera's AspectRatio.
663 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
664 [EditorBrowsable(EditorBrowsableState.Never)]
665 public static Radian ConvertFovFromVerticalToHorizontal(float aspect, Radian verticalFov)
667 if(verticalFov == null)
671 return new Radian(2.0f * (float)Math.Atan(Math.Tan(verticalFov.ConvertToFloat() * 0.5f) * aspect));
675 /// Convert from horizontal fov to vertical fov consider with camera's AspectRatio.
677 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
678 [EditorBrowsable(EditorBrowsableState.Never)]
679 public static Radian ConvertFovFromHorizontalToVertical(float aspect, Radian horizontalFov)
681 if(horizontalFov == null)
685 return new Radian(2.0f * (float)Math.Atan(Math.Tan(horizontalFov.ConvertToFloat() * 0.5f) / aspect));
689 /// Release swigCPtr.
691 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
692 [EditorBrowsable(EditorBrowsableState.Never)]
693 protected override void ReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
695 Interop.Camera.DeleteCamera(swigCPtr);