58 data[0] = (double)_data[0];
59 data[1] = (double)_data[1];
60 data[2] = (double)_data[2];
71 Vector3(
double _x,
double _y,
double _z) : data{_x, _y, _z} { }
74 double &operator[](
const unsigned int idx)
79 double operator[](
const unsigned int idx)
const 91 return Vector3(x+rhs.x, y+rhs.y, z+rhs.z);
96 return Vector3(x-rhs.x, y-rhs.y, z-rhs.z);
99 Vector3 operator*(
const double &rhs)
const 101 return Vector3(x*rhs, y*rhs, z*rhs);
107 return Vector3(x*rhs.x, y*rhs.y, z*rhs.z);
110 Vector3 operator/(
const double &rhs)
const 112 return Vector3(x/rhs, y/rhs, z/rhs);
117 return Vector3(x/rhs.x, y/rhs.y, z/rhs.z);
123 return Vector3(pow(x, rhs), pow(y, rhs), pow(z, rhs));
128 return Vector3(y*rhs.z - z*rhs.y, z*rhs.x-x*rhs.z, x*rhs.y - y*rhs.x);
133 return sqrt(normsq());
136 double normsq()
const 141 friend std::ostream &operator<<(std::ostream &os,
const Vector3 &obj)
143 os <<
"[" << obj.x <<
", " << obj.y <<
", " << obj.z <<
"]";
189 set(rotation, translation);
195 set(axis, angle, translation);
198 void set(
double _data[16])
200 memcpy(data, _data, 16*
sizeof(
double));
203 void set(
const Vector3 &axis,
const double &angle,
const Vector3 &translation)
205 double s = sin(angle), c = cos(angle), c1 = 1-c;
206 double x = axis.x, y = axis.y, z = axis.z;
208 data[0] = c + x*x*c1; data[4] = x*y*c1 - z*s; data[ 8] = x*z*c1 + y*s;
209 data[1] = y*x*c1 + z*s; data[5] = c + y*y*c1; data[ 9] = y*z*c1 - x*s;
210 data[2] = z*x*c1 - y*s; data[6] = z*y*c1 + x*s; data[10] = c + z*z*c1;
211 data[3] = 0; data[7] = 0; data[11] = 0;
213 this->x = translation.x;
214 this->y = translation.y;
215 this->z = translation.z;
221 double sa = sin(rotation[2]), ca = cos(rotation[2]);
222 double sb = sin(rotation[1]), cb = cos(rotation[1]);
223 double sg = sin(rotation[0]), cg = cos(rotation[0]);
226 data[0] = ca*cb; data[4] = ca*sb*sg - sa*cg; data[8] = ca*sb*cg + sa*sg;
227 data[1] = sa*cb; data[5] = sa*sb*sg + ca*cg; data[9] = sa*sb*cg - ca*sg;
228 data[2] = -sb; data[6] = cb*sg; data[10] = cb*cg;
229 data[3] = 0; data[7] = 0; data[11] = 0;
237 double &operator[](
const unsigned int idx)
242 double operator[](
const unsigned int idx)
const 251 for (
unsigned char ii = 0; ii < 4; ++ii)
252 for (
unsigned char jj = 0; jj < 4; ++jj)
255 for (
unsigned char kk = 0; kk < 4; ++kk)
256 sum += data[ii+kk*4]*rhs.data[jj*4+kk];
257 result[ii+jj*4] = sum;
265 return Vector3(data[0]*rhs.x + data[1]*rhs.y + data[ 2]*rhs.z,
266 data[4]*rhs.x + data[5]*rhs.y + data[ 6]*rhs.z,
267 data[8]*rhs.x + data[9]*rhs.y + data[10]*rhs.z);
270 friend std::ostream &operator<<(std::ostream &os,
const Transform &obj)
272 os <<
"[" << obj.data[0] <<
", " << obj.data[4] <<
", " << obj.data[8] <<
", " << obj.data[12] << std::endl
273 <<
" " << obj.data[1] <<
", " << obj.data[5] <<
", " << obj.data[9] <<
", " << obj.data[13] << std::endl
274 <<
" " << obj.data[2] <<
", " << obj.data[6] <<
", " << obj.data[10] <<
", " << obj.data[14] << std::endl
275 <<
" " << obj.data[3] <<
", " << obj.data[7] <<
", " << obj.data[11] <<
", " << obj.data[15] <<
"]" << std::endl;
297 #endif // PGL_MATH_H_
Vector3 operator*(const Vector3 &rhs) const
Elementwise product.
Definition: math.h:105
Vector3 operator^(const double &rhs) const
Power.
Definition: math.h:121
Definition: controller.h:27
Transform with zero translation.
Definition: math.h:282
3-component vector.
Definition: math.h:43
Transform with identity rotation.
Definition: math.h:289