using System; using System.Runtime.InteropServices; namespace UnityEngine.XR.ARSubsystems { /// /// Camera intrinsics describe physical characteristics of a camera. /// /// /// These intrinsics are based on a pinhole camera model. A pinhole camera is a simple type of lens-less camera, a /// box with a single pinhole in one side. Rays of light enter the pinhole and land on the opposite wall of the box /// (the image plane), forming an image. Most cameras use larger apertures with lenses to focus the light, but the /// pinhole camera provides a simplified mathematical model. /// [StructLayout(LayoutKind.Sequential)] public struct XRCameraIntrinsics : IEquatable { /// /// The focal length in pixels. /// /// /// The focal length in pixels. /// /// /// The focal length is the distance between the camera's pinhole and the image plane. /// In a pinhole camera, the x and y values would be the same, but these can vary for /// real cameras. /// public Vector2 focalLength => m_FocalLength; Vector2 m_FocalLength; /// /// The principal point from the top-left corner of the image, expressed in pixels. /// /// /// The principal point from the top-left corner of the image, expressed in pixels. /// /// /// The principal point is the point of intersection between the image plane and a line perpendicular to the /// image plane passing through the camera's pinhole. /// public Vector2 principalPoint => m_PrincipalPoint; Vector2 m_PrincipalPoint; /// /// The width and height of the image in pixels. /// /// /// The width and height of the image in pixels. /// public Vector2Int resolution => m_Resolution; Vector2Int m_Resolution; /// /// Constructs a from the given parameters. /// /// The focal length in pixels. /// The principal point from the top-left of the image, in pixels. /// The dimensions of the image. public XRCameraIntrinsics(Vector2 focalLength, Vector2 principalPoint, Vector2Int resolution) { m_FocalLength = focalLength; m_PrincipalPoint = principalPoint; m_Resolution = resolution; } /// /// Tests for equality. /// /// The other to compare against. /// `True` if every field in is equal to this , otherwise false. public bool Equals(XRCameraIntrinsics other) { return (m_FocalLength.Equals(other.m_FocalLength) && m_PrincipalPoint.Equals(other.m_PrincipalPoint) && m_Resolution.Equals(other.m_Resolution)); } /// /// Tests for equality. /// /// The `object` to compare against. /// `True` if is of type and /// also returns `true`; otherwise `false`. public override bool Equals(System.Object obj) { return ((obj is XRCameraIntrinsics) && Equals((XRCameraIntrinsics)obj)); } /// /// Tests for equality. Same as . /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// `True` if is equal to , otherwise `false`. public static bool operator ==(XRCameraIntrinsics lhs, XRCameraIntrinsics rhs) => lhs.Equals(rhs); /// /// Tests for inequality. Same as `!`. /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// `True` if is not equal to , otherwise `false`. public static bool operator !=(XRCameraIntrinsics lhs, XRCameraIntrinsics rhs) => !lhs.Equals(rhs); /// /// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`. /// /// A hash code generated from this object's fields. public override int GetHashCode() { int hashCode = 486187739; unchecked { hashCode = (hashCode * 486187739) + m_FocalLength.GetHashCode(); hashCode = (hashCode * 486187739) + m_PrincipalPoint.GetHashCode(); hashCode = (hashCode * 486187739) + m_Resolution.GetHashCode(); } return hashCode; } /// /// Generates a string representation of this . /// /// A string representation of this . public override string ToString() { return string.Format("focalLength: {0} principalPoint: {1} resolution: {2}", m_FocalLength, m_PrincipalPoint, m_Resolution); } } }