Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_sg_sf_rotf 4 #ifndef tools_sg_sf_rotf 5 #define tools_sg_sf_rotf 5 #define tools_sg_sf_rotf 6 6 7 #include "sf" 7 #include "sf" 8 8 9 #include "../lina/rotf" 9 #include "../lina/rotf" 10 10 11 #include "../HEADER" 11 #include "../HEADER" 12 12 13 namespace tools { 13 namespace tools { 14 namespace sg { 14 namespace sg { 15 15 16 class sf_rotf : public bsf<rotf> { 16 class sf_rotf : public bsf<rotf> { 17 TOOLS_HEADER(sf_rotf,tools::sg::sf_rotf,bsf< 17 TOOLS_HEADER(sf_rotf,tools::sg::sf_rotf,bsf<rotf>) 18 public: 18 public: 19 virtual bool write(io::iwbuf& a_buffer) { 19 virtual bool write(io::iwbuf& a_buffer) { 20 const vec4<float>& vec = m_value.quat(); 20 const vec4<float>& vec = m_value.quat(); 21 const float* d = get_data(vec); 21 const float* d = get_data(vec); 22 return a_buffer.write_vec(vec.size(),d); 22 return a_buffer.write_vec(vec.size(),d); 23 } 23 } 24 virtual bool read(io::irbuf& a_buffer) { 24 virtual bool read(io::irbuf& a_buffer) { 25 vec4<float>& vec = m_value.quat(); 25 vec4<float>& vec = m_value.quat(); 26 uint32 n; 26 uint32 n; 27 float* v; 27 float* v; 28 if(!a_buffer.read_vec(n,v)) return false; 28 if(!a_buffer.read_vec(n,v)) return false; 29 if(n!=vec.size()) { 29 if(n!=vec.size()) { 30 delete [] v; 30 delete [] v; 31 #ifdef TOOLS_MEM 31 #ifdef TOOLS_MEM 32 mem::decrement(s_new().c_str()); 32 mem::decrement(s_new().c_str()); 33 #endif 33 #endif 34 return false; 34 return false; 35 } 35 } 36 for(uint32 index=0;index<n;index++) vec[in 36 for(uint32 index=0;index<n;index++) vec[index] = v[index]; 37 delete [] v; 37 delete [] v; 38 #ifdef TOOLS_MEM 38 #ifdef TOOLS_MEM 39 mem::decrement(s_new().c_str()); 39 mem::decrement(s_new().c_str()); 40 #endif 40 #endif 41 return true; 41 return true; 42 } 42 } 43 virtual bool dump(std::ostream&) { 43 virtual bool dump(std::ostream&) { 44 //a_out << parent::m_value << std::endl; 44 //a_out << parent::m_value << std::endl; 45 return true; 45 return true; 46 } 46 } 47 virtual bool s_value(std::string& a_s) const 47 virtual bool s_value(std::string& a_s) const {a_s.clear();return false;} 48 virtual bool s2value(const std::string&) {re 48 virtual bool s2value(const std::string&) {return false;} 49 public: 49 public: 50 sf_rotf():parent(){} 50 sf_rotf():parent(){} 51 sf_rotf(const rotf& a_value):parent(a_value) 51 sf_rotf(const rotf& a_value):parent(a_value){} 52 virtual ~sf_rotf(){} 52 virtual ~sf_rotf(){} 53 public: 53 public: 54 sf_rotf(const sf_rotf& a_from):parent(a_from 54 sf_rotf(const sf_rotf& a_from):parent(a_from){} 55 sf_rotf& operator=(const sf_rotf& a_from){ 55 sf_rotf& operator=(const sf_rotf& a_from){ 56 parent::operator=(a_from); 56 parent::operator=(a_from); 57 return *this; 57 return *this; 58 } 58 } 59 public: 59 public: 60 sf_rotf& operator=(const rotf& a_value){ 60 sf_rotf& operator=(const rotf& a_value){ 61 parent::operator=(a_value); 61 parent::operator=(a_value); 62 return *this; 62 return *this; 63 } 63 } 64 public: //iv2ps 64 public: //iv2ps 65 void setValue(const vec3f& a_axis,float a_an 65 void setValue(const vec3f& a_axis,float a_angle) { 66 value(rotf(a_axis,a_angle)); 66 value(rotf(a_axis,a_angle)); 67 } 67 } 68 void setValue(const rotf& a_value) { 68 void setValue(const rotf& a_value) { 69 value(a_value); 69 value(a_value); 70 } 70 } 71 }; 71 }; 72 72 73 }} 73 }} 74 74 75 #endif 75 #endif