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 add_fields();
0064 mtx.set_identity();
0065 }
0066 virtual ~matrix(){
0067 }
0068 public:
0069 matrix(const matrix& a_from):parent(a_from),mtx(a_from.mtx) {
0070 add_fields();
0071 }
0072 matrix& operator=(const matrix& a_from){
0073 parent::operator=(a_from);
0074 mtx = a_from.mtx;
0075 return *this;
0076 }
0077 public:
0078 // shortcuts :
0079 void set_identity() {mtx.set_identity();}
0080
0081 void set_translate(float a_x,float a_y,float a_z) {mtx.set_translate(a_x,a_y,a_z);}
0082 void set_translate(const vec3f& a_v) {mtx.set_translate(a_v);}
0083
0084 void set_scale(float a_x,float a_y,float a_z) {mtx.set_scale(a_x,a_y,a_z);}
0085 void set_scale(float a_s) {mtx.set_scale(a_s);}
0086
0087 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);}
0088 void set_rotate(const vec3f& a_v,float a_angle) {mtx.set_rotate(a_v,a_angle);}
0089 bool set_rotate(const vec3f& a_from,const vec3f& a_to) {return mtx.set_rotate(a_from,a_to,m_tmp);}
0090
0091 void mul_mtx(const mat4f& a_m) {mtx.mul_mtx(a_m,m_tmp);}
0092
0093 void mul_translate(float a_x,float a_y,float a_z) {mtx.mul_translate(a_x,a_y,a_z);}
0094 void mul_translate(const vec3f& a_v) {mtx.mul_translate(a_v);}
0095 void mul_scale(float a_x,float a_y,float a_z) {mtx.mul_scale(a_x,a_y,a_z);}
0096 void mul_scale(float a_s) {mtx.mul_scale(a_s);}
0097
0098 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);}
0099
0100 void mul_rotate(const vec3f& a_v,float a_angle) {mtx.mul_rotate(a_v,a_angle);}
0101 void mul_rotate(const vec4f& a_v) {mtx.mul_rotate(a_v.v0(),a_v.v1(),a_v.v2(),a_v.v3());}
0102
0103 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);}
0104
0105 void left_mul_scale(float a_x,float a_y,float a_z) {mtx.left_mul_scale(a_x,a_y,a_z);}
0106
0107 void left_mul_translate(float a_x,float a_y,float a_z) {mtx.left_mul_translate(a_x,a_y,a_z);}
0108
0109 void left_mul_translate(const vec3f& a_v) {mtx.left_mul_translate(a_v);}
0110
0111 bool mul_rotate(const vec3f& a_from,const vec3f& a_to) {return mtx.mul_rotate(a_from,a_to,m_tmp);}
0112 protected:
0113 float m_tmp[16]; //OPTIMIZATION
0114 };
0115
0116 }}
0117
0118 #endif