1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
//Erstellung des PickingTrees
EResult CEditableTerrain::CalcPickNode(SPickNode *pFather, SPickNode *pNode, const int x, const int z, const int w, const int h)
{
//als erstes die Aabb bestimmen...
//Schritt 0: Datenübertragung
pNode->m_pFather = pFather;
pNode->m_ptCoord.x = x;
pNode->m_ptCoord.y = z;
//Kinder nullen
for(int i = 0; i < 4; i++)pNode->m_pChilds[i] = NULL;
//Schritt 1: Maximale und Minimale Höhe bestimmen
BYTE cMaxHeight = 0, cMinHeight = 255;
for(int a = x; a < x + w; a++)
for(int b = z; b < z + h; b++)
{
cMaxHeight = stMax(m_pHeightMap[a + b * m_dwWidth], cMaxHeight);
cMinHeight = stMin(m_pHeightMap[a + b * m_dwWidth], cMinHeight);
}
//Die Minima, Maxima wurden gefunden...
//Schritt 2: Vektoren anlegen
pNode->m_Aabb.vMax = stVector((x + w) * m_fStepX + 0.5f * m_fStepX,
cMaxHeight * m_fStepY + 0.5f,
(z + h) * m_fStepZ + 0.5f * m_fStepZ);
pNode->m_Aabb.vMin = stVector((x) * m_fStepX - 0.5f * m_fStepX,
cMinHeight * m_fStepY - 0.5f,
(z) * m_fStepZ - 0.5f * m_fStepZ);
//Als begrenzende Werte sind 8 oder 16 gut
//Wenn die Breite != 1, Kinder anlegen
if(w != 1)
{
//ansonsten weiter unterteilen...
//Speicher reservieren...
for(int i = 0; i < 4; i++)pNode->m_pChilds[i] = new SPickNode;
CalcPickNode(pNode, pNode->m_pChilds[0], x, z, w / 2, h / 2);
CalcPickNode(pNode, pNode->m_pChilds[1], x + w / 2, z, w / 2, h / 2);
CalcPickNode(pNode, pNode->m_pChilds[2], x, z + h / 2, w / 2, h / 2);
CalcPickNode(pNode, pNode->m_pChilds[3], x + w / 2, z + h / 2, w / 2, h / 2);
}
//alles ok
return E_OK;
}
|