Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
precompile-grid.cc
Go to the documentation of this file.
1 /*
2  * lib-controler : Un contrôleur générique de scène 3D.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-controler
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include "controler-types.hh"
26 #include "precompile-grid.hh"
27 #include <cassert>
28 //******************************************************************************
30  FParameterGrid(AParameterGrid)
31 {
32  assert(FParameterGrid!=NULL);
33  FParameterGrid->addPrecompileToUpdate(this);
34 }
35 //******************************************************************************
37  CPrecompile (APrecompile),
38  FParameterGrid(static_cast<CParameterGrid*>
39  (APrecompile.FParameterGrid->copy()))
40 {
41  assert(FParameterGrid!=NULL);
42  FParameterGrid->addPrecompileToUpdate(this);
43 }
44 //******************************************************************************
46 {
47  FParameterGrid->removePrecompileToUpdate(this);
48 }
49 //******************************************************************************
51 { return new CPrecompileGrid(*this); }
52 //******************************************************************************
54 {
55  switch (AParameter->getType())
56  {
57  case PARAMETER_GRID:
58  setGrid(static_cast<CParameterGrid *>(AParameter));
59  break;
60  }
61 }
62 //******************************************************************************
64 { return FParameterGrid; }
65 //******************************************************************************
67 {
68  assert(AGrid != NULL);
69  AGrid->addPrecompileToUpdate(this);
70  FParameterGrid->removePrecompileToUpdate(this);
71  FParameterGrid = AGrid;
72  setToUpdate();
73 }
74 //******************************************************************************
76 { return PRECOMPILE_GRID; }
77 //******************************************************************************
79 {
80  int size= FParameterGrid->getLGGrid();
81  bool xy = FParameterGrid->getDisplayGridXY();
82  bool xz = FParameterGrid->getDisplayGridXZ();
83  bool yz = FParameterGrid->getDisplayGridYZ();
84  bool px = FParameterGrid->getDisplayPositiveGridX();
85  bool py = FParameterGrid->getDisplayPositiveGridY();
86  bool pz = FParameterGrid->getDisplayPositiveGridZ();
87  int xmin= px ? 0 : -size;
88  int ymin= py ? 0 : -size;
89  int zmin= pz ? 0 : -size;
90 
91  glLineWidth(FParameterGrid->getLWGrid());
92 
93  glBegin(GL_LINES);
94 
95  glColor3fv(FParameterGrid->getCLGrid());
96 
97  for (int i=-size; i<=+size; ++i)
98  {
99  if (xy)
100  {
101  /* X direction: */
102  if (i>=0 || !py) { glVertex3f(xmin, i, 0); glVertex3f(size, i, 0); }
103  /* Y direction: */
104  if (i>=0 || !px) { glVertex3f(i, ymin, 0); glVertex3f(i, size, 0); }
105  }
106  if (xz)
107  {
108  /* X direction: */
109  if (i>=0 || !pz) { glVertex3f(xmin, 0, i); glVertex3f(size, 0, i); }
110  /* Z direction: */
111  if (i>=0 || !px) { glVertex3f(i, 0, zmin); glVertex3f(i, 0, size); }
112  }
113  if (yz)
114  {
115  /* Y direction: */
116  if (i>=0 || !pz) { glVertex3f(0, ymin, i); glVertex3f(0, size, i); }
117  /* Z direction: */
118  if (i>=0 || !py) { glVertex3f(0, i, zmin); glVertex3f(0, i, size); }
119  }
120  }
121 
122  glEnd();
123 }
124 //******************************************************************************