Warning, /include/Geant4/tools/sg/matrix_action 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_action
0005 #define tools_sg_matrix_action
0006
0007 #include "win_action"
0008
0009 #include "../lina/mat4f"
0010 #include "states"
0011
0012 namespace tools {
0013 namespace sg {
0014
0015 class matrix_action : public win_action,public states {
0016 TOOLS_ACTION(matrix_action,tools::sg::matrix_action,win_action)
0017 public:
0018 matrix_action(std::ostream& a_out,unsigned int a_ww,unsigned int a_wh)
0019 :parent(a_out,a_ww,a_wh)
0020 ,states(a_ww,a_wh)
0021 ,m_cur(0)
0022 ,m_landscape(true)
0023 {
0024 m_projs.resize(5);
0025 m_models.resize(5);
0026 reset();
0027 m_identity.set_identity();
0028 }
0029 virtual ~matrix_action(){}
0030 public:
0031 matrix_action(const matrix_action& a_from)
0032 :parent(a_from)
0033 ,states(a_from)
0034 ,m_projs(a_from.m_projs)
0035 ,m_models(a_from.m_models)
0036 ,m_cur(a_from.m_cur)
0037 ,m_landscape(a_from.m_landscape)
0038 {
0039 m_identity.set_identity();
0040 }
0041 matrix_action& operator=(const matrix_action& a_from){
0042 parent::operator=(a_from);
0043 states::operator=(a_from);
0044 m_projs = a_from.m_projs;
0045 m_models = a_from.m_models;
0046 m_cur = a_from.m_cur;
0047 m_landscape = a_from.m_landscape;
0048 return *this;
0049 }
0050 public:
0051 void push_matrices() {
0052 if((m_cur+1)>=(int)m_projs.size()) {
0053 m_projs.resize(m_projs.size()+5);
0054 m_models.resize(m_models.size()+5);
0055 }
0056 m_cur++;
0057 m_projs[m_cur].set_matrix(m_projs[m_cur-1]);
0058 m_models[m_cur].set_matrix(m_models[m_cur-1]);
0059 //OPTIMIZATION : in fact the two lines below are not needed !
0060 // m_state.m_proj = m_projs[m_cur];
0061 // m_state.m_model = m_models[m_cur];
0062 }
0063
0064 //WARNING : in the three below methods, there is no
0065 // protection against m_cur<0 being zero here.
0066 void pop_matrices() {
0067 m_cur--;
0068 //OPTIMIZATION : in fact the two lines below are not needed !
0069 // m_state.m_proj = m_projs[m_cur];
0070 // m_state.m_model = m_models[m_cur];
0071 }
0072 mat4f& projection_matrix() {return m_projs[m_cur];}
0073 mat4f& model_matrix() {return m_models[m_cur];}
0074
0075 bool end() const {return m_cur==0?true:false;}
0076 int cur() const {return m_cur;}
0077
0078 bool project_point(float& a_x,float& a_y,float& a_z,float& a_w) {
0079 a_w = 1;
0080 model_matrix().mul_4f(a_x,a_y,a_z,a_w);
0081 projection_matrix().mul_4f(a_x,a_y,a_z,a_w);
0082 if(a_w==0.0F) return false;
0083 a_x /= a_w;
0084 a_y /= a_w;
0085 a_z /= a_w;
0086 return true;
0087 }
0088
0089 // bool project_normal(float& a_x,float& a_y,float& a_z) {
0090 // model_matrix().mul_dir_3f(a_x,a_y,a_z);
0091 // projection_matrix().mul_dir_3f(a_x,a_y,a_z);
0092 // return true;
0093 // }
0094
0095 void model_point(float& a_x,float& a_y,float& a_z,float& a_w) {
0096 a_w = 1;
0097 model_matrix().mul_4f(a_x,a_y,a_z,a_w);
0098 }
0099
0100 // for marker rendering :
0101 void projected_origin(float& a_x,float& a_y,float& a_z) {
0102 a_x = 0;
0103 a_y = 0;
0104 a_z = 0;
0105 float w;
0106 project_point(a_x,a_y,a_z,w); //if render : in [-1,1][-1,1]
0107 }
0108
0109 protected:
0110 void reset() {
0111 m_cur = 0;
0112 if(m_landscape) {
0113 m_projs[m_cur].set_identity();
0114 } else {
0115 m_projs[m_cur].set_matrix(0,-1,0,0,
0116 1, 0,0,0,
0117 0, 0,1,0,
0118 0, 0,0,1);
0119 }
0120 m_models[m_cur].set_identity();
0121 sg::state& _state = state();
0122 _state.m_proj = m_projs[m_cur];
0123 _state.m_model = m_models[m_cur];
0124 }
0125 protected:
0126 std::vector<mat4f> m_projs;
0127 std::vector<mat4f> m_models;
0128 int m_cur;
0129 mat4f m_identity;
0130 private:
0131 bool m_landscape; //false not yet ready.
0132 };
0133
0134 }}
0135
0136 #endif