inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_sg_mtx_action 00005 #define inlib_sg_mtx_action 00006 00007 #include "win_action" 00008 00009 #include "../mat4f" 00010 00011 namespace inlib { 00012 namespace sg { 00013 00014 class mtx_action : public win_action { 00015 public: 00016 mtx_action(std::ostream& a_out,unsigned int a_ww,unsigned int a_wh) 00017 : win_action(a_out,a_ww,a_wh) 00018 ,m_cur(0) 00019 { 00020 m_projs.resize(5); 00021 m_models.resize(5); 00022 m_projs[0].set_identity(); 00023 m_models[0].set_identity(); 00024 m_cur = 0; 00025 } 00026 virtual ~mtx_action(){} 00027 protected: 00028 mtx_action(const inlib::sg::mtx_action& a_from) 00029 : win_action(a_from) 00030 {} 00031 inlib::sg::mtx_action& operator=(const inlib::sg::mtx_action& a_from){ 00032 win_action::operator=(a_from); 00033 return *this; 00034 } 00035 public: 00036 void push_matrices() { 00037 if((m_cur+1)>=(int)m_projs.size()) { 00038 m_projs.resize(m_projs.size()+5); 00039 m_models.resize(m_models.size()+5); 00040 } 00041 m_cur++; 00042 m_projs[m_cur].set_matrix(m_projs[m_cur-1]); 00043 m_models[m_cur].set_matrix(m_models[m_cur-1]); 00044 } 00045 00046 //WARNING : in the three below methods, there is no 00047 // protection against m_cur<0 being zero here. 00048 void pop_matrices() {m_cur--;} 00049 inlib::mat4f& projection_matrix() {return m_projs[m_cur];} 00050 inlib::mat4f& model_matrix() {return m_models[m_cur];} 00051 00052 bool end() const {return m_cur==0?true:false;} 00053 00054 void reset() { 00055 m_projs[0].set_identity(); 00056 m_models[0].set_identity(); 00057 m_cur = 0; 00058 } 00059 00060 private: 00061 std::vector<inlib::mat4f> m_projs; 00062 std::vector<inlib::mat4f> m_models; 00063 int m_cur; 00064 }; 00065 00066 }} 00067 00068 #endif