/* * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ namespace Movement { template void Spline::evaluate_percent( float t, Vector3 & c ) const { index_type Index; float u; computeIndex(t, Index, u); evaluate_percent(Index, u, c); } template void Spline::evaluate_derivative(float t, Vector3& hermite) const { index_type Index; float u; computeIndex(t, Index, u); evaluate_derivative(Index, u, hermite); } template SplineBase::index_type Spline::computeIndexInBoundsAtLength(length_type length_) const { // Temporary disabled: causes infinite loop with t = 1.f /* index_type hi = index_hi; index_type lo = index_lo; index_type i = lo + (float)(hi - lo) * t; while ((lengths[i] > length) || (lengths[i + 1] <= length)) { if (lengths[i] > length) hi = i - 1; // too big else if (lengths[i + 1] <= length) lo = i + 1; // too small i = (hi + lo) / 2; }*/ index_type i = index_lo; index_type N = index_hi; while (i+1 < N && lengths[i+1] < length_) ++i; return i; } template void Spline::computeIndex(float t, index_type& out_idx, float& out_u) const { ASSERT(t >= 0.f && t <= 1.f); length_type length_ = t * length(); out_idx = computeIndexInBoundsAtLength(length_); ASSERT(out_idx < index_hi); out_u = (length_ - length(out_idx)) / (float)length(out_idx, out_idx+1); } template SplineBase::index_type Spline::computeIndexInBounds( float t ) const { ASSERT(t >= 0.f && t <= 1.f); return computeIndexInBoundsAtLength(t * length()); } template void Spline::initLengths() { index_type i = index_lo; length_type length = 0; lengths.resize(index_hi+1); while (i < index_hi) { length += SegLength(i); lengths[++i] = length; } } template void Spline::clear() { SplineBase::clear(); lengths.clear(); } }