g4tools  5.4.0
color
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_color
5 #define tools_sg_color
6 
7 #include "node"
8 
9 #include "sf_vec"
10 #include "render_action"
11 #include "../colorf"
12 
13 namespace tools {
14 namespace sg {
15 
16 class color : public node {
18 public:
20  sf<float> transparency; //alpha=1-transparency. Opaque is transparency=0.
21 public:
22  virtual const desc_fields& node_desc_fields() const {
24  static const desc_fields s_v(parent::node_desc_fields(),2, //WARNING : take care of count.
27  );
28  return s_v;
29  }
30 private:
31  void add_fields(){
32  add_field(&rgb);
34  }
35 public:
36  virtual void render(render_action& a_action) {
37  // GL-ES : ::glMaterialfv does not work. We then use :
38  // ::glEnable(GL_COLOR_MATERIAL) and ::glColor.
39 
40  //if(a_action.state().m_GL_LIGHTING) {
41  // float params[4];
42  // params[0] = rgb.value().r();
43  // params[1] = rgb.value().g();
44  // params[2] = rgb.value().b();
45  // params[3] = 1-transparency.value();
46  // ::glMaterialfv(GL_FRONT,GL_DIFFUSE,params);
47  //} else {
48  //}
49 
50  state& state = a_action.state();
51  state.m_color[0] = rgb.value().r();
52  state.m_color[1] = rgb.value().g();
53  state.m_color[2] = rgb.value().b();
55  a_action.color4f(state.m_color);
56  }
57 public:
59  :parent()
61  ,transparency(0.0f)
62  {
63  add_fields();
64  }
65  virtual ~color(){}
66 public:
67  color(const color& a_from)
68  :parent(a_from)
69  ,rgb(a_from.rgb)
70  ,transparency(a_from.transparency)
71  {
72  add_fields();
73  }
74  color& operator=(const color& a_from){
75  parent::operator=(a_from);
76 
77  rgb = a_from.rgb;
78  transparency = a_from.transparency;
79 
80  return *this;
81  }
82 };
83 
84 }}
85 
86 #endif
node
tools::sg::state
Definition: state:25
tools::sg::color::render
virtual void render(render_action &a_action)
Definition: color:36
render_action
tools::colorf_default
const colorf & colorf_default()
Definition: colorf:161
tools::sg::node
Definition: node:28
TOOLS_NODE
#define TOOLS_NODE(a__class, a__sclass, a__parent)
Definition: node:324
tools::sg::desc_fields
Definition: field_desc:148
tools::sg::render_action::color4f
virtual void color4f(float, float, float, float)=0
tools::sg::color::color
color()
Definition: color:58
tools::sg::color
Definition: color:16
tools::sg::color::transparency
sf< float > transparency
Definition: color:20
tools::sg::color::~color
virtual ~color()
Definition: color:65
tools::sg::sf_vec
Definition: sf_vec:15
tools::sg::color::color
color(const color &a_from)
Definition: color:67
tools::sg::color::operator=
color & operator=(const color &a_from)
Definition: color:74
sf_vec
tools::sg::render_action
Definition: render_action:24
tools::sg::color::node_desc_fields
virtual const desc_fields & node_desc_fields() const
Definition: color:22
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::node::add_field
void add_field(field *a_field)
Definition: node:128
tools::sg::color::rgb
sf_vec< colorf, float > rgb
Definition: color:19
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::state::m_color
colorf m_color
Definition: state:259
tools::sg::states::state
const sg::state & state() const
Definition: states:76
tools::sg::sf< float >
TOOLS_ARG_FIELD_DESC
#define TOOLS_ARG_FIELD_DESC(a__field)
Definition: field:71