n维顶点模板类

template<int nD, class T >
class Vec
{
    
    
public:
    T V[nD];
    Vec()
    {
    
    
        for (int i = 0; i < nD; i++)
        {
    
    
            V[i] = T(0);
        }
    }
    Vec(T x, T y)
    {
    
    
        V[0] = x;
        V[1] = y;
    }
    Vec(T x, T y, T z)
    {
    
    
        V[0] = x;
        V[1] = y;
        V[2] = z;
    }
    Vec(T x, T y, T z, T w)
    {
    
    
        V[0] = x;
        V[1] = y;
        V[2] = z;
        V[3] = w;
    }
    T &operator[](int i)
    {
    
    
        return V[i];
    }
};
typedef Vec<2, float> Vec2;
typedef Vec<3, float> Vec3;
typedef Vec<4, float> Vec4;

猜你喜欢

转载自blog.csdn.net/weixin_44478077/article/details/126907627