Example #1
0
        /// <summary>
        /// Projects a 2D coordinate on a 2D rectangle in 3D (world) space.
        /// Useful for positioning things in front of the camera.
        /// </summary>
        /// <param name="plane">The rectangle to project the coordinate on</param>
        /// <param name="planeCoordinates">Vector2(0,0) is bottom-left and Vector2(1,1) is top-right</param>
        /// <returns>A point on the rectangle in 3D world space</returns>
        public static ImmutableTransform ProjectPointOnPlane(ImmutableTransform plane, Vector2 planeCoordinates)
        {
            var relativePlaneCoordinates = planeCoordinates - new Vector2(0.5f, 0.5f);
            var planePosition            = new Vector3(relativePlaneCoordinates.x * plane.Scale.x, relativePlaneCoordinates.y * plane.Scale.y, 0f);

            return(plane.TranslateLocally(planePosition));
        }