Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / vector_2i.h
blobbd5563a844ebf6c6cdce38d646276c21d856115a
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef RY_VECTOR2I_H
20 #define RY_VECTOR2I_H
22 #include "nel/misc/types_nl.h"
25 // ***************************************************************************
26 /**
27 * A 2D vector of sint32.
29 class CVector2i
31 public:
33 public: // Attributes.
34 sint32 x,y;
36 public: // Methods.
37 // Object.
38 /// Constructor which do nothing.
39 CVector2i() {}
40 /// Constructor .
41 CVector2i(sint32 _x, sint32 _y) : x(_x), y(_y) {}
42 /// Copy Constructor.
43 CVector2i(const CVector2i &v) : x(v.x), y(v.y) {}
45 // Base Maths.
46 CVector2i &operator+=(const CVector2i &v) {x+=v.x; y+=v.y; return *this;}
47 CVector2i &operator-=(const CVector2i &v) {x-=v.x; y-=v.y; return *this;}
48 CVector2i &operator*=(sint32 i) {x*=i; y*=i; return *this;}
49 CVector2i &operator/=(sint32 i) {x/=i; y/=i; return *this;}
50 CVector2i operator+(const CVector2i &v) const {return CVector2i(x+v.x, y+v.y);}
51 CVector2i operator-(const CVector2i &v) const {return CVector2i(x-v.x, y-v.y);}
52 CVector2i operator*(sint32 i) const {return CVector2i(x*i, y*i);}
53 CVector2i operator/(sint32 i) const {return CVector2i(x/i, y/i);}
54 CVector2i operator-() const {return CVector2i(-x, -y);}
56 // Advanced Maths.
57 // Dot product.
58 sint32 operator*(const CVector2i &v) const {return x*v.x + y*v.y;}
59 // Return the norm of the vector.
60 sint32 norm() const {return (sint32)sqrt((double)sqrnorm());}
61 // Return the square of the norm of the vector.
62 sint32 sqrnorm() const {return x*x + y*y;}
63 // Normalize the vector.
64 void normalize()
66 sint32 i= norm();
67 if(i>0)
68 *this/=i;
70 /// Return the vector normalized.
71 CVector2i normed() const
73 CVector2i v= *this;
74 v.normalize();
75 return v;
78 // Misc.
79 void set(sint32 _x, sint32 _y) {x= _x; y=_y;}
80 bool operator==(const CVector2i &v) const {return x==v.x && y==v.y;}
81 bool operator!=(const CVector2i &v) const {return !(*this==v);}
82 bool isNull() const {return x==0.0f && y==0.0f;}
84 // serial.
85 void serial(NLMISC::IStream &i) {i.serial(x,y);}
88 #endif