00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_AGENT_3DVECTOR_H
00027 #define NL_AGENT_3DVECTOR_H
00028
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/ai/logic/boolval.h"
00031 #include "nel/misc/vectord.h"
00032
00033
00034
00035
00036
00037 namespace NLAIAGENT
00038 {
00047 class IVector: public IObjetOp
00048 {
00049 protected:
00050 NLMISC::CVectorD _Value;
00051
00052 public:
00053
00055 IVector(double x, double y, double z):_Value(x, y, z)
00056 {
00057 }
00058
00059 IVector(const NLMISC::CVectorD &v):_Value(v)
00060 {
00061 }
00062
00063 IVector(const IVector &value):IObjetOp(value), _Value((NLMISC::CVectorD)value._Value)
00064 {
00065 }
00066 IVector()
00067 {
00068 }
00069 IVector(NLMISC::IStream &is)
00070 {
00071 load(is);
00072 }
00073
00074 virtual ~IVector()
00075 {
00076 }
00077
00078 virtual void save(NLMISC::IStream &os)
00079 {
00080 os.serial( _Value );
00081 }
00082
00083 virtual void load(NLMISC::IStream &is)
00084 {
00085 is.serial( _Value );
00086 }
00087
00088 virtual bool isEqual(const IBasicObjectIA &a) const
00089 {
00090 return !(*(IObjectIA *)this == (IObjetOp &)a);
00091 }
00092
00093 virtual bool isTrue() const
00094 {
00095 return true;
00096 }
00097
00098 const NLMISC::CVectorD &getValueRef() const
00099 {
00100 return _Value;
00101 }
00102
00103 NLMISC::CVectorD getValue() const
00104 {
00105 return _Value;
00106 }
00107
00108 void setValue(NLMISC::CVectorD value)
00109 {
00110 _Value = value;
00111 }
00112
00113 double x() const
00114 {
00115 return _Value.x;
00116 }
00117
00118 double y() const
00119 {
00120 return _Value.y;
00121 }
00122
00123 double z() const
00124 {
00125 return _Value.z;
00126 }
00127
00128 void x(const double u)
00129 {
00130 _Value.x = u;
00131 }
00132
00133 void y(const double v)
00134 {
00135 _Value.y = v;
00136 }
00137
00138 void z(const double w)
00139 {
00140 _Value.z = w;
00141 }
00142
00143 double squareLength()
00144 {
00145 return _Value.x * _Value.x + _Value.y * _Value.y + _Value.z * _Value.z;
00146 }
00147
00148 double length()
00149 {
00150 return (double) sqrt(squareLength());
00151 }
00152
00153 void unit()
00154 {
00155 _Value.normalize();
00156 }
00157
00158 virtual IObjectIA &operator = (const IObjectIA &a)
00159 {
00160 NLMISC::CVectorD v((NLMISC::CVectorD)((const IVector &)a).getValue());
00161 _Value = v;
00162 return *this;
00163 }
00164
00165 virtual IObjetOp &operator += (const IObjetOp &a)
00166 {
00167 NLMISC::CVectorD v = (NLMISC::CVectorD)((const IVector &)a).getValue();
00168 _Value += v;
00169 return *this;
00170 }
00171
00172 virtual IObjetOp &operator -= (const IObjetOp &a)
00173 {
00174 NLMISC::CVectorD v = (NLMISC::CVectorD)((const IVector &)a).getValue();
00175 _Value -= v;
00176 return *this;
00177 }
00178
00179 virtual IObjetOp *operator + (const IObjetOp &a)
00180 {
00181 IObjetOp *o = (IObjetOp *)clone();
00182 *o += a;
00183 return o;
00184 }
00185
00186 virtual IObjetOp *operator - (const IObjetOp &a)
00187 {
00188 IObjetOp *o = (IObjetOp *)clone();
00189 *o -= a;
00190 return o;
00191 }
00192
00193 virtual IObjetOp *operator != (IObjetOp &a) const
00194 {
00195 NLMISC::CVectorD v = (NLMISC::CVectorD)((const IVector &)a).getValue();
00196 NLAILOGIC::CBoolType *x = new NLAILOGIC::CBoolType(_Value != v);
00197 return x;
00198 }
00199
00200 virtual IObjetOp *operator == (IObjetOp &a) const
00201 {
00202 NLMISC::CVectorD v = (NLMISC::CVectorD)((const IVector &)a).getValue();
00203 NLAILOGIC::CBoolType *x = new NLAILOGIC::CBoolType(_Value == v);
00204 return x;
00205 }
00206
00207 virtual sint32 getMethodIndexSize() const;
00208 virtual tQueue isMember(const IVarName *,const IVarName *,const IObjectIA &) const;
00209 virtual CProcessResult runMethodeMember(sint32, sint32, IObjectIA *);
00210 virtual CProcessResult runMethodeMember(sint32 index,IObjectIA *);
00211 virtual sint32 isClassInheritedFrom(const IVarName &) const;
00212 };
00213
00223 class VectorType: public IVector
00224 {
00225 public:
00226
00227 static const NLAIC::CIdentType IdVectorType;
00228
00229 public:
00230 VectorType(double x, double y, double z):IVector(x, y, z)
00231 {
00232 }
00233
00234 VectorType(const NLMISC::CVectorD &v):IVector(v)
00235 {
00236 }
00237
00238 VectorType():IVector()
00239 {
00240 }
00241
00242 VectorType(const VectorType &a):IVector(a)
00243 {
00244 }
00245
00246 VectorType(NLMISC::IStream &is):IVector(is)
00247 {
00248 }
00249
00250 virtual const NLAIC::IBasicType *clone() const
00251 {
00252 NLAIC::IBasicInterface *m = new VectorType(*this);
00253 return m;
00254 }
00255
00256 virtual const NLAIC::IBasicType *newInstance() const
00257 {
00258 return clone();
00259 }
00260
00261 virtual const NLAIC::CIdentType &getType() const;
00262
00263
00264 virtual void getDebugString(std::string &text) const
00265 {
00266 text = NLAIC::stringGetBuild("Vector <%f %f %f>",getValue().x, getValue().y, getValue().z);
00267 }
00268
00269 virtual const CProcessResult &run();
00270 };
00271 }
00272
00273
00274 #endif // NL_AGENT_3DVECTOR_H
00275
00276