/* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // // cm_q3_trace.c // Quake3 BSP map model patches // #include "cm_q3_local.h" /* =============== Patch_FlatnessTest =============== */ static int Patch_FlatnessTest (float maxflat2, vec3_t point0, vec3_t point1, vec3_t point2) { float d; int ft0, ft1; vec3_t t, n; vec3_t v1, v2, v3; Vec3Subtract (point2, point0, n); if (!VectorNormalizef (n, n)) return 0; Vec3Subtract (point1, point0, t); d = -DotProduct (t, n); Vec3MA (t, d, n, t); if (DotProduct (t, t) < maxflat2) return 0; Vec3Average (point1, point0, v1); Vec3Average (point2, point1, v2); Vec3Average (v1, v2, v3); ft0 = Patch_FlatnessTest (maxflat2, point0, v1, v3); ft1 = Patch_FlatnessTest (maxflat2, v3, v2, point2); return 1 + (int)(floor (max (ft0, ft1)) + 0.5f); } /* =============== Patch_GetFlatness =============== */ void Patch_GetFlatness (float maxflat, vec3_t *points, int *patch_cp, int *flat) { int i, p, u, v; float maxflat2 = maxflat * maxflat; flat[0] = flat[1] = 0; for (v=0 ; v