void SubModel::fillContainer(const AABSPTree<Triangle>::Node& pNode, int &pTreeNodePos, int &pTrianglePos, Vector3& pLo, Vector3& pHi) { TreeNode treeNode = TreeNode(pNode.valueArray.size(), pTrianglePos); treeNode.setSplitAxis(pNode.splitAxis); treeNode.setSplitLocation(pNode.splitLocation); int currentTreeNodePos = pTreeNodePos++; Vector3 lo = Vector3(inf(),inf(),inf()); Vector3 hi = Vector3(-inf(),-inf(),-inf()); for(int i=0;i<pNode.valueArray.size(); i++) { G3D::_AABSPTree::Handle<Triangle>* h= pNode.valueArray[i]; Triangle t = h->value; TriangleBox triangleBox = TriangleBox(t.vertex(0),t.vertex(1), t.vertex(2)); lo = lo.min(triangleBox.getBounds().getLo().getVector3()); hi = hi.max(triangleBox.getBounds().getHi().getVector3()); getTriangles()[pTrianglePos++] = triangleBox; } if(pNode.child[0] != 0) { treeNode.setChildPos(0, pTreeNodePos); fillContainer(*pNode.child[0], pTreeNodePos, pTrianglePos, lo, hi); } if(pNode.child[1] != 0) { treeNode.setChildPos(1, pTreeNodePos); fillContainer(*pNode.child[1], pTreeNodePos, pTrianglePos, lo, hi); } treeNode.setBounds(lo,hi); // get absolute bounds pLo = pLo.min(lo); pHi = pHi.max(hi); getTreeNodes()[currentTreeNodePos] = treeNode; }
void CalculateBox (const dgVector* const position, const dgInt32* const faceIndices) { dgVector p0; dgVector p1; TriangleBox (position, faceIndices, p0, p1); p0 = p0.CompProduct3(dgVector (DG_DEFORMABLE_PADDING, DG_DEFORMABLE_PADDING, DG_DEFORMABLE_PADDING, dgFloat32 (0.0f))); p1 = p1.CompProduct3(dgVector (DG_DEFORMABLE_PADDING, DG_DEFORMABLE_PADDING, DG_DEFORMABLE_PADDING, dgFloat32 (0.0f))); m_minBox.m_x = dgFloor (p0.m_x) * DG_DEFORMABLE_INV_PADDING; m_minBox.m_y = dgFloor (p0.m_y) * DG_DEFORMABLE_INV_PADDING; m_minBox.m_z = dgFloor (p0.m_z) * DG_DEFORMABLE_INV_PADDING; m_minBox.m_w = dgFloat32 (0.0f); m_maxBox.m_x = dgFloor (p1.m_x + dgFloat32 (1.0f)) * DG_DEFORMABLE_INV_PADDING; m_maxBox.m_y = dgFloor (p1.m_y + dgFloat32 (1.0f)) * DG_DEFORMABLE_INV_PADDING; m_maxBox.m_z = dgFloor (p1.m_z + dgFloat32 (1.0f)) * DG_DEFORMABLE_INV_PADDING; m_maxBox.m_w = dgFloat32 (0.0f); dgVector side0 (m_maxBox - m_minBox); dgVector side1 (side0.m_y, side0.m_z, side0.m_x, dgFloat32 (0.0f)); m_surfaceArea = side0 % side1; }
dgInt32 UpdateBox (const dgVector* const position, const dgInt32* const faceIndices) { dgVector p0; dgVector p1; TriangleBox (position, faceIndices, p0, p1); p0 = p0.CompProduct3(dgVector (DG_DEFORMABLE_PADDING, DG_DEFORMABLE_PADDING, DG_DEFORMABLE_PADDING, dgFloat32 (0.0f))); p1 = p1.CompProduct3(dgVector (DG_DEFORMABLE_PADDING, DG_DEFORMABLE_PADDING, DG_DEFORMABLE_PADDING, dgFloat32 (0.0f))); dgVector minP (dgFloor (p0.m_x) * DG_DEFORMABLE_INV_PADDING, dgFloor (p0.m_y) * DG_DEFORMABLE_INV_PADDING, dgFloor (p0.m_z) * DG_DEFORMABLE_INV_PADDING, dgFloat32(0.0f)); dgVector maxP (dgFloor (p1.m_x + dgFloat32 (1.0f)) * DG_DEFORMABLE_INV_PADDING, dgFloor (p1.m_y + dgFloat32 (1.0f)) * DG_DEFORMABLE_INV_PADDING, dgFloor (p1.m_z + dgFloat32 (1.0f)) * DG_DEFORMABLE_INV_PADDING, dgFloat32(0.0f)); dgInt32 state = dgCompareBox (minP, maxP, m_minBox, m_maxBox); if (state) { m_minBox = minP; m_maxBox = maxP; dgVector side0 (m_maxBox - m_minBox); dgVector side1 (side0.m_y, side0.m_z, side0.m_x, dgFloat32 (0.0f)); m_surfaceArea = side0 % side1; } return state; }