Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_matrix 5 #define tools_sg_matrix 6 7 #include "node" 8 #include "sf_mat4f" 9 #include "../lina/mat4f" 10 #include "render_action" 11 #include "pick_action" 12 #include "bbox_action" 13 #include "event_action" 14 #include "visible_action" 15 16 namespace tools { 17 namespace sg { 18 19 class matrix : public node { 20 TOOLS_NODE(matrix,tools::sg::matrix,node) 21 public: 22 sf_mat4f mtx; 23 public: 24 virtual const desc_fields& node_desc_fields( 25 TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::mat 26 static const desc_fields s_v(parent::node_ 27 TOOLS_ARG_FIELD_DESC(mtx) 28 ); 29 return s_v; 30 } 31 private: 32 void add_fields(){ 33 add_field(&mtx); 34 } 35 public: 36 virtual void render(render_action& a_action) 37 a_action.model_matrix().mul_mtx(mtx.value( 38 a_action.state().m_model = a_action.model_ 39 a_action.load_model_matrix(a_action.model_ 40 } 41 virtual void pick(pick_action& a_action) { 42 a_action.model_matrix().mul_mtx(mtx.value( 43 a_action.state().m_model = a_action.model_ 44 } 45 virtual void bbox(bbox_action& a_action) { 46 a_action.model_matrix().mul_mtx(mtx.value( 47 a_action.state().m_model = a_action.model_ 48 } 49 virtual void event(event_action& a_action) { 50 a_action.model_matrix().mul_mtx(mtx.value( 51 a_action.state().m_model = a_action.model_ 52 } 53 virtual void get_matrix(get_matrix_action& a 54 a_action.model_matrix().mul_mtx(mtx.value( 55 a_action.state().m_model = a_action.model_ 56 } 57 virtual void is_visible(visible_action& a_ac 58 a_action.model_matrix().mul_mtx(mtx.value( 59 a_action.state().m_model = a_action.model_ 60 } 61 public: 62 matrix():parent(),mtx(mat4f()) { 63 #ifdef TOOLS_MEM 64 mem::increment(s_class().c_str()); 65 #endif 66 add_fields(); 67 mtx.set_identity(); 68 } 69 virtual ~matrix(){ 70 #ifdef TOOLS_MEM 71 mem::decrement(s_class().c_str()); 72 #endif 73 } 74 public: 75 matrix(const matrix& a_from):parent(a_from), 76 #ifdef TOOLS_MEM 77 mem::increment(s_class().c_str()); 78 #endif 79 add_fields(); 80 } 81 matrix& operator=(const matrix& a_from){ 82 parent::operator=(a_from); 83 mtx = a_from.mtx; 84 return *this; 85 } 86 public: 87 // shortcuts : 88 void set_identity() {mtx.set_identity();} 89 90 void set_translate(float a_x,float a_y,float 91 void set_translate(const vec3f& a_v) {mtx.se 92 93 void set_scale(float a_x,float a_y,float a_z 94 void set_scale(float a_s) {mtx.set_scale(a_s 95 96 void set_rotate(float a_x,float a_y,float a_ 97 void set_rotate(const vec3f& a_v,float a_ang 98 bool set_rotate(const vec3f& a_from,const ve 99 100 void mul_mtx(const mat4f& a_m) {mtx.mul_mtx( 101 102 void mul_translate(float a_x,float a_y,float 103 void mul_translate(const vec3f& a_v) {mtx.mu 104 void mul_scale(float a_x,float a_y,float a_z 105 void mul_scale(float a_s) {mtx.mul_scale(a_s 106 107 void mul_rotate(float a_x,float a_y,float a_ 108 109 void mul_rotate(const vec3f& a_v,float a_ang 110 void mul_rotate(const vec4f& a_v) {mtx.mul_r 111 112 void left_mul_rotate(float a_x,float a_y,flo 113 114 void left_mul_scale(float a_x,float a_y,floa 115 116 void left_mul_translate(float a_x,float a_y, 117 118 void left_mul_translate(const vec3f& a_v) {m 119 120 bool mul_rotate(const vec3f& a_from,const ve 121 protected: 122 float m_tmp[16]; //OPTIMIZATION 123 }; 124 125 }} 126 127 #endif