Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/matrix 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_sg_matrix
0005 #define tools_sg_matrix
0006 
0007 #include "node"
0008 #include "sf_mat4f"
0009 #include "../lina/mat4f"
0010 #include "render_action"
0011 #include "pick_action"
0012 #include "bbox_action"
0013 #include "event_action"
0014 #include "visible_action"
0015 
0016 namespace tools {
0017 namespace sg {
0018 
0019 class matrix : public node {
0020   TOOLS_NODE(matrix,tools::sg::matrix,node)
0021 public:
0022   sf_mat4f mtx;
0023 public:
0024   virtual const desc_fields& node_desc_fields() const {
0025     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::matrix)
0026     static const desc_fields s_v(parent::node_desc_fields(),1, //WARNING : take care of count.
0027       TOOLS_ARG_FIELD_DESC(mtx)
0028     );
0029     return s_v;
0030   }
0031 private:
0032   void add_fields(){
0033     add_field(&mtx);
0034   }
0035 public:
0036   virtual void render(render_action& a_action) {
0037     a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
0038     a_action.state().m_model = a_action.model_matrix();
0039     a_action.load_model_matrix(a_action.model_matrix());
0040   }
0041   virtual void pick(pick_action& a_action) {
0042     a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
0043     a_action.state().m_model = a_action.model_matrix();
0044   }
0045   virtual void bbox(bbox_action& a_action) {
0046     a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
0047     a_action.state().m_model = a_action.model_matrix();
0048   }
0049   virtual void event(event_action& a_action) {
0050     a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
0051     a_action.state().m_model = a_action.model_matrix();
0052   }
0053   virtual void get_matrix(get_matrix_action& a_action) {
0054     a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
0055     a_action.state().m_model = a_action.model_matrix();
0056   }
0057   virtual void is_visible(visible_action& a_action) {
0058     a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
0059     a_action.state().m_model = a_action.model_matrix();
0060   }
0061 public:
0062   matrix():parent(),mtx(mat4f()) {
0063 #ifdef TOOLS_MEM
0064     mem::increment(s_class().c_str());
0065 #endif
0066     add_fields();
0067     mtx.set_identity();
0068   }
0069   virtual ~matrix(){
0070 #ifdef TOOLS_MEM
0071     mem::decrement(s_class().c_str());
0072 #endif
0073   }
0074 public:
0075   matrix(const matrix& a_from):parent(a_from),mtx(a_from.mtx) {
0076 #ifdef TOOLS_MEM
0077     mem::increment(s_class().c_str());
0078 #endif
0079     add_fields();
0080   }
0081   matrix& operator=(const matrix& a_from){
0082     parent::operator=(a_from);
0083     mtx = a_from.mtx;
0084     return *this;
0085   }
0086 public:
0087   // shortcuts :
0088   void set_identity() {mtx.set_identity();}
0089 
0090   void set_translate(float a_x,float a_y,float a_z) {mtx.set_translate(a_x,a_y,a_z);}
0091   void set_translate(const vec3f& a_v) {mtx.set_translate(a_v);}
0092 
0093   void set_scale(float a_x,float a_y,float a_z) {mtx.set_scale(a_x,a_y,a_z);}
0094   void set_scale(float a_s) {mtx.set_scale(a_s);}
0095 
0096   void set_rotate(float a_x,float a_y,float a_z,float a_angle) {mtx.set_rotate(a_x,a_y,a_z,a_angle);}
0097   void set_rotate(const vec3f& a_v,float a_angle) {mtx.set_rotate(a_v,a_angle);}
0098   bool set_rotate(const vec3f& a_from,const vec3f& a_to) {return mtx.set_rotate(a_from,a_to,m_tmp);}
0099 
0100   void mul_mtx(const mat4f& a_m) {mtx.mul_mtx(a_m,m_tmp);}
0101 
0102   void mul_translate(float a_x,float a_y,float a_z) {mtx.mul_translate(a_x,a_y,a_z);}
0103   void mul_translate(const vec3f& a_v) {mtx.mul_translate(a_v);}
0104   void mul_scale(float a_x,float a_y,float a_z) {mtx.mul_scale(a_x,a_y,a_z);}
0105   void mul_scale(float a_s) {mtx.mul_scale(a_s);}
0106 
0107   void mul_rotate(float a_x,float a_y,float a_z,float a_angle) {mtx.mul_rotate(a_x,a_y,a_z,a_angle);}
0108 
0109   void mul_rotate(const vec3f& a_v,float a_angle) {mtx.mul_rotate(a_v,a_angle);}
0110   void mul_rotate(const vec4f& a_v) {mtx.mul_rotate(a_v.v0(),a_v.v1(),a_v.v2(),a_v.v3());}
0111 
0112   void left_mul_rotate(float a_x,float a_y,float a_z,float a_angle) {mtx.left_mul_rotate(a_x,a_y,a_z,a_angle);}
0113 
0114   void left_mul_scale(float a_x,float a_y,float a_z) {mtx.left_mul_scale(a_x,a_y,a_z);}
0115 
0116   void left_mul_translate(float a_x,float a_y,float a_z) {mtx.left_mul_translate(a_x,a_y,a_z);}
0117 
0118   void left_mul_translate(const vec3f& a_v) {mtx.left_mul_translate(a_v);}
0119 
0120   bool mul_rotate(const vec3f& a_from,const vec3f& a_to) {return mtx.mul_rotate(a_from,a_to,m_tmp);}
0121 protected:
0122   float m_tmp[16]; //OPTIMIZATION
0123 };
0124 
0125 }}
0126 
0127 #endif