/********************************************************************************
 *                                                                               *
 *   Copyright (C) Golaem S.A.  All Rights Reserved.                             *
 *                                                                               *
 *   Original code & license:                                                    *
 *                                                                               *
 *   OpenSteer -- Steering Behaviors for Autonomous Characters                   *
 *                                                                               *
 *   Copyright (c) 2002-2003, Sony Computer Entertainment America                *
 *   Original author: Craig Reynolds <craig_reynolds@playstation.sony.com>       *
 *                                                                               *
 *   Permission is hereby granted, free of charge, to any person obtaining a     *
 *   copy of this software and associated documentation files (the "Software"),  *
 *   to deal in the Software without restriction, including without limitation   *
 *   the rights to use, copy, modify, merge, publish, distribute, sublicense,    *
 *   and/or sell copies of the Software, and to permit persons to whom the       *
 *   Software is furnished to do so, subject to the following conditions:        *
 *                                                                               *
 *   The above copyright notice and this permission notice shall be included in  *
 *   all copies or substantial portions of the Software.                         *
 *                                                                               *
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  *
 *   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,    *
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL    *
 *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  *
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING     *
 *   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER         *
 *   DEALINGS IN THE SOFTWARE.                                                   *
 *                                                                               *
 ********************************************************************************/

#pragma once

#include <glmSDKAPI.h>
#include <glmVector3.h>
#include <glmQuaternion.h>

namespace glm
{
    namespace boidutils
    {
        float GLM_SDK_API bec_interpolate(float alpha, float x0, float x1);
        Vector3 GLM_SDK_API bec_interpolate(float alpha, const Vector3& x0, const Vector3& x1);

        //-------------------------------------------------------------------------
        // blends new values into an accumulator to produce a smoothed time series
        //
        // Modifies its third argument, a reference to the float accumulator holding
        // the "smoothed time series."
        //
        // The first argument (smoothRate) is typically made proportional to "dt" the
        // simulation time step.  If smoothRate is 0 the accumulator will not change,
        // if smoothRate is 1 the accumulator will be set to the new value with no
        // smoothing.  Useful values are "near zero".
        //
        // Usage:
        //         blendIntoAccumulator (dt * 0.4f, currentFPS, smoothedFPS);
        //-------------------------------------------------------------------------
        void GLM_SDK_API blendIntoAccumulator(const float smoothRate, const float newValue, float& smoothedAccumulator);
        void GLM_SDK_API blendIntoAccumulator(const float smoothRate, const Vector3& newValue, Vector3& smoothedAccumulator);

        void GLM_SDK_API limitUpAxisAngle(Vector3& axis, float maxAngle);

        void GLM_SDK_API bec_truncateLength(Vector3& v, const float maxLength);

        //-------------------------------------------------------------------------
        // Enforce an upper bound on the angle by which a given arbitrary vector
        // deviates from a given reference direction (specified by a unit basis
        // vector).  The effect is to clip the "source" vector to be inside a cone
        // defined by the basis and an angle.
        //-------------------------------------------------------------------------
        void GLM_SDK_API limitMaxDeviationAngle(Vector3& source, const float cosineOfConeAngle, const Vector3& basis);

        //-------------------------------------------------------------------------
        // return component of vector parallel to a unit basis vector
        // (IMPORTANT NOTE: assumes "basis" has unit magnitude (length==1))
        //-------------------------------------------------------------------------
        Vector3 GLM_SDK_API parallelComponent(const Vector3& v, const Vector3& unitBasis);

        //-------------------------------------------------------------------------
        // return component of vector perpendicular to a unit basis vector
        // (IMPORTANT NOTE: assumes "basis" has unit magnitude (length==1))
        //-------------------------------------------------------------------------
        Vector3 GLM_SDK_API perpendicularComponent(const Vector3& v, const Vector3& unitBasis);

    } // namespace boidutils
} // namespace glm
