snap curve vertices to solve some finicky collision problems and probably also makes...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 17 Oct 2004 11:51:38 +0000 (11:51 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 17 Oct 2004 11:51:38 +0000 (11:51 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4662 d7cf8633-e32d-0410-b094-e92efae38249

model_brush.c
model_shared.c
model_shared.h

index 86d65ea..91dd5a0 100644 (file)
@@ -4302,6 +4302,9 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                        Q3PatchTesselateFloat(3, sizeof(float[3]), out->data_collisionvertex3f, patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
                        Q3PatchTriangleElements(out->data_collisionelement3i, finalwidth, finalheight);
 
                        Q3PatchTesselateFloat(3, sizeof(float[3]), out->data_collisionvertex3f, patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
                        Q3PatchTriangleElements(out->data_collisionelement3i, finalwidth, finalheight);
 
+                       Mod_SnapVertices(3, out->num_vertices, out->data_vertex3f, 0.25);
+                       Mod_SnapVertices(3, out->num_collisionvertices, out->data_collisionvertex3f, 1);
+
                        oldnumtriangles = out->num_triangles;
                        oldnumtriangles2 = out->num_collisiontriangles;
                        out->num_triangles = Mod_RemoveDegenerateTriangles(out->num_triangles, out->data_element3i, out->data_element3i, out->data_vertex3f);
                        oldnumtriangles = out->num_triangles;
                        oldnumtriangles2 = out->num_collisiontriangles;
                        out->num_triangles = Mod_RemoveDegenerateTriangles(out->num_triangles, out->data_element3i, out->data_element3i, out->data_vertex3f);
index 366a03f..20dc64f 100644 (file)
@@ -1322,6 +1322,14 @@ int Mod_CountSkinFiles(skinfile_t *skinfile)
        return i;
 }
 
        return i;
 }
 
+void Mod_SnapVertices(int numcomponents, int numvertices, float *vertices, float snap)
+{
+       int i;
+       double isnap = 1.0 / snap;
+       for (i = 0;i < numvertices*numcomponents;i++)
+               vertices[i] = floor(vertices[i]*isnap)*snap;
+}
+
 int Mod_RemoveDegenerateTriangles(int numtriangles, const int *inelement3i, int *outelement3i, const float *vertex3f)
 {
        int i, outtriangles;
 int Mod_RemoveDegenerateTriangles(int numtriangles, const int *inelement3i, int *outelement3i, const float *vertex3f)
 {
        int i, outtriangles;
index 830428d..6f57d46 100644 (file)
@@ -692,6 +692,7 @@ skinfile_t *Mod_LoadSkinFiles(void);
 void Mod_FreeSkinFiles(skinfile_t *skinfile);
 int Mod_CountSkinFiles(skinfile_t *skinfile);
 
 void Mod_FreeSkinFiles(skinfile_t *skinfile);
 int Mod_CountSkinFiles(skinfile_t *skinfile);
 
+void Mod_SnapVertices(int numcomponents, int numvertices, float *vertices, float snap);
 int Mod_RemoveDegenerateTriangles(int numtriangles, const int *inelement3i, int *outelement3i, const float *vertex3f);
 
 #endif // MODEL_SHARED_H
 int Mod_RemoveDegenerateTriangles(int numtriangles, const int *inelement3i, int *outelement3i, const float *vertex3f);
 
 #endif // MODEL_SHARED_H