-------------------------------------------------------------------------------------- Description: Updates bounding box (if m_updateBoundingBox flag is set) after data is modified. --------------------------------------------------------------------------------------
| 462 | // Updates bounding box (if m_updateBoundingBox flag is set) after data is modified. |
| 463 | // -------------------------------------------------------------------------------------- |
| 464 | void Tr2RuntimeInstanceData::UpdateBoundingBox() |
| 465 | { |
| 466 | if( m_explicitBoundingBox ) |
| 467 | { |
| 468 | return; |
| 469 | } |
| 470 | unsigned positionOffset = -1; |
| 471 | for( auto it = m_layout.m_items.begin(); it != m_layout.m_items.end(); ++it ) |
| 472 | { |
| 473 | if( it->m_usage == Tr2VertexDefinition::POSITION && |
| 474 | it->m_usageIndex == 0 && |
| 475 | Tr2VertexDefinition::GetDataTypeSizeInMembers( it->m_dataType ) >= 3 ) |
| 476 | { |
| 477 | positionOffset = it->m_offset; |
| 478 | break; |
| 479 | } |
| 480 | } |
| 481 | m_aabb = CcpMath::AxisAlignedBox(); |
| 482 | if( positionOffset != -1 ) |
| 483 | { |
| 484 | for( unsigned i = 0; i < m_count; ++i ) |
| 485 | { |
| 486 | const Vector3* pos = |
| 487 | reinterpret_cast<Vector3*>( m_data.get() + positionOffset + m_stride * i ); |
| 488 | m_aabb.Include( *pos ); |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | // -------------------------------------------------------------------------------------- |
| 494 | // Description: |