00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
#ifndef _ZFXMATH_INCLUDE_CUBICBEZIER_H_
00015
#define _ZFXMATH_INCLUDE_CUBICBEZIER_H_
00016
00017
namespace ZFXMath
00018 {
00030
template<
class PrecisionType,
class FuncValueType>
00031 class TCubicBezier
00032 {
00033
00034
public:
00035
00036
TCubicBezier() {};
00037
00043 TCubicBezier(
const FuncValueType& cP0,
00044
const FuncValueType& cP1,
00045
const FuncValueType& cP2,
00046
const FuncValueType& cP3 ) { m_ControlPoint[0] = cP0;
00047 m_ControlPoint[1] = cP1;
00048 m_ControlPoint[2] = cP2;
00049 m_ControlPoint[3] = cP3; }
00050
00060 TCubicBezier(
const FuncValueType& cP0,
00061
const FuncValueType& cP3 ) { m_ControlPoint[0] = cP0;
00062 m_ControlPoint[1] = cP0 + ( cP3 - cP0 ) / 3.0;
00063 m_ControlPoint[2] = cP0 + ( cP3 - cP0 ) / 1.5;
00064 m_ControlPoint[3] = cP3; }
00065
00066
00067
TCubicBezier(
const FuncValueType* pCP ) { memcpy( m_ControlPoint, pCP,
sizeof(
TCubicBezier ) ); }
00068
00069
TCubicBezier(
const TCubicBezier& cB ) { memcpy( m_ControlPoint, cB.m_ControlPoint,
sizeof( TCubicBezier ) ); }
00070
00076 FuncValueType
operator () (
const int i )
const
00077
{
00078
return m_ControlPoint[ Check( i ) ];
00079 }
00080
00086 FuncValueType&
operator () (
const int i )
00087 {
00088
return m_ControlPoint[ Check( i ) ];
00089 }
00090
00096 FuncValueType
operator () (
const PrecisionType& u )
const
00097
{
00098
return Evaluate( u );
00099 }
00100
00106 FuncValueType
operator () (
const PrecisionType& u )
00107 {
00108
return Evaluate( u );
00109 }
00110
00111
00117 FuncValueType
Evaluate(
const PrecisionType& u )
const
00118
{
00119 PrecisionType invu = 1 - u;
00120
return ( m_ControlPoint[0] * invu * invu * invu
00121 + m_ControlPoint[1] * 3 * u * invu * invu
00122 + m_ControlPoint[2] * 3 * u * u * invu
00123 + m_ControlPoint[3] * u * u * u );
00124 }
00125
00126
private:
00127
inline int Check(
const int index )
const
00128
{
00129
00130 assert( index >= 0 && index < 4 );
00131
00132
return index;
00133 }
00134
00135 FuncValueType m_ControlPoint[4];
00136 };
00137 }
00138
00139
#endif //_ZFXMATH_INCLUDE_CUBICBEZIER_H_
00140
00141
00142
00143