/// <summary> /// <para>Projects a position in 3D space into draw target pixel coordinates</para> /// <para>Returns false if the projected point is behind the camera</para> /// </summary> /// <param name="position">3D world space position to project into draw target coordinates</param> /// <param name="coordinate">draw target coordinates of the projected position</param> /// <returns>True if the projected position is in front of the camera</returns> /// <param name="target">Draw Target space to project the point onto</param> public bool ProjectToTarget(ref Vector3 position, out Vector2 coordinate, Graphics.DrawTarget target) { if (target == null) { throw new ArgumentNullException(); } Vector2 size = target.Size; bool result = ProjectToCoordinate(this, ref position, out coordinate, ref size); coordinate.X = size.X * (coordinate.X * 0.5f + 0.5f); coordinate.Y = size.Y * (coordinate.Y * 0.5f + 0.5f); return(result); }
/// <summary> /// <para>Projects a position in draw target pixel coordinates into a 3D position in world space, based on a projection depth</para> /// <para>NOTE: For 3D Cameras this method is expensive! Where possible use <see cref="DrawState.ProjectFromScreen"/></para> /// </summary> /// <param name="coordinate">Coordinate in draw target pixels to project into world space</param> /// <param name="projectDepth">World space depth to project from the camera position</param> /// <param name="position">projected position</param> /// <param name="target">Draw Target space to unproject the point from</param> public void ProjectFromTarget(ref Vector2 coordinate, float projectDepth, out Vector3 position, Graphics.DrawTarget target) { Vector2 size = target.Size; ProjectFromCoordinate(this, false, ref coordinate, projectDepth, out position, ref size); }