1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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/>.
22 #include "nel/misc/types_nl.h"
25 //--------------------------------------------------------------------------
27 //--------------------------------------------------------------------------
29 // A coordinate with orientation and surface id
34 //----------------------------------------------------------------------------
39 UNITS_PER_METER
= 1000
42 //----------------------------------------------------------------------------
45 explicit CAICoord(): _coord(0) {}
46 explicit CAICoord(double d
): _coord((sint32
)(d
*UNITS_PER_METER
)) {}
47 CAICoord(const CAICoord
&coord
): _coord(coord
._coord
) {}
48 //CAICoord(CAICoord &aicoord): _coord(aicoord._coord) {}
50 //----------------------------------------------------------------------------
51 // convertions to other types
53 // (StepH) still now, we have no fpu acceleration :( so its quickest to do a simple int div .. waiting DM response.
54 inline double asDouble() const { return (double)_coord
/(double)UNITS_PER_METER
; }
55 inline sint32
asInt() const { return _coord
; }
56 inline sint32
asIntMeters() const { return _coord
>>10; }
57 inline sint32
asInt16Meters() const { return _coord
>>14; }
59 //----------------------------------------------------------------------------
62 CAICoord
operator-() const
64 CAICoord
c(-_coord
,true);
68 //----------------------------------------------------------------------------
69 // maths with CAICoord
71 const CAICoord
&operator=(const CAICoord
&other
) { _coord
=other
._coord
; return *this; }
72 const CAICoord
&operator+=(const CAICoord
&other
) { _coord
+=other
._coord
; return *this; }
73 const CAICoord
&operator-=(const CAICoord
&other
) { _coord
-=other
._coord
; return *this; }
74 const CAICoord
&operator*=(const CAICoord
&other
) { _coord
*=other
._coord
; return *this; }
75 const CAICoord
&operator/=(const CAICoord
&other
) { _coord
/=other
._coord
; return *this; }
77 const CAICoord
operator+(const CAICoord
&other
) const { CAICoord
c(*this); c
+=other
; return c
; }
78 const CAICoord
operator-(const CAICoord
&other
) const { CAICoord
c(*this); c
-=other
; return c
; }
79 const CAICoord
operator*(const CAICoord
&other
) const { CAICoord
c(*this); c
*=other
; return c
; }
80 const CAICoord
operator/(const CAICoord
&other
) const { CAICoord
c(*this); c
/=other
; return c
; }
82 //----------------------------------------------------------------------------
85 const CAICoord
&operator=(double d
) { *this=CAICoord(d
); return *this; }
86 const CAICoord
&operator+=(double d
) { *this+=CAICoord(d
); return *this; }
87 const CAICoord
&operator-=(double d
) { *this-=CAICoord(d
); return *this; }
88 const CAICoord
&operator*=(double d
) { *this=CAICoord(asDouble()*d
); return *this; }
89 const CAICoord
&operator/=(double d
) { *this=CAICoord(asDouble()*(1.0/d
)); return *this; }
91 const CAICoord
operator+(double d
) const { CAICoord
c(*this); c
+=d
; return c
; }
92 const CAICoord
operator-(double d
) const { CAICoord
c(*this); c
-=d
; return c
; }
93 const CAICoord
operator*(double d
) const { CAICoord
c(*this); c
*=d
; return c
; }
94 const CAICoord
operator/(double d
) const { CAICoord
c(*this); c
/=d
; return c
; }
96 //----------------------------------------------------------------------------
99 const CAICoord
&operator*=(int i
) { _coord
*=i
; return *this; }
100 const CAICoord
&operator/=(int i
) { _coord
/=i
; return *this; }
102 const CAICoord
operator*(int i
) const { CAICoord
c(*this); c
*=i
; return c
; }
103 const CAICoord
operator/(int i
) const { CAICoord
c(*this); c
/=i
; return c
; }
106 //----------------------------------------------------------------------------
107 // compareson with CAICoord
109 bool operator==(const CAICoord
&other
) const { return _coord
== other
._coord
; }
110 bool operator!=(const CAICoord
&other
) const { return _coord
!= other
._coord
; }
111 bool operator>=(const CAICoord
&other
) const { return _coord
>= other
._coord
; }
112 bool operator<=(const CAICoord
&other
) const { return _coord
<= other
._coord
; }
113 bool operator> (const CAICoord
&other
) const { return _coord
> other
._coord
; }
114 bool operator< (const CAICoord
&other
) const { return _coord
< other
._coord
; }
116 //----------------------------------------------------------------------------
117 // compareson with double
119 bool operator==(double d
) const { return _coord
== CAICoord(d
)._coord
; }
120 bool operator!=(double d
) const { return _coord
!= CAICoord(d
)._coord
; }
121 bool operator>=(double d
) const { return _coord
>= CAICoord(d
)._coord
; }
122 bool operator<=(double d
) const { return _coord
<= CAICoord(d
)._coord
; }
123 bool operator> (double d
) const { return _coord
> CAICoord(d
)._coord
; }
124 bool operator< (double d
) const { return _coord
< CAICoord(d
)._coord
; }
126 //----------------------------------------------------------------------------
127 // compareson with int
129 bool operator==(int d
) const { return _coord
== CAICoord(d
)._coord
; }
130 bool operator!=(int d
) const { return _coord
!= CAICoord(d
)._coord
; }
131 bool operator>=(int d
) const { return _coord
>= CAICoord(d
)._coord
; }
132 bool operator<=(int d
) const { return _coord
<= CAICoord(d
)._coord
; }
133 bool operator> (int d
) const { return _coord
> CAICoord(d
)._coord
; }
134 bool operator< (int d
) const { return _coord
< CAICoord(d
)._coord
; }
136 //----------------------------------------------------------------------------
139 void serial(NLMISC::IStream
&i
)
144 //----------------------------------------------------------------------------
147 inline std::string
toString() const
149 return NLMISC::toString("%.2f",asDouble());
152 operator sint32() const
158 CAICoord(int coord
, bool priv
):_coord(coord
) {}
160 sint32 _coord
; // the coordinate is now mapped directly onto the mirror value