-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbsp_ren.cpp
272 lines (213 loc) · 10.6 KB
/
bsp_ren.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/***********************************************
* $author: javery
* $date : 9 Mar 02
* $descp : BSP renderer.
* $path : C:\Program Files\Microsoft Visual Studio\MyProjects\KaosDemoEngine\bsp_ren.cpp
* $ver : 0.0.0
***********************************************/
#include "bsp_comp.h"
#include "bsp_ren.h"
#include "camera.h"
#include "polygon.h"
#include <windows.h>
#include <gl/gl.h>
/*
**************************************************
* R_BSP_RenderNode
* Renders the specified bsp node, and all pertinent
* data (light/texturemaps).
**************************************************
*/
void R_BSP_RenderNode( pbspNode_t pNode , pCamera_t pCam )
{
pPoly_t ppoly = pNode->pPoly;
pVect3_t pnormal = &ppoly->Normal;
if( pNode == NULL )
{
return;
}
glPushMatrix();
if( pNode->type == NT_TREE )
{
if( 1 )
{
if( !PLY_FLG_TYPE(ppoly->PolyFlag) )
{
glBegin( GL_LINES );
glNormal3f( pnormal->xComponent , pnormal->yComponent , pnormal->zComponent );
glVertex3f( ppoly->pVerticies[ 0 ]->xComponent , ppoly->pVerticies[ 0 ]->yComponent , ppoly->pVerticies[ 0 ]->zComponent );
glVertex3f( ppoly->pVerticies[ 1 ]->xComponent , ppoly->pVerticies[ 1 ]->yComponent , ppoly->pVerticies[ 1 ]->zComponent );
glVertex3f( ppoly->pVerticies[ 1 ]->xComponent , ppoly->pVerticies[ 1 ]->yComponent , ppoly->pVerticies[ 1 ]->zComponent );
glVertex3f( ppoly->pVerticies[ 2 ]->xComponent , ppoly->pVerticies[ 2 ]->yComponent , ppoly->pVerticies[ 2 ]->zComponent );
glVertex3f( ppoly->pVerticies[ 2 ]->xComponent , ppoly->pVerticies[ 2 ]->yComponent , ppoly->pVerticies[ 2 ]->zComponent );
glVertex3f( ppoly->pVerticies[ 0 ]->xComponent , ppoly->pVerticies[ 0 ]->yComponent , ppoly->pVerticies[ 0 ]->zComponent );
glEnd();
}
else
{
/*glBegin( GL_QUADS );
glNormal3f( pnormal->xComponent , pnormal->yComponent , pnormal->zComponent );
glVertex3f( ppoly->pVerticies[0]->xComponent,ppoly->pVerticies[0]->yComponent , ppoly->pVerticies[0]->zComponent );
glVertex3f( ppoly->pVerticies[1]->xComponent,ppoly->pVerticies[1]->yComponent , ppoly->pVerticies[1]->zComponent );
glVertex3f( ppoly->pVerticies[1]->xComponent,ppoly->pVerticies[1]->yComponent , ppoly->pVerticies[1]->zComponent );
glVertex3f( ppoly->pVerticies[2]->xComponent,ppoly->pVerticies[2]->yComponent , ppoly->pVerticies[2]->zComponent );
glVertex3f( ppoly->pVerticies[2]->xComponent,ppoly->pVerticies[2]->yComponent , ppoly->pVerticies[2]->zComponent );
glVertex3f( ppoly->pVerticies[3]->xComponent,ppoly->pVerticies[3]->yComponent , ppoly->pVerticies[3]->zComponent );
glVertex3f( ppoly->pVerticies[3]->xComponent,ppoly->pVerticies[3]->yComponent , ppoly->pVerticies[3]->zComponent );
glVertex3f( ppoly->pVerticies[0]->xComponent,ppoly->pVerticies[0]->yComponent , ppoly->pVerticies[0]->zComponent );
glEnd();*/
}
}
}
else if( pNode->type == NT_LEAF )
{
for(int index = 0;index < pNode->Polys.setSize-1;index++)
{
if( 1 )
{
// add aliases to this code block.
if( !PLY_FLG_TYPE(pNode->Polys.pPolygons[ index ]->PolyFlag) )
{
glBegin( GL_LINES );
glNormal3f( pNode->Polys.pPolygons[ index ]->Normal.xComponent ,
pNode->Polys.pPolygons[ index ]->Normal.yComponent ,
pNode->Polys.pPolygons[ index ]->Normal.zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->zComponent );
glEnd();
}
/* else// if( pNode->Polys.pPolygons[ index ]->PolyFlag==PT_QUADRANGULAR )
{
glBegin( GL_LINES );
glNormal3f( pNode->Polys.pPolygons[ index ]->Normal.xComponent ,
pNode->Polys.pPolygons[ index ]->Normal.yComponent ,
pNode->Polys.pPolygons[ index ]->Normal.zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 3 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 3 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 3 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 3 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 3 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 3 ]->zComponent );
glVertex3f( pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->xComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->yComponent ,
pNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->zComponent );
glEnd();
}*/
}
}
}
glPopMatrix();
}
/*
**************************************************
* R_BSP_RecurseRootNode
* In-onder walk/rendering of compiled bsp tree.
**************************************************
*/
void R_BSP_RecurseRootNode( pbspNode_t pRootNode , pCamera_t pCam )
{
static pbspNode_t nodeLine = pRootNode;
float eval=0.0f;
if( pRootNode == NULL )
{
return;
}
/* float fEval = MTPl_Evaluate( &pRootNode->SplitPlane , &pCam->Direction );
if( fEval < 0 )
// case 1 : viewport behiend partioning plane.
{
R_BSP_RecurseRootNode( pRootNode->prChild , pCam );
R_BSP_RenderNode( pRootNode , pCam );
R_BSP_RecurseRootNode( pRootNode->plChild , pCam );
}
if( fEval > 0 )
// case 2 : viewport in front of partioning plane.
{
R_BSP_RecurseRootNode( pRootNode->plChild , pCam );
R_BSP_RenderNode( pRootNode , pCam );
R_BSP_RecurseRootNode( pRootNode->prChild , pCam );
}
else
// ambigious case ( viewport consistent with partioning plane ).
{
// R_BSP_RecurseRootNode( pRootNode->plChild , pCam );
// R_BSP_RecurseRootNode( pRootNode->prChild , pCam );
} */
// tree partioning plane.
if( pRootNode->type == NT_TREE )
{
// NOTE: this could become buggy. Take the position into account.
eval = MTPl_Evaluate( &pRootNode->SplitPlane , &pCam->Position );
if( eval < 0 )
{
R_BSP_RecurseRootNode( pRootNode->plChild , pCam );
R_BSP_RecurseRootNode( pRootNode->prChild , pCam );
}
else
{
R_BSP_RecurseRootNode( pRootNode->prChild , pCam );
R_BSP_RecurseRootNode( pRootNode->plChild , pCam );
}
}
// tree leave ( containing pushed polygons set )
else
{
for(int index = 0;index < pRootNode->Polys.setSize;index++)
{
glBegin( GL_LINES );
glNormal3f( pRootNode->Polys.pPolygons[ index ]->Normal.xComponent ,
pRootNode->Polys.pPolygons[ index ]->Normal.yComponent ,
pRootNode->Polys.pPolygons[ index ]->Normal.zComponent );
glVertex3f( pRootNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->xComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->yComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->zComponent );
glVertex3f( pRootNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->xComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->yComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->zComponent );
glVertex3f( pRootNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->xComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->yComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 1 ]->zComponent );
glVertex3f( pRootNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->xComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->yComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->zComponent );
glVertex3f( pRootNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->xComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->yComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 2 ]->zComponent );
glVertex3f( pRootNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->xComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->yComponent ,
pRootNode->Polys.pPolygons[ index ]->pVerticies[ 0 ]->zComponent );
glEnd();
}
}
}