// // Distributed under the BSD Licence (see LICENCE file). // // Copyright (c) 2014, Nition, http://www.momentstudio.co.nz/ // Copyright (c) 2017, Máté Cserép, http://codenet.hu // All rights reserved. // namespace TerraBrush.NetOctree { using System; using System.Runtime.Serialization; using Godot; /// /// Representation of rays. /// /// /// A ray is an infinite line starting at and going in some . /// /// This class was inspired by the Ray type of the Unity Engine and /// designed with the exact same interface to provide maximum compatibility. /// [DataContract] public struct Ray { /// /// Gets or sets the origin of the ray. /// [DataMember] public Vector3 Origin { get; set; } /// /// The direction of the ray. /// [DataMember] private Vector3 _direction; /// /// Gets or sets the direction of the ray. /// public Vector3 Direction { get { return _direction; } set { _direction = value.Normalized(); } } /// /// Creates a ray starting at origin along direction. /// /// The origin of the ray. /// The direction of the ray. public Ray(Vector3 origin, Vector3 direction) { Origin = origin; _direction = direction.Normalized(); } /// /// Returns a point at the given distance along the ray. /// /// The distance. /// The point on the ray. public Vector3 GetPoint(float distance) { return Origin + Direction * distance; } /// /// Returns a nicely formatted string for this ray. /// public override string ToString() { return String.Format("Origin: {0}, Dir: {1}", Origin, Direction ); } /// /// Returns a nicely formatted string for this ray. /// /// The format for the origin and direction. public string ToString(string format) { return String.Format("Origin: {0}, Dir: {1}", Origin.ToString(format), Direction.ToString(format) ); } } }