g4tools  5.4.0
matrix
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
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 {
21 public:
23 public:
24  virtual const desc_fields& node_desc_fields() const {
26  static const desc_fields s_v(parent::node_desc_fields(),1, //WARNING : take care of count.
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(),m_tmp);
38  a_action.state().m_model = a_action.model_matrix();
39  a_action.load_model_matrix(a_action.model_matrix());
40  }
41  virtual void pick(pick_action& a_action) {
42  a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
43  a_action.state().m_model = a_action.model_matrix();
44  }
45  virtual void bbox(bbox_action& a_action) {
46  a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
47  a_action.state().m_model = a_action.model_matrix();
48  }
49  virtual void event(event_action& a_action) {
50  a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
51  a_action.state().m_model = a_action.model_matrix();
52  }
53  virtual void get_matrix(get_matrix_action& a_action) {
54  a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
55  a_action.state().m_model = a_action.model_matrix();
56  }
57  virtual void is_visible(visible_action& a_action) {
58  a_action.model_matrix().mul_mtx(mtx.value(),m_tmp);
59  a_action.state().m_model = a_action.model_matrix();
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),mtx(a_from.mtx) {
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 :
89 
90  void set_translate(float a_x,float a_y,float a_z) {mtx.set_translate(a_x,a_y,a_z);}
91  void set_translate(const vec3f& a_v) {mtx.set_translate(a_v);}
92 
93  void set_scale(float a_x,float a_y,float a_z) {mtx.set_scale(a_x,a_y,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_z,float a_angle) {mtx.set_rotate(a_x,a_y,a_z,a_angle);}
97  void set_rotate(const vec3f& a_v,float a_angle) {mtx.set_rotate(a_v,a_angle);}
98  bool set_rotate(const vec3f& a_from,const vec3f& a_to) {return mtx.set_rotate(a_from,a_to,m_tmp);}
99 
100  void mul_mtx(const mat4f& a_m) {mtx.mul_mtx(a_m,m_tmp);}
101 
102  void mul_translate(float a_x,float a_y,float a_z) {mtx.mul_translate(a_x,a_y,a_z);}
103  void mul_translate(const vec3f& a_v) {mtx.mul_translate(a_v);}
104  void mul_scale(float a_x,float a_y,float a_z) {mtx.mul_scale(a_x,a_y,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_z,float a_angle) {mtx.mul_rotate(a_x,a_y,a_z,a_angle);}
108 
109  void mul_rotate(const vec3f& a_v,float a_angle) {mtx.mul_rotate(a_v,a_angle);}
110  void mul_rotate(const vec4f& a_v) {mtx.mul_rotate(a_v.v0(),a_v.v1(),a_v.v2(),a_v.v3());}
111 
112  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);}
113 
114  void left_mul_scale(float a_x,float a_y,float a_z) {mtx.left_mul_scale(a_x,a_y,a_z);}
115 
116  void left_mul_translate(float a_x,float a_y,float a_z) {mtx.left_mul_translate(a_x,a_y,a_z);}
117 
119 
120  bool mul_rotate(const vec3f& a_from,const vec3f& a_to) {return mtx.mul_rotate(a_from,a_to,m_tmp);}
121 protected:
122  float m_tmp[16]; //OPTIMIZATION
123 };
124 
125 }}
126 
127 #endif
node
tools::vec4::v1
const T & v1() const
Definition: vec4:86
tools::sg::matrix::mul_rotate
void mul_rotate(float a_x, float a_y, float a_z, float a_angle)
Definition: matrix:107
sf_mat4f
tools::sg::matrix::mul_rotate
void mul_rotate(const vec4f &a_v)
Definition: matrix:110
tools::sg::sf_mat4f::left_mul_scale
void left_mul_scale(float a_x, float a_y, float a_z)
Definition: sf_mat4f:103
tools::sg::matrix_action::model_matrix
mat4f & model_matrix()
Definition: matrix_action:73
tools::sg::event_action
Definition: event_action:14
pick_action
tools::sg::matrix::mul_mtx
void mul_mtx(const mat4f &a_m)
Definition: matrix:100
render_action
tools::sg::node
Definition: node:28
tools::sg::bbox_action
Definition: bbox_action:15
tools::sg::matrix::set_translate
void set_translate(float a_x, float a_y, float a_z)
Definition: matrix:90
tools::sg::sf_mat4f::left_mul_rotate
void left_mul_rotate(float a_x, float a_y, float a_z, float a_angle)
Definition: sf_mat4f:98
TOOLS_NODE
#define TOOLS_NODE(a__class, a__sclass, a__parent)
Definition: node:324
tools::sg::matrix::left_mul_translate
void left_mul_translate(float a_x, float a_y, float a_z)
Definition: matrix:116
tools::sg::sf_mat4f::mul_scale
void mul_scale(float a_x, float a_y, float a_z)
Definition: sf_mat4f:79
event_action
tools::sg::sf_mat4f::left_mul_translate
void left_mul_translate(float a_x, float a_y, float a_z)
Definition: sf_mat4f:108
tools::sg::matrix::matrix
matrix()
Definition: matrix:62
tools::sg::matrix::get_matrix
virtual void get_matrix(get_matrix_action &a_action)
Definition: matrix:53
tools::sg::matrix::set_identity
void set_identity()
Definition: matrix:88
tools::sg::sf_mat4f::set_translate
void set_translate(float a_x, float a_y, float a_z)
Definition: sf_mat4f:41
tools::sg::desc_fields
Definition: field_desc:148
tools::sg::sf_mat4f::set_rotate
void set_rotate(float a_x, float a_y, float a_z, float a_angle)
Definition: sf_mat4f:57
tools::sg::matrix::m_tmp
float m_tmp[16]
Definition: matrix:122
tools::sg::matrix::set_scale
void set_scale(float a_s)
Definition: matrix:94
tools::sg::matrix::is_visible
virtual void is_visible(visible_action &a_action)
Definition: matrix:57
tools::sg::matrix::left_mul_translate
void left_mul_translate(const vec3f &a_v)
Definition: matrix:118
tools::sg::pick_action
Definition: pick_action:59
tools::sg::matrix::set_rotate
bool set_rotate(const vec3f &a_from, const vec3f &a_to)
Definition: matrix:98
tools::sg::sf_mat4f
Definition: sf_mat4f:18
tools::vec4::v0
const T & v0() const
Definition: vec4:85
tools::sg::matrix::set_scale
void set_scale(float a_x, float a_y, float a_z)
Definition: matrix:93
tools::sg::sf_mat4f::mul_mtx
void mul_mtx(const mat4f &a_m, float a_tmp[])
Definition: sf_mat4f:66
tools::sg::matrix::mul_scale
void mul_scale(float a_s)
Definition: matrix:105
tools::sg::matrix::left_mul_rotate
void left_mul_rotate(float a_x, float a_y, float a_z, float a_angle)
Definition: matrix:112
tools::sg::matrix::mul_rotate
bool mul_rotate(const vec3f &a_from, const vec3f &a_to)
Definition: matrix:120
tools::vec3f
Definition: vec3f:13
tools::sg::render_action
Definition: render_action:24
tools::vec4::v2
const T & v2() const
Definition: vec4:87
tools::sg::matrix::render
virtual void render(render_action &a_action)
Definition: matrix:36
tools::sg::sf_mat4f::mul_rotate
void mul_rotate(float a_x, float a_y, float a_z, float a_angle)
Definition: sf_mat4f:88
visible_action
tools::sg::matrix::set_rotate
void set_rotate(float a_x, float a_y, float a_z, float a_angle)
Definition: matrix:96
tools::sg::matrix::mul_translate
void mul_translate(const vec3f &a_v)
Definition: matrix:103
tools::sg::matrix::event
virtual void event(event_action &a_action)
Definition: matrix:49
tools::sg::get_matrix_action
Definition: get_matrix_action:17
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::matrix::mtx
sf_mat4f mtx
Definition: matrix:22
tools::sg::node::add_field
void add_field(field *a_field)
Definition: node:128
tools::sg::matrix
Definition: matrix:19
tools::sg::matrix::set_rotate
void set_rotate(const vec3f &a_v, float a_angle)
Definition: matrix:97
tools::sg::matrix::matrix
matrix(const matrix &a_from)
Definition: matrix:75
tools::sg::matrix::set_translate
void set_translate(const vec3f &a_v)
Definition: matrix:91
tools::sg::matrix::bbox
virtual void bbox(bbox_action &a_action)
Definition: matrix:45
tools::sg::state::m_model
mat4f m_model
Definition: state:245
tools::sg::matrix::mul_translate
void mul_translate(float a_x, float a_y, float a_z)
Definition: matrix:102
tools::mat4f
Definition: mat4f:12
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
tools::sg::matrix::mul_rotate
void mul_rotate(const vec3f &a_v, float a_angle)
Definition: matrix:109
tools::vec4::v3
const T & v3() const
Definition: vec4:88
tools::sg::sf_mat4f::set_scale
void set_scale(float a_x, float a_y, float a_z)
Definition: sf_mat4f:49
tools::sg::matrix::~matrix
virtual ~matrix()
Definition: matrix:69
tools::sg::render_action::load_model_matrix
virtual void load_model_matrix(const mat4f &)=0
tools::sg::matrix::pick
virtual void pick(pick_action &a_action)
Definition: matrix:41
tools::sg::sf_mat4f::mul_translate
void mul_translate(float a_x, float a_y, float a_z)
Definition: sf_mat4f:71
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::matrix::left_mul_scale
void left_mul_scale(float a_x, float a_y, float a_z)
Definition: matrix:114
tools::sg::matrix::mul_scale
void mul_scale(float a_x, float a_y, float a_z)
Definition: matrix:104
tools::sg::matrix::operator=
matrix & operator=(const matrix &a_from)
Definition: matrix:81
tools::sg::states::state
const sg::state & state() const
Definition: states:76
tools::sg::visible_action
Definition: visible_action:12
tools::sg::matrix::node_desc_fields
virtual const desc_fields & node_desc_fields() const
Definition: matrix:24
tools::sg::sf_mat4f::set_identity
void set_identity()
Definition: sf_mat4f:37
tools::vec4f
Definition: vec4f:13
TOOLS_ARG_FIELD_DESC
#define TOOLS_ARG_FIELD_DESC(a__field)
Definition: field:71
bbox_action