/// <summary>
        ///     Combines the surface values.
        /// </summary>
        /// <returns>The combined surface value.</returns>
        /// <param name="surfaceA">Surface a.</param>
        /// <param name="surfaceB">Surface b.</param>
        /// <param name="combine">Combine.</param>
        public static float Combine(float surfaceA, float surfaceB, PhysicMaterialCombine combine)
        {
            switch (combine)
            {
            case PhysicMaterialCombine.Average:
                return((surfaceA + surfaceB) / 2.0f);

            case PhysicMaterialCombine.Maximum:
                return(HydraMathUtils.Max(surfaceA, surfaceB));

            case PhysicMaterialCombine.Minimum:
                return(HydraMathUtils.Min(surfaceA, surfaceB));

            case PhysicMaterialCombine.Multiply:
                return(surfaceA * surfaceB);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #2
0
        /// <summary>
        ///     Returns the maximum value that can be returned given the const/curve settings.
        ///     Note, in the case of curves, this will be inaccurate because there is no
        ///     nice way of getting the bounding box for an animation curve.
        /// </summary>
        /// <returns>The max value.</returns>
        public float GetMaxValue()
        {
            switch (rangeMode)
            {
            case RangeMode.Constant:
                return(m_ConstValueA);

            case RangeMode.Curve:
                return(m_CurveA.GetMaxValue());

            case RangeMode.RandomBetweenTwoConstants:
                return(HydraMathUtils.Max(m_ConstValueA, m_ConstValueB));

            case RangeMode.RandomBetweenTwoCurves:
                return(HydraMathUtils.Max(m_CurveA.GetMaxValue(), m_CurveB.GetMaxValue()));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        /// <summary>
        ///     Returns an approximation for the greatest value along the curve.
        ///
        ///     Unity doesn't provide a way to get the bounding box, so
        ///     we'll cheat and just check a certain number of samples.
        /// </summary>
        /// <returns>The max value.</returns>
        /// <param name="extends">Extends.</param>
        public static float GetMaxValue(this AnimationCurve extends)
        {
            float max = extends[0].value;

            if (extends.length == 1)
            {
                return(max);
            }

            float startTime  = extends.GetStartTime();
            float lengthTime = extends.GetTimeLength();
            float delta      = CURVE_BOUNDS_DELTA * lengthTime;

            for (int index = 1; index < CURVE_BOUNDS_SAMPLES; index++)
            {
                float time = startTime + delta * index;
                max = HydraMathUtils.Max(max, extends.Evaluate(time));
            }

            return(max);
        }
        /// <summary>
        ///     Draws a cone size handle.
        /// </summary>
        /// <returns>The radius, angle and length in a Vector3 tuple.</returns>
        /// <param name="rotation">Rotation.</param>
        /// <param name="position">Position.</param>
        /// <param name="radius">Radius.</param>
        /// <param name="angle">Angle.</param>
        /// <param name="length">Length.</param>
        public static Vector3 ConeSizeHandle(Quaternion rotation, Vector3 position, float radius, float angle, float length)
        {
            // Base circle
            radius = CircleRadiusHandle(rotation, position, radius);

            // Now we need to do some maths to get the radius of the secondary circle
            float secondaryRadius = radius + Mathf.Tan(Mathf.Deg2Rad * angle) * length;

            // Draw the struts
            Vector3 secondaryCirclePosition = position + rotation * Vector3.forward * length;

            Handles.DrawLine(position + rotation * Vector3.up * radius,
                             secondaryCirclePosition + rotation * Vector3.up * secondaryRadius);
            Handles.DrawLine(position + rotation * Vector3.down * radius,
                             secondaryCirclePosition + rotation * Vector3.down * secondaryRadius);
            Handles.DrawLine(position + rotation * Vector3.left * radius,
                             secondaryCirclePosition + rotation * Vector3.left * secondaryRadius);
            Handles.DrawLine(position + rotation * Vector3.right * radius,
                             secondaryCirclePosition + rotation * Vector3.right * secondaryRadius);

            // Draw the secondary circle
            float newSecondaryRadius = CircleRadiusHandle(rotation, secondaryCirclePosition, secondaryRadius);

            newSecondaryRadius = HydraMathUtils.Max(newSecondaryRadius, radius);

            if (!HydraMathUtils.Approximately(newSecondaryRadius, secondaryRadius))
            {
                float delta = newSecondaryRadius - radius;
                angle = Mathf.Rad2Deg * Mathf.Atan(delta / length);
            }

            // Draw the dot in the middle of the secondary circle
            length += NormalMoveHandle(secondaryCirclePosition, rotation, rotation * Vector3.forward);

            return(new Vector3(radius, angle, length));
        }
Exemple #5
0
 /// <summary>
 ///     Validates the start delay.
 /// </summary>
 /// <returns>The start delay.</returns>
 /// <param name="delay">Delay.</param>
 public static float ValidateStartDelay(float delay)
 {
     return(HydraMathUtils.Max(delay, 0.0f));
 }