Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_text_hershey_marker 5 #define tools_sg_text_hershey_marker 6 7 #include "text_hershey" 8 9 namespace tools { 10 namespace sg { 11 12 class text_hershey_marker : public text_hershey { 13 TOOLS_NODE(text_hershey_marker,tools::sg::text_hershey_marker,text_hershey) 14 public: 15 virtual bool draw_in_frame_buffer() const {return true;} 16 17 virtual void render(render_action& a_action) { 18 //Same logic as Inventor SoLightModel.model = BASE_COLOR. 19 a_action.set_lighting(false); 20 a_action.set_depth_test(false); 21 22 float x,y,z; 23 a_action.projected_origin(x,y,z); 24 25 const state& state = a_action.state(); 26 27 float sy = 2.0f*float(height.value())/float(state.m_wh); //in [-1,1] 28 29 float old_height = height.value(); 30 height.value_no_cmp(sy); 31 32 std::vector<float> segs; 33 get_segments(segs); //must be after changing the height. 34 35 a_action.load_matrices_to_identity(); 36 37 {tools::mat4f _mtx; 38 _mtx.set_translate(x,y,0); 39 if(state.m_ww) _mtx.mul_scale(float(state.m_wh)/float(state.m_ww),1,1); 40 a_action.load_proj_matrix(_mtx);} 41 42 a_action.draw_vertex_array_xy(gl::lines(),segs); 43 44 a_action.load_matrices_from_state(); 45 46 height.value_no_cmp(old_height); 47 48 a_action.set_depth_test(state.m_GL_DEPTH_TEST); 49 a_action.set_lighting(a_action.state().m_GL_LIGHTING); 50 51 } 52 53 virtual void pick(pick_action& a_action) { 54 float x,y,z; 55 a_action.projected_origin(x,y,z); 56 57 const state& state = a_action.state(); 58 59 float sy = 2.0f*float(height.value())/float(state.m_wh); //in [-1,1] 60 61 float old_height = height.value(); 62 height.value_no_cmp(sy); 63 64 std::vector<float> segs; 65 get_segments(segs); 66 67 a_action.set_matrices_to_identity(); 68 69 {tools::mat4f& _mtx = a_action.model_matrix(); 70 _mtx.set_translate(x,y,0); 71 if(state.m_ww) _mtx.mul_scale(float(state.m_wh)/float(state.m_ww),1,1);} 72 73 a_action.add__lines_xy(*this,segs); 74 75 a_action.set_matrices_from_state(); 76 77 height.value_no_cmp(old_height); 78 } 79 80 virtual void bbox(bbox_action& a_action) { 81 a_action.add_one_point(0,0,0); 82 } 83 public: 84 text_hershey_marker() 85 :parent() 86 { 87 height = 10; //in pixels 88 } 89 virtual ~text_hershey_marker(){} 90 public: 91 text_hershey_marker(const text_hershey_marker& a_from) 92 :parent(a_from) 93 {} 94 text_hershey_marker& operator=(const text_hershey_marker& a_from){ 95 parent::operator=(a_from); 96 return *this; 97 } 98 }; 99 100 }} 101 102 #endif