-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBSPTypes.cpp
127 lines (108 loc) · 2.62 KB
/
BSPTypes.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "stdafx.h"
#include "BSPTypes.h"
cBSPNode * cBSPNode::ParseNode(cByteStream *pData, DWORD dwTreeType)
{
//figure out what type it is;
DWORD bspType = pData->ReadDWORD();
switch (bspType)
{
case 'PORT':
{
cBSPPortal * Prt = new cBSPPortal();
Prt->Parse(pData, dwTreeType);
return Prt;
}
case 'LEAF':
{
cBSPLeaf * Leaf = new cBSPLeaf();
Leaf->Parse(pData, dwTreeType);
return Leaf;
}
default:
{
cBSPNode * Node = new cBSPNode();
Node->Parse(pData, dwTreeType, bspType);
return Node;
}
}
}
void cBSPNode::Parse(cByteStream *pData, DWORD dwTreeType, DWORD dwNodeType)
{
//plane - Plane
float fX = pData->ReadFloat(); //Normal to Plane
float fY = pData->ReadFloat();
float fZ = pData->ReadFloat();
float fDist = pData->ReadFloat(); //Distance
switch ( dwNodeType )
{
case 'BPnn':
case 'BPIn':
m_pChild30 = cBSPNode::ParseNode(pData, dwTreeType);
break;
case 'BpIN':
case 'BpnN':
m_pChild34 = cBSPNode::ParseNode(pData, dwTreeType);
break;
case 'BPIN':
case 'BPnN':
m_pChild30 = cBSPNode::ParseNode(pData, dwTreeType);
m_pChild34 = cBSPNode::ParseNode(pData, dwTreeType);
break;
}
if ((dwTreeType == 0) || (dwTreeType == 1))
{
//bounds - Sphere
pData->ReadGroup(3*sizeof(float)); //Origin
float fRadius = pData->ReadFloat(); //Radius
}
if (dwTreeType)
return;
//Triangle index list...
DWORD dwTriCount = pData->ReadDWORD();
for (DWORD i = 0; i < dwTriCount; i++)
{
WORD wTriIndex = pData->ReadWORD();
}
}
void cBSPPortal::Parse(cByteStream *pData, DWORD dwTreeType)
{
//plane - Plane
pData->ReadGroup(3*sizeof(float)); //Normal
float fDist = pData->ReadFloat(); //Distance
m_pChild30 = cBSPNode::ParseNode(pData, dwTreeType);
m_pChild34 = cBSPNode::ParseNode(pData, dwTreeType);
if (dwTreeType)
return;
//bounds - Sphere
pData->ReadGroup(3*sizeof(float)); //Origin
pData->ReadFloat(); //Radius
//Triangle index list...
DWORD dwTriCount = pData->ReadDWORD();
DWORD dwPolyCount = pData->ReadDWORD();
for (DWORD i = 0; i < dwTriCount; i++)
{
WORD wTriIndex = pData->ReadWORD();
}
for (DWORD i = 0; i < dwPolyCount; i++)
{
//unpack a CPortalPoly here
WORD wIndex = pData->ReadWORD();
WORD wWhat = pData->ReadWORD();
}
}
void cBSPLeaf::Parse(cByteStream *pData, DWORD dwTreeType)
{
m_dwLeaf38 = pData->ReadDWORD();
if (dwTreeType != 1)
return;
m_dwLeaf3C = pData->ReadDWORD();
//bounds - Sphere
pData->ReadGroup(3*sizeof(float)); //Origin
pData->ReadFloat(); //Radius
//Triangle index list...
DWORD dwTriCount = pData->ReadDWORD();
for (DWORD i = 0; i < dwTriCount; i++)
{
WORD wTriIndex = pData->ReadWORD();
}
}