00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef NL_LOCAL_RETRIEVER_H
00027 #define NL_LOCAL_RETRIEVER_H
00028
00029 #include <vector>
00030 #include <string>
00031 #include <list>
00032
00033 #include "nel/misc/types_nl.h"
00034 #include "nel/misc/vector.h"
00035 #include "nel/misc/file.h"
00036
00037 #include "nel/misc/aabbox.h"
00038 #include "nel/misc/polygon.h"
00039
00040 #include "pacs/vector_2s.h"
00041 #include "pacs/surface_quad.h"
00042 #include "pacs/chain.h"
00043 #include "pacs/retrievable_surface.h"
00044 #include "pacs/chain_quad.h"
00045 #include "pacs/exterior_mesh.h"
00046 #include "pacs/face_grid.h"
00047
00048 #include "nel/pacs/u_global_position.h"
00049
00050
00051
00052 namespace NLPACS
00053 {
00054
00055 class CCollisionSurfaceTemp;
00056
00063 class CLocalRetriever
00064 {
00065 public:
00072 class CTip
00073 {
00074 public:
00081 struct CChainTip
00082 {
00084 sint32 Chain;
00085
00087 bool Start;
00088
00090 CChainTip(sint32 chainId = 0, bool start = 0) : Chain(chainId), Start(start) {}
00091
00093 void serial(NLMISC::IStream &f) { f.serial(Chain, Start); }
00094 };
00095
00096 CTip() : Point(NLMISC::CVector::Null) {}
00097
00099 NLMISC::CVector Point;
00100
00101
00102 std::vector<CChainTip> Chains;
00103
00104 public:
00106 void serial(NLMISC::IStream &f)
00107 {
00108 f.serial(Point);
00109 f.serialCont(Chains);
00110 }
00111
00113 void translate(const NLMISC::CVector &translation)
00114 {
00115 Point += translation;
00116 }
00117 };
00118
00119
00126 class CTopology : public std::vector<sint32>
00127 {
00128 public:
00129 void serial(NLMISC::IStream &f) { f.serialCont(*this); }
00130 };
00131
00132
00140 class CLocalPosition : public ULocalPosition
00141 {
00142 public:
00144 CLocalPosition(sint32 surface=-1, const NLMISC::CVector &estimation=NLMISC::CVector::Null)
00145 {
00146 Surface=surface;
00147 Estimation=estimation;
00148 }
00149
00151
00152 };
00153
00160 enum EType
00161 {
00162 Landscape = 0,
00163 Interior
00164 };
00165
00166
00173 class CInteriorFace
00174 {
00175 public:
00176 uint32 Verts[3];
00177 uint32 Surface;
00178 public:
00179 void serial(NLMISC::IStream &f) { f.serial(Verts[0], Verts[1], Verts[2], Surface); }
00180 };
00181
00182
00183 protected:
00184 friend class CRetrieverInstance;
00185
00187 std::vector<COrderedChain> _OrderedChains;
00188 std::vector<COrderedChain3f> _FullOrderedChains;
00189
00191 std::vector<CChain> _Chains;
00192
00194 std::vector<CRetrievableSurface> _Surfaces;
00195
00197 NLMISC::CAABBox _BBox;
00198
00200 std::vector<CTip> _Tips;
00201
00203 std::vector<uint16> _BorderChains;
00204
00206 std::vector<CTopology> _Topologies[NumCreatureModels];
00207
00209 static const float _TipThreshold;
00210
00212 static const float _EdgeTipThreshold;
00213
00215 CChainQuad _ChainQuad;
00216
00218 EType _Type;
00219
00221
00223
00224
00226 std::vector<NLMISC::CVector> _InteriorVertices;
00227
00229 std::vector<CInteriorFace> _InteriorFaces;
00230
00232 CFaceGrid _FaceGrid;
00233
00235 std::string _Id;
00236
00237
00238
00239
00240
00241 private:
00243 struct CIntersectionMarker
00244 {
00245 float Position;
00246 uint16 OChain;
00247 uint16 Edge;
00248 bool In;
00249
00250 CIntersectionMarker() {}
00251 CIntersectionMarker(float position, uint16 ochain, uint16 edge, bool in) : Position(position), OChain(ochain), Edge(edge), In(in) {}
00252
00253 bool operator< (const CIntersectionMarker &comp) const { return Position < comp.Position; }
00254 };
00255
00256 public:
00258
00259
00260 CLocalRetriever();
00261
00262
00263
00265
00266
00268 const std::vector<CTip> &getTips() const { return _Tips; }
00270 const CTip &getTip(uint n) const { return _Tips[n]; }
00271
00273 const std::vector<COrderedChain> &getOrderedChains() const { return _OrderedChains; }
00275 const COrderedChain &getOrderedChain(uint n) const { return _OrderedChains[n]; }
00276
00278 const std::vector<COrderedChain3f> &getFullOrderedChains() const { return _FullOrderedChains; }
00280 const COrderedChain3f &getFullOrderedChain(uint n) const { return _FullOrderedChains[n]; }
00281
00283 const std::vector<CChain> &getChains() const { return _Chains; }
00285 const CChain &getChain(uint n) const { return _Chains[n]; }
00286
00288 const std::vector<uint16> &getBorderChains() const { return _BorderChains; }
00290 uint16 getBorderChain(uint n) const { return _BorderChains[n]; }
00291
00293 const std::vector<CRetrievableSurface> &getSurfaces() const { return _Surfaces; }
00295 const CRetrievableSurface &getSurface(uint n) const { return _Surfaces[n]; }
00296
00298 EType getType() const { return _Type; }
00299
00301 const NLMISC::CAABBox &getBBox() const { return _BBox; }
00302
00304 const CExteriorMesh &getExteriorMesh() const { return _ExteriorMesh; }
00305
00307 const std::vector<NLMISC::CVector> &getInteriorVertices() const { return _InteriorVertices; }
00308
00310 const std::vector<CInteriorFace> &getInteriorFaces() const { return _InteriorFaces; }
00311
00313 const std::string &getIdentifier() const { return _Id; }
00314
00316 void buildInteriorSurfaceBBoxes(std::vector<NLMISC::CAABBox> &surfaceBBoxes) const;
00317
00319 void buildSurfacePolygons(uint32 surface, std::list<NLMISC::CPolygon> &polygons) const;
00320
00322 void buildSurfacePolygons(std::list< std::list<NLMISC::CPolygon> > &polygons) const
00323 {
00324 uint i;
00325 for (i=0; i<_Surfaces.size(); ++i)
00326 {
00327 polygons.push_back();
00328 buildSurfacePolygons(i, polygons.back());
00329 }
00330 }
00331
00332
00333
00334
00336
00337
00339 sint32 addSurface(uint8 normalq, uint8 orientationq,
00340 uint8 mat, uint8 charact, uint8 level,
00341 bool isUnderWater, float waterHeight,
00342 const NLMISC::CVector ¢er,
00343 const CSurfaceQuadTree &quad);
00344
00349 sint32 addChain(const std::vector<NLMISC::CVector> &vertices,
00350 sint32 left, sint32 right);
00351
00353 void setType(EType type) { _Type = type; }
00354
00356 void setExteriorMesh(const CExteriorMesh &em) { _ExteriorMesh = em; }
00357
00359 void setBBox(const NLMISC::CAABBox &bbox) { _BBox = bbox; }
00360
00361
00363 std::vector<NLMISC::CVector> &getInteriorVertices() { return _InteriorVertices; }
00364
00366 std::vector<CInteriorFace> &getInteriorFaces() { return _InteriorFaces; }
00367
00369 void setIdentifier(const std::string &id) { _Id = id; }
00370
00371
00373 CChainQuad &getChainQuad() { return _ChainQuad; }
00374
00375
00377 void initFaceGrid();
00378
00379
00381 void computeTopologies();
00382
00384 void computeLoopsAndTips();
00385
00387 void findBorderChains();
00388
00390 void updateChainIds();
00391
00392
00394 void sortTips();
00395
00396
00398 void translate(const NLMISC::CVector &translation);
00399
00400
00402 void flushFullOrderedChains() { _FullOrderedChains.clear(); }
00403
00404
00406 void serial(NLMISC::IStream &f);
00407
00408
00409
00411
00413
00419 void testCollision(CCollisionSurfaceTemp &cst, const NLMISC::CAABBox &bboxMove, const NLMISC::CVector2f &transBase) const;
00420
00421
00422
00423
00424
00425
00426
00428 bool insurePosition(ULocalPosition &local) const;
00429
00431 void retrievePosition(NLMISC::CVector estimated, CCollisionSurfaceTemp &cst) const;
00432
00434 void snapToInteriorGround(ULocalPosition &position, bool &snapped) const;
00435
00437 float getHeight(const ULocalPosition &position) const;
00438
00440 void findPath(const CLocalPosition &A, const CLocalPosition &B, std::vector<CVector2s> &path, NLPACS::CCollisionSurfaceTemp &cst) const;
00441
00442
00444 void unify();
00445
00446 public:
00447 const NLMISC::CVector &getStartVector(uint32 chain) const;
00448 const NLMISC::CVector &getStopVector(uint32 chain) const;
00449
00450 const NLMISC::CVector &getStartVector(uint32 chain, sint32 surface) const;
00451 const NLMISC::CVector &getStopVector(uint32 chain, sint32 surface) const;
00452
00453 uint16 getStartTip(uint32 chain, sint32 surface) const;
00454 uint16 getStopTip(uint32 chain, sint32 surface) const;
00455
00456 void setStartTip(uint32 chain, sint32 surface, uint16 startTip);
00457 void setStopTip(uint32 chain, sint32 surface, uint16 stopTip);
00458
00459 uint32 getPreviousChain(uint32 chain, sint32 surface) const;
00460 uint32 getNextChain(uint32 chain, sint32 surface) const;
00461
00462 public:
00463 void dumpSurface(uint surf, const NLMISC::CVector &vect = NLMISC::CVector::Null) const;
00464
00465 float distanceToBorder(const ULocalPosition &pos) const;
00466 };
00467
00468 };
00469
00470 #endif // NL_LOCAL_RETRIEVER_H
00471
00472