00001
00002
00008
00009
00010
00012
00013 #include "Environment.h"
00014 #include "CentralBody/CentralBody.h"
00015 namespace O_SESSAME {
00016
00018 Environment::Environment() : m_CalculatedForces(3),
00019 m_CalculatedTorques(3),
00020 m_ForcesFunctor(const_cast<Environment*>(this), &Environment::GetForces),
00021 m_TorquesFunctor(const_cast<Environment*>(this), &Environment::GetTorques)
00022 {
00023 m_pCB = NULL;
00024 }
00025
00027 Environment::~Environment()
00028 {
00029 if(m_pCB)
00030 m_pCB->ReleaseReference();
00031 }
00032
00039 Vector Environment::GetTorques(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState)
00040 {
00041 m_CalculatedTorques.setToValue(0);
00042 m_funcIterator = m_TorqueFunctions.begin();
00043 while (m_funcIterator != m_TorqueFunctions.end())
00044 {
00045 m_CalculatedTorques += (*m_funcIterator).Evaluate(_currentTime, _currentOrbitState, _currentAttitudeState);
00046 ++m_funcIterator;
00047 }
00048 return m_CalculatedTorques;
00049 }
00050
00057 Vector Environment::GetForces(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState)
00058 {
00059 m_CalculatedForces.setToValue(0);
00060 m_funcIterator = m_ForceFunctions.begin();
00061 while (m_funcIterator != m_ForceFunctions.end())
00062 {
00063 m_CalculatedForces += (*m_funcIterator).Evaluate(_currentTime, _currentOrbitState, _currentAttitudeState);
00064 ++m_funcIterator;
00065 }
00066 return m_CalculatedForces;
00067 }
00068
00072 void Environment::SetCentralBody(CentralBody *_pCB)
00073 {
00074 m_pCB = _pCB;
00075 return;
00076 }
00077
00081 const CentralBody* Environment::GetCentralBody() const
00082 {
00083 return m_pCB;
00084 }
00085
00089 void Environment::AddForceFunction(const EnvFunction &_forceFunc)
00090 {
00091
00093 m_funcIterator = m_ForceFunctions.begin();
00094 while (m_funcIterator != m_ForceFunctions.end())
00095 {
00096 if(*m_funcIterator == _forceFunc)
00097 return;
00098 }*/
00099 m_ForceFunctions.push_back(_forceFunc);
00100 return;
00101 }
00105 void Environment::AddTorqueFunction(const EnvFunction &_torqueFunc)
00106 {
00107
00109 m_funcIterator = m_TorqueFunctions.begin();
00110 while (m_funcIterator != m_TorqueFunctions.end())
00111 {
00112 if(*m_funcIterator == _torqueFunc)
00113 return;
00114 }*/
00115 m_TorqueFunctions.push_back(_torqueFunc);
00116 return;
00117 }
00118
00122 const Functor& Environment::GetForceFunction() const
00123 {
00124 return m_ForcesFunctor;
00125 }
00126
00130 const Functor& Environment::GetTorqueFunction() const
00131 {
00132 return m_TorquesFunctor;
00133 }
00135
00137
00142 EnvFunction::EnvFunction(pt2EnvFunc _EnvFuncPtr) : m_NumParameters(0) , m_EnvFuncParameters(m_NumParameters)
00143 {
00144 m_EnvFuncPtr = _EnvFuncPtr;
00145 }
00152 EnvFunction::EnvFunction(pt2EnvFunc _EnvFuncPtr, const int &_numParameters) : m_NumParameters(_numParameters) , m_EnvFuncParameters(m_NumParameters)
00153 {
00154 m_EnvFuncPtr = _EnvFuncPtr;
00155 }
00163 Vector EnvFunction::Evaluate(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState)
00164 {
00165 return m_EnvFuncPtr(_currentTime, _currentOrbitState, _currentAttitudeState, m_EnvFuncParameters);
00166 }
00167
00177 void EnvFunction::AddParameter(void* _parameter, int _paramNumber)
00178 {
00179 if (_paramNumber > m_NumParameters)
00180 {
00181
00182 int delta = _paramNumber - m_NumParameters;
00183 if(delta > 1)
00184 {
00185 for(int ii = 1; ii < delta; ++ii)
00186 {
00187 m_EnvFuncParameters.push_back(0);
00188 }
00189 }
00190 m_EnvFuncParameters.push_back(_parameter);
00191 }
00192 else
00193 m_EnvFuncParameters.insert(m_EnvFuncParameters.begin() + _paramNumber - 1, _parameter);
00194
00195 m_NumParameters = _paramNumber;
00196
00197 }
00198
00204 void EnvFunction::ChangeParameter(void* _parameter, int _paramNumber)
00205 {
00206 RemoveParameter(_paramNumber);
00207 AddParameter(_parameter, _paramNumber);
00208 }
00209
00218 void EnvFunction::RemoveParameter(int _paramNumber)
00219 {
00220 if(_paramNumber <= m_NumParameters)
00221 m_EnvFuncParameters.erase(m_EnvFuncParameters.begin()+_paramNumber);
00222 else if(_paramNumber == -1)
00223 m_EnvFuncParameters.pop_back();
00224 else
00225 return;
00226
00227 --m_NumParameters;
00228 }
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260