/// <summary> /// Get the projected position of a 3D ray. /// </summary> /// <param name="ray">The ray to project.</param> /// <param name="projectedX">Projected x.</param> /// <param name="projectedY">Projected y.</param> /// <param name="distance">Distance of the projected point.</param> /// <returns>Whether the ray intersected the plane.</returns> public bool ProjectRay(Ray ray, out int projectedX, out int projectedY, out float?distance) { Matrix worldInverseTransform = this.transform.WorldInverseTransform; ray.Position = Common.Math.Vector3.Transform(ray.Position, worldInverseTransform); ray.Direction = Common.Math.Vector3.TransformNormal(ray.Direction, worldInverseTransform); projectedX = 0; projectedY = 0; distance = null; // Ignored negative rays if (ray.Position.Y > 0) { Plane plane = new Plane(Common.Math.Vector3.Up, 0); distance = ray.Intersects(plane); // if Intersection exists if (distance.HasValue) { Common.Math.Vector3 target = ray.GetPoint(distance.Value); if (target.X < 0.5f && target.X > -0.5f && target.Z < 0.5f && target.Z > -0.5f) { Vector2 coord = new Vector2(target.X + 0.5f, target.Z + 0.5f); // Scale coord to the size. projectedX = (int)(coord.X * this.width); projectedY = (int)(coord.Y * this.height); return(true); } } } return(false); }
/// <summary> /// Convert a system.numerics vector3 to waveengine vector3 /// </summary> /// <param name="wave">Wave vector</param> /// <returns>System numerics vector</returns> public static System.Numerics.Vector3 ToSystemNumerics(this Common.Math.Vector3 wave) { return(new System.Numerics.Vector3(wave.X, wave.Y, wave.Z)); }
/// <summary> /// Convert a system.numerics vector3 to waveengine vector3 /// </summary> /// <param name="numerics">Wave vector</param> /// <param name="result">The result</param> public static void ToWave(this System.Numerics.Vector3 numerics, out Common.Math.Vector3 result) { result.X = numerics.X; result.Y = numerics.Y; result.Z = numerics.Z; }
/// <summary> /// Convert a waveengine vector3 to system.numerics vector3 /// </summary> /// <param name="wave">Wave vector</param> /// <param name="numerics">System numerics vector</param> public static void ToSystemNumerics(this Common.Math.Vector3 wave, out System.Numerics.Vector3 numerics) { numerics.X = wave.X; numerics.Y = wave.Y; numerics.Z = wave.Z; }