Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
controler-operations.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.hh"
26 #include "operations.hh"
27 #include "view-precompile.hh"
28 
29 #include <cassert>
30 #include <cstring>
31 using namespace std;
32 //******************************************************************************
34 {
35  return true;
36 }
37 //******************************************************************************
39 {
40  return false;
41 }
42 //******************************************************************************
43 #ifdef NO_ACCENTED_CHARS
44 char CControler::unaccent(char AChar) const
45 {
46  static const char* from = "àâÀÂéèëêÉÈËÊîïÎÏôÔùûÙÛ";
47  static const char* to = "aaAAeeeeEEEEiiIIoOuuUU";
48 
49  char* pos = strchr(from, AChar);
50 
51  if (pos != NULL)
52  return * (to - from + pos);
53 
54  return AChar;
55 }
56 #endif // NO_ACCENTED_CHARS
57 
58 string CControler::treatAccent(const string& AString) const
59 {
60  string result = AString;
61 
62 #ifdef NO_ACCENTED_CHARS
63  for (unsigned int i=0; i<result.length(); ++i)
64  result[i] = unaccent(result[i]);
65 
66 #endif // NO_ACCENTED_CHARS
67 
68  return result;
69 }
70 
71 string CControler::getMessage() const
72 {
73  return treatAccent(FMessage);
74 }
75 //******************************************************************************
76 void CControler::setMessage(const string & AMessage)
77 { FMessage = AMessage; }
78 //******************************************************************************
79 void CControler::setMessage(int ANumber, const string & AMessage)
80 {
81  stringstream s;
82  s<<ANumber<<AMessage;
83  setMessage(s.str());
84 }
85 //******************************************************************************
86 void CControler::setMessage(int ANumber1, int ANumber2, const string & AMessage)
87 {
88  stringstream s;
89  s<<ANumber1<<" "<<ANumber2<<AMessage;
90  setMessage(s.str());
91 }
92 //******************************************************************************
93 void CControler::setMessage(const string & AMessage1, int ANumber,
94  const string & AMessage2)
95 {
96  stringstream s;
97  s<<AMessage1<<ANumber<<AMessage2;
98  setMessage(s.str());
99 }
100 //******************************************************************************
102 {
106  return true;
107 }
108 //******************************************************************************
109 bool CControler::lookAtMouseClick(TViewId AView, int x, int y)
110 {
111  CViewPrecompile * view = FViews[AView];
112 
113  if (view != NULL)
114  {
115  float res[3];
116  view -> unproject(x,y,res);
117 
119  aimed_pos -> setLookAt(0,res[0]);
120  aimed_pos -> setLookAt(1,res[1]);
121  aimed_pos -> setLookAt(2,res[2]);
122  return true;
123  }
124  return false;
125 }
126 //******************************************************************************