g4tools  5.4.0
text_hershey_marker
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_text_hershey_marker
5 #define tools_sg_text_hershey_marker
6 
7 #include "text_hershey"
8 
9 namespace tools {
10 namespace sg {
11 
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  {std::vector<float>::iterator it;
38  for(it=segs.begin();it!=segs.end();) {
39  *it += x;it++; //Android don't like *it++.
40  *it += y;it++;
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 
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  {std::vector<float>::iterator it;
70  for(it=segs.begin();it!=segs.end();) {
71  *it += x;it++;
72  *it += y;it++;
73  }}
74 
75  a_action.add__lines_xy(*this,segs);
76 
77  a_action.set_matrices_from_state();
78 
79  height.value_no_cmp(old_height);
80  }
81 
82  virtual void bbox(bbox_action& a_action) {
83  a_action.add_one_point(0,0,0);
84  }
85 public:
87  :parent()
88  {
89  height = 10; //in pixels
90  }
92 public:
94  :parent(a_from)
95  {}
97  parent::operator=(a_from);
98  return *this;
99  }
100 };
101 
102 }}
103 
104 #endif
tools::sg::text_hershey_marker::draw_in_frame_buffer
virtual bool draw_in_frame_buffer() const
Definition: text_hershey_marker:15
tools::sg::state
Definition: state:25
tools::sg::render_action::set_lighting
virtual void set_lighting(bool)=0
tools::sg::state::m_GL_LIGHTING
bool m_GL_LIGHTING
Definition: state:248
tools::sg::state::m_GL_DEPTH_TEST
bool m_GL_DEPTH_TEST
Definition: state:247
tools::sg::text_hershey_marker
Definition: text_hershey_marker:12
tools::sg::base_text::height
sf< float > height
Definition: base_text:30
tools::sg::text_hershey_marker::bbox
virtual void bbox(bbox_action &a_action)
Definition: text_hershey_marker:82
tools::sg::node
Definition: node:28
tools::gl::lines
mode_t lines()
Definition: glprims:17
tools::sg::bbox_action
Definition: bbox_action:15
TOOLS_NODE
#define TOOLS_NODE(a__class, a__sclass, a__parent)
Definition: node:324
tools::sg::primitive_visitor::add_one_point
void add_one_point(float a_x, float a_y, float a_z)
Definition: primitive_visitor:63
tools::sg::text_hershey_marker::pick
virtual void pick(pick_action &a_action)
Definition: text_hershey_marker:53
tools::sg::pick_action::set_matrices_from_state
void set_matrices_from_state()
Definition: pick_action:330
tools::sg::text_hershey
Definition: text_hershey:82
tools::sg::node::operator=
node & operator=(const node &)
Definition: node:124
tools::sg::text_hershey_marker::text_hershey_marker
text_hershey_marker(const text_hershey_marker &a_from)
Definition: text_hershey_marker:93
tools::sg::pick_action
Definition: pick_action:59
tools::sg::bsf::value_no_cmp
void value_no_cmp(const T &a_value)
Definition: bsf:104
tools::sg::pick_action::set_matrices_to_identity
void set_matrices_to_identity()
Definition: pick_action:326
tools::sg::state::m_wh
unsigned int m_wh
Definition: state:242
tools::sg::text_hershey_marker::render
virtual void render(render_action &a_action)
Definition: text_hershey_marker:17
tools::sg::render_action
Definition: render_action:24
tools::sg::pick_action::add__lines_xy
bool add__lines_xy(sg::node &a_node, const std::vector< float > &a_xys, bool a_stop=false)
Definition: pick_action:407
tools::sg::text_hershey_marker::~text_hershey_marker
virtual ~text_hershey_marker()
Definition: text_hershey_marker:91
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::render_action::draw_vertex_array_xy
virtual void draw_vertex_array_xy(gl::mode_t, size_t, const float *)=0
tools::sg::render_action::set_depth_test
virtual void set_depth_test(bool)=0
tools::sg::matrix_action::projected_origin
void projected_origin(float &a_x, float &a_y, float &a_z)
Definition: matrix_action:101
tools::sg::text_hershey_marker::text_hershey_marker
text_hershey_marker()
Definition: text_hershey_marker:86
tools::sg::render_action::load_matrices_from_state
void load_matrices_from_state()
Definition: render_action:95
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::states::state
const sg::state & state() const
Definition: states:76
text_hershey
tools::sg::render_action::load_matrices_to_identity
void load_matrices_to_identity()
Definition: render_action:91
tools::sg::text_hershey::get_segments
void get_segments(std::vector< float > &a_segs) const
Definition: text_hershey:290
tools::sg::text_hershey_marker::operator=
text_hershey_marker & operator=(const text_hershey_marker &a_from)
Definition: text_hershey_marker:96