最近
研究でCG扱うことになってきたので、C++でかっちりした自分用のライブラリでも書こうと。以前からまー作ろうかなぁと思ってたのもあったんで、結構マジで。
第1弾はベクトル。
まー、3D-Graphics扱うなら必須だよねぇ。。。ってことで。
しかもfloatとdoubleとlong doubleと使い分けられるように、とか思い初めてtemplateバリバリで。
そーするとさー、
CVector4D
CVector4D
ってなってたら、v1 + v2はCVector4D
template<typename T> class CVector4D { public: // 中略 template<typename U> CVector4D(const CVector4D< U >& v) { // 略 } template<typename U> CVector4D<T> operator +=(const CVector4D< U >& v) { // 略 } }; template<typename T, typename U> class CFloatConversion; template<float, double> class CFloatConversion { public: typedef double SuperType; typedef float SubType; }; template<double, float> class CFloatConversion { public: typedef double SuperType; typedef float SubType; }; // などなど。他略 template<typename T, typename U> inline CVector4D<typename CFloatConversion<T, U> :: SuperType> operator +(const CVector4D<T>& v1, const CVector4D< U >& v2) { CVector4D<typename CFloatConversion<T, U> :: SuperType> result(v1); result += v2; return result; }
長い・・・。
足し算1個が8行。引き算も。スカラー積も。まじすか。