1 #include "..\include\raMain.h" 5 m_bbMin(bbMin), m_bbMax(bbMax)
8 for (
int n = pParent->m_Points.
GetSize() - 3; n >= 0; n -= 3)
11 IsPointInOctant(pParent->m_Points[n ]) &&
12 IsPointInOctant(pParent->m_Points[n + 1]) &&
13 IsPointInOctant(pParent->m_Points[n + 2]) )
15 m_Points.
Add(pParent->m_Points[n]);
16 m_Points.
Add(pParent->m_Points[n + 1]);
17 m_Points.
Add(pParent->m_Points[n + 2]);
18 pParent->m_Points.
Remove(n + 2);
19 pParent->m_Points.
Remove(n + 1);
20 pParent->m_Points.
Remove(n);
24 if((((
float)m_bbMax.
x - (
float)m_bbMin.
x) > 1) && (m_Points.
GetSize() > 0))
32 void raOctree::CreateChildNodes()
36 for(
int x = -1; x <= 1; x+=2)
38 for(
int y = -1; y <= 1; y+=2)
40 for(
int z = -1; z <= 1; z+=2)
44 bbMin.
x = 0.25f * x * (((float)m_bbMax.
x - (
float)m_bbMin.
x)
45 + ((
float)m_bbMax.
x + 3 * (float)m_bbMin.
x));
46 bbMin.
y = 0.25f * y * (((float)m_bbMax.
y - (
float)m_bbMin.
y)
47 + ((
float)m_bbMax.
y + 3 * (float)m_bbMin.
y));
48 bbMin.
z = 0.25f * z * (((float)m_bbMax.
z - (
float)m_bbMin.
z)
49 + ((
float)m_bbMax.
z + 3 * (float)m_bbMin.
z));
51 bbMax.
x = 0.25f * x * (((float)m_bbMax.
x - (
float)m_bbMin.
x)
52 + (3 * (
float)m_bbMax.
x + (float)m_bbMin.
x));
53 bbMax.
y = 0.25f * y * (((float)m_bbMax.
y - (
float)m_bbMin.
y)
54 + (3 * (
float)m_bbMax.
y + (float)m_bbMin.
y));
55 bbMax.
z = 0.25f * z * (((float)m_bbMax.
z - (
float)m_bbMin.
z)
56 + (3 * (
float)m_bbMax.
z + (float)m_bbMin.
z));
58 m_pChildren[i++] =
new raOctree(bbMin, bbMax,
this);
64 bool raOctree::IsPointInOctant(
raVector3 p)
66 return ( (p.
x >= m_bbMin.
x && p.
x <= m_bbMax.
x) &&
67 (p.
y >= m_bbMin.
y && p.
y <= m_bbMax.
y) &&
68 (p.
z >= m_bbMin.
z && p.
z <= m_bbMax.
z));
75 for(
int i = 0; i < 8; i++)
77 delete m_pChildren[i];
87 if(! D3DXBoxBoundProbe((D3DXVECTOR3*)&m_bbMin, (D3DXVECTOR3*)&m_bbMax, (D3DXVECTOR3*)pRayPos, (D3DXVECTOR3*)pRayDir))
90 bool bIntersects =
false;
92 float mindist = FLT_MAX;
96 for (
int n = 0; n < m_Points.
GetSize(); n += 3)
98 if(D3DXIntersectTri((D3DXVECTOR3 *)&m_Points[n], (D3DXVECTOR3 *)&m_Points[n + 1], (D3DXVECTOR3 *)&m_Points[n + 2],
99 (D3DXVECTOR3 *)pRayPos, (D3DXVECTOR3 *)pRayDir, &u, &v, &dist))
112 for(
int i = 0; i < 8; i++)
114 if (m_pChildren[i]->
Intersects(pRayPos, pRayDir, &dist))
HRESULT Remove(raInt nIndex)
raOctree(const raEntity< VertexType, bIndexed, IndexType > *pEntity)
virtual bool Intersects(const raVector3 *pRayPos, const raVector3 *pRayDir, float *pDist)
HRESULT Add(const TYPE &value)