Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SceneGridGround.cpp
1 #include <GLviewer/Scenes/SceneGridGround.hh>
2 #include <GLviewer/GLProjectionParametersInterface.hh>
3 
4 using namespace BIAS;
5 
7 SceneGridGround(double from, double to, double gridSize, double z)
8 {
9  Resize(from,to,gridSize,z);
10  colorR_ = 0.4;
11  colorG_ = 0.4;
12  colorB_ = 0.4;
13  xyPlane_ = true;
14 }
15 
17 {
18 }
19 
21 Resize(double from, double to, double gridSize, double z)
22 {
23  from_ = from;
24  to_ = to;
25  gridSize_ = gridSize;
26  z_ = z;
27 
28  // Make a bounding box to fit the grid for any rotation
29  const double extent = fabs(z);
30  boundingBoxMin_= Vector3<double>(from - extent, from - extent, from - extent);
31  boundingBoxMax_= Vector3<double>(to + extent, to + extent, to + extent);
32 }
33 
36 {
37  minVal = boundingBoxMin_;
38  maxVal = boundingBoxMax_;
39 }
40 
41 void SceneGridGround::SetColor(float r, float g, float b)
42 {
43  colorR_ = r;
44  colorG_ = g;
45  colorB_ = b;
46 }
47 
49 {
50  xyPlane_ = xyplane;
51 }
52 
54 {
55  glPushAttrib(GL_LIGHTING);
56  glDisable(GL_LIGHTING);
57 
58  if (!xyPlane_) {
59  glMatrixMode(GL_MODELVIEW);
60  glPushMatrix();
61  // multiply with 90 degree rotation around x axis
62  double m[16];
63  memset((void*)m, 0, 16*sizeof(double));
64  m[0] = 1; m[6] = 1; m[9] = -1; m[15] = 1;
65  glMultMatrixd(m);
66  }
68  Vector4<float> bgcolor;
69  if (glcam != NULL)
70  bgcolor = glcam->GetClearColor();
71  else
72  bgcolor = Vector4<float>(0.0,0.0,0.0,0.0);
73 
74  // Draw the funky ground grid
75  double col;
76  glBegin(GL_LINES);
77  for (float x = from_; x < to_; x += gridSize_) {
78  for (float y = from_; y < to_; y += gridSize_) {
79  // Draw the x and y (or z) axes at the center
80  if (x == 0 && y == 0) {
81  glColor3f(1.0,0.0,0.0); // draw x axis
82  glVertex3f(x,y,z_);
83  glVertex3f(x+gridSize_,y,z_);
84  if (xyPlane_)
85  glColor3f(0.0,1.0,0.0); // draw y axis
86  else
87  glColor3f(0.0,0.0,1.0); // draw z axis
88  glVertex3f(x,y,z_);
89  glVertex3f(x,y+gridSize_,z_);
90  } else {
91  col = 1.0 - sqrt((x+gridSize_)*(x+gridSize_)+y*y) / (to_-from_ )*2.0;
92  if (col < 0.0) col = 0.0;
93  glColor3f(col*colorR_+(1.0-col)*bgcolor[0],
94  col*colorG_+(1.0-col)*bgcolor[1],
95  col*colorB_+(1.0-col)*bgcolor[2]);
96  glVertex3f(x+gridSize_,y,z_);
97  col = 1.0 - sqrt(x*x+y*y) / (to_-from_ )*2.0; // / (to_-from_ )*0.2;
98  if (col < 0.0) col = 0.0;
99  glColor3f(col*colorR_+(1.0-col)*bgcolor[0],
100  col*colorG_+(1.0-col)*bgcolor[1],
101  col*colorB_+(1.0-col)*bgcolor[2]);
102  glVertex3f(x,y,z_);
103  glVertex3f(x,y,z_);
104  col = 1.0 - sqrt(x*x+(y+gridSize_)*(y+gridSize_)) / (to_-from_ )*2.0;
105  if (col < 0.0) col = 0.0;
106  glColor3f(col*colorR_+(1.0-col)*bgcolor[0],
107  col*colorG_+(1.0-col)*bgcolor[1],
108  col*colorB_+(1.0-col)*bgcolor[2]);
109  glVertex3f(x,y+gridSize_,z_);
110  }
111  }
112  }
113  glEnd();
114 
115  if (!xyPlane_) {
116  glPopMatrix();
117  }
118  glPopAttrib(); // GL_LIGHTING
119 }
virtual void GetBoundingBox(BIAS::Vector3< double > &minVal, BIAS::Vector3< double > &maxVal)
Implementation of the SceneBase GetBoundingBox method.
virtual BIAS::Vector4< float > GetClearColor()=0
Abstract interface class to handle changes in rendering parameters by controllers and in rendering co...
virtual void Draw()
Implementation of the SceneBase Draw method.
SceneGridGround(double from=-1000.0, double to=1000.0, double gridSize=50.0, double z=0.0)
Create a square grid ground from position (from, from, z) to position (to, to, z) at constant z value...
void DrawInXYPlane(bool xyplane)
Specify if grid ground is parallel to x/y plane or x/z plane.
virtual GLProjectionParametersInterface * GetGLProjectionParametersInterface()
Get the camera as projectionparametersinterface, can be of type GLProjection of of any from GLProject...
Definition: SceneBase.hh:85
void Resize(double from=-1000.0, double to=1000.0, double gridSize=50.0, double z=0.0)
Initialize the square ground.
void SetColor(float r, float g, float b)
Set the color of the grid ground.
BIAS::Vector3< double > boundingBoxMin_
BIAS::Vector3< double > boundingBoxMax_