Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / nel / src / pacs / exterior_mesh.cpp
blobd7c72c96ff56f2ea67bfa7b63dbb8d428f862855
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
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/>.
17 #include "stdpacs.h"
19 #include "nel/pacs/exterior_mesh.h"
20 #include "nel/pacs/local_retriever.h"
21 #include "nel/pacs/collision_desc.h"
24 using namespace std;
25 using namespace NLMISC;
27 namespace NLPACS
29 // Functions for vertices comparison.
30 // total order relation
31 static inline bool isStrictlyLess(const CVector &a, const CVector &b)
33 if (a.x < b.x) return true;
34 if (a.x > b.x) return false;
35 if (a.y < b.y) return true;
36 if (a.y > b.y) return false;
37 if (a.z < b.y) return true;
38 return false;
41 static inline bool isStrictlyGreater(const CVector &a, const CVector &b)
43 if (a.x > b.x) return true;
44 if (a.x < b.x) return false;
45 if (a.y > b.y) return true;
46 if (a.y < b.y) return false;
47 if (a.z > b.y) return true;
48 return false;
51 CExteriorMesh::CExteriorMesh() { }
53 void CExteriorMesh::setEdges(const vector<CExteriorMesh::CEdge> &edges)
55 _Edges = edges;
56 _OrderedEdges.clear();
58 uint i;
59 for (i=0; i+1<_Edges.size(); )
61 _OrderedEdges.resize(_OrderedEdges.size()+1);
62 COrderedEdges &edges = _OrderedEdges.back();
63 edges.Start = i;
64 if (isStrictlyLess(_Edges[i].Start, _Edges[i+1].Start))
66 edges.Forward = true;
69 ++i;
71 while (i+1<_Edges.size() && _Edges[i].Link != -2 && isStrictlyLess(_Edges[i].Start, _Edges[i+1].Start));
73 else
75 edges.Forward = false;
78 ++i;
80 while (i+1<_Edges.size() && _Edges[i].Link != -2 && isStrictlyGreater(_Edges[i].Start, _Edges[i+1].Start));
82 edges.End = i;
84 if (_Edges[i].Link == -2)
85 ++i;
89 void CExteriorMesh::serial(NLMISC::IStream &f)
92 Version 0:
93 - base version.
95 (void)f.serialVersion(0);
97 f.serialCont(_Edges);
98 f.serialCont(_OrderedEdges);
99 f.serialCont(_Links);
100 f.serial(_BBox);