Public Member Functions | |
void | build (const std::vector< CVector > &vertices, const std::vector< uint16 > &triangles) |
float | getCameraCollision (class CCameraCol &camCol) |
Data Fields | |
NLMISC::CAABBox | BBox |
CStaticGrid | QuadGrid |
CQuadGrid< CMeshCol * >::CIterator | QuadGridIt |
std::vector< uint16 > | Triangles |
std::vector< CVector > | Vertices |
|
Definition at line 370 of file visual_collision_manager.cpp. References NL3D::CVisualCollisionManager::CStaticGrid::add(), NL3D::CVisualCollisionManager::CStaticGrid::compile(), NL3D::CVisualCollisionManager::CStaticGrid::create(), NLMISC::CAABBox::extend(), nlassert, QuadGrid, NLMISC::CAABBox::setCenter(), and uint. Referenced by NL3D::CVisualCollisionManager::addMeshCollision().
00371 { 00372 uint i; 00373 nlassert(!vertices.empty()); 00374 00375 // copy 00376 Vertices= vertices; 00377 Triangles= triangles; 00378 00379 // Build the bbox for this col mesh 00380 BBox.setCenter(vertices[0]); 00381 for(i=1;i<vertices.size();i++) 00382 BBox.extend(vertices[i]); 00383 00384 // Build the Static Grid 00385 uint numTris= triangles.size()/3; 00386 QuadGrid.create(16, numTris, BBox); 00387 // Add all triangles 00388 for(i=0;i<numTris;i++) 00389 { 00390 CAABBox bb; 00391 bb.setCenter(Vertices[Triangles[i*3+0]]); 00392 bb.extend(Vertices[Triangles[i*3+1]]); 00393 bb.extend(Vertices[Triangles[i*3+2]]); 00394 QuadGrid.add(i, bb); 00395 } 00396 // compile 00397 QuadGrid.compile(); 00398 } |
|
Definition at line 330 of file visual_collision_manager.cpp. References NL3D::CCameraCol::BBox, NL3D::CCameraCol::End, NLMISC::CAABBox::intersect(), min, NL3D::CCameraCol::minimizeDistanceAgainstTri(), QuadGrid, NL3D::CVisualCollisionManager::CStaticGrid::select(), NL3D::CCameraCol::Start, and uint.
00331 { 00332 // first test if intersect with the bboxes 00333 if(!camCol.BBox.intersect(BBox)) 00334 return 1; 00335 00336 // Select triangles 00337 static std::vector<uint16> selection; 00338 uint numSel= QuadGrid.select(camCol.BBox, selection); 00339 00340 // **** For all triangles, test if intersect the camera collision 00341 float sqrMinDist= FLT_MAX; 00342 for(uint i=0;i<numSel;i++) 00343 { 00344 uint triId= selection[i]; 00345 // build the triangle 00346 camCol.minimizeDistanceAgainstTri( 00347 Vertices[Triangles[triId*3+0]], 00348 Vertices[Triangles[triId*3+1]], 00349 Vertices[Triangles[triId*3+2]], 00350 sqrMinDist); 00351 } 00352 00353 // **** return the collision found, between [0,1] 00354 if(sqrMinDist == FLT_MAX) 00355 return 1; 00356 else 00357 { 00358 float f= 1; 00359 float d= (camCol.End-camCol.Start).norm(); 00360 if(d>0) 00361 { 00362 f= sqrtf(sqrMinDist) / d; 00363 f= min(f, 1.f); 00364 } 00365 return f; 00366 } 00367 } |
|
Definition at line 188 of file visual_collision_manager.h. Referenced by NL3D::CVisualCollisionManager::addMeshCollision(). |
|
Definition at line 192 of file visual_collision_manager.h. Referenced by build(), and getCameraCollision(). |
|
Definition at line 190 of file visual_collision_manager.h. Referenced by NL3D::CVisualCollisionManager::addMeshCollision(). |
|
Definition at line 186 of file visual_collision_manager.h. |
|
Definition at line 185 of file visual_collision_manager.h. |