00001 /* 00002 * lib-controler : Un contrôleur générique de scène 3D. 00003 * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC 00004 * http://www.sic.sp2mi.univ-poitiers.fr/ 00005 * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS, 00006 * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/ 00007 * 00008 * This file is part of lib-controler 00009 * 00010 * This program is free software: you can redistribute it and/or modify 00011 * it under the terms of the GNU Lesser General Public License as published by 00012 * the Free Software Foundation, either version 3 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public License 00021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 //****************************************************************************** 00025 #include "controler-types.hh" 00026 #include "parameters-default-values.hh" 00027 #include "parameter-aimed-position.hh" 00028 #include "math-extension.hh" 00029 #include <cassert> 00030 #include <cstring> 00031 using namespace std; 00032 //****************************************************************************** 00033 CParameterAimedPosition::CParameterAimedPosition(int ANbRef) : 00034 CParameter(ANbRef) 00035 { 00036 reinit(); 00037 } 00038 //****************************************************************************** 00039 CParameterAimedPosition:: 00040 CParameterAimedPosition(const CParameterAimedPosition & AParam) : 00041 CParameter(AParam), 00042 FRotation (AParam.FRotation) 00043 { 00044 FLookAt[0] = AParam.FLookAt[0]; 00045 FLookAt[1] = AParam.FLookAt[1]; 00046 FLookAt[2] = AParam.FLookAt[2]; 00047 } 00048 //****************************************************************************** 00049 CParameterAimedPosition::~CParameterAimedPosition() 00050 {} 00051 //****************************************************************************** 00052 CParameter * CParameterAimedPosition::copy() const 00053 { return new CParameterAimedPosition(*this); } 00054 //****************************************************************************** 00055 void CParameterAimedPosition::save(ostream& AStream) 00056 { AStream<<(*this); } 00057 //------------------------------------------------------------------------------ 00058 void CParameterAimedPosition::load(istream& AStream) 00059 { AStream>>(*this); } 00060 //------------------------------------------------------------------------------ 00061 void CParameterAimedPosition::reinit() 00062 { 00063 FRotation = DEFAULT_AIMED_POSITION_ROTATION; 00064 FLookAt[0] = DEFAULT_AIMED_POSITION_LOOK_AT_X; 00065 FLookAt[1] = DEFAULT_AIMED_POSITION_LOOK_AT_Y; 00066 FLookAt[2] = DEFAULT_AIMED_POSITION_LOOK_AT_Z; 00067 00068 putAllNeedToUpdate(); 00069 } 00070 //****************************************************************************** 00071 ostream& operator<<(ostream& AStream, 00072 const CParameterAimedPosition & AParameter) 00073 { 00074 AStream<<"CParameterAimedPosition:"<<endl; 00075 00076 AStream<<" Rotation: " <<AParameter.FRotation<<endl; 00077 00078 AStream<<" LookAt: "<<AParameter.FLookAt[0]<<" " 00079 <<AParameter.FLookAt[1]<<" "<<AParameter.FLookAt[2]<<endl; 00080 00081 AStream<<endl; 00082 00083 return AStream; 00084 } 00085 //------------------------------------------------------------------------------ 00086 istream& operator>>(istream& AStream, 00087 CParameterAimedPosition & AParameter) 00088 { 00089 char tmp[256]; 00090 00091 AStream>>tmp; assert ( !strcmp(tmp, "CParameterAimedPosition:") ); 00092 00093 AStream>>tmp; assert ( !strcmp(tmp, "Rotation:") ); 00094 AStream>>AParameter.FRotation; 00095 00096 AStream>>tmp; assert ( !strcmp(tmp, "LookAt:") ); 00097 AStream>>AParameter.FLookAt[0]>>AParameter.FLookAt[1]>>AParameter.FLookAt[2]; 00098 00099 AParameter.putAllNeedToUpdate(); 00100 00101 return AStream; 00102 } 00103 //****************************************************************************** 00104 float CParameterAimedPosition::getRotation() const 00105 { return FRotation; } 00106 //------------------------------------------------------------------------------ 00107 void CParameterAimedPosition::setRotation(float ARotation) 00108 { 00109 if (! areEqual(FRotation, ARotation)) 00110 { 00111 FRotation = ARotation; 00112 putAllNeedToUpdate(); 00113 } 00114 } 00115 //------------------------------------------------------------------------------ 00116 void CParameterAimedPosition::incRotation(float ADelta) 00117 { 00118 if (! isZero(ADelta)) 00119 { 00120 FRotation += ADelta; 00121 putAllNeedToUpdate(); 00122 } 00123 } 00124 //****************************************************************************** 00125 float CParameterAimedPosition::getLookAt(int AIndice) const 00126 { 00127 assert(0<=AIndice && AIndice<=2); 00128 return FLookAt[AIndice]; 00129 } 00130 //------------------------------------------------------------------------------ 00131 void CParameterAimedPosition::setLookAt(int AIndice, float AValue) 00132 { 00133 assert(0<=AIndice && AIndice<=2); 00134 00135 if (! areEqual(getLookAt(AIndice), AValue)) 00136 { 00137 FLookAt[AIndice] = AValue; 00138 putAllNeedToUpdate(); 00139 } 00140 } 00141 //****************************************************************************** 00142 int CParameterAimedPosition::getType() const 00143 { return PARAMETER_AIMED_POSITION; } 00144 //******************************************************************************