Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
parameter-aimed-position.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"
28 #include "math-extension.hh"
29 #include <cassert>
30 #include <cstring>
31 using namespace std;
32 //******************************************************************************
34  CParameter(ANbRef)
35 {
36  reinit();
37 }
38 //******************************************************************************
41  CParameter(AParam),
42  FRotation (AParam.FRotation)
43 {
44  FLookAt[0] = AParam.FLookAt[0];
45  FLookAt[1] = AParam.FLookAt[1];
46  FLookAt[2] = AParam.FLookAt[2];
47 }
48 //******************************************************************************
50 {}
51 //******************************************************************************
53 { return new CParameterAimedPosition(*this); }
54 //******************************************************************************
55 void CParameterAimedPosition::save(ostream& AStream)
56 { AStream<<(*this); }
57 //------------------------------------------------------------------------------
58 void CParameterAimedPosition::load(istream& AStream)
59 { AStream>>(*this); }
60 //------------------------------------------------------------------------------
62 {
67 
69 }
70 //******************************************************************************
71 ostream& operator<<(ostream& AStream,
72  const CParameterAimedPosition & AParameter)
73 {
74  AStream<<"CParameterAimedPosition:"<<endl;
75 
76  AStream<<" Rotation: " <<AParameter.FRotation<<endl;
77 
78  AStream<<" LookAt: "<<AParameter.FLookAt[0]<<" "
79  <<AParameter.FLookAt[1]<<" "<<AParameter.FLookAt[2]<<endl;
80 
81  AStream<<endl;
82 
83  return AStream;
84 }
85 //------------------------------------------------------------------------------
86 istream& operator>>(istream& AStream,
87  CParameterAimedPosition & AParameter)
88 {
89  char tmp[256];
90 
91  AStream>>tmp; assert ( !strcmp(tmp, "CParameterAimedPosition:") );
92 
93  AStream>>tmp; assert ( !strcmp(tmp, "Rotation:") );
94  AStream>>AParameter.FRotation;
95 
96  AStream>>tmp; assert ( !strcmp(tmp, "LookAt:") );
97  AStream>>AParameter.FLookAt[0]>>AParameter.FLookAt[1]>>AParameter.FLookAt[2];
98 
99  AParameter.putAllNeedToUpdate();
100 
101  return AStream;
102 }
103 //******************************************************************************
105 { return FRotation; }
106 //------------------------------------------------------------------------------
108 {
109  if (! areEqual(FRotation, ARotation))
110  {
111  FRotation = ARotation;
113  }
114 }
115 //------------------------------------------------------------------------------
117 {
118  if (! isZero(ADelta))
119  {
120  FRotation += ADelta;
122  }
123 }
124 //******************************************************************************
125 float CParameterAimedPosition::getLookAt(int AIndice) const
126 {
127  assert(0<=AIndice && AIndice<=2);
128  return FLookAt[AIndice];
129 }
130 //------------------------------------------------------------------------------
131 void CParameterAimedPosition::setLookAt(int AIndice, float AValue)
132 {
133  assert(0<=AIndice && AIndice<=2);
134 
135  if (! areEqual(getLookAt(AIndice), AValue))
136  {
137  FLookAt[AIndice] = AValue;
139  }
140 }
141 //******************************************************************************
143 { return PARAMETER_AIMED_POSITION; }
144 //******************************************************************************