/* ============= GetVertex ============= */ static int GetVertex(mapentity_t *entity, const vec3_t in) { int h; int i; hashvert_t *hv; vec3_t vert; struct lumpdata *vertices = &entity->lumps[LUMP_VERTEXES]; dvertex_t *dvertex; for (i = 0; i < 3; i++) { if (fabs(in[i] - Q_rint(in[i])) < ZERO_EPSILON) vert[i] = Q_rint(in[i]); else vert[i] = in[i]; } h = HashVec(vert); for (hv = hashverts[h]; hv; hv = hv->next) { if (fabs(hv->point[0] - vert[0]) < POINT_EPSILON && fabs(hv->point[1] - vert[1]) < POINT_EPSILON && fabs(hv->point[2] - vert[2]) < POINT_EPSILON) { hv->numedges++; return hv->num; } } hv = hvert_p++; hv->num = map.cTotal[LUMP_VERTEXES]++; hv->numedges = 1; hv->next = hashverts[h]; hashverts[h] = hv; VectorCopy(vert, hv->point); if (vertices->index == vertices->count) Error("Internal error: didn't allocate enough vertices?"); /* emit a vertex */ dvertex = (dvertex_t *)vertices->data + vertices->index; dvertex->point[0] = vert[0]; dvertex->point[1] = vert[1]; dvertex->point[2] = vert[2]; vertices->index++; return hv->num; }
/* * @brief Uses hashing */ static int32_t GetVertexNum(const vec3_t in) { int32_t h; int32_t i; vec_t *p; vec3_t vert; int32_t vnum; c_totalverts++; for (i = 0; i < 3; i++) { const vec_t v = floor(in[i] + 0.5); if (fabs(in[i] - v) < INTEGRAL_EPSILON) vert[i] = v; else vert[i] = in[i]; } h = HashVec(vert); for (vnum = hash_verts[h]; vnum; vnum = vertex_chain[vnum]) { p = d_bsp.vertexes[vnum].point; if (fabs(p[0] - vert[0]) < POINT_EPSILON && fabs(p[1] - vert[1]) < POINT_EPSILON && fabs( p[2] - vert[2]) < POINT_EPSILON) return vnum; } // emit a vertex if (d_bsp.num_vertexes == MAX_BSP_VERTS) Com_Error(ERR_FATAL, "MAX_BSP_VERTS\n"); d_bsp.vertexes[d_bsp.num_vertexes].point[0] = vert[0]; d_bsp.vertexes[d_bsp.num_vertexes].point[1] = vert[1]; d_bsp.vertexes[d_bsp.num_vertexes].point[2] = vert[2]; vertex_chain[d_bsp.num_vertexes] = hash_verts[h]; hash_verts[h] = d_bsp.num_vertexes; c_uniqueverts++; d_bsp.num_vertexes++; return d_bsp.num_vertexes - 1; }
/** * @brief Returns the number of an existing vertex or allocates a new one * @note Uses hashing */ static int GetVertexnum (const vec3_t in) { vec3_t vert; c_totalverts++; for (int i = 0; i < 3; i++) { if (fabs(in[i] - Q_rint(in[i])) < INTEGRAL_EPSILON) vert[i] = Q_rint(in[i]); else vert[i] = in[i]; } int h = HashVec(vert); for (int vnum = hashverts[h]; vnum; vnum = vertexchain[vnum]) { const float* p = curTile->vertexes[vnum].point; if (fabs(p[0] - vert[0]) < POINT_EPSILON && fabs(p[1] - vert[1]) < POINT_EPSILON && fabs(p[2] - vert[2]) < POINT_EPSILON) return vnum; } /* emit a vertex */ if (curTile->numvertexes == MAX_MAP_VERTS) Sys_Error("numvertexes == MAX_MAP_VERTS"); curTile->vertexes[curTile->numvertexes].point[0] = vert[0]; curTile->vertexes[curTile->numvertexes].point[1] = vert[1]; curTile->vertexes[curTile->numvertexes].point[2] = vert[2]; vertexchain[curTile->numvertexes] = hashverts[h]; hashverts[h] = curTile->numvertexes; c_uniqueverts++; curTile->numvertexes++; curTile->numnormals++; return curTile->numvertexes - 1; }
/* ============= GetVertex ============= */ int GetVertex (vec3_t in, int planenum) { int h; int i; hashvert_t *hv; vec3_t vert; for (i=0 ; i<3 ; i++) { if ( fabs(in[i] - Q_rint(in[i])) < 0.001) vert[i] = Q_rint(in[i]); else vert[i] = in[i]; } h = HashVec (vert); for (hv=hashverts[h] ; hv ; hv=hv->next) { if ( fabs(hv->point[0]-vert[0])<POINT_EPSILON && fabs(hv->point[1]-vert[1])<POINT_EPSILON && fabs(hv->point[2]-vert[2])<POINT_EPSILON ) { hv->numedges++; if (hv->numplanes == 3) return hv->num; // allready known to be a corner for (i=0 ; i<hv->numplanes ; i++) if (hv->planenums[i] == planenum) return hv->num; // allready know this plane if (hv->numplanes == 2) c_cornerverts++; else hv->planenums[hv->numplanes] = planenum; hv->numplanes++; return hv->num; } } hv = hvert_p; hv->numedges = 1; hv->numplanes = 1; hv->planenums[0] = planenum; hv->next = hashverts[h]; hashverts[h] = hv; VectorCopy (vert, hv->point); hv->num = numvertexes; if (hv->num==MAX_MAP_VERTS) Error ("GetVertex: MAX_MAP_VERTS"); hvert_p++; // emit a vertex if (numvertexes == MAX_MAP_VERTS) Error ("numvertexes == MAX_MAP_VERTS"); dvertexes[numvertexes].point[0] = vert[0]; dvertexes[numvertexes].point[1] = vert[1]; dvertexes[numvertexes].point[2] = vert[2]; numvertexes++; return hv->num; }
static wedge_t * FindEdge(vec3_t p1, vec3_t p2, vec_t *t1, vec_t *t2) { vec3_t origin; vec3_t dir; wedge_t *w; vec_t temp; int h; VectorSubtract(p2, p1, dir); CanonicalVector(dir); *t1 = DotProduct(p1, dir); *t2 = DotProduct(p2, dir); VectorMA(p1, -*t1, dir, origin); if (*t1 > *t2) { temp = *t1; *t1 = *t2; *t2 = temp; } h = HashVec(origin); for (w = wedge_hash[h]; w; w = w->next) { temp = w->origin[0] - origin[0]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) continue; temp = w->origin[1] - origin[1]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) continue; temp = w->origin[2] - origin[2]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) continue; temp = w->dir[0] - dir[0]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) continue; temp = w->dir[1] - dir[1]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) continue; temp = w->dir[2] - dir[2]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) continue; return w; } if (numwedges >= cWEdges) Error(errLowWedgeCount); w = pWEdges + numwedges; numwedges++; w->next = wedge_hash[h]; wedge_hash[h] = w; VectorCopy(origin, w->origin); VectorCopy(dir, w->dir); w->head.next = w->head.prev = &w->head; w->head.t = VECT_MAX; return w; }
static wedge_t *FindEdge(const vec3_t p1, const vec3_t p2, vec_t* t1, vec_t* t2) { vec3_t origin; vec3_t dir; wedge_t* w; vec_t temp; int h; VectorSubtract(p2, p1, dir); if (!CanonicalVector(dir)) { #if _DEBUG Warning("CanonicalVector: degenerate @ (%4.3f %4.3f %4.3f )\n", p1[0], p1[1], p1[2]); #endif } *t1 = DotProduct(p1, dir); *t2 = DotProduct(p2, dir); VectorMA(p1, -*t1, dir, origin); if (*t1 > *t2) { temp = *t1; *t1 = *t2; *t2 = temp; } h = HashVec(origin); for (w = wedge_hash[h]; w; w = w->next) { #ifdef HLBSP_TJUNC_PRECISION_FIX if (fabs (w->origin[0] - origin[0]) > EQUAL_EPSILON || fabs (w->origin[1] - origin[1]) > EQUAL_EPSILON || fabs (w->origin[2] - origin[2]) > EQUAL_EPSILON ) { continue; } if (fabs (w->dir[0] - dir[0]) > NORMAL_EPSILON || fabs (w->dir[1] - dir[1]) > NORMAL_EPSILON || fabs (w->dir[2] - dir[2]) > NORMAL_EPSILON ) { continue; } #else temp = w->origin[0] - origin[0]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) { continue; } temp = w->origin[1] - origin[1]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) { continue; } temp = w->origin[2] - origin[2]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) { continue; } temp = w->dir[0] - dir[0]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) { continue; } temp = w->dir[1] - dir[1]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) { continue; } temp = w->dir[2] - dir[2]; if (temp < -EQUAL_EPSILON || temp > EQUAL_EPSILON) { continue; } #endif return w; } hlassume(numwedges < MAX_WEDGES, assume_MAX_WEDGES); w = &wedges[numwedges]; numwedges++; w->next = wedge_hash[h]; wedge_hash[h] = w; VectorCopy(origin, w->origin); VectorCopy(dir, w->dir); w->head.next = w->head.prev = &w->head; w->head.t = 99999; return w; }
wedge_t *FindEdge (vec3_t p1, vec3_t p2, vec_t *t1, vec_t *t2) { vec3_t origin; vec3_t dir; wedge_t *w; vec_t temp; int h; VectorSubtract (p2, p1, dir); // ignore degenerate edges if (!CanonicalVector (dir)) { c_degenerateEdges++; return NULL; } *t1 = DotProduct (p1, dir); *t2 = DotProduct (p2, dir); VectorMA (p1, -*t1, dir, origin); if (*t1 > *t2) { temp = *t1; *t1 = *t2; *t2 = temp; } h = HashVec (origin); for (w = wedge_hash[h] ; w ; w=w->next) { temp = w->origin[0] - origin[0]; if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL) continue; temp = w->origin[1] - origin[1]; if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL) continue; temp = w->origin[2] - origin[2]; if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL) continue; temp = w->dir[0] - dir[0]; if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL) continue; temp = w->dir[1] - dir[1]; if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL) continue; temp = w->dir[2] - dir[2]; if (temp < -pMath_EPSILON_EQUAL || temp > pMath_EPSILON_EQUAL) continue; return w; } if (numwedges == MAX_WEDGES) Error ("FindEdge: numwedges == MAX_WEDGES"); w = &wedges[numwedges]; numwedges++; w->next = wedge_hash[h]; wedge_hash[h] = w; VectorCopy (origin, w->origin); VectorCopy (dir, w->dir); w->head.next = w->head.prev = &w->head; w->head.t = 99999; return w; }
// ===================================================================================== // GetVertex // ===================================================================================== static int GetVertex(const vec3_t in, const int planenum) { int h; int i; hashvert_t* hv; vec3_t vert; for (i = 0; i < 3; i++) { if (fabs(in[i] - VectorRound(in[i])) < 0.001) { vert[i] = VectorRound(in[i]); } else { vert[i] = in[i]; } } h = HashVec(vert); for (hv = hashverts[h]; hv; hv = hv->next) { if (fabs(hv->point[0] - vert[0]) < POINT_EPSILON && fabs(hv->point[1] - vert[1]) < POINT_EPSILON && fabs(hv->point[2] - vert[2]) < POINT_EPSILON) { hv->numedges++; if (hv->numplanes == 3) { return hv->num; // allready known to be a corner } for (i = 0; i < hv->numplanes; i++) { if (hv->planenums[i] == planenum) { return hv->num; // allready know this plane } } if (hv->numplanes != 2) { hv->planenums[hv->numplanes] = planenum; } hv->numplanes++; return hv->num; } } hv = hvert_p; hv->numedges = 1; hv->numplanes = 1; hv->planenums[0] = planenum; hv->next = hashverts[h]; hashverts[h] = hv; VectorCopy(vert, hv->point); hv->num = g_numvertexes; hlassume(hv->num != MAX_MAP_VERTS, assume_MAX_MAP_VERTS); hvert_p++; // emit a vertex hlassume(g_numvertexes < MAX_MAP_VERTS, assume_MAX_MAP_VERTS); g_dvertexes[g_numvertexes].point[0] = vert[0]; g_dvertexes[g_numvertexes].point[1] = vert[1]; g_dvertexes[g_numvertexes].point[2] = vert[2]; g_numvertexes++; return hv->num; }