00001 /* -*- mode:c++ -*- ******************************************************** 00002 * file: Move.h 00003 * 00004 * author: Andreas Koepke, Michael Swigulski 00005 * 00006 * copyright: (C) 2005, 2010 Telecommunication Networks Group (TKN) at 00007 * Technische Universitaet Berlin, Germany. 00008 * 00009 * This program is free software; you can redistribute it 00010 * and/or modify it under the terms of the GNU General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 2 of the License, or (at your option) any later 00013 * version. 00014 * For further information see file COPYING 00015 * in the top level directory 00016 *************************************************************************** 00017 * part of: framework implementation developed by tkn 00018 **************************************************************************/ 00019 00020 #ifndef MOVE_H 00021 #define MOVE_H 00022 00023 #include <string> 00024 #include <cmath> 00025 #include <cassert> 00026 00027 #include <omnetpp.h> 00028 00029 #include "Coord.h" 00030 #include "BaseUtility.h" 00031 #include "ImNotifiable.h" 00032 00042 class Move : public BBItem { 00043 00045 BBITEM_METAINFO(BBItem); 00046 00047 protected: 00049 Coord startPos; 00051 simtime_t startTime; 00053 Coord direction; 00055 double speed; 00056 00057 public: 00058 00062 double getSpeed() const 00063 { 00064 return speed; 00065 } 00066 00070 void setSpeed(double speed) 00071 { 00072 this->speed = speed; 00073 } 00074 00078 const Coord& getStartPos() const 00079 { 00080 return startPos; 00081 } 00082 00086 simtime_t getStartTime() const 00087 { 00088 return startTime; 00089 } 00090 00094 void setStart(const Coord& startPos, simtime_t startTime) 00095 { 00096 this->startPos = startPos; 00097 this->startTime = startTime; 00098 } 00099 00104 void setStart(const Coord& startPos) 00105 { 00106 setStart(startPos, simTime()); 00107 } 00108 00112 const Coord& getDirection() const 00113 { 00114 return direction; 00115 } 00116 00121 void setDirectionByVector(const Coord& direction) 00122 { 00123 assert( FWMath::close(direction.squareLength(), 1.0) 00124 || FWMath::close(direction.squareLength(), 0.0)); 00125 this->direction = direction; 00126 } 00127 00135 void setDirectionByTarget(const Coord& target) 00136 { 00137 direction = target - startPos; 00138 00139 assert( !FWMath::close(direction.length(), 0.0) ); 00140 direction /= direction.length(); 00141 } 00142 00153 virtual Coord getPositionAt(simtime_t actualTime) const 00154 { 00155 // if speed is very close to 0.0, the host is practically standing still 00156 if ( FWMath::close(speed, 0.0) ) return startPos; 00157 00158 // otherwise: actualPos = startPos + ( direction * v * t ) 00159 return startPos + ( direction * speed * SIMTIME_DBL(actualTime - startTime) ); 00160 } 00161 00162 public: 00163 00167 std::string info() const { 00168 std::ostringstream ost; 00169 ost << " HostMove " 00170 << " startPos: " << startPos.info() 00171 << " direction: " << direction.info() 00172 << " startTime: " << startTime 00173 << " speed: " << speed; 00174 return ost.str(); 00175 } 00176 }; 00177 00178 #endif 00179