namespace X10D.Unity { using UnityEngine; /// /// A set of extension methods for . /// public static class Vector3Extensions { /// /// Converts a vector normal to an Euler rotation. /// /// The vector normal. /// Returns a representing the Euler rotation. public static Vector3 NormalToEulerAngles(this Vector3 v) { float x = v.x; v.x = v.z; v.z = x; v.z *= 2.0f * v.y; v.y = 0.0f; return v * 90.0f; } /// /// Rounds a vector to the nearest value. /// /// The vector to round. /// The nearest value. /// Returns a containing the rounded values. public static Vector3 Round(this Vector3 v, int nearest = 1) { return new Vector3(v.x.Round(nearest), v.y.Round(nearest), v.z.Round(nearest)); } /// /// Inverts the X component of a vector. /// /// The vector to evaluate. /// Returns a whose values are (-X, Y, Z). public static Vector3 InvertX(this Vector3 v) { return new Vector3(-v.x, v.y, v.z); } /// /// Inverts the Y component of a vector. /// /// The vector to evaluate. /// Returns a whose values are (X, -Y, Z). public static Vector3 InvertY(this Vector3 v) { return new Vector3(v.x, -v.y, v.z); } /// /// Inverts the Z component of a vector. /// /// The vector to evaluate. /// Returns a whose values are (X, Y, -Z). public static Vector3 InvertZ(this Vector3 v) { return new Vector3(v.x, v.y, -v.z); } } }