1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
19 #include "nel/ligo/zone_edge.h"
20 #include "nel/ligo/ligo_config.h"
21 #include "nel/ligo/ligo_error.h"
24 #include "nel/misc/matrix.h"
26 using namespace NLMISC
;
35 // ***************************************************************************
37 bool CZoneEdge::build (const std::vector
<NLMISC::CVector
> &theEdge
, const std::vector
<uint32
> &theId
, uint rotation
,
38 sint32 offsetX
, sint32 offsetY
, const CLigoConfig
&config
, CLigoError
&errors
)
41 // no need, it s an uint nlassert (rotation>=0);
42 nlassert (rotation
<=3);
43 nlassert (theEdge
.size() == theId
.size());
51 // Check first position
52 CVector
toCheck (theEdge
[0].x
, theEdge
[0].y
, 0);
53 if ((float)fabs (toCheck
.norm())>config
.Snap
)
56 errors
.pushVertexError (CLigoError::UnknownError
, 0);
60 // Check last position
61 uint lastIndex
= (uint
)theEdge
.size()-1;
62 toCheck
= CVector (theEdge
[lastIndex
].x
, theEdge
[lastIndex
].y
, 0);
63 if (((toCheck
-CVector (config
.CellSize
, 0, 0)).norm())>config
.Snap
)
66 errors
.pushVertexError (CLigoError::UnknownError
, 0);
83 // ***************************************************************************
85 bool CZoneEdge::isSymetrical (const CLigoConfig
&config
, CLigoError
&errors
) const
93 // For each internal vertices
95 for (vert
=0; vert
<_TheEdge
.size(); vert
++)
98 CVector sym
= CVector (config
.CellSize
-_TheEdge
[vert
].x
, _TheEdge
[vert
].y
, _TheEdge
[vert
].z
);
102 for (vert2
=0; vert2
<_TheEdge
.size(); vert2
++)
108 if ((_TheEdge
[vert2
]-sym
).norm() <= config
.Snap
)
117 if (vert2
>=_TheEdge
.size())
122 // Push error message
123 errors
.pushVertexError (CLigoError::NotSymetrical
, _Id
[vert
]);
124 errors
.MainError
= CLigoError::NotSymetrical
;
132 // ***************************************************************************
134 bool CZoneEdge::isTheSame (const CZoneEdge
&other
, const CLigoConfig
&config
, CLigoError
&errors
) const
136 // Same vertex count ?
137 if (_TheEdge
.size() != other
._TheEdge
.size())
140 errors
.MainError
= CLigoError::NotSameVerticesNumber
;
147 // For each internal vertices
149 for (vert
=0; vert
<_TheEdge
.size(); vert
++)
152 const CVector
&pos0
= _TheEdge
[vert
];
153 const CVector
&pos1
= other
._TheEdge
[vert
];
154 if ((pos0
-pos1
).norm() > config
.Snap
)
159 // Push error message
160 errors
.pushVertexError (CLigoError::NotSameVertex
, other
._Id
[vert
]);
161 errors
.MainError
= CLigoError::NotSameVertex
;
169 // ***************************************************************************
171 void CZoneEdge::serial (NLMISC::IStream
& s
)
173 // Serial the version
174 /*sint ver =*/ s
.serialVersion (0);
176 s
.xmlPush ("VERTICES");
177 s
.serialCont (_TheEdge
);
180 s
.xmlPush ("VERTICES_ID");
184 s
.xmlSerial (_Rotation
, "ROTATION");
186 s
.xmlSerial (_OffsetX
, _OffsetY
, "OFFSET");
189 // ***************************************************************************
191 void CZoneEdge::invert (const CLigoConfig
&config
)
194 const std::vector
<NLMISC::CVector
> copy
= _TheEdge
;
196 // For each internal vertices
198 for (vert
=0; vert
<_TheEdge
.size(); vert
++)
201 const CVector
&pos
= copy
[_TheEdge
.size()-vert
-1];
202 _TheEdge
[vert
] = CVector (config
.CellSize
- pos
.x
, pos
.y
, pos
.z
);
206 // ***************************************************************************
208 void CZoneEdge::buildMatrix (NLMISC::CMatrix
& mat
, const CLigoConfig
&config
) const
210 // Build a transformation matrix
212 mat
.rotateZ ((float)Pi
*(float)_Rotation
/2.f
);
213 mat
.setPos (CVector (config
.CellSize
*(float)_OffsetX
, config
.CellSize
*(float)_OffsetY
, 0));
216 // ***************************************************************************