Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BVHNode* CreateBVHNode(BVHNodeBBox* bboxData, int count)
- {
- D3DXVECTOR4 minBounds = { FLT_MAX, FLT_MAX, FLT_MAX, 0 };
- D3DXVECTOR4 maxBounds = { -FLT_MAX, -FLT_MAX, -FLT_MAX, 0 };
- for (int i = 0; i < count; i++)
- {
- //find bounding box
- D3DXVec4Minimize(&minBounds, &bboxData[i].m_minBounds, &minBounds);
- D3DXVec4Maximize(&maxBounds, &bboxData[i].m_maxBounds, &maxBounds);
- }
- D3DXVECTOR4 bboxSize = maxBounds - minBounds;
- float maxDim = max(max(bboxSize.x, bboxSize.y), bboxSize.z);
- if (maxDim == bboxSize.x)
- {
- //Sort bounding boxes along he X axis
- }
- else if (maxDim == bboxSize.y)
- {
- //Sort bounding boxes along he Y axis
- }
- else
- {
- //Sort bounding boxes along he Z axis
- }
- BVHNode* node;
- node = new BVHNode();
- if (count == 1)
- {
- //this is a leaf node
- node->m_left = nullptr;
- node->m_right = nullptr;
- node->m_box = *bboxData;
- }
- else
- {
- //create the two branches
- node->m_left = CreateBVHNode(bboxData, count / 2);
- node->m_right = CreateBVHNode(bboxData + count / 2, count - count / 2);
- //find bounding box
- D3DXVec4Minimize( &node->m_box.m_minBounds,
- &node->m_left->m_box.m_minBounds,
- &node->m_right->m_box.m_minBounds);
- D3DXVec4Maximize( &node->m_box.m_maxBounds,
- &node->m_left->m_box.m_maxBounds,
- &node->m_right->m_box.m_maxBounds);
- //this is an intermediate
- node->m_box.m_minBounds.w = -1.0f;
- }
- return node;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement