// This code written in 2010 by Forest Hale (lordhavoc ghdigital com), and placed into public domain.
#include <stdlib.h>
-#include <memory.h>
+#include <string.h>
#include "bih.h"
static int BIH_BuildNode(bih_t *bih, int numchildren, int *leaflist, float *totalmins, float *totalmaxs)
int i;
int j;
int longestaxis;
- int axis;
+ int axis = 0;
int nodenum;
- int front;
- int back;
+ int front = 0;
+ int back = 0;
bih_node_t *node;
bih_leaf_t *child;
float splitdist;
}
// we now have front and back children divided in leaflist...
- node->type = BIH_SPLITX + axis;
+ node->type = (bih_nodetype_t)((int)BIH_SPLITX + axis);
node->front = BIH_BuildNode(bih, front, leaflist, frontmins, frontmaxs);
node->frontmin = frontmins[axis];
node->back = BIH_BuildNode(bih, back, leaflist + front, backmins, backmaxs);
continue;
switch (bihleaf->type)
{
- case BIH_LEAF:
- // brush
+ case BIH_BRUSH:
brush = model->brush.data_brushes + bihleaf->itemindex;
if (brush->colbrushf && brush->colbrushf->numtriangles)
{
R_Mesh_Draw(0, brush->colbrushf->numpoints, 0, brush->colbrushf->numtriangles, brush->colbrushf->elements, NULL, 0, 0);
}
break;
- case BIH_LEAF + 1:
- // triangle
+ case BIH_COLLISIONTRIANGLE:
triangleindex = bihleaf->itemindex;
VectorCopy(model->brush.data_collisionvertex3f + 3*model->brush.data_collisionelement3i[triangleindex*3+0], vertex3f[0]);
VectorCopy(model->brush.data_collisionvertex3f + 3*model->brush.data_collisionelement3i[triangleindex*3+1], vertex3f[1]);
GL_Color((bihleafindex & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 5) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 10) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, r_showcollisionbrushes.value);
R_Mesh_Draw(0, 3, 0, 1, polygonelement3i, polygonelement3s, 0, 0);
break;
- default:
+ case BIH_RENDERTRIANGLE:
+ triangleindex = bihleaf->itemindex;
+ VectorCopy(model->surfmesh.data_vertex3f + 3*model->surfmesh.data_element3i[triangleindex*3+0], vertex3f[0]);
+ VectorCopy(model->surfmesh.data_vertex3f + 3*model->surfmesh.data_element3i[triangleindex*3+1], vertex3f[1]);
+ VectorCopy(model->surfmesh.data_vertex3f + 3*model->surfmesh.data_element3i[triangleindex*3+2], vertex3f[2]);
+ R_Mesh_VertexPointer(vertex3f[0], 0, 0);
+ GL_Color((bihleafindex & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 5) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, ((bihleafindex >> 10) & 31) * (1.0f / 32.0f) * r_refdef.view.colorscale, r_showcollisionbrushes.value);
+ R_Mesh_Draw(0, 3, 0, 1, polygonelement3i, polygonelement3s, 0, 0);
break;
}
}
leaf = model->collision_bih.leafs + (-1-nodenum);
switch(leaf->type)
{
- case BIH_LEAF:
- // brush
+ case BIH_BRUSH:
brush = model->brush.data_brushes[leaf->itemindex].colbrushf;
Collision_TracePointBrushFloat(trace, point, brush);
break;
- case BIH_LEAF + 1:
+ case BIH_COLLISIONTRIANGLE:
// collision triangle - skipped because they have no volume
break;
- case BIH_LEAF + 2:
+ case BIH_RENDERTRIANGLE:
// render triangle - skipped because they have no volume
break;
- default:
- break;
}
}
#endif
switch(leaf->type)
{
- case BIH_LEAF:
- // brush
+ case BIH_BRUSH:
brush = model->brush.data_brushes[leaf->itemindex].colbrushf;
Collision_TraceLineBrushFloat(trace, linestart, lineend, brush, brush);
break;
- case BIH_LEAF + 1:
- // collision triangle
+ case BIH_COLLISIONTRIANGLE:
if (!mod_q3bsp_curves_collisions.integer)
return;
e = model->brush.data_collisionelement3i + 3*leaf->itemindex;
texture = model->data_textures + leaf->textureindex;
Collision_TraceLineTriangleFloat(trace, linestart, lineend, model->brush.data_collisionvertex3f + e[0] * 3, model->brush.data_collisionvertex3f + e[1] * 3, model->brush.data_collisionvertex3f + e[2] * 3, texture->supercontents, texture->surfaceflags, texture);
break;
- case BIH_LEAF + 2:
- // render triangle
+ case BIH_RENDERTRIANGLE:
e = model->surfmesh.data_element3i + 3*leaf->itemindex;
texture = model->data_textures + leaf->textureindex;
Collision_TraceLineTriangleFloat(trace, linestart, lineend, model->surfmesh.data_vertex3f + e[0] * 3, model->surfmesh.data_vertex3f + e[1] * 3, model->surfmesh.data_vertex3f + e[2] * 3, texture->supercontents, texture->surfaceflags, texture);
break;
- default:
- break;
}
}
#endif
switch(leaf->type)
{
- case BIH_LEAF:
- // brush
+ case BIH_BRUSH:
brush = model->brush.data_brushes[leaf->itemindex].colbrushf;
Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, brush, brush);
break;
- case BIH_LEAF + 1:
- // collision triangle
+ case BIH_COLLISIONTRIANGLE:
if (!mod_q3bsp_curves_collisions.integer)
return;
e = model->brush.data_collisionelement3i + 3*leaf->itemindex;
texture = model->data_textures + leaf->textureindex;
Collision_TraceBrushTriangleFloat(trace, thisbrush_start, thisbrush_end, model->brush.data_collisionvertex3f + e[0] * 3, model->brush.data_collisionvertex3f + e[1] * 3, model->brush.data_collisionvertex3f + e[2] * 3, texture->supercontents, texture->surfaceflags, texture);
break;
- case BIH_LEAF + 2:
- // render triangle
+ case BIH_RENDERTRIANGLE:
e = model->surfmesh.data_element3i + 3*leaf->itemindex;
texture = model->data_textures + leaf->textureindex;
Collision_TraceBrushTriangleFloat(trace, thisbrush_start, thisbrush_end, model->surfmesh.data_vertex3f + e[0] * 3, model->surfmesh.data_vertex3f + e[1] * 3, model->surfmesh.data_vertex3f + e[2] * 3, texture->supercontents, texture->surfaceflags, texture);
break;
- default:
- break;
}
}
{
for (triangleindex = 0, e = renderelement3i + 3*surface->num_firsttriangle;triangleindex < surface->num_triangles;triangleindex++, e += 3)
{
- bihleafs[bihleafindex].type = BIH_LEAF + 2;
+ bihleafs[bihleafindex].type = BIH_RENDERTRIANGLE;
bihleafs[bihleafindex].textureindex = surface->texture - model->data_textures;
bihleafs[bihleafindex].itemindex = triangleindex+surface->num_firsttriangle;
bihleafs[bihleafindex].mins[0] = min(rendervertex3f[3*e[0]+0], min(rendervertex3f[3*e[1]+0], rendervertex3f[3*e[2]+0])) - 1;
{
if (!brush->colbrushf)
continue;
- bihleafs[bihleafindex].type = BIH_LEAF;
+ bihleafs[bihleafindex].type = BIH_BRUSH;
bihleafs[bihleafindex].textureindex = brush->texture - model->data_textures;
bihleafs[bihleafindex].itemindex = brushindex+model->firstmodelbrush;
VectorCopy(brush->colbrushf->mins, bihleafs[bihleafindex].mins);
{
for (triangleindex = 0, e = collisionelement3i + 3*surface->num_firstcollisiontriangle;triangleindex < surface->num_collisiontriangles;triangleindex++, e += 3)
{
- bihleafs[bihleafindex].type = BIH_LEAF + 1;
+ bihleafs[bihleafindex].type = BIH_COLLISIONTRIANGLE;
bihleafs[bihleafindex].textureindex = surface->texture - model->data_textures;
bihleafs[bihleafindex].itemindex = triangleindex+surface->num_firstcollisiontriangle;
bihleafs[bihleafindex].mins[0] = min(collisionvertex3f[3*e[0]+0], min(collisionvertex3f[3*e[1]+0], collisionvertex3f[3*e[2]+0])) - 1;