Warning, /include/Geant4/tools/lina/rotf is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_rotf
0005 #define tools_rotf
0006
0007 // rotation done with quaternion.
0008
0009 #include "qrot"
0010 #include "vec3f"
0011 #include "vec4f"
0012 #include "mat4f"
0013
0014 namespace tools {
0015
0016 class rotf : public qrot<vec3f,vec4f> {
0017 typedef qrot<vec3f,vec4f> parent;
0018 private:
0019 rotf(float a_q0,float a_q1,float a_q2,float a_q3):parent(a_q0,a_q1,a_q2,a_q3) {}
0020 public:
0021 rotf():parent() {} //zero rotation around the positive Z axis.
0022 rotf(const vec3f& a_axis,float a_radians):parent(a_axis,a_radians,::sinf,::cosf) {}
0023 rotf(const vec3f& a_from,const vec3f& a_to):parent(a_from,a_to,::sqrtf,::fabsf) {}
0024 virtual ~rotf(){}
0025 public:
0026 rotf(const rotf& a_from):parent(a_from) {}
0027 rotf& operator=(const rotf& a_from){
0028 parent::operator=(a_from);
0029 return *this;
0030 }
0031 public:
0032 rotf& operator*=(const rotf& a_q) {
0033 parent::operator*=(a_q);
0034 return *this;
0035 }
0036 rotf operator*(const rotf& a_r) const {
0037 rotf tmp(*this);
0038 tmp *= a_r;
0039 return tmp;
0040 }
0041 public:
0042 bool set_value(const vec3f& a_from,const vec3f& a_to){
0043 return parent::set_value(a_from,a_to,::sqrtf,::fabsf);
0044 }
0045 bool set_value(const vec3f& a_from,float a_a){
0046 return parent::set_value(a_from,a_a,::sinf,::cosf);
0047 }
0048 bool value(vec3f& a_from,float& a_a) const {
0049 return parent::value(a_from,a_a,::sinf,::acosf); //WARNING acos and not cos
0050 }
0051
0052 void value(mat4f& a_m) const {parent::value(a_m);}
0053 void set_value(const mat4f& a_m) {parent::set_value(a_m,::sqrtf);}
0054
0055 //NOTE : don't handle a static object because of mem balance.
0056 //static const rotf& identity() {
0057 // static const rotf s_v(0,0,0,1);
0058 // return s_v;
0059 //}
0060 };
0061
0062 }
0063
0064 #include <sstream>
0065
0066 namespace tools {
0067
0068 inline bool tos(const rotf& a_v,std::string& a_s) {
0069 vec3f axis;
0070 float angle = 0;
0071 if(!a_v.value(axis,angle)) {a_s.clear();return false;}
0072 std::ostringstream strm;
0073 strm << axis[0] << " "
0074 << axis[1] << " "
0075 << axis[2] << " "
0076 << angle;
0077 a_s = strm.str();
0078 return true;
0079 }
0080
0081 }
0082
0083 #endif