#ifndef TRANSFORM_H #define TRANSFORM_H #include #include "lin_alg.h" struct Transform { Transform() { rot = mat_ident; trans = vec_zero; } matrix3d rot; vector3d trans; vector3d operator * (const vector3d & v) const {return rot * v + trans;} void Rotation(const vector3d & v, double t) { double C = cos(t); double S = sin(t); rot.a.x = C+(1-C)*v.x*v.x; rot.a.y = v.x*(1-C)*v.y-S*v.z; rot.a.z = (1-C)*v.z*v.x+S*v.y; rot.b.x = v.x*(1-C)*v.y+S*v.z; rot.b.y = v.y*v.y*(1-C)+C; rot.b.z = -v.x*S+v.y*(1-C)*v.z; rot.c.x = (1-C)*v.z*v.x-S*v.y; rot.c.y = v.x*S+v.y*(1-C)*v.z; rot.c.z = C+(1-C)*v.z*v.z; } void Translate(const vector3d & v) {trans = v;} void Scale(double d) { rot.a *= d; rot.b *= d; rot.c *= d; trans *= d; } Transform operator * (const Transform & t) const { Transform tr; tr.rot = rot * t.rot; tr.trans = rot * t.trans + trans; return tr; } Transform& operator = (const Transform & t) { rot = t.rot; trans = t.trans; return *this; } void MakeInverse() { rot = rot.Inverse(); trans = rot * -trans; } }; #endif