diff --git a/include/common/qvec.hh b/include/common/qvec.hh index 8678129f..c78a169a 100644 --- a/include/common/qvec.hh +++ b/include/common/qvec.hh @@ -772,7 +772,7 @@ public: return v; } - inline void set_row(size_t row, const qvec &values) + constexpr void set_row(size_t row, const qvec &values) { for (size_t i = 0; i < NCol; i++) { at(row, i) = values[i]; @@ -785,7 +785,7 @@ public: return reinterpret_cast &>(m_values[col * NRow]); } - inline void set_col(size_t col, const qvec &values) const + inline void set_col(size_t col, const qvec &values) { reinterpret_cast &>(m_values[col * NRow]) = values; } @@ -880,22 +880,6 @@ namespace qv #undef DEPRECATE_SNIFF #define DEPRECATE_SNIFF -template -DEPRECATE_SNIFF constexpr void VectorSubtract(const Tx &x, const Ty &y, Tout &out) -{ - out[0] = x[0] - y[0]; - out[1] = x[1] - y[1]; - out[2] = x[2] - y[2]; -} - -template -DEPRECATE_SNIFF constexpr void VectorAdd(const Tx &x, const Ty &y, Tout &out) -{ - out[0] = x[0] + y[0]; - out[1] = x[1] + y[1]; - out[2] = x[2] + y[2]; -} - template DEPRECATE_SNIFF constexpr void VectorCopy(const TFrom &in, TTo &out) { diff --git a/light/entities.cc b/light/entities.cc index 71de80b3..e9107a0c 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -1292,7 +1292,7 @@ static void CreateSurfaceLightOnFaceSubdivision(const mface_t *face, const model midpoint += plane.normal * offset; /* Add the model offset */ - VectorAdd(midpoint, face_modelinfo->offset, midpoint); + midpoint += face_modelinfo->offset; CreateSurfaceLight(midpoint, plane.normal, surflight_template); } diff --git a/light/ltface.cc b/light/ltface.cc index 3f830b91..4e792051 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -641,7 +641,7 @@ static void CalcPoints( * the surface to help avoid edge cases just inside walls */ surf->midpoint = TexCoordToWorld(surf->exactmid[0], surf->exactmid[1], &surf->texorg); - VectorAdd(surf->midpoint, offset, surf->midpoint); + surf->midpoint += offset; surf->width = (surf->texsize[0] + 1) * oversample; surf->height = (surf->texsize[1] + 1) * oversample; @@ -681,7 +681,7 @@ static void CalcPoints( VectorCopy(res.m_interpolatedNormal, norm); // apply model offset after calling CalcPointNormal - VectorAdd(point, offset, point); + point += offset; } } @@ -778,7 +778,7 @@ static bool Lightsurf_Init( plane->dist = qv::dot(plane->normal, planepoint); /* Correct bounding sphere */ - VectorAdd(lightsurf->origin, modelinfo->offset, lightsurf->origin); + lightsurf->origin += modelinfo->offset; lightsurf->bounds = lightsurf->bounds.translate(modelinfo->offset); /* Allocate occlusion array */ @@ -1991,7 +1991,7 @@ static void LightFace_Bounce( } lightsample_t *sample = &lightmap->samples[i]; - VectorAdd(sample->color, indirect, sample->color); + sample->color += indirect; hit = true; ++total_bounce_ray_hits; @@ -2097,7 +2097,7 @@ static void LightFace_Bounce( qvec3d indirectTmp; VectorCopy(colorAvg, indirectTmp); - VectorAdd(sample->color, indirectTmp, sample->color); + sample->color += indirectTmp; } } @@ -2185,7 +2185,7 @@ LightFace_SurfaceLight(const lightsurf_t *lightsurf, lightmapdict_t *lightmaps) VectorScale(indirect, dirtscale, indirect); lightsample_t *sample = &lightmap->samples[i]; - VectorAdd(sample->color, indirect, sample->color); + sample->color += indirect; hit = true; ++total_surflight_ray_hits; diff --git a/qbsp/map.cc b/qbsp/map.cc index 59fb3e74..7e1233d8 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -70,10 +70,7 @@ struct texdef_etp_t bool tx2 = false; }; -struct texdef_brush_primitives_t -{ - qmat texMat { }; -}; +using texdef_brush_primitives_t = qmat; static texdef_valve_t TexDef_BSPToValve(const texvecf &in_vecs); static qvec2f projectToAxisPlane(const qvec3d &snapped_normal, const qvec3d &point); @@ -1192,14 +1189,6 @@ static void SetTexinfo_BrushPrimitives( vecs.at(1, 3) = texHeight * texMat.at(1, 2); } -static void BSP_GetSTCoordsForPoint(const vec_t *point, const int texSize[2], const texvecf &in_vecs, vec_t *st_out) -{ - for (int i = 0; i < 2; i++) { - st_out[i] = (point[0] * in_vecs.at(i, 0) + point[1] * in_vecs.at(i, 1) + point[2] * in_vecs.at(i, 2) + in_vecs.at(i, 3)) / - static_cast(texSize[i]); - } -} - // From FaceToBrushPrimitFace in GtkRadiant static texdef_brush_primitives_t TexDef_BSPToBrushPrimitives( const qbsp_plane_t plane, const int texSize[2], const texvecf &in_vecs) @@ -1207,34 +1196,23 @@ static texdef_brush_primitives_t TexDef_BSPToBrushPrimitives( qvec3d texX, texY; ComputeAxisBase(plane.normal, texX, texY); - // ST of (0,0) (1,0) (0,1) - vec_t ST[3][5]; // [ point index ] [ xyz ST ] - // compute projection vector - qvec3d proj; - VectorCopy(plane.normal, proj); - VectorScale(proj, plane.dist, proj); + qvec3d proj = plane.normal * plane.dist; // (0,0) in plane axis base is (0,0,0) in world coordinates + projection on the affine plane // (1,0) in plane axis base is texX in world coordinates + projection on the affine plane // (0,1) in plane axis base is texY in world coordinates + projection on the affine plane // use old texture code to compute the ST coords of these points - VectorCopy(proj, ST[0]); - BSP_GetSTCoordsForPoint(&ST[0][0], texSize, in_vecs, &ST[0][3]); - VectorCopy(texX, ST[1]); - VectorAdd(ST[1], proj, ST[1]); - BSP_GetSTCoordsForPoint(&ST[1][0], texSize, in_vecs, &ST[1][3]); - VectorCopy(texY, ST[2]); - VectorAdd(ST[2], proj, ST[2]); - BSP_GetSTCoordsForPoint(&ST[2][0], texSize, in_vecs, &ST[2][3]); + qvec2d st[] = { + in_vecs.uvs(proj, texSize[0], texSize[1]), + in_vecs.uvs(texX + proj, texSize[0], texSize[1]), + in_vecs.uvs(texY + proj, texSize[0], texSize[1]) + }; // compute texture matrix texdef_brush_primitives_t res; - res.texMat.at(0, 2) = ST[0][3]; - res.texMat.at(1, 2) = ST[0][4]; - res.texMat.at(0, 0) = ST[1][3] - res.texMat.at(0, 2); - res.texMat.at(1, 0) = ST[1][4] - res.texMat.at(1, 2); - res.texMat.at(0, 1) = ST[2][3] - res.texMat.at(0, 2); - res.texMat.at(1, 1) = ST[2][4] - res.texMat.at(1, 2); + res.set_col(2, st[0]); + res.set_col(0, st[1] - st[0]); + res.set_col(1, st[2] - st[0]); return res; } @@ -1721,7 +1699,7 @@ static void TranslateMapFace(mapface_t *face, const qvec3d &offset) { std::array new_planepts; for (int i = 0; i < 3; i++) { - VectorAdd(face->planepts[i], offset, new_planepts[i]); + new_planepts[i] = face->planepts[i] + offset; } face->set_planepts(new_planepts); @@ -2064,13 +2042,13 @@ static void ConvertMapFace(std::ofstream &f, const mapface_t &mapface, const con const texdef_brush_primitives_t bp = TexDef_BSPToBrushPrimitives(mapface.plane, texSize, texinfo.vecs); f << "( ( "; - fprintDoubleAndSpc(f, bp.texMat.at(0, 0)); - fprintDoubleAndSpc(f, bp.texMat.at(0, 1)); - fprintDoubleAndSpc(f, bp.texMat.at(0, 2)); + fprintDoubleAndSpc(f, bp.at(0, 0)); + fprintDoubleAndSpc(f, bp.at(0, 1)); + fprintDoubleAndSpc(f, bp.at(0, 2)); f << ") ( "; - fprintDoubleAndSpc(f, bp.texMat.at(1, 0)); - fprintDoubleAndSpc(f, bp.texMat.at(1, 1)); - fprintDoubleAndSpc(f, bp.texMat.at(1, 2)); + fprintDoubleAndSpc(f, bp.at(1, 0)); + fprintDoubleAndSpc(f, bp.at(1, 1)); + fprintDoubleAndSpc(f, bp.at(1, 2)); // N.B.: always print the Q2/Q3 flags fmt::print(f, ") ) {} 0 0 0", mapface.texname);