Example #1
0
        /// <summary>
        /// Gets an existing <see cref="WaterViewSource"/> if there is one fitting the parameters, otherwise creates a new one
        /// </summary>
        /// <param name="engine">The <see cref="Engine"/> to create the views in</param>
        /// <param name="height">The height of the <see cref="Water"/> planes (Y axis)</param>
        /// <param name="baseView">The <see cref="View"/> the <see cref="Water"/> planes are shown in</param>
        /// <param name="clipTolerance">How far to shift the clip plane along its normal vector to reduce graphical glitches at corners</param>
        /// <returns>A <see cref="WaterViewSource"/> fitting the parameters</returns>
        /// <seealso cref="Engine.WaterViewSources"/>
        public static WaterViewSource FromEngine(Engine engine, double height, View baseView, float clipTolerance)
        {
            #region Sanity checks
            if (engine == null)
            {
                throw new ArgumentNullException(nameof(engine));
            }
            if (baseView == null)
            {
                throw new ArgumentNullException(nameof(baseView));
            }
            #endregion

            // ReSharper disable CompareOfFloatsByEqualityOperator
            var view = engine.WaterViewSources.FirstOrDefault(
                candidate => candidate.Height == height &&
                candidate.BaseView == baseView &&
                candidate.ClipTolerance == clipTolerance);
            // ReSharper restore CompareOfFloatsByEqualityOperator

            if (view == null)
            {
                engine.WaterViewSources.Add(view = new WaterViewSource(height, baseView, clipTolerance));
            }

            view.ReferenceCount++;
            return(view);
        }
Example #2
0
        //--------------------//

        #region Setup
        /// <summary>
        /// Creates views as reflection and refraction sources - Call after setting position!
        /// </summary>
        /// <param name="view">The original view to reflect</param>
        /// <param name="clipTolerance">How far to shift the clip plane along its normal vector to reduce graphical glitches at corners</param>
        /// <remarks>This method may be called only once on an instance</remarks>
        public void SetupChildViews(View view, float clipTolerance = 2)
        {
            #region Sanity checks
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }
            if (_viewSource != null)
            {
                throw new InvalidOperationException(Resources.CallMethodOnlyOnce);
            }
            #endregion

            // Make sure the required views get rendered first
            _viewSource = WaterViewSource.FromEngine(Engine, Position.Y, view, clipTolerance);
            RequiredViews.Add(_viewSource.RefractedView);
            RequiredViews.Add(_viewSource.ReflectedView);
        }