Code: Select all
//an additional constructor
vector3d(const T* ptr) : X(ptr[0]), Y(ptr[1]), Z(ptr[2]) {};
//additional operators
T& operator[] (int i) { return (&X)[i]; }
const T& operator[] (int i) const { return (&X)[i]; }
float[3] to vector3d:
Code: Select all
float[3] f = {1,2,3};
vector3df v(f); //this makes a vector from the float
Code: Select all
vector3df v(1,2,3);
float *f = &v[0]; //this makes a float[3] from the vector3d