#include <local_retriever.h>
Nevrax France
Definition at line 63 of file local_retriever.h.
Public Types | |
enum | EType { Landscape = 0, Interior } |
Public Member Functions | |
float | distanceToBorder (const ULocalPosition &pos) const |
void | dumpSurface (uint surf, const NLMISC::CVector &vect=NLMISC::CVector::Null) const |
void | findPath (const CLocalPosition &A, const CLocalPosition &B, std::vector< CVector2s > &path, NLPACS::CCollisionSurfaceTemp &cst) const |
Finds a path in a given surface, from the point A to the point B. | |
void | forceBorderChainId (uint32 chainId, uint32 borderId) |
float | getHeight (const ULocalPosition &position) const |
uint32 | getNextChain (uint32 chain, sint32 surface) const |
uint32 | getPreviousChain (uint32 chain, sint32 surface) const |
const NLMISC::CVector & | getStartVector (uint32 chain, sint32 surface) const |
const NLMISC::CVector & | getStartVector (uint32 chain) const |
const NLMISC::CVector & | getStopVector (uint32 chain, sint32 surface) const |
const NLMISC::CVector & | getStopVector (uint32 chain) const |
bool | insurePosition (ULocalPosition &local) const |
Assures a position is really inside a surface (and independent from any accuracy issue) and returns true if the position was moved. | |
void | replaceChain (uint32 chainId, const std::vector< CChainReplacement > &replacement) |
void | retrieveAccuratePosition (CVector2s estimated, CCollisionSurfaceTemp &cst, bool &onBorder) const |
Retrieves a position inside the retriever (from the local position), returns true if the position is close to a border. | |
void | retrievePosition (NLMISC::CVector estimated, CCollisionSurfaceTemp &cst) const |
Retrieves a position inside the retriever (from the local position), returns true if the position is close to a border. | |
void | snapToInteriorGround (ULocalPosition &position, bool &snapped) const |
Snaps on the ground. | |
bool | testPosition (ULocalPosition &local, CCollisionSurfaceTemp &cst) const |
Retrieves a position inside the retriever (from the local position), returns true if the position is close to a border. | |
void | unify () |
Mutators | |
sint32 | addChain (const std::vector< NLMISC::CVector > &vertices, sint32 left, sint32 right) |
sint32 | addSurface (uint8 normalq, uint8 orientationq, uint8 mat, uint8 charact, uint8 level, bool isUnderWater, float waterHeight, bool clusterHint, const NLMISC::CVector ¢er, const CSurfaceQuadTree &quad, sint8 quantHeight=0) |
Adds a surface to the local retriever, using its features. Returns the id of the newly created surface. | |
void | clear () |
Clear. | |
void | computeLoopsAndTips () |
Builds tips. | |
void | computeTopologies () |
Builds topologies tables. | |
void | findBorderChains () |
Found chains on the edges of the retriever and fills _BorderChains tables. | |
void | flushFullOrderedChains () |
CChainQuad & | getChainQuad () |
Returns the chain quad. | |
std::vector< CInteriorFace > & | getInteriorFaces () |
Returns the interior faces. | |
std::vector< NLMISC::CVector > & | getInteriorVertices () |
Returns the interior vertices. | |
void | initFaceGrid () |
Inits the face grid. | |
void | serial (NLMISC::IStream &f) |
Serialises the CLocalRetriever. | |
void | setBBox (const NLMISC::CAABBox &bbox) |
Sets the bbox of the retriever. | |
void | setExteriorMesh (const CExteriorMesh &em) |
Sets the exterior mesh. | |
void | setFullOrderedChains (const std::vector< COrderedChain3f > &foc) |
void | setIdentifier (const std::string &id) |
Returns the identifier of the retriever. | |
void | setType (EType type) |
Set the type of the retriever (see EType). | |
void | sortTips () |
Sorts chains references inside the tips. NOT IMPLEMENTED YET. | |
void | translate (const NLMISC::CVector &translation) |
Translates the local retriever by the translation vector. | |
void | updateChainIds () |
Updates surfaces links from the links contained in the chains... | |
Selectors | |
void | build3dSurfacePolygons (std::list< std::list< NLMISC::CPolygon > > &polygons) const |
Builds the polygons (loops) of all surfaces in the retriever. | |
void | build3dSurfacePolygons (uint32 surface, std::list< NLMISC::CPolygon > &polygons) const |
Builds the polygons (loops) of a given surface. | |
void | buildInteriorSurfaceBBoxes (std::vector< NLMISC::CAABBox > &surfaceBBoxes) const |
build BBoxes of interior surfaces in surfaceBBoxes (cleared first) | |
void | buildSurfacePolygons (std::list< std::list< NLMISC::CPolygon > > &polygons) const |
Builds the polygons (loops) of all surfaces in the retriever. | |
void | buildSurfacePolygons (uint32 surface, std::list< NLMISC::CPolygon > &polygons) const |
Builds the polygons (loops) of a given surface. | |
void | forceLoaded (bool state) |
Force Loaded State. | |
const NLMISC::CAABBox & | getBBox () const |
Returns the bbox. | |
uint16 | getBorderChain (uint n) const |
Returns the id of the nth chain on the edges of the retriever. | |
const std::vector< uint16 > & | getBorderChains () const |
Returns the ids of the chains on the edges of the retriever. | |
const CChain & | getChain (uint n) const |
retruns the nth chain. | |
const std::vector< CChain > & | getChains () const |
Returns the chains. | |
const CExteriorMesh & | getExteriorMesh () const |
Returns the exterior mesh of the retriever. | |
const COrderedChain3f & | getFullOrderedChain (uint n) const |
Returns the nth full ordered chain. | |
const std::vector< COrderedChain3f > & | getFullOrderedChains () const |
Returns the full ordered chains. | |
const std::string & | getIdentifier () const |
Returns the identifier of the retriever. | |
const std::vector< CInteriorFace > & | getInteriorFaces () const |
Returns the interior faces. | |
const std::vector< NLMISC::CVector > & | getInteriorVertices () const |
Returns the interior vertices. | |
const COrderedChain & | getOrderedChain (uint n) const |
Returns the nth ordered chain. | |
const std::vector< COrderedChain > & | getOrderedChains () const |
Returns the ordered chains. | |
const CRetrievableSurface & | getSurface (uint n) const |
Returns the nth surface. | |
const std::vector< CRetrievableSurface > & | getSurfaces () const |
Returns the surfaces. | |
EType | getType () const |
Returns the type of the retriever. | |
bool | isLoaded () const |
Is loaded ? | |
Constructors | |
CLocalRetriever () | |
Collisions part. | |
void | computeCollisionChainQuad () |
compute the chain quad, used for collisions. the ChainQuad is serialised in serial(). _OrderedChains must be OK. | |
void | testCollision (CCollisionSurfaceTemp &cst, const NLMISC::CAABBox &bboxMove, const NLMISC::CVector2f &transBase) const |
Data Fields | |
std::vector< uint > | FreeOChains |
bool | LoadCheckFlag |
Protected Attributes | |
std::vector< CTip > | __Tips |
The tips making links between different chains. | |
NLMISC::CAABBox | _BBox |
The bbox of the local retriever. | |
std::vector< uint16 > | _BorderChains |
The chains on the edges of the zone. | |
CChainQuad | _ChainQuad |
For collisions, the chainquad. | |
std::vector< CChain > | _Chains |
The chains insinde the zone. | |
std::vector< COrderedChain3f > | _FullOrderedChains |
bool | _Loaded |
Tells if retriever is loaded. | |
std::vector< COrderedChain > | _OrderedChains |
The chains insinde the zone. | |
std::vector< CRetrievableSurface > | _Surfaces |
The surfaces inside the zone. | |
std::vector< CTopology > | _Topologies [NumMaxCreatureModels] |
The topologies within the zone. | |
EType | _Type |
The type of the retriever. | |
Internior retriever specific | |
CExteriorMesh | _ExteriorMesh |
The exterior mesh, for collisions. | |
CFaceGrid | _FaceGrid |
The face selection grid. | |
std::string | _Id |
An human readable identifier of the retriever. | |
std::vector< CInteriorFace > | _InteriorFaces |
The faces of the collision mesh. | |
std::vector< NLMISC::CVector > | _InteriorVertices |
The vertices of the collision mesh. | |
Static Protected Attributes | |
const float | _EdgeTipThreshold = 0.1f |
The tip recognition threshold. | |
const float | _TipThreshold = 0.1f |
The tip recognition threshold. | |
Friends | |
class | CRetrieverInstance |
|
The different types of retriever (landscape or interior.)
Definition at line 160 of file local_retriever.h. Referenced by getType().
|
|
Definition at line 56 of file local_retriever.cpp. References _Loaded, and LoadCheckFlag.
00057 { 00058 _Type = Landscape; 00059 _Loaded = false; 00060 LoadCheckFlag = false; 00061 } |
|
Adds a chain to the local retriever, using the vertices of the chain, the left and right surfaces id and the edge on which the chain is stuck Definition at line 361 of file local_retriever.cpp. References NLPACS::CRetrievableSurface::_Chains, _Chains, _FullOrderedChains, _OrderedChains, NLPACS::CChain::_StartTip, NLPACS::CChain::_StopTip, _Surfaces, NLPACS::CChain::make(), nlerror, nlwarning, sint, sint32, uint, and uint16. Referenced by NLPACS::buildSurfaces().
00363 { 00364 vector<CVector> vertices = verts; 00365 uint i; 00366 00367 if (vertices.size() < 2) 00368 { 00369 nlwarning("in NLPACS::CLocalRetriever::addChain()"); 00370 nlwarning("The chain has less than 2 vertices"); 00371 return -1; 00372 } 00373 00374 // Remove doubled vertices due to CVector2s snapping 00375 vector<CVector2s> converts; 00376 00377 for (i=0; i<vertices.size(); ++i) 00378 converts.push_back(CVector2s(vertices[i])); 00379 00380 vector<CVector2s>::iterator next2s = converts.begin(), it2s, prev2s; 00381 prev2s = next2s; ++next2s; 00382 it2s = next2s; ++next2s; 00383 00384 vector<CVector>::iterator it3f = vertices.begin(); 00385 CVector prev3f = *it3f; 00386 ++it3f; 00387 00388 00389 for (; it2s != converts.end() && next2s != converts.end(); ) 00390 { 00391 // if the next point is equal to the previous 00392 if (*it2s == *prev2s || *it2s == *next2s) 00393 { 00394 // then remove the next point 00395 it2s = converts.erase(it2s); 00396 it3f = vertices.erase(it3f); 00397 00398 prev2s = it2s; 00399 --prev2s; 00400 next2s = it2s; 00401 ++next2s; 00402 } 00403 else 00404 { 00405 // else remember the next point, and step to the next... 00406 ++prev2s; 00407 ++it2s; 00408 ++next2s; 00409 ++it3f; 00410 prev3f = *it3f; 00411 } 00412 } 00413 00414 if (vertices.size() < 2) 00415 { 00416 nlwarning("in NLPACS::CLocalRetriever::addChain()"); 00417 nlwarning("The chain was snapped to a single point"); 00418 return -1; 00419 } 00420 00421 sint32 newId = _Chains.size(); 00422 _Chains.resize(newId+1); 00423 CChain &chain = _Chains.back(); 00424 00425 if (left>(sint)_Surfaces.size()) 00426 nlerror ("left surface id MUST be id<%d (id=%d)", _Surfaces.size(), left); 00427 if (right>(sint)_Surfaces.size()) 00428 nlerror ("right surface id MUST be id<%d (id=%d)", _Surfaces.size(), right); 00429 00430 // checks if we can build the chain. 00431 if (newId > 65535) 00432 nlerror("in NLPACS::CLocalRetriever::addChain(): reached the maximum number of chains"); 00433 00434 CRetrievableSurface *leftSurface = (left>=0) ? &(_Surfaces[left]) : NULL; 00435 CRetrievableSurface *rightSurface = (right>=0) ? &(_Surfaces[right]) : NULL; 00436 00437 // adds the chain and the link to the surface links vector. 00438 if (leftSurface != NULL) 00439 leftSurface->_Chains.push_back(CRetrievableSurface::CSurfaceLink(newId, right)); 00440 if (rightSurface != NULL) 00441 rightSurface->_Chains.push_back(CRetrievableSurface::CSurfaceLink(newId, left)); 00442 00443 chain._StartTip = 0xffff; 00444 chain._StopTip = 0xffff; 00445 00446 // make the chain and its subchains. 00447 vector<uint> empty; 00448 chain.make(vertices, left, right, _OrderedChains, (uint16)newId, _FullOrderedChains, empty); 00449 00450 return newId; 00451 } |
|
Adds a surface to the local retriever, using its features. Returns the id of the newly created surface.
Definition at line 320 of file local_retriever.cpp. References NLPACS::CRetrievableSurface::_Center, NLPACS::CRetrievableSurface::_Character, NLPACS::CRetrievableSurface::_Flags, NLPACS::CRetrievableSurface::_IsCeiling, NLPACS::CRetrievableSurface::_IsFloor, NLPACS::CRetrievableSurface::_Level, NLPACS::CRetrievableSurface::_Material, NLPACS::CRetrievableSurface::_NormalQuanta, NLPACS::CRetrievableSurface::_OrientationQuanta, NLPACS::CRetrievableSurface::_Quad, NLPACS::CRetrievableSurface::_QuantHeight, _Surfaces, NLPACS::CRetrievableSurface::_WaterHeight, level, sint32, sint8, and uint8. Referenced by NLPACS::buildSurfaces().
00327 { 00328 // creates a new surface... 00329 sint32 newId = _Surfaces.size(); 00330 _Surfaces.resize(newId+1); 00331 CRetrievableSurface &surf = _Surfaces.back(); 00332 00333 // ... and fills it 00334 surf._NormalQuanta = normalq; 00335 surf._OrientationQuanta = orientationq; 00336 surf._Material = mat; 00337 surf._Character = charact; 00338 surf._Level = level; 00339 surf._Quad = quad; 00340 surf._Center = center; 00341 surf._QuantHeight = quantHeight; 00342 00343 // WARNING!! MODIFY THESE IF QUANTAS VALUES CHANGE !! 00344 surf._IsFloor = (surf._NormalQuanta <= 1); 00345 surf._IsCeiling = (surf._NormalQuanta >= 3); 00346 00347 surf._Flags = 0; 00348 surf._Flags |= (surf._IsFloor) ? (1<<CRetrievableSurface::IsFloorBit) : 0; 00349 surf._Flags |= (surf._IsCeiling) ? (1<<CRetrievableSurface::IsCeilingBit) : 0; 00350 surf._Flags |= (!surf._IsFloor && !surf._IsCeiling) ? (1<<CRetrievableSurface::IsSlantBit) : 0; 00351 surf._Flags |= clusterHint ? (1<<CRetrievableSurface::ClusterHintBit) : 0; 00352 00353 surf._Flags |= (isUnderWater) ? (1<<CRetrievableSurface::IsUnderWaterBit) : 0; 00354 surf._WaterHeight = waterHeight; 00355 00356 surf._Flags |= ((0xffffffff<<(CRetrievableSurface::NormalQuantasStartBit)) & CRetrievableSurface::NormalQuantasBitMask); 00357 00358 return newId; 00359 } |
|
Builds the polygons (loops) of all surfaces in the retriever.
Definition at line 448 of file local_retriever.h. References _Surfaces, build3dSurfacePolygons(), and uint.
00449 { 00450 uint i; 00451 for (i=0; i<_Surfaces.size(); ++i) 00452 { 00453 polygons.push_back(); 00454 build3dSurfacePolygons(i, polygons.back()); 00455 } 00456 } |
|
Builds the polygons (loops) of a given surface.
Definition at line 714 of file local_retriever.cpp. References NLPACS::CRetrievableSurface::_Chains, _Chains, _FullOrderedChains, NLPACS::CChain::_Left, NLPACS::CRetrievableSurface::_Loops, NLPACS::CChain::_SubChains, _Surfaces, NLPACS::COrderedChain3f::getVertices(), NLPACS::COrderedChain3f::isForward(), sint, uint, uint32, and NLMISC::CPolygon::Vertices. Referenced by build3dSurfacePolygons().
00715 { 00716 const CRetrievableSurface &surf = _Surfaces[surface]; 00717 00718 uint i, j, k, l; 00719 00720 for (i=0; i<surf._Loops.size(); ++i) 00721 { 00722 polygons.push_back(); 00723 CPolygon &poly = polygons.back(); 00724 00725 for (j=0; j<surf._Loops[i].size(); ++j) 00726 { 00727 const CRetrievableSurface::TLoop &loop = surf._Loops[i]; 00728 const CChain &chain = _Chains[surf._Chains[loop[j]].Chain]; 00729 bool chainforward = ((uint32)chain._Left == surface); 00730 00731 if (chainforward) 00732 { 00733 for (k=0; k<chain._SubChains.size(); ++k) 00734 { 00735 const COrderedChain3f &ochain = _FullOrderedChains[chain._SubChains[k]]; 00736 bool ochainforward = ochain.isForward(); 00737 00738 if (ochainforward) 00739 { 00740 for (l=0; l<ochain.getVertices().size()-1; ++l) 00741 poly.Vertices.push_back(ochain[l]); 00742 } 00743 else 00744 { 00745 for (l=ochain.getVertices().size()-1; l>0; --l) 00746 poly.Vertices.push_back(ochain[l]); 00747 } 00748 } 00749 } 00750 else 00751 { 00752 for (k=chain._SubChains.size()-1; (sint)k>=0; --k) 00753 { 00754 const COrderedChain3f &ochain = _FullOrderedChains[chain._SubChains[k]]; 00755 bool ochainforward = ochain.isForward(); 00756 00757 if (ochainforward) 00758 { 00759 for (l=ochain.getVertices().size()-1; (sint)l>0; --l) 00760 poly.Vertices.push_back(ochain[l]); 00761 } 00762 else 00763 { 00764 for (l=0; l<ochain.getVertices().size()-1; ++l) 00765 poly.Vertices.push_back(ochain[l]); 00766 } 00767 } 00768 } 00769 } 00770 } 00771 } |
|
build BBoxes of interior surfaces in surfaceBBoxes (cleared first)
Definition at line 1935 of file local_retriever.cpp. References _InteriorFaces, _InteriorVertices, _Surfaces, nlassert, NLPACS::CLocalRetriever::CInteriorFace::Surface, uint, and NLPACS::CLocalRetriever::CInteriorFace::Verts.
01936 { 01937 // resize dest, and init. 01938 vector<bool> firstTriangle; 01939 surfaceBBoxes.clear(); 01940 surfaceBBoxes.resize(_Surfaces.size()); 01941 firstTriangle.resize(_Surfaces.size(), true); 01942 01943 // For all _InteriorFaces. 01944 for(uint iIntFace=0; iIntFace<_InteriorFaces.size(); iIntFace++) 01945 { 01946 const CInteriorFace &intFace= _InteriorFaces[iIntFace]; 01947 01948 // Extend the surface of this face with her 3 points. 01949 01950 // check good id. 01951 if(intFace.Surface==(uint)-1) 01952 continue; 01953 nlassert(intFace.Surface<_Surfaces.size()); 01954 01955 // If first time we extend the bbox of this surface 01956 if(firstTriangle[intFace.Surface]) 01957 { 01958 surfaceBBoxes[intFace.Surface].setCenter(_InteriorVertices[intFace.Verts[0]] ); 01959 firstTriangle[intFace.Surface]= false; 01960 } 01961 else 01962 surfaceBBoxes[intFace.Surface].extend(_InteriorVertices[intFace.Verts[0]] ); 01963 01964 // extend with other 2 points 01965 surfaceBBoxes[intFace.Surface].extend(_InteriorVertices[intFace.Verts[1]] ); 01966 surfaceBBoxes[intFace.Surface].extend(_InteriorVertices[intFace.Verts[2]] ); 01967 } 01968 01969 } |
|
Builds the polygons (loops) of all surfaces in the retriever.
Definition at line 434 of file local_retriever.h. References _Surfaces, buildSurfacePolygons(), and uint.
00435 { 00436 uint i; 00437 for (i=0; i<_Surfaces.size(); ++i) 00438 { 00439 polygons.push_back(); 00440 buildSurfacePolygons(i, polygons.back()); 00441 } 00442 } |
|
Builds the polygons (loops) of a given surface.
Definition at line 655 of file local_retriever.cpp. References _Chains, NLPACS::CChain::_Left, NLPACS::CRetrievableSurface::_Loops, _OrderedChains, NLPACS::CChain::_SubChains, _Surfaces, NLPACS::COrderedChain::getVertices(), NLPACS::COrderedChain::isForward(), sint, uint, uint32, and NLMISC::CPolygon::Vertices. Referenced by buildSurfacePolygons().
00656 { 00657 const CRetrievableSurface &surf = _Surfaces[surface]; 00658 00659 uint i, j, k, l; 00660 00661 for (i=0; i<surf._Loops.size(); ++i) 00662 { 00663 polygons.push_back(); 00664 CPolygon &poly = polygons.back(); 00665 00666 for (j=0; j<surf._Loops[i].size(); ++j) 00667 { 00668 const CChain &chain = _Chains[surf._Loops[i][j]]; 00669 bool chainforward = ((uint32)chain._Left == surface); 00670 00671 if (chainforward) 00672 { 00673 for (k=0; k<chain._SubChains.size(); ++k) 00674 { 00675 const COrderedChain &ochain = _OrderedChains[chain._SubChains[k]]; 00676 bool ochainforward = ochain.isForward(); 00677 00678 if (ochainforward) 00679 { 00680 for (l=0; l<ochain.getVertices().size()-1; ++l) 00681 poly.Vertices.push_back(ochain[l].unpack3f()); 00682 } 00683 else 00684 { 00685 for (l=ochain.getVertices().size()-1; l>0; --l) 00686 poly.Vertices.push_back(ochain[l].unpack3f()); 00687 } 00688 } 00689 } 00690 else 00691 { 00692 for (k=chain._SubChains.size(); (sint)k>0; --k) 00693 { 00694 const COrderedChain &ochain = _OrderedChains[chain._SubChains[k]]; 00695 bool ochainforward = ochain.isForward(); 00696 00697 if (ochainforward) 00698 { 00699 for (l=ochain.getVertices().size()-1; (sint)l>0; --l) 00700 poly.Vertices.push_back(ochain[l].unpack3f()); 00701 } 00702 else 00703 { 00704 for (l=0; l<ochain.getVertices().size()-1; ++l) 00705 poly.Vertices.push_back(ochain[l].unpack3f()); 00706 } 00707 } 00708 } 00709 } 00710 } 00711 } |
|
Clear.
Definition at line 64 of file local_retriever.cpp. References __Tips, _BorderChains, _ChainQuad, _Chains, _ExteriorMesh, _FaceGrid, _FullOrderedChains, _InteriorFaces, _InteriorVertices, _Loaded, _OrderedChains, _Surfaces, _Topologies, NLPACS::CFaceGrid::clear(), NLPACS::CExteriorMesh::clear(), NLPACS::CChainQuad::clear(), LoadCheckFlag, NLPACS::NumMaxCreatureModels, and uint.
00065 { 00066 contReset(_OrderedChains); 00067 contReset(_FullOrderedChains); 00068 contReset(_Chains); 00069 contReset(_Surfaces); 00070 contReset(__Tips); 00071 contReset(_BorderChains); 00072 uint i; 00073 for (i=0; i<NumMaxCreatureModels; ++i) 00074 contReset(_Topologies[i]); 00075 _ChainQuad.clear(); 00076 _ExteriorMesh.clear(); 00077 contReset(_InteriorVertices); 00078 contReset(_InteriorFaces); 00079 _FaceGrid.clear(); 00080 _Id.resize(0); 00081 _Loaded = false; 00082 LoadCheckFlag = false; 00083 } |
|
compute the chain quad, used for collisions. the ChainQuad is serialised in serial(). _OrderedChains must be OK.
Definition at line 1800 of file local_retriever.cpp. References _ChainQuad, _OrderedChains, and NLPACS::CChainQuad::build(). Referenced by NLPACS::computeRetriever().
01801 { 01802 _ChainQuad.build(_OrderedChains); 01803 } |
|
Builds tips.
Definition at line 456 of file local_retriever.cpp. References _Chains, NLPACS::CRetrievableSurface::_Chains, NLPACS::CRetrievableSurface::_Loops, _Surfaces, dumpSurface(), getStartVector(), getStopVector(), nlerror, nlinfo, nlwarning, sint, uint, uint32, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z. Referenced by NLPACS::computeRetriever().
00457 { 00458 // for each surface, 00459 // examine each chain tip to match another tip inside the surface tips 00460 // if there is no matching tip, then creates a new one 00461 00462 uint i, j; 00463 00464 for (i=0; i<_Surfaces.size(); ++i) 00465 { 00466 CRetrievableSurface &surface = _Surfaces[i]; 00467 00468 vector<bool> chainFlags; 00469 chainFlags.resize(surface._Chains.size()); 00470 for (j=0; j<chainFlags.size(); ++j) 00471 chainFlags[j] = false; 00472 00473 uint totalAdded = 0; 00474 00475 while (true) 00476 { 00477 for (j=0; j<chainFlags.size() && chainFlags[j]; ++j) 00478 ; 00479 00480 if (j == chainFlags.size()) 00481 break; 00482 00483 uint32 loopId = surface._Loops.size(); 00484 surface._Loops.push_back(CRetrievableSurface::TLoop()); 00485 CRetrievableSurface::TLoop &loop = surface._Loops.back(); 00486 00487 CVector loopStart = getStartVector(surface._Chains[j].Chain, i); 00488 CVector currentEnd = getStopVector(surface._Chains[j].Chain, i); 00489 _Chains[surface._Chains[j].Chain].setLoopIndexes(i, loopId, loop.size()); 00490 loop.push_back(j); 00491 chainFlags[j] = true; 00492 00493 float loopCloseDistance; 00494 00495 while (true) 00496 { 00497 // loopCloseDistance = hybrid2dNorm(loopStart-currentEnd); 00498 loopCloseDistance = (loopStart-currentEnd).norm(); 00499 00500 // choose the best matching start vector 00501 sint bestChain = -1; 00502 float best = 1.0e10f; 00503 CVector thisStart; 00504 for (j=0; j<chainFlags.size(); ++j) 00505 { 00506 if (chainFlags[j]) 00507 continue; 00508 thisStart = getStartVector(surface._Chains[j].Chain, i); 00509 // float d = hybrid2dNorm(thisStart-currentEnd); 00510 float d = (thisStart-currentEnd).norm(); 00511 if (d < best) 00512 { 00513 best = d; 00514 bestChain = j; 00515 } 00516 } 00517 00518 if ((bestChain == -1 || best > 3.0e-2f)&& loopCloseDistance > 3.0e-2f) 00519 { 00520 nlwarning("in NLPACS::CLocalRetriever::computeTips()"); 00521 00522 dumpSurface(i); 00523 00524 for (j=0; j<surface._Chains.size(); ++j) 00525 { 00526 CVector start = getStartVector(surface._Chains[j].Chain, i); 00527 CVector end = getStopVector(surface._Chains[j].Chain, i); 00528 nlinfo("surf=%d chain=%d", i, surface._Chains[j].Chain); 00529 nlinfo("start=(%f,%f,%f)", start.x, start.y, start.z); 00530 nlinfo("end=(%f,%f,%f)", end.x, end.y, end.z); 00531 } 00532 00533 nlwarning("bestChain=%d best=%f", bestChain, best); 00534 nlwarning("loopCloseDistance=%f", loopCloseDistance); 00535 nlerror("Couldn't close loop on surface=%d", i); 00536 } 00537 else if (best > 1.0e0f && loopCloseDistance < 3.0e-2f || 00538 loopCloseDistance < 1.0e-3f) 00539 { 00540 break; 00541 } 00542 00543 currentEnd = getStopVector(surface._Chains[bestChain].Chain, i); 00544 _Chains[surface._Chains[bestChain].Chain].setLoopIndexes(i, loopId, loop.size()); 00545 loop.push_back(bestChain); 00546 chainFlags[bestChain] = true; 00547 ++totalAdded; 00548 } 00549 } 00550 } 00551 /* 00552 dumpSurface(9); 00553 dumpSurface(10); 00554 00555 for (i=0; i<_Chains.size(); ++i) 00556 { 00557 if (i == 127) 00558 nlinfo(""); 00559 00560 uint whichTip; 00561 // for both tips (start and stop) 00562 for (whichTip=0; whichTip<=1; ++whichTip) 00563 { 00564 // get the tip id 00565 uint thisTip = (whichTip) ? _Chains[i].getStopTip() : _Chains[i].getStartTip(); 00566 00567 if (thisTip != 0xffff && thisTip >= _Tips.size()) 00568 { 00569 nlwarning("in NLPACS::CLocalRetriever::computeLoopsAndTips()"); 00570 nlerror("checked a tip that doesn't exist on chain %d (tipId=%d)", i, thisTip); 00571 } 00572 00573 // if it is unaffected yet creates an new tip and affect it to the common chains 00574 if (thisTip == 0xffff) 00575 { 00576 uint turn; 00577 uint tipId = _Tips.size(); 00578 00579 if (tipId == 62) 00580 nlinfo(""); 00581 00582 _Tips.resize(tipId+1); 00583 CTip &tip = _Tips[tipId]; 00584 tip.Point = (whichTip) ? getStopVector(i) : getStartVector(i); 00585 00586 for (turn=0; turn<=1; ++turn) 00587 { 00588 uint chain = i; 00589 00590 // 00591 if (whichTip) 00592 _Chains[chain]._StopTip = tipId; 00593 else 00594 _Chains[chain]._StartTip = tipId; 00595 00596 sint32 surf = (!turn && !whichTip || turn && whichTip) ? _Chains[chain].getLeft() : _Chains[chain].getRight(); 00597 00598 while (surf >= 0) 00599 { 00600 00601 CChain &nextChain = (turn) ? _Chains[chain = getNextChain(chain, surf)] : _Chains[chain = getPreviousChain(chain, surf)]; 00602 bool isForward = (nextChain.getLeft() == surf); // tells if the left surf is the current surf 00603 bool selectTip = isForward && !turn || !isForward && turn; 00604 uint16 &tipRef = selectTip ? nextChain._StopTip : nextChain._StartTip; 00605 surf = (isForward) ? nextChain.getRight() : nextChain.getLeft(); 00606 00607 if (tipRef != 0xffff && tipRef != tipId) 00608 { 00609 nlwarning("in NLPACS::CLocalRetriever::computeLoopsAndTips()"); 00610 nlerror("Trying to setup a already created tip (tipId=%d, previous=%d)", tipId, tipRef); 00611 } 00612 else if (tipRef != 0xffff) 00613 { 00614 break; 00615 } 00616 00617 tipRef = tipId; 00618 } 00619 } 00620 } 00621 } 00622 } 00623 00624 for (i=0; i<_Chains.size(); ++i) 00625 { 00626 uint startTip = _Chains[i].getStartTip(), 00627 stopTip = _Chains[i].getStopTip(); 00628 00629 00630 // if (_Chains[i].getEdge() >= 0 && startTip == stopTip) 00631 // { 00632 // nlwarning("NLPACS::CLocalRetriever::computeLoopsAndTips(): chain %d on edge %d has same StartTip and StopTip", i, _Chains[i].getEdge(), startTip, stopTip); 00633 // } 00634 00635 00636 _Tips[startTip].Chains.push_back(CTip::CChainTip(i, true)); 00637 _Tips[stopTip].Chains.push_back(CTip::CChainTip(i, false)); 00638 } 00639 */ 00640 for (i=0; i<_Surfaces.size(); ++i) 00641 { 00642 for (j=0; j<_Surfaces[i]._Loops.size(); ++j) 00643 { 00644 _Surfaces[i]._Loops[j].Length = 0.0f; 00645 uint k; 00646 00647 for (k=0; k<_Surfaces[i]._Loops[j].size(); ++k) 00648 _Surfaces[i]._Loops[j].Length += _Chains[_Surfaces[i]._Chains[_Surfaces[i]._Loops[j][k]].Chain].getLength(); 00649 } 00650 } 00651 } |
|
Builds topologies tables.
Definition at line 822 of file local_retriever.cpp. References _Chains, NLPACS::CRetrievableSurface::_Chains, NLPACS::CRetrievableSurface::_Character, _Surfaces, _Topologies, NLPACS::CRetrievableSurface::_Topologies, NLPACS::CChain::getLeft(), NLPACS::CChain::getRight(), NLPACS::NumCreatureModels, sint, sint32, and uint. Referenced by NLPACS::computeRetriever().
00823 { 00824 //nlinfo("compute topologies"); 00825 00826 // Find topologies out... 00827 uint character; 00828 for (character=0; character<NumCreatureModels; ++character) 00829 { 00830 // for each type of creature, flood fill surfaces... 00831 sint32 surface; 00832 uint topology = 0; 00833 00834 for (surface=0; surface<(sint)_Surfaces.size(); ++surface) 00835 { 00836 if (_Surfaces[surface]._Topologies[character] == -1 && 00837 _Surfaces[surface]._Character == character) 00838 { 00839 vector<sint32> surfacesStack; 00840 surfacesStack.push_back(surface); 00841 00842 while (!surfacesStack.empty()) 00843 { 00844 CRetrievableSurface ¤t = _Surfaces[surfacesStack.back()]; 00845 surfacesStack.pop_back(); 00846 current._Topologies[character] = topology; 00847 00848 uint i; 00849 for (i=0; i<current._Chains.size(); ++i) 00850 { 00851 CChain &chain = _Chains[current._Chains[i].Chain]; 00852 sint32 link = (chain.getLeft() == surface) ? chain.getRight() : chain.getLeft(); 00853 if (link>=0 && link<(sint)_Surfaces.size() && 00854 _Surfaces[link]._Topologies[character] == -1 && 00855 _Surfaces[link]._Character >= character) 00856 { 00857 surfacesStack.push_back(link); 00858 _Surfaces[link]._Topologies[character] = topology; 00859 } 00860 } 00861 } 00862 00863 ++topology; 00864 } 00865 } 00866 00867 _Topologies[character].resize(topology); 00868 //nlinfo("generated %d topologies for character %d", topology, character); 00869 } 00870 00871 uint surface; 00872 for (surface=0; surface<_Surfaces.size(); ++surface) 00873 { 00874 CRetrievableSurface ¤t = _Surfaces[surface]; 00875 00876 for (character=0; character<NumCreatureModels; ++character) 00877 if (current._Topologies[character] >= 0) 00878 _Topologies[character][current._Topologies[character]].push_back(surface); 00879 } 00880 } |
|
Definition at line 291 of file local_retriever.cpp. References _Chains, NLPACS::CRetrievableSurface::_Chains, _OrderedChains, _Surfaces, NLPACS::ULocalPosition::Estimation, NLPACS::CChain::getSubChain(), NLPACS::CChain::getSubChains(), isLoaded(), NLPACS::ULocalPosition::Surface, and uint. Referenced by NLPACS::CGlobalRetriever::distanceToBorder().
00292 { 00293 if (!isLoaded()) 00294 return 0.0f; 00295 00296 const CRetrievableSurface &surf = _Surfaces[pos.Surface]; 00297 uint i, j; 00298 float minDist = 1.0e10f, dist; 00299 00300 for (i=0; i<surf._Chains.size(); ++i) 00301 { 00302 const CChain &chain = _Chains[surf._Chains[i].Chain]; 00303 for (j=0; j<chain.getSubChains().size(); ++j) 00304 { 00305 dist = _OrderedChains[chain.getSubChain(j)].distance(pos.Estimation); 00306 if (dist < minDist) 00307 { 00308 minDist = dist; 00309 } 00310 } 00311 } 00312 00313 return minDist; 00314 } |
|
Definition at line 248 of file local_retriever.cpp. References _Chains, NLPACS::CRetrievableSurface::_Chains, _FullOrderedChains, NLPACS::CRetrievableSurface::_Loops, _OrderedChains, _Surfaces, buffer, NLPACS::COrderedChain3f::getIndexInParent(), NLPACS::CChain::getLeft(), NLPACS::COrderedChain3f::getParentId(), NLPACS::CChain::getRight(), NLPACS::CChain::getStartTip(), NLPACS::CChain::getStopTip(), NLPACS::CChain::getSubChain(), NLPACS::CChain::getSubChains(), NLPACS::COrderedChain::getVertices(), NLPACS::COrderedChain3f::getVertices(), NLPACS::COrderedChain3f::isForward(), NLPACS::CRetrievableSurface::TLoop::Length, nlinfo, uint, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z. Referenced by computeLoopsAndTips().
00249 { 00250 const CRetrievableSurface &surface = _Surfaces[surf]; 00251 00252 nlinfo("dump surf %d", surf); 00253 nlinfo("%d chains, %d loops", surface._Chains.size(), surface._Loops.size()); 00254 00255 uint i, j, k; 00256 00257 for (i=0; i<surface._Chains.size(); ++i) 00258 { 00259 uint chainId = surface._Chains[i].Chain; 00260 const CChain &chain = _Chains[chainId]; 00261 nlinfo("-- chain %d[%d]: %d sub left=%d right=%d start=%d stop=%d", i, chainId, chain.getSubChains().size(), chain.getLeft(), chain.getRight(), chain.getStartTip(), chain.getStopTip()); 00262 00263 for (j=0; j<chain.getSubChains().size(); ++j) 00264 { 00265 const COrderedChain3f &ochain = _FullOrderedChains[chain.getSubChain(j)]; 00266 const COrderedChain &ochains = _OrderedChains[chain.getSubChain(j)]; 00267 nlinfo(" subchain %d[%d]: fwd=%d parent=%d idx=%d", j, chain.getSubChain(j), ochain.isForward(), ochain.getParentId(), ochain.getIndexInParent()); 00268 for (k=0; k<ochain.getVertices().size(); ++k) 00269 nlinfo(" v[%d]=(%.3f,%.3f,%.3f) (%d,%d)", k, ochain.getVertices()[k].x+vect.x, ochain.getVertices()[k].y+vect.y, ochain.getVertices()[k].z+vect.z, ochains.getVertices()[k].x, ochains.getVertices()[k].y); 00270 } 00271 00272 } 00273 00274 for (i=0; i<surface._Loops.size(); ++i) 00275 { 00276 const CRetrievableSurface::TLoop &loop = surface._Loops[i]; 00277 nlinfo("-- loop %d: %d chains length=%.2f", i, loop.size(), loop.Length); 00278 static char wbuffer[256]; 00279 static char buffer[10240]; 00280 sprintf(buffer, " chains:"); 00281 for (j=0; j<loop.size(); ++j) 00282 { 00283 sprintf(wbuffer, " %d[%d]", loop[j], surface._Chains[loop[j]].Chain); 00284 strcat(buffer, wbuffer); 00285 } 00286 nlinfo("%s", buffer); 00287 } 00288 } |
|
Found chains on the edges of the retriever and fills _BorderChains tables.
Definition at line 782 of file local_retriever.cpp. References _BorderChains, _Chains, index, sint32, and uint. Referenced by NLPACS::computeRetriever().
00783 { 00784 uint chain; 00785 00786 // for each chain, if it belongs to an edge of the 00787 // local retriever, then adds it to the _BorderChains. 00788 for (chain=0; chain<_Chains.size(); ++chain) 00789 if (_Chains[chain].isBorderChain()) 00790 { 00791 sint32 index = _BorderChains.size(); 00792 _BorderChains.push_back(chain); 00793 _Chains[chain].setBorderChainIndex(index); 00794 } 00795 } |
|
Finds a path in a given surface, from the point A to the point B.
Definition at line 1576 of file local_retriever.cpp. References _ChainQuad, NLPACS::CRetrievableSurface::_Chains, _Chains, NLPACS::CRetrievableSurface::_Loops, _OrderedChains, NLPACS::CChain::_SubChains, _Surfaces, NLPACS::CCollisionSurfaceTemp::EdgeChainEntries, NLPACS::CEdgeChainEntry::EdgeEnd, NLPACS::CEdgeChainEntry::EdgeStart, NLPACS::ULocalPosition::Estimation, from, NLPACS::CChain::getLeft(), NLPACS::CChain::getLeftLoop(), NLPACS::CChain::getLeftLoopIndex(), NLPACS::CChain::getLength(), NLPACS::COrderedChain::getParentId(), NLPACS::CChain::getRightLoop(), NLPACS::CChain::getRightLoopIndex(), NLPACS::CRetrievableSurface::TLoop::Length, nlerror, nlwarning, NLPACS::CEdgeChainEntry::OChainId, NLPACS::CChainQuad::selectEdges(), sint, sint32, NLPACS::ULocalPosition::Surface, uint, NLMISC::CVector::x, and NLMISC::CVector::y. Referenced by NLPACS::CGlobalRetriever::findPath().
01580 { 01581 if (A.Surface != B.Surface) 01582 { 01583 nlwarning("in NLPACS::CLocalRetriever::findPath()"); 01584 nlerror("Try to find a path between 2 points that are not in the same surface (A=%d, B=%d)", A.Surface, B.Surface); 01585 } 01586 01587 CVector a = A.Estimation, 01588 b = B.Estimation, 01589 n = CVector(a.y-b.y, b.x-a.x, 0.0f); 01590 01591 _ChainQuad.selectEdges(a, b, cst); 01592 01594 vector<CIntersectionMarker> intersections; 01595 01596 uint i, j; 01597 sint32 surfaceId = A.Surface; 01598 const CRetrievableSurface &surface = _Surfaces[surfaceId]; 01599 01600 for (i=0; i<cst.EdgeChainEntries.size(); ++i) 01601 { 01602 CEdgeChainEntry &entry = cst.EdgeChainEntries[i]; 01603 const COrderedChain &chain = _OrderedChains[entry.OChainId]; 01604 01605 if (_Chains[chain.getParentId()].getLeft() != surfaceId && 01606 _Chains[chain.getParentId()].getRight() != surfaceId) 01607 continue; 01608 01609 for (j=entry.EdgeStart; j<entry.EdgeEnd; ++j) 01610 { 01611 // here the edge collision test 01612 01613 CVector p0 = chain[j].unpack3f(), 01614 p1 = chain[j+1].unpack3f(); 01615 01616 float vp0 = (p0-a)*n, 01617 vp1 = (p1-a)*n; 01618 01619 if (vp0*vp1 <= 0.0f) 01620 { 01621 CVector np = CVector(p0.y-p1.y, p1.x-p0.x, 0.0f); 01622 01623 float va = (a-p0)*np, 01624 vb = (b-p0)*np; 01625 01626 // here we have an intersection 01627 if (va*vb <= 0.0f) 01628 { 01629 const CChain &parent = _Chains[chain.getParentId()]; 01630 bool isIn = (va-vb < 0.0f) ^ (parent.getLeft() == surfaceId) ^ chain.isForward(); 01631 01632 intersections.push_back(CIntersectionMarker(va/(va-vb), entry.OChainId, j, isIn)); 01633 } 01634 } 01635 } 01636 } 01637 01638 sort(intersections.begin(), intersections.end()); 01639 01640 uint intersStart = 0; 01641 uint intersEnd = intersections.size(); 01642 01643 if (intersEnd > 0) 01644 { 01645 while (intersStart < intersections.size() && 01646 intersections[intersStart].In && intersections[intersStart].Position < 1.0e-4f) 01647 ++intersStart; 01648 01649 while (intersStart < intersEnd && 01650 !intersections[intersEnd-1].In && intersections[intersEnd-1].Position > 1.0f-1.0e-4f) 01651 --intersEnd; 01652 01653 // Check intersections have a valid order 01654 if ((intersEnd-intersStart) & 1) 01655 { 01656 nlwarning("in NLPACS::CLocalRetriever::findPath()"); 01657 nlerror("Found an odd (%d) number of intersections", intersections.size()); 01658 } 01659 01660 for (i=intersStart; i<intersEnd; ) 01661 { 01662 uint exitLoop, enterLoop; 01663 01664 const CChain &exitChain = _Chains[_OrderedChains[intersections[i].OChain].getParentId()]; 01665 exitLoop = (exitChain.getLeft() == surfaceId) ? exitChain.getLeftLoop() : exitChain.getRightLoop(); 01666 01667 if (intersections[i++].In) 01668 { 01669 nlwarning("in NLPACS::CLocalRetriever::findPath()"); 01670 nlerror("Entered the surface before exited", intersections.size()); 01671 } 01672 01673 const CChain &enterChain = _Chains[_OrderedChains[intersections[i].OChain].getParentId()]; 01674 enterLoop = (enterChain.getLeft() == surfaceId) ? enterChain.getLeftLoop() : enterChain.getRightLoop(); 01675 01676 if (!intersections[i++].In) 01677 { 01678 nlwarning("in NLPACS::CLocalRetriever::findPath()"); 01679 nlerror("Exited twice the surface", intersections.size()); 01680 } 01681 01682 if (exitLoop != enterLoop) 01683 { 01684 nlwarning("in NLPACS::CLocalRetriever::findPath()"); 01685 nlerror("Exited and rentered by a different loop"); 01686 } 01687 } 01688 } 01689 01690 // dumpSurface(surfaceId); 01691 01692 path.push_back(CVector2s(A.Estimation)); 01693 01694 for (i=intersStart; i<intersEnd; ) 01695 { 01696 uint exitChainId = _OrderedChains[intersections[i].OChain].getParentId(), 01697 enterChainId = _OrderedChains[intersections[i+1].OChain].getParentId(); 01698 const CChain &exitChain = _Chains[exitChainId], 01699 &enterChain = _Chains[enterChainId]; 01700 uint loopId, exitLoopIndex, enterLoopIndex; 01701 01702 if (exitChain.getLeft() == surfaceId) 01703 { 01704 loopId = exitChain.getLeftLoop(); 01705 exitLoopIndex = exitChain.getLeftLoopIndex(); 01706 } 01707 else 01708 { 01709 loopId = exitChain.getRightLoop(); 01710 exitLoopIndex = exitChain.getRightLoopIndex(); 01711 } 01712 01713 const CRetrievableSurface::TLoop &loop = surface._Loops[loopId]; 01714 01715 if (enterChain.getLeft() == surfaceId) 01716 enterLoopIndex = enterChain.getLeftLoopIndex(); 01717 else 01718 enterLoopIndex = enterChain.getRightLoopIndex(); 01719 01720 float forwardLength = (exitChain.getLength()+enterChain.getLength())*0.5f; 01721 01722 sint loopIndex = exitLoopIndex; 01723 uint thisChainId = exitChainId; 01724 bool thisChainForward = (enterChain.getLeft() == surfaceId); 01725 uint thisOChainId = intersections[i].OChain; 01726 sint thisOChainIndex = _OrderedChains[thisOChainId].getIndexInParent(); 01727 bool forward; 01728 01729 if (exitChainId != enterChainId) 01730 { 01731 for (j=(exitLoopIndex+1)%loop.size(); j!=enterLoopIndex; j=(j+1)%loop.size()) 01732 forwardLength += _Chains[surface._Chains[loop[j]].Chain].getLength(); 01733 forward = (forwardLength <= loop.Length-forwardLength); 01734 } 01735 else 01736 { 01737 forward = !thisChainForward ^ (_OrderedChains[intersections[i].OChain].getIndexInParent() < _OrderedChains[intersections[i+1].OChain].getIndexInParent()); 01738 } 01739 01740 path.push_back(CVector2s(A.Estimation+intersections[i].Position*(B.Estimation-A.Estimation))); 01741 01742 while (true) 01743 { 01744 sint from = (thisOChainId == intersections[i].OChain) ? intersections[i].Edge : -1, 01745 to = (thisOChainId == intersections[i+1].OChain) ? intersections[i+1].Edge : -1; 01746 bool oforward = thisChainForward ^ forward ^ _OrderedChains[thisOChainId].isForward(); 01747 01748 if (from != -1 && to != -1) 01749 oforward = (intersections[i].Edge < intersections[i+1].Edge); 01750 01751 _OrderedChains[thisOChainId].traverse(from, to, oforward, path); 01752 01753 if (thisOChainId == intersections[i+1].OChain) 01754 break; 01755 01756 thisOChainIndex = (thisChainForward ^ forward) ? thisOChainIndex-1 : thisOChainIndex+1; 01757 01758 if (thisOChainIndex < 0 || thisOChainIndex >= (sint)_Chains[thisChainId]._SubChains.size()) 01759 { 01760 if (forward) 01761 { 01762 loopIndex++; 01763 if (loopIndex == (sint)loop.size()) 01764 loopIndex = 0; 01765 } 01766 else 01767 { 01768 loopIndex--; 01769 if (loopIndex < 0) 01770 loopIndex = loop.size()-1; 01771 } 01772 01773 thisChainId = surface._Chains[loop[loopIndex]].Chain; 01774 thisChainForward = (_Chains[thisChainId].getLeft() == surfaceId); 01775 thisOChainIndex = (thisChainForward && forward || !thisChainForward && !forward) ? 01776 0 : _Chains[thisChainId]._SubChains.size()-1; 01777 } 01778 01779 thisOChainId = _Chains[thisChainId]._SubChains[thisOChainIndex]; 01780 } 01781 01782 path.push_back(CVector2s(A.Estimation+intersections[i+1].Position*(B.Estimation-A.Estimation))); 01783 i += 2; 01784 } 01785 01786 path.push_back(CVector2s(B.Estimation)); 01787 } |
|
Adds a chain to the local retriever, using the vertices of the chain, the left and right surfaces id and the edge on which the chain is stuck Definition at line 529 of file local_retriever.h. References _FullOrderedChains.
00529 { _FullOrderedChains.clear(); } |
|
Definition at line 602 of file local_retriever.h. References _Chains, nlwarning, and uint32.
|
|
Force Loaded State.
Definition at line 425 of file local_retriever.h. References _Loaded.
00425 { _Loaded= state; } |
|
Returns the bbox.
Definition at line 407 of file local_retriever.h. Referenced by NLPACS::CRetrieverInstance::make().
00407 { return _BBox; } |
|
Returns the id of the nth chain on the edges of the retriever.
Definition at line 396 of file local_retriever.h. References _BorderChains, uint, and uint16.
00396 { return _BorderChains[n]; } |
|
Returns the ids of the chains on the edges of the retriever.
Definition at line 394 of file local_retriever.h. References _BorderChains. Referenced by NLPACS::CGlobalRetriever::check(), NLPACS::CRetrieverInstance::init(), NLPACS::CRetrieverInstance::link(), and NLPACS::linkExteriorToInterior().
00394 { return _BorderChains; } |
|
|
Returns the chain quad.
Definition at line 500 of file local_retriever.h. References _ChainQuad. Referenced by NLPACS::CGlobalRetriever::getBorders().
00500 { return _ChainQuad; } |
|
Returns the chains.
Definition at line 389 of file local_retriever.h. References _Chains. Referenced by NLPACS::CGlobalRetriever::check(), NLPACS::CRetrieverInstance::link(), NLPACS::linkExteriorToInterior(), and testCollision().
00389 { return _Chains; } |
|
Returns the exterior mesh of the retriever.
Definition at line 410 of file local_retriever.h. References _ExteriorMesh. Referenced by NLPACS::CRetrieverInstance::initEdgeQuad(), NLPACS::CRetrieverInstance::linkEdgeQuad(), and NLPACS::linkExteriorToInterior().
00410 { return _ExteriorMesh; } |
|
Returns the nth full ordered chain.
Definition at line 386 of file local_retriever.h. References _FullOrderedChains, and uint. Referenced by NLPACS::CLocalRetriever::CIterator::get3d(), and NLPACS::CGlobalRetriever::getBorders().
00386 { return _FullOrderedChains[n]; } |
|
Returns the full ordered chains.
Definition at line 384 of file local_retriever.h. References _FullOrderedChains. Referenced by NLPACS::CGlobalRetriever::getBorders(), and NLPACS::linkExteriorToInterior().
00384 { return _FullOrderedChains; } |
|
Definition at line 1479 of file local_retriever.cpp. References _FaceGrid, _InteriorFaces, _InteriorVertices, _Loaded, _Surfaces, NLPACS::ULocalPosition::Estimation, NLPACS::IQuadNode::getMaxHeight(), NLPACS::IQuadNode::getMinHeight(), NLMISC::CPlane::intersect(), NLMISC::CPlane::make(), NLPACS::CFaceGrid::select(), sint8, NLPACS::ULocalPosition::Surface, NLPACS::CLocalRetriever::CInteriorFace::Surface, uint32, v, NLPACS::CLocalRetriever::CInteriorFace::Verts, NLMISC::CVector::x, NLMISC::CVector::y, and NLMISC::CVector::z. Referenced by NLPACS::CGlobalRetriever::getMeanHeight(), and NLPACS::CRetrieverInstance::snap().
01480 { 01481 if (!_Loaded) 01482 return 0.0f; 01483 01484 if (_Type == Interior) 01485 { 01486 // first preselect faces around the (x, y) position (CQuadGrid ?) 01487 vector<uint32> selection; 01488 _FaceGrid.select(position.Estimation, selection); 01489 01490 // from the preselect faces, look for the only face that belongs to the surface 01491 // and that contains the position 01492 CVector pos = position.Estimation; 01493 CVector posh = pos+CVector(0.0f, 0.0f, 1.0f); 01494 float bestDist = 1.0e10f; 01495 CVector best; 01496 vector<uint32>::iterator it; 01497 for (it=selection.begin(); it!=selection.end(); ++it) 01498 { 01499 const CInteriorFace &f = _InteriorFaces[*it]; 01500 if (f.Surface == (uint32)position.Surface) 01501 { 01502 CVector v[3]; 01503 v[0] = _InteriorVertices[f.Verts[0]]; 01504 v[1] = _InteriorVertices[f.Verts[1]]; 01505 v[2] = _InteriorVertices[f.Verts[2]]; 01506 01507 float a,b,c; // 2D cartesian coefficients of line in plane X/Y. 01508 // Line p0-p1. 01509 a = -(v[1].y-v[0].y); 01510 b = (v[1].x-v[0].x); 01511 c = -(v[0].x*a + v[0].y*b); 01512 if (a*pos.x + b*pos.y + c < 0) continue; 01513 // Line p1-p2. 01514 a = -(v[2].y-v[1].y); 01515 b = (v[2].x-v[1].x); 01516 c = -(v[1].x*a + v[1].y*b); 01517 if (a*pos.x + b*pos.y + c < 0) continue; 01518 // Line p2-p0. 01519 a = -(v[0].y-v[2].y); 01520 b = (v[0].x-v[2].x); 01521 c = -(v[2].x*a + v[2].y*b); 01522 if (a*pos.x + b*pos.y + c < 0) continue; 01523 01524 CPlane p; 01525 p.make(v[0], v[1], v[2]); 01526 01527 CVector i = p.intersect(pos, posh); 01528 01529 float d = (float)fabs(pos.z-i.z); 01530 01531 if (d < bestDist) 01532 { 01533 bestDist = d; 01534 best = i; 01535 } 01536 } 01537 } 01538 01539 // and computes the real position on this face 01540 return (bestDist < 200.0f) ? best.z : position.Estimation.z; 01541 } 01542 else 01543 { 01544 if (_Surfaces[position.Surface].getQuadTree().getRoot() != NULL) 01545 { 01546 // find quad leaf. 01547 const CQuadLeaf *leaf = _Surfaces[position.Surface].getQuadTree().getLeaf(position.Estimation); 01548 01549 // if there is no acceptable leaf, just give up 01550 if (leaf == NULL) 01551 { 01552 //nlinfo("COL: quadtree: don't find the quadLeaf!"); 01553 return position.Estimation.z; 01554 } 01555 else 01556 { 01557 // else return mean height. 01558 float meanHeight = (leaf->getMinHeight()+leaf->getMaxHeight())*0.5f; 01559 return meanHeight; 01560 } 01561 } 01562 else 01563 { 01564 sint8 qh = _Surfaces[position.Surface].getQuantHeight(); 01565 return qh*2.0f + 1.0f; 01566 } 01567 } 01568 } |
|
Returns the identifier of the retriever.
Definition at line 419 of file local_retriever.h. Referenced by NLPACS::CGlobalRetriever::getIdentifier(), and NLPACS::CGlobalRetriever::retrievePosition().
00419 { return _Id; } |
|
Returns the interior faces.
Definition at line 493 of file local_retriever.h. References _InteriorFaces.
00493 { return _InteriorFaces; } |
|
Returns the interior faces.
Definition at line 416 of file local_retriever.h. References _InteriorFaces. Referenced by NLPACS::buildSnapping().
00416 { return _InteriorFaces; } |
|
Returns the interior vertices.
Definition at line 490 of file local_retriever.h. References _InteriorVertices.
00490 { return _InteriorVertices; } |
|
Returns the interior vertices.
Definition at line 413 of file local_retriever.h. References _InteriorVertices. Referenced by NLPACS::buildSnapping().
00413 { return _InteriorVertices; } |
|
Definition at line 182 of file local_retriever.cpp. References NLPACS::CRetrievableSurface::_Chains, _Chains, NLPACS::CRetrievableSurface::_Loops, _Surfaces, sint32, uint, and uint32.
00183 { 00184 uint loop; 00185 uint loopIndex; 00186 00187 if (_Chains[chain].getLeft() == surface) 00188 { 00189 loop = _Chains[chain]._LeftLoop; 00190 loopIndex = _Chains[chain]._LeftLoopIndex; 00191 } 00192 else 00193 { 00194 loop = _Chains[chain]._RightLoop; 00195 loopIndex = _Chains[chain]._RightLoopIndex; 00196 } 00197 00198 const CRetrievableSurface &surf = _Surfaces[surface]; 00199 const CRetrievableSurface::TLoop &sLoop = surf._Loops[loop]; 00200 return surf._Chains[sLoop[(loopIndex+1)%sLoop.size()]].Chain; 00201 } |
|
Returns the nth ordered chain.
Definition at line 381 of file local_retriever.h. References _OrderedChains, and uint. Referenced by NLPACS::CGlobalRetriever::check(), NLPACS::computeRetriever(), NLPACS::CGlobalRetriever::findPath(), NLPACS::CGlobalRetriever::getBorders(), NLPACS::CLocalRetriever::CIterator::operator *(), and NLPACS::CLocalRetriever::CIterator::setupIndex().
00381 { return _OrderedChains[n]; } |
|
Returns the ordered chains.
Definition at line 379 of file local_retriever.h. References _OrderedChains. Referenced by NLPACS::CGlobalRetriever::check(), NLPACS::computeRetriever(), and testCollision().
00379 { return _OrderedChains; } |
|
Definition at line 161 of file local_retriever.cpp. References NLPACS::CRetrievableSurface::_Chains, _Chains, NLPACS::CRetrievableSurface::_Loops, _Surfaces, sint32, uint, and uint32.
00162 { 00163 uint loop; 00164 uint loopIndex; 00165 00166 if (_Chains[chain].getLeft() == surface) 00167 { 00168 loop = _Chains[chain]._LeftLoop; 00169 loopIndex = _Chains[chain]._LeftLoopIndex; 00170 } 00171 else 00172 { 00173 loop = _Chains[chain]._RightLoop; 00174 loopIndex = _Chains[chain]._RightLoopIndex; 00175 } 00176 00177 const CRetrievableSurface &surf = _Surfaces[surface]; 00178 const CRetrievableSurface::TLoop &sLoop = surf._Loops[loop]; 00179 return surf._Chains[sLoop[(loopIndex+sLoop.size()-1)%sLoop.size()]].Chain; 00180 } |
|
Definition at line 101 of file local_retriever.cpp. References _Chains, _FullOrderedChains, NLPACS::COrderedChain3f::getVertices(), NLPACS::COrderedChain3f::isForward(), sint32, and uint32.
00102 { 00103 bool onLeft = _Chains[chain].getLeft() == surface; 00104 const COrderedChain3f &ochain = onLeft ? _FullOrderedChains[_Chains[chain].getSubChains().front()] : 00105 _FullOrderedChains[_Chains[chain].getSubChains().back()]; 00106 00107 if (ochain.isForward() && onLeft || !ochain.isForward() && !onLeft) 00108 return ochain.getVertices().front(); 00109 else 00110 return ochain.getVertices().back(); 00111 } |
|
Definition at line 86 of file local_retriever.cpp. References _Chains, _FullOrderedChains, NLPACS::COrderedChain3f::getVertices(), NLPACS::COrderedChain3f::isForward(), and uint32. Referenced by computeLoopsAndTips(), NLPACS::CRetrieverInstance::link(), and NLPACS::linkExteriorToInterior().
00087 { 00088 const COrderedChain3f &ochain = _FullOrderedChains[_Chains[chain].getSubChains().front()]; 00089 return (ochain.isForward()) ? ochain.getVertices().front() : ochain.getVertices().back(); 00090 } |
|
Definition at line 113 of file local_retriever.cpp. References _Chains, _FullOrderedChains, NLPACS::COrderedChain3f::getVertices(), NLPACS::COrderedChain3f::isForward(), sint32, and uint32.
00114 { 00115 bool onLeft = _Chains[chain].getLeft() == surface; 00116 const COrderedChain3f &ochain = onLeft ? _FullOrderedChains[_Chains[chain].getSubChains().back()] : 00117 _FullOrderedChains[_Chains[chain].getSubChains().front()]; 00118 00119 if (ochain.isForward() && onLeft || !ochain.isForward() && !onLeft) 00120 return ochain.getVertices().back(); 00121 else 00122 return ochain.getVertices().front(); 00123 } |
|
Definition at line 92 of file local_retriever.cpp. References _Chains, _FullOrderedChains, NLPACS::COrderedChain3f::getVertices(), NLPACS::COrderedChain3f::isForward(), and uint32. Referenced by computeLoopsAndTips(), NLPACS::CRetrieverInstance::link(), and NLPACS::linkExteriorToInterior().
00093 { 00094 const COrderedChain3f &ochain = _FullOrderedChains[_Chains[chain].getSubChains().back()]; 00095 return (ochain.isForward()) ? ochain.getVertices().back() : ochain.getVertices().front(); 00096 } |
|
Returns the nth surface.
Definition at line 401 of file local_retriever.h. References _Surfaces, and uint. Referenced by NLPACS::CGlobalRetriever::findAStarPath(), NLPACS::CGlobalRetriever::getBorders(), NLPACS::CGlobalRetriever::getMaterial(), NLPACS::CGlobalRetriever::getSurfaceById(), NLPACS::CGlobalRetriever::isWaterPosition(), NLPACS::CRetrieverInstance::retrievePosition(), NLPACS::CGlobalRetriever::testCollisionWithCollisionChains(), and NLPACS::CGlobalRetriever::testMovementWithCollisionChains().
00401 { return _Surfaces[n]; } |
|
Returns the surfaces.
Definition at line 399 of file local_retriever.h. References _Surfaces. Referenced by NLPACS::CGlobalRetriever::check(), NLPACS::CGlobalRetriever::getMaterial(), NLPACS::CGlobalRetriever::getSurfaceById(), NLPACS::CGlobalRetriever::initRetrieveTable(), NLPACS::CGlobalRetriever::makeInstance(), and NLPACS::CGlobalRetriever::testCollisionWithCollisionChains().
00399 { return _Surfaces; } |
|
Returns the type of the retriever.
Definition at line 404 of file local_retriever.h. References EType. Referenced by NLPACS::CRetrieverInstance::init(), NLPACS::CRetrieverInstance::initEdgeQuad(), NLPACS::CGlobalRetriever::makeInstance(), NLPACS::CGlobalRetriever::makeLinks(), and NLPACS::CGlobalRetriever::retrievePosition().
00404 { return _Type; } |
|
Inits the face grid.
Definition at line 1393 of file local_retriever.cpp. References _FaceGrid, _InteriorFaces, _InteriorVertices, NLPACS::CFaceGrid::create(), NLMISC::CAABBox::extend(), NLMISC::CAABBox::getMax(), NLMISC::CAABBox::getMin(), NLPACS::CFaceGrid::CFaceGridBuild::init(), NLPACS::CFaceGrid::CFaceGridBuild::insert(), NLMISC::CAABBox::setCenter(), uint, and NLPACS::CLocalRetriever::CInteriorFace::Verts. Referenced by NLPACS::buildSnapping().
01394 { 01395 CFaceGrid::CFaceGridBuild fgb; 01396 fgb.init(64, 4.0f); 01397 01398 uint i; 01399 for (i=0; i<_InteriorFaces.size(); ++i) 01400 { 01401 CAABBox box; 01402 CInteriorFace &f = _InteriorFaces[i]; 01403 box.setCenter(_InteriorVertices[f.Verts[0]]); 01404 box.extend(_InteriorVertices[f.Verts[1]]); 01405 box.extend(_InteriorVertices[f.Verts[2]]); 01406 01407 fgb.insert(box.getMin(), box.getMax(), i); 01408 } 01409 01410 _FaceGrid.create(fgb); 01411 } |
|
Assures a position is really inside a surface (and independent from any accuracy issue) and returns true if the position was moved.
Definition at line 960 of file local_retriever.cpp. References _Chains, _Loaded, _OrderedChains, _Surfaces, NLPACS::ULocalPosition::Estimation, NLPACS::CRetrievableSurface::getChain(), NLPACS::CRetrievableSurface::getChains(), NLPACS::CChain::getLeft(), NLPACS::CChain::getSubChain(), NLPACS::CChain::getSubChains(), NLPACS::COrderedChain::getVertices(), InsurePositionThreshold, NLPACS::COrderedChain::isForward(), nlassert, nlwarning, sint, sint32, NLPACS::CRetrieverInstance::snapVector(), NLMISC::CVector2f::sqrnorm(), NLPACS::ULocalPosition::Surface, uint, NLMISC::CVector::x, NLMISC::CVector2f::x, NLMISC::CVector::y, and NLMISC::CVector2f::y. Referenced by NLPACS::CGlobalRetriever::insurePosition(), and NLPACS::CGlobalRetriever::retrievePosition().
00961 { 00962 if (!_Loaded) 00963 return false; 00964 00965 if (local.Surface < 0 || local.Surface >= (sint)_Surfaces.size()) 00966 { 00967 nlwarning("PACS: can't insure position to inexistant surface %d", local.Surface); 00968 return false; 00969 } 00970 00971 // the surface 00972 const NLPACS::CRetrievableSurface &surface = _Surfaces[local.Surface]; 00973 00974 uint i, j, k; 00975 CVector2f M = CVector2f(local.Estimation); 00976 bool moved = false; 00977 00978 // for each chain and each subchain of the surface, 00979 // check if point is located on the good side of the border (and far enough to avoid accuracy issues) 00980 for (i=0; i<surface.getChains().size(); ++i) 00981 { 00982 uint ichain = surface.getChain(i).Chain; 00983 const NLPACS::CChain &chain = _Chains[ichain]; 00984 00985 for (j=0; j<chain.getSubChains().size(); ++j) 00986 { 00987 uint iochain = chain.getSubChain(j); 00988 const NLPACS::COrderedChain &ochain = _OrderedChains[iochain]; 00989 00990 uint isAtLeft = ((chain.getLeft() == local.Surface) ? 1 : 0); 00991 uint isForward = (ochain.isForward() ? 1 : 0); 00992 bool shouldBeUpper = !((isAtLeft ^ isForward) != 0); // shouldBeAtLeft for vertical segment 00993 00994 for (k=0; (sint)k<(sint)(ochain.getVertices().size()-1); ++k) 00995 { 00996 CVector2f A = ochain[k].unpack(); 00997 CVector2f B = ochain[k+1].unpack(); 00998 CVector2f AB = B-A; 00999 01000 float lambda = ((M-A)*AB)/AB.sqrnorm(); 01001 01002 if (lambda<0.0f || lambda>1.0f) 01003 continue; 01004 01005 CVector2f n = (shouldBeUpper ? CVector2f(-AB.y, AB.x) : CVector2f(AB.y, -AB.x)).normed(); 01006 float d = (M-A)*n; 01007 01008 // if point is too close of the border or on the wrong side 01009 // move it far enough 01010 if (d < InsurePositionThreshold && d > -InsurePositionThreshold) 01011 { 01012 M += (InsurePositionThreshold*1.1f-d)*n; 01013 moved = true; 01014 } 01015 } 01016 } 01017 } 01018 01019 NLPACS::CRetrieverInstance::snapVector(M); 01020 01021 local.Estimation.x = M.x; 01022 local.Estimation.y = M.y; 01023 01024 { 01025 float fx1024 = local.Estimation.x * 1024.0f; 01026 float fy1024 = local.Estimation.x * 1024.0f; 01027 sint32 ix1024 = (sint32)floor(fx1024); 01028 sint32 iy1024 = (sint32)floor(fy1024); 01029 01030 nlassert ((float)ix1024 == fx1024); 01031 nlassert ((float)iy1024 == fy1024); 01032 } 01033 01034 return moved; 01035 } |
|
|
Definition at line 1973 of file local_retriever.cpp. References _BorderChains, _Chains, _FullOrderedChains, _OrderedChains, NLPACS::CChain::_StartTip, NLPACS::CChain::_StopTip, _Surfaces, border, NLPACS::CRetrievableSurface::CSurfaceLink::Chain, FreeOChains, NLPACS::CChain::make(), nlassert, nlerror, nlwarning, sint, sint32, NLPACS::CRetrievableSurface::CSurfaceLink::Surface, uint, uint16, and uint32.
01974 { 01975 // free subchains 01976 uint i, j; 01977 for (i=0; i<_Chains[chainId]._SubChains.size(); ++i) 01978 { 01979 FreeOChains.push_back(_Chains[chainId]._SubChains[i]); 01980 _OrderedChains[_Chains[chainId]._SubChains[i]] = COrderedChain(); 01981 _FullOrderedChains[_Chains[chainId]._SubChains[i]] = COrderedChain3f(); 01982 } 01983 01984 // create new chains in replacement of this chain 01985 01986 for (i=0; i<replacement.size(); ++i) 01987 { 01988 vector<CVector> vertices = replacement[i].Vertices; 01989 sint left = replacement[i].Left; 01990 sint right = replacement[i].Right; 01991 01992 if (CChain::isBorderChainId(right)) 01993 { 01994 // check border already exists for this particular chain 01995 sint32 border = CChain::convertBorderChainId(right); 01996 01997 if (border < (sint)_BorderChains.size() && (chainId != _BorderChains[border] || chainId != replacement[i].Chain)) 01998 { 01999 nlwarning("replaceChain(): replacement of a border is forced whereas this border is already used and not replaced!"); 02000 } 02001 02002 if (border >= (sint)_BorderChains.size()) 02003 { 02004 if (border > (sint)_BorderChains.size()) 02005 { 02006 nlwarning("replaceChain(): _BorderChains size increased of more than 1 step, holes may result!"); 02007 } 02008 02009 _BorderChains.resize(border+1, 0xffff); 02010 } 02011 02012 _BorderChains[border] = replacement[i].Chain; 02013 } 02014 02015 nlassert(vertices.size() >= 2); 02016 02017 // Remove doubled vertices due to CVector2s snapping 02018 vector<CVector2s> converts; 02019 02020 for (j=0; j<vertices.size(); ++j) 02021 converts.push_back(CVector2s(vertices[j])); 02022 02023 vector<CVector2s>::iterator next2s = converts.begin(), it2s, prev2s; 02024 prev2s = next2s; ++next2s; 02025 it2s = next2s; ++next2s; 02026 02027 vector<CVector>::iterator it3f = vertices.begin(); 02028 CVector prev3f = *it3f; 02029 ++it3f; 02030 02031 02032 for (; it2s != converts.end() && next2s != converts.end(); ) 02033 { 02034 // if the next point is equal to the previous 02035 if (*it2s == *prev2s || *it2s == *next2s) 02036 { 02037 // then remove the next point 02038 it2s = converts.erase(it2s); 02039 it3f = vertices.erase(it3f); 02040 02041 prev2s = it2s; 02042 --prev2s; 02043 next2s = it2s; 02044 ++next2s; 02045 } 02046 else 02047 { 02048 // else remember the next point, and step to the next... 02049 ++prev2s; 02050 ++it2s; 02051 ++next2s; 02052 ++it3f; 02053 prev3f = *it3f; 02054 } 02055 } 02056 02057 nlassert(vertices.size() >= 2); 02058 02059 sint32 newId = replacement[i].Chain; 02060 if (newId >= (sint)_Chains.size()) 02061 _Chains.resize(newId+1); 02062 02063 //CChain &nchain = _Chains[newId]; 02064 02065 if (left>(sint)_Surfaces.size()) 02066 nlerror ("left surface id MUST be id<%d (id=%d)", _Surfaces.size(), left); 02067 if (right>(sint)_Surfaces.size()) 02068 nlerror ("right surface id MUST be id<%d (id=%d)", _Surfaces.size(), right); 02069 02070 // checks if we can build the chain. 02071 if (newId > 65535) 02072 nlerror("in NLPACS::CLocalRetriever::addChain(): reached the maximum number of chains"); 02073 02074 //CRetrievableSurface *leftSurface = (left>=0) ? &(_Surfaces[left]) : NULL; 02075 //CRetrievableSurface *rightSurface = (right>=0) ? &(_Surfaces[right]) : NULL; 02076 02077 CChain &chain = _Chains[newId]; 02078 02079 chain._StartTip = 0xffff; 02080 chain._StopTip = 0xffff; 02081 02082 // make the chain and its subchains. 02083 chain.make(vertices, left, right, _OrderedChains, (uint16)newId, _FullOrderedChains, FreeOChains); 02084 } 02085 02086 for (i=0; i<_Surfaces.size(); ++i) 02087 { 02088 // remove old chain and replace by new chains in surface links 02089 for (j=0; j<_Surfaces[i]._Chains.size(); ++j) 02090 { 02091 if (_Surfaces[i]._Chains[j].Chain == (sint)chainId) 02092 { 02093 _Surfaces[i]._Chains.erase(_Surfaces[i]._Chains.begin()+j); 02094 02095 uint k; 02096 for (k=0; k<replacement.size(); ++k) 02097 { 02098 CRetrievableSurface::CSurfaceLink link; 02099 02100 link.Chain = replacement[k].Chain; 02101 link.Surface = (replacement[k].Left == (sint)i ? replacement[k].Right : replacement[k].Left); 02102 _Surfaces[i]._Chains.push_back(link); 02103 } 02104 02105 break; 02106 } 02107 } 02108 02109 // remove old chain and replace by new chains in surface loops 02110 for (j=0; j<_Surfaces[i]._Loops.size(); ++j) 02111 { 02112 uint k; 02113 02114 for (k=0; k<_Surfaces[i]._Loops[j].size(); ++k) 02115 { 02116 if (_Surfaces[i]._Loops[j][k] == chainId) 02117 { 02118 _Surfaces[i]._Loops[j].erase(_Surfaces[i]._Loops[j].begin()+k); 02119 uint m; 02120 02121 for (m=0; m<replacement.size(); ++m) 02122 _Surfaces[i]._Loops[j].insert(_Surfaces[i]._Loops[j].begin()+k+m, replacement[m].Chain); 02123 02124 break; 02125 } 02126 } 02127 } 02128 } 02129 } |
|
Retrieves a position inside the retriever (from the local position), returns true if the position is close to a border.
Definition at line 1238 of file local_retriever.cpp. References _ChainQuad, _Chains, _Loaded, _OrderedChains, NLPACS::CCollisionSurfaceTemp::decSurface(), NLPACS::CCollisionSurfaceTemp::EdgeChainEntries, NLPACS::COrderedChain::getMax(), NLMISC::CAABBox::getMax(), NLPACS::COrderedChain::getMin(), NLMISC::CAABBox::getMin(), NLPACS::COrderedChain::getParentId(), NLPACS::COrderedChain::getVertices(), NLPACS::CCollisionSurfaceTemp::incSurface(), NLPACS::COrderedChain::isForward(), min, NLPACS::CCollisionSurfaceTemp::PossibleSurfaces, NLPACS::CChainQuad::selectEdges(), NLMISC::CAABBox::setMinMax(), sint32, uint, NLPACS::CVector2s::unpack3f(), NLPACS::CVector2s::x, NLMISC::CVector::x, NLPACS::CVector2s::y, and NLMISC::CVector::y.
01239 { 01240 if (!_Loaded) 01241 return; 01242 01243 CAABBox box; 01244 CVector estimated = estim.unpack3f(); 01245 const double BorderThreshold = 2.0e-2f; 01246 box.setMinMax(CVector(estimated.x-(float)BorderThreshold, _BBox.getMin().y, 0.0f), 01247 CVector(estimated.x+(float)BorderThreshold, _BBox.getMax().y, 0.0f)); 01248 uint numEdges = _ChainQuad.selectEdges(box, cst); 01249 01250 uint ochain, i; 01251 01252 onBorder = false; 01253 01254 cst.PossibleSurfaces.clear(); 01255 01256 // WARNING!! 01257 // cst.SurfaceLUT is assumed to be 0 filled !! 01258 01259 //nldebug("estim=(%d,%d)", estim.x, estim.y); 01260 01261 // for each ordered chain, checks if the estimated position is between the min and max. 01262 for (i=0; i<numEdges; ++i) 01263 { 01264 ochain = cst.EdgeChainEntries[i].OChainId; 01265 01266 const COrderedChain &sub = _OrderedChains[ochain]; 01267 const CVector2s &min = sub.getMin(), 01268 &max = sub.getMax(); 01269 01270 // checks the position against the min and max of the chain 01271 if (estim.x < min.x || estim.x > max.x) 01272 continue; 01273 01274 bool isUpper; 01275 //bool isOnBorder = false; 01276 01277 sint32 left = _Chains[sub.getParentId()].getLeft(), 01278 right = _Chains[sub.getParentId()].getRight(); 01279 01280 if (estim.y < min.y) 01281 { 01282 if (estim.x == max.x) 01283 continue; 01284 isUpper = false; 01285 } 01286 else if (estim.y > max.y) 01287 { 01288 if (estim.x == max.x) 01289 continue; 01290 isUpper = true; 01291 } 01292 else 01293 { 01294 const vector<CVector2s> &vertices = sub.getVertices(); 01295 uint start = 0, stop = vertices.size()-1; 01296 01297 // then finds the smallest segment of the chain that includes the estimated position. 01298 while (stop-start > 1) 01299 { 01300 uint mid = (start+stop)/2; 01301 01302 if (vertices[mid].x > estim.x) 01303 stop = mid; 01304 else 01305 start = mid; 01306 } 01307 01308 // if a vertical edge 01309 if (vertices[start].x == vertices[stop].x) 01310 { 01311 // look for maximal bounds 01312 while (start > 0 && vertices[start].x == vertices[start-1].x) 01313 --start; 01314 01315 while (stop < vertices.size()-1 && vertices[stop].x == vertices[stop+1].x) 01316 ++stop; 01317 01318 // if upper or lower the bounds, do nothing 01319 if (estim.y > vertices[start].y && estim.y > vertices[stop].y || 01320 estim.y < vertices[start].y && estim.y < vertices[stop].y) 01321 continue; 01322 01323 onBorder = true; 01324 continue; 01325 } 01326 else if (vertices[stop].x == estim.x) 01327 { 01328 // if (yes) 01329 continue; 01330 } 01331 01332 // and then checks if the estimated position is up or down the chain. 01333 01334 // first trivial case (up both tips) 01335 if (estim.y > vertices[start].y && estim.y > vertices[stop].y) 01336 { 01337 isUpper = true; 01338 } 01339 // second trivial case (down both tips) 01340 else if (estim.y < vertices[start].y && estim.y < vertices[stop].y) 01341 { 01342 isUpper = false; 01343 } 01344 // full test... 01345 else 01346 { 01347 const CVector2s &vstart = vertices[start], 01348 &vstop = vertices[stop]; 01349 01350 // this test is somewhat more accurate 01351 // no division performed 01352 sint32 det = (estim.y-vstart.y)*(vstop.x-vstart.x) - (estim.x-vstart.x)*(vstop.y-vstart.y); 01353 01354 isUpper = (det > 0); 01355 01356 if (det == 0) 01357 onBorder = true; 01358 } 01359 } 01360 01361 // Depending on the chain is forward, up the position, increase/decrease the surface table... 01362 if (sub.isForward()) 01363 { 01364 if (isUpper) 01365 { 01366 cst.incSurface(left); 01367 cst.decSurface(right); 01368 } 01369 else 01370 { 01371 cst.decSurface(left); 01372 cst.incSurface(right); 01373 } 01374 } 01375 else 01376 { 01377 if (isUpper) 01378 { 01379 cst.decSurface(left); 01380 cst.incSurface(right); 01381 } 01382 else 01383 { 01384 cst.incSurface(left); 01385 cst.decSurface(right); 01386 } 01387 } 01388 } 01389 } |
|
Retrieves a position inside the retriever (from the local position), returns true if the position is close to a border.
Definition at line 1064 of file local_retriever.cpp. References _ChainQuad, _Chains, _Loaded, _OrderedChains, NLPACS::CCollisionSurfaceTemp::decSurface(), NLPACS::CCollisionSurfaceTemp::EdgeChainEntries, NLPACS::COrderedChain::getMax(), NLMISC::CAABBox::getMax(), NLPACS::COrderedChain::getMin(), NLMISC::CAABBox::getMin(), NLPACS::COrderedChain::getParentId(), NLPACS::COrderedChain::getVertices(), NLPACS::CCollisionSurfaceTemp::incSurface(), NLPACS::COrderedChain::isForward(), min, NLPACS::CCollisionSurfaceTemp::PossibleSurfaces, NLPACS::CChainQuad::selectEdges(), NLMISC::CAABBox::setMinMax(), sint16, sint32, NLPACS::CCollisionSurfaceTemp::SurfaceLUT, uint, NLPACS::Vector2sAccuracy, NLPACS::CVector2s::x, NLMISC::CVector::x, NLPACS::CVector2s::y, and NLMISC::CVector::y. Referenced by NLPACS::CRetrieverInstance::retrievePosition(), and testPosition().
01065 { 01066 if (!_Loaded) 01067 return; 01068 01069 CAABBox box; 01070 const double BorderThreshold = 2.0e-2f; 01071 box.setMinMax(CVector(estimated.x-(float)BorderThreshold, _BBox.getMin().y, 0.0f), CVector(estimated.x+(float)BorderThreshold, _BBox.getMax().y, 0.0f)); 01072 uint numEdges = _ChainQuad.selectEdges(box, cst); 01073 01074 uint ochain, i; 01075 CVector2s estim = CVector2s(estimated); 01076 01077 cst.PossibleSurfaces.clear(); 01078 01079 // WARNING!! 01080 // cst.SurfaceLUT is assumed to be 0 filled !! 01081 01082 //nldebug("estim=(%d,%d)", estim.x, estim.y); 01083 01084 // for each ordered chain, checks if the estimated position is between the min and max. 01085 for (i=0; i<numEdges; ++i) 01086 { 01087 ochain = cst.EdgeChainEntries[i].OChainId; 01088 01089 const COrderedChain &sub = _OrderedChains[ochain]; 01090 const CVector2s &min = sub.getMin(), 01091 &max = sub.getMax(); 01092 01093 // checks the position against the min and max of the chain 01094 if (estim.x < min.x || estim.x > max.x) 01095 continue; 01096 01097 bool isUpper; 01098 bool isOnBorder = false; 01099 01100 sint32 left = _Chains[sub.getParentId()].getLeft(), 01101 right = _Chains[sub.getParentId()].getRight(); 01102 01103 if (estim.y < min.y) 01104 { 01105 if (estim.x == max.x) 01106 continue; 01107 isUpper = false; 01108 // nlinfo("Box: min(%d,%d) max(%d,%d) forward=%d left=%d right=%d upper=false", min.x, min.y, max.x, max.y, sub.isForward(), left, right); 01109 } 01110 else if (estim.y > max.y) 01111 { 01112 if (estim.x == max.x) 01113 continue; 01114 isUpper = true; 01115 // nlinfo("Box: min(%d,%d) max(%d,%d) forward=%d left=%d right=%d upper=true", min.x, min.y, max.x, max.y, sub.isForward(), left, right); 01116 } 01117 else 01118 { 01119 const vector<CVector2s> &vertices = sub.getVertices(); 01120 uint start = 0, stop = vertices.size()-1; 01121 01123 01124 // then finds the smallest segment of the chain that includes the estimated position. 01125 while (stop-start > 1) 01126 { 01127 uint mid = (start+stop)/2; 01128 01129 if (vertices[mid].x > estim.x) 01130 stop = mid; 01131 else 01132 start = mid; 01133 } 01134 01135 // if a vertical edge 01136 if (vertices[start].x == vertices[stop].x) 01137 { 01138 // look for maximal bounds 01139 while (start > 0 && vertices[start].x == vertices[start-1].x) 01140 --start; 01141 01142 while (stop < vertices.size()-1 && vertices[stop].x == vertices[stop+1].x) 01143 ++stop; 01144 01145 // if upper or lower the bounds, do nothing 01146 if (estim.y > vertices[start].y && estim.y > vertices[stop].y || 01147 estim.y < vertices[start].y && estim.y < vertices[stop].y) 01148 continue; 01149 01150 isOnBorder = true; 01151 if (left >= 0) 01152 { 01153 cst.SurfaceLUT[left].FoundCloseEdge = true; 01154 cst.SurfaceLUT[left].OnVerticalEdge = true; 01155 } 01156 if (right >= 0) 01157 { 01158 cst.SurfaceLUT[right].FoundCloseEdge = true; 01159 cst.SurfaceLUT[right].OnVerticalEdge = true; 01160 } 01161 // nlinfo("Edge: start(%d,%d) stop(%d,%d) forward=%d left=%d right=%d border=true", vertices[start].x, vertices[start].y, vertices[stop].x, vertices[stop].y, sub.isForward(), left, right); 01162 continue; 01163 } 01164 else if (vertices[stop].x == estim.x) 01165 { 01166 // if (yes) 01167 continue; 01168 } 01169 01170 // and then checks if the estimated position is up or down the chain. 01171 01172 // first trivial case (up both tips) 01173 if (estim.y > vertices[start].y && estim.y > vertices[stop].y) 01174 { 01175 isUpper = true; 01176 // nlinfo("Edge: start(%d,%d) stop(%d,%d) forward=%d left=%d right=%d upper=true", vertices[start].x, vertices[start].y, vertices[stop].x, vertices[stop].y, sub.isForward(), left, right); 01177 } 01178 // second trivial case (down both tips) 01179 else if (estim.y < vertices[start].y && estim.y < vertices[stop].y) 01180 { 01181 isUpper = false; 01182 // nlinfo("Edge: start(%d,%d) stop(%d,%d) forward=%d left=%d right=%d upper=false", vertices[start].x, vertices[start].y, vertices[stop].x, vertices[stop].y, sub.isForward(), left, right); 01183 } 01184 // full test... 01185 else 01186 { 01187 const CVector2s &vstart = vertices[start], 01188 &vstop = vertices[stop]; 01189 01190 sint16 intersect = vstart.y + (vstop.y-vstart.y)*(estim.x-vstart.x)/(vstop.x-vstart.x); 01191 01192 isUpper = estim.y > intersect; 01193 isOnBorder = (fabs(estim.y - intersect)<BorderThreshold*Vector2sAccuracy); 01194 // nlinfo("Edge: start(%d,%d) stop(%d,%d) forward=%d left=%d right=%d upper=%s border=%s", vertices[start].x, vertices[start].y, vertices[stop].x, vertices[stop].y, sub.isForward(), left, right, isUpper ? "true":"false", isOnBorder ? "true":"false"); 01195 } 01196 } 01197 01198 if (isOnBorder) 01199 { 01200 cst.incSurface(left); 01201 cst.incSurface(right); 01202 if (left >= 0) cst.SurfaceLUT[left].FoundCloseEdge = true; 01203 if (right >= 0) cst.SurfaceLUT[right].FoundCloseEdge = true; 01204 continue; 01205 } 01206 01207 // Depending on the chain is forward, up the position, increase/decrease the surface table... 01208 if (sub.isForward()) 01209 { 01210 if (isUpper) 01211 { 01212 cst.incSurface(left); 01213 cst.decSurface(right); 01214 } 01215 else 01216 { 01217 cst.decSurface(left); 01218 cst.incSurface(right); 01219 } 01220 } 01221 else 01222 { 01223 if (isUpper) 01224 { 01225 cst.decSurface(left); 01226 cst.incSurface(right); 01227 } 01228 else 01229 { 01230 cst.incSurface(left); 01231 cst.decSurface(right); 01232 } 01233 } 01234 } 01235 } |
|
Serialises the CLocalRetriever.
Definition at line 895 of file local_retriever.cpp. References __Tips, _BorderChains, _ChainQuad, _Chains, _ExteriorMesh, _FaceGrid, _FullOrderedChains, _InteriorFaces, _InteriorVertices, _Loaded, _OrderedChains, _Surfaces, _Topologies, LoadCheckFlag, NLPACS::NumMaxCreatureModels, NLMISC::IStream::serial(), NLMISC::IStream::serialCont(), NLMISC::IStream::serialEnum(), NLMISC::IStream::serialVersion(), sint, and uint. Referenced by NLPACS::CRetrieverBank::addRetriever().
00896 { 00897 /* 00898 Version 0: 00899 - base version (with collision info). 00900 Version 1: 00901 - interior vertices and faces, for interior ground snapping 00902 Version 2: 00903 - face grid added. 00904 Version 3: 00905 - identifier added. 00906 Version 4: 00907 - topologies no more in stream (obsolete) 00908 */ 00909 sint ver= f.serialVersion(4); 00910 00911 if (ver < 4) 00912 throw EOlderStream(); 00913 00914 uint i; 00915 f.serialCont(_Chains); 00916 f.serialCont(_OrderedChains); 00917 f.serialCont(_FullOrderedChains); 00918 f.serialCont(_Surfaces); 00919 f.serialCont(__Tips); 00920 f.serialCont(_BorderChains); 00921 if (ver < 4) 00922 { 00923 for (i=0; i<NumMaxCreatureModels; ++i) 00924 f.serialCont(_Topologies[i]); 00925 } 00926 f.serial(_ChainQuad); 00927 f.serial(_BBox); 00928 f.serialEnum(_Type); 00929 f.serial(_ExteriorMesh); 00930 00931 // a fix for old versions (with wrong _Type value) 00932 if (_Type != CLocalRetriever::Interior) _Type = CLocalRetriever::Landscape; 00933 00934 if (ver >= 1) 00935 { 00936 f.serialCont(_InteriorVertices); 00937 f.serialCont(_InteriorFaces); 00938 00939 } 00940 if (ver >= 2) 00941 { 00942 f.serial(_FaceGrid); 00943 } 00944 if (ver >= 3) 00945 { 00946 f.serial(_Id); 00947 } 00948 00949 _Loaded = true; 00950 LoadCheckFlag = false; 00951 } |
|
Sets the bbox of the retriever.
Definition at line 486 of file local_retriever.h. Referenced by NLPACS::computeRetriever().
00486 { _BBox = bbox; } |
|
Sets the exterior mesh.
Definition at line 483 of file local_retriever.h. References _ExteriorMesh. Referenced by NLPACS::computeRetriever(), and NLPACS::linkExteriorToInterior().
00483 { _ExteriorMesh = em; } |
|
Adds a chain to the local retriever, using the vertices of the chain, the left and right surfaces id and the edge on which the chain is stuck Definition at line 532 of file local_retriever.h. References _FullOrderedChains.
00532 { _FullOrderedChains = foc; } |
|
Returns the identifier of the retriever.
Definition at line 496 of file local_retriever.h.
00496 { _Id = id; } |
|
Set the type of the retriever (see EType).
Definition at line 480 of file local_retriever.h. References type. Referenced by NLPACS::computeRetriever().
|
|
Snaps on the ground.
Definition at line 1413 of file local_retriever.cpp. References _FaceGrid, _InteriorFaces, _InteriorVertices, _Loaded, NLPACS::ULocalPosition::Estimation, NLMISC::CPlane::intersect(), NLMISC::CPlane::make(), NLMISC::CVector2f::normed(), NLPACS::CFaceGrid::select(), NLPACS::ULocalPosition::Surface, NLPACS::CLocalRetriever::CInteriorFace::Surface, uint32, v, NLPACS::Vector2sAccuracy, NLPACS::CLocalRetriever::CInteriorFace::Verts, NLMISC::CVector2f::x, x, NLMISC::CVector2f::y, y, and NLMISC::CVector::z. Referenced by NLPACS::CRetrieverInstance::retrievePosition(), NLPACS::CRetrieverInstance::snap(), and NLPACS::CRetrieverInstance::snapToInteriorGround().
01414 { 01415 if (!_Loaded) 01416 return; 01417 01418 // first preselect faces around the (x, y) position (CQuadGrid ?) 01419 vector<uint32> selection; 01420 _FaceGrid.select(position.Estimation, selection); 01421 01422 // from the preselect faces, look for the only face that belongs to the surface 01423 // and that contains the position 01424 CVector pos = position.Estimation; 01425 CVector posh = pos+CVector(0.0f, 0.0f, 1.0f); 01426 CVector2f pos2d = position.Estimation; 01427 float bestDist = 1.0e10f; 01428 CVector best; 01429 vector<uint32>::iterator it; 01430 snapped = false; 01431 for (it=selection.begin(); it!=selection.end(); ++it) 01432 { 01433 const CInteriorFace &f = _InteriorFaces[*it]; 01434 if (f.Surface == (uint32)position.Surface) 01435 { 01436 CVector v[3]; 01437 v[0] = _InteriorVertices[f.Verts[0]]; 01438 v[1] = _InteriorVertices[f.Verts[1]]; 01439 v[2] = _InteriorVertices[f.Verts[2]]; 01440 01441 CVector2f n; 01442 float c; // 2D cartesian coefficients of line in plane X/Y. 01443 // Line p0-p1. 01444 n = CVector2f(-(v[1].y-v[0].y), (v[1].x-v[0].x)).normed(); 01445 c = -(v[0].x*n.x + v[0].y*n.y); 01446 if (n*pos2d + c < -1.0f/Vector2sAccuracy) continue; 01447 // Line p1-p2. 01448 n = CVector2f(-(v[2].y-v[1].y), (v[2].x-v[1].x)).normed(); 01449 c = -(v[1].x*n.x + v[1].y*n.y); 01450 if (n*pos2d + c < -1.0f/Vector2sAccuracy) continue; 01451 // Line p2-p0. 01452 n = CVector2f(-(v[0].y-v[2].y), (v[0].x-v[2].x)).normed(); 01453 c = -(v[2].x*n.x + v[2].y*n.y); 01454 if (n*pos2d + c < -1.0f/Vector2sAccuracy) continue; 01455 01456 CPlane p; 01457 p.make(v[0], v[1], v[2]); 01458 01459 CVector i = p.intersect(pos, posh); 01460 01461 float d = (float)fabs(pos.z-i.z); 01462 01463 if (d < bestDist) 01464 { 01465 bestDist = d; 01466 best = i; 01467 } 01468 } 01469 } 01470 01471 // and computes the real position on this face 01472 if (bestDist < 400.0f) 01473 { 01474 snapped = true; 01475 position.Estimation = best; 01476 } 01477 } |
|
Sorts chains references inside the tips. NOT IMPLEMENTED YET.
Definition at line 775 of file local_retriever.cpp.
00776 { 00777 } |
|
add possible collisions chains to the temp result.
Definition at line 1807 of file local_retriever.cpp. References _ChainQuad, _ExteriorMesh, _Loaded, NLPACS::CCollisionSurfaceTemp::allocEdgeCollideNode(), NLPACS::CCollisionSurfaceTemp::CollisionChains, NLPACS::CCollisionSurfaceTemp::EdgeChainEntries, NLPACS::CEdgeChainEntry::EdgeEnd, NLPACS::CEdgeChainEntry::EdgeStart, NLPACS::CCollisionChain::FirstEdgeCollide, getChains(), NLPACS::CCollisionSurfaceTemp::getEdgeCollideNode(), NLPACS::CExteriorMesh::getLink(), NLPACS::CExteriorMesh::getLinks(), getOrderedChains(), NLPACS::COrderedChain::getParentId(), NLPACS::COrderedChain::getVertices(), NLPACS::CEdgeCollide::make(), NLPACS::CEdgeCollideNode::Next, NLPACS::CEdgeChainEntry::OChainId, NLPACS::CCollisionSurfaceTemp::OChainLUT, NLPACS::CChainQuad::selectEdges(), sint, uint, uint16, and uint32. Referenced by NLPACS::CGlobalRetriever::findCollisionChains().
01808 { 01809 if (!_Loaded) 01810 return; 01811 01812 // H_AUTO(PACS_LR_testCollision); 01813 01814 sint i; 01815 01816 // 0. select ordered chains in the chainquad. 01817 //===================================== 01818 // H_BEFORE(PACS_LR_testCol_selEdges); 01819 sint nEce= _ChainQuad.selectEdges(bboxMove, cst); 01820 // H_AFTER(PACS_LR_testCol_selEdges); 01821 // NB: cst.OChainLUT is assured to be full of 0xFFFF after this call (if was right before). 01822 01823 01824 // 1. regroup them in chains. build cst.CollisionChains 01825 //===================================== 01826 // NB: use cst.OChainLUT to look if a Chain has been inserted before. 01827 uint16 *chainLUT= cst.OChainLUT; 01828 01829 // bkup where we begin to add chains. 01830 uint firstChainAdded= cst.CollisionChains.size(); 01831 01832 // For all edgechain entry. 01833 for(i=0;i<nEce;i++) 01834 { 01835 CEdgeChainEntry &ece= cst.EdgeChainEntries[i]; 01836 // this is the ordered chain in the retriever. 01837 const COrderedChain &oChain= this->getOrderedChains()[ece.OChainId]; 01838 // this is the id of the chain is the local retriever. 01839 uint16 chainId= oChain.getParentId(); 01840 01841 // test if edge is interior and points to another instance 01842 // \todo Ben: flag interior chains that points to doors to speed up the test 01843 if (_Type == Interior && CChain::isBorderChainId(this->getChains()[chainId].getRight())) 01844 { 01845 // then look for a door that match this edge 01846 uint l; 01847 for (l=0; l<_ExteriorMesh.getLinks().size() && _ExteriorMesh.getLink(l).ChainId != chainId; ++l) 01848 ; 01849 01850 // if found a door, then leave the edge as is 01851 if (l < _ExteriorMesh.getLinks().size()) 01852 continue; 01853 } 01854 01855 01856 // add/retrieve the id in cst.CollisionChains. 01857 //================================= 01858 uint ccId; 01859 // if never added. 01860 if(chainLUT[chainId]==0xFFFF) 01861 { 01862 // H_AUTO(PACS_LR_testCol_addToLUT); 01863 // add a new CCollisionChain. 01864 ccId= cst.CollisionChains.size(); 01865 cst.CollisionChains.push_back(CCollisionChain()); 01866 // Fill it with default. 01867 cst.CollisionChains[ccId].Tested= false; 01868 cst.CollisionChains[ccId].ExteriorEdge = false; 01869 cst.CollisionChains[ccId].FirstEdgeCollide= 0xFFFFFFFF; 01870 cst.CollisionChains[ccId].ChainId= chainId; 01871 // Fill Left right info. 01872 cst.CollisionChains[ccId].LeftSurface.SurfaceId= this->getChains()[chainId].getLeft(); 01873 cst.CollisionChains[ccId].RightSurface.SurfaceId= this->getChains()[chainId].getRight(); 01874 // NB: cst.CollisionChains[ccId].*Surface.RetrieverInstanceId is not filled here because we don't have 01875 // this info at this level. 01876 01877 // store this Id in the LUT of chains. 01878 chainLUT[chainId]= ccId; 01879 } 01880 else 01881 { 01882 // get the id of this collision chain. 01883 ccId= chainLUT[chainId]; 01884 } 01885 01886 // add edge collide to the list. 01887 //================================= 01888 // H_BEFORE(PACS_LR_testCol_addToList); 01889 CCollisionChain &colChain= cst.CollisionChains[ccId]; 01890 const std::vector<CVector2s> &oChainVertices= oChain.getVertices(); 01891 for(sint edge=ece.EdgeStart; edge<ece.EdgeEnd; edge++) 01892 { 01893 CVector2f p0= oChainVertices[edge].unpack(); 01894 CVector2f p1= oChainVertices[edge+1].unpack(); 01895 01896 // alloc a new edgeCollide. 01897 uint32 ecnId= cst.allocEdgeCollideNode(); 01898 CEdgeCollideNode &ecn= cst.getEdgeCollideNode(ecnId); 01899 01900 // append to the front of the list. 01901 ecn.Next= colChain.FirstEdgeCollide; 01902 colChain.FirstEdgeCollide= ecnId; 01903 01904 // build this edge. 01905 p0+= transBase; 01906 p1+= transBase; 01907 ecn.make(p0, p1); 01908 } 01909 // H_AFTER(PACS_LR_testCol_addToList); 01910 } 01911 01912 01913 01914 // 2. Reset LUT to 0xFFFF. 01915 //===================================== 01916 01917 // H_BEFORE(PACS_LR_testCol_resetLUT); 01918 // for all collisions chains inserted (starting from firstChainAdded), reset LUT. 01919 for(i=firstChainAdded; i<(sint)cst.CollisionChains.size(); i++) 01920 { 01921 uint ccId= cst.CollisionChains[i].ChainId; 01922 chainLUT[ccId]= 0xFFFF; 01923 } 01924 // H_AFTER(PACS_LR_testCol_resetLUT); 01925 } |
|
Retrieves a position inside the retriever (from the local position), returns true if the position is close to a border.
Definition at line 1038 of file local_retriever.cpp. References _Loaded, _Surfaces, NLPACS::ULocalPosition::Estimation, nlwarning, NLPACS::CCollisionSurfaceTemp::PossibleSurfaces, retrievePosition(), sint, NLPACS::ULocalPosition::Surface, NLPACS::CCollisionSurfaceTemp::SurfaceLUT, uint, NLMISC::CVector::x, and NLMISC::CVector::y. Referenced by NLPACS::CGlobalRetriever::testPosition().
01039 { 01040 if (!_Loaded) 01041 return false; 01042 01043 if (local.Surface < 0 || local.Surface >= (sint)_Surfaces.size()) 01044 { 01045 nlwarning("PACS: can't test inexistant surface %d", local.Surface); 01046 return false; 01047 } 01048 01049 if (fabs(local.Estimation.x) >= 256.0 || fabs(local.Estimation.y) >= 256.0) 01050 return false; 01051 01052 retrievePosition(local.Estimation, cst); 01053 01054 bool result = (cst.SurfaceLUT[local.Surface].Counter == 2 || cst.SurfaceLUT[local.Surface].OnVerticalEdge); 01055 01056 uint i; 01057 for (i=0; i<cst.PossibleSurfaces.size(); ++i) 01058 cst.SurfaceLUT[cst.PossibleSurfaces[i]].reset(); 01059 01060 return result; 01061 } |
|
Translates the local retriever by the translation vector.
Definition at line 882 of file local_retriever.cpp. References _OrderedChains, _Surfaces, and uint.
00883 { 00884 uint i; 00885 for (i=0; i<_OrderedChains.size(); ++i) 00886 _OrderedChains[i].translate(translation); 00887 for (i=0; i<_Surfaces.size(); ++i) 00888 _Surfaces[i].translate(translation); 00889 /* 00890 for (i=0; i<_Tips.size(); ++i) 00891 _Tips[i].translate(translation); 00892 */ 00893 } |
|
Definition at line 206 of file local_retriever.cpp. Referenced by NLPACS::computeRetriever().
00207 { 00208 /* 00209 uint i, j; 00210 00211 for (i=0; i<_Chains.size(); ++i) 00212 _Chains[i].unify(_OrderedChains); 00213 00214 for (i=0; i<_Tips.size(); ++i) 00215 { 00216 NLPACS::CLocalRetriever::CTip &tip = _Tips[i]; 00217 CVector2s ptip = tip.Point; 00218 00219 for (j=0; j<tip.Chains.size(); ++j) 00220 { 00221 if (tip.Chains[j].Start) 00222 { 00223 if (_Chains[tip.Chains[j].Chain].getStartVector(_OrderedChains) != ptip) 00224 nlwarning("chain %d is not stuck to tip %d", tip.Chains[j].Chain, i); 00225 _Chains[tip.Chains[j].Chain].setStartVector(ptip, _OrderedChains); 00226 } 00227 else 00228 { 00229 if (_Chains[tip.Chains[j].Chain].getStopVector(_OrderedChains) != ptip) 00230 nlwarning("chain %d is not stuck to tip %d", tip.Chains[j].Chain, i); 00231 _Chains[tip.Chains[j].Chain].setStopVector(ptip, _OrderedChains); 00232 } 00233 } 00234 } 00235 00236 _FullOrderedChains.resize(_OrderedChains.size()); 00237 for (i=0; i<_OrderedChains.size(); ++i) 00238 _FullOrderedChains[i].unpack(_OrderedChains[i]); 00239 */ 00240 } |
|
Updates surfaces links from the links contained in the chains...
Definition at line 797 of file local_retriever.cpp. References _Chains, NLPACS::CRetrievableSurface::_Chains, _Surfaces, nlerror, nlwarning, sint32, and uint. Referenced by NLPACS::computeRetriever().
00798 { 00799 uint surf, link; 00800 00801 for (surf=0; surf<_Surfaces.size(); ++surf) 00802 { 00803 CRetrievableSurface &surface = _Surfaces[surf]; 00804 00805 for (link=0; link<surface._Chains.size(); ++link) 00806 { 00807 sint32 chain = surface._Chains[link].Chain; 00808 00809 if (_Chains[chain]._Left == (sint32)surf) 00810 surface._Chains[link].Surface = _Chains[chain]._Right; 00811 else if (_Chains[chain]._Right == (sint32)surf) 00812 surface._Chains[link].Surface = _Chains[chain]._Left; 00813 else 00814 { 00815 nlwarning("in NLPACS::CLocalRetriever::updateEdgesOnSurfaces()"); 00816 nlerror("Can't find back point to surface %d on chain %d", surf, chain); 00817 } 00818 } 00819 } 00820 } |
|
Definition at line 285 of file local_retriever.h. |
|
The tips making links between different chains.
Definition at line 301 of file local_retriever.h. |
|
The bbox of the local retriever.
Definition at line 298 of file local_retriever.h. |
|
The chains on the edges of the zone.
Definition at line 304 of file local_retriever.h. Referenced by clear(), findBorderChains(), getBorderChain(), getBorderChains(), replaceChain(), and serial(). |
|
For collisions, the chainquad.
Definition at line 316 of file local_retriever.h. Referenced by clear(), computeCollisionChainQuad(), findPath(), getChainQuad(), retrieveAccuratePosition(), retrievePosition(), serial(), and testCollision(). |
|
The chains insinde the zone.
Definition at line 292 of file local_retriever.h. Referenced by addChain(), build3dSurfacePolygons(), buildSurfacePolygons(), clear(), computeLoopsAndTips(), computeTopologies(), distanceToBorder(), dumpSurface(), findBorderChains(), findPath(), forceBorderChainId(), getChain(), getChains(), getNextChain(), getPreviousChain(), getStartVector(), getStopVector(), insurePosition(), replaceChain(), retrieveAccuratePosition(), retrievePosition(), serial(), and updateChainIds(). |
|
The tip recognition threshold.
Definition at line 42 of file local_retriever.cpp. |
|
The exterior mesh, for collisions.
Definition at line 324 of file local_retriever.h. Referenced by clear(), getExteriorMesh(), serial(), setExteriorMesh(), testCollision(), and NLPACS::CRetrieverInstance::testExteriorCollision(). |
|
The face selection grid.
Definition at line 333 of file local_retriever.h. Referenced by clear(), getHeight(), initFaceGrid(), serial(), and snapToInteriorGround(). |
|
Definition at line 289 of file local_retriever.h. Referenced by addChain(), build3dSurfacePolygons(), clear(), dumpSurface(), flushFullOrderedChains(), getFullOrderedChain(), getFullOrderedChains(), getStartVector(), getStopVector(), replaceChain(), serial(), and setFullOrderedChains(). |
|
An human readable identifier of the retriever.
Definition at line 336 of file local_retriever.h. |
|
The faces of the collision mesh.
Definition at line 330 of file local_retriever.h. Referenced by buildInteriorSurfaceBBoxes(), clear(), getHeight(), getInteriorFaces(), initFaceGrid(), serial(), and snapToInteriorGround(). |
|
The vertices of the collision mesh.
Definition at line 327 of file local_retriever.h. Referenced by buildInteriorSurfaceBBoxes(), clear(), getHeight(), getInteriorVertices(), initFaceGrid(), serial(), and snapToInteriorGround(). |
|
Tells if retriever is loaded.
Definition at line 341 of file local_retriever.h. Referenced by clear(), CLocalRetriever(), forceLoaded(), getHeight(), insurePosition(), isLoaded(), retrieveAccuratePosition(), retrievePosition(), serial(), snapToInteriorGround(), testCollision(), and testPosition(). |
|
The chains insinde the zone.
Definition at line 288 of file local_retriever.h. Referenced by addChain(), buildSurfacePolygons(), clear(), computeCollisionChainQuad(), distanceToBorder(), dumpSurface(), findPath(), getOrderedChain(), getOrderedChains(), insurePosition(), replaceChain(), retrieveAccuratePosition(), retrievePosition(), serial(), and translate(). |
|
The surfaces inside the zone.
Definition at line 295 of file local_retriever.h. Referenced by addChain(), addSurface(), build3dSurfacePolygons(), buildInteriorSurfaceBBoxes(), buildSurfacePolygons(), clear(), computeLoopsAndTips(), computeTopologies(), distanceToBorder(), dumpSurface(), findPath(), getHeight(), getNextChain(), getPreviousChain(), getSurface(), getSurfaces(), insurePosition(), replaceChain(), serial(), testPosition(), translate(), and updateChainIds(). |
|
The tip recognition threshold.
Definition at line 41 of file local_retriever.cpp. |
|
The topologies within the zone.
Definition at line 307 of file local_retriever.h. Referenced by clear(), computeTopologies(), and serial(). |
|
The type of the retriever.
Definition at line 319 of file local_retriever.h. |
|
Definition at line 598 of file local_retriever.h. Referenced by replaceChain(). |
|
Definition at line 345 of file local_retriever.h. Referenced by clear(), CLocalRetriever(), and serial(). |