2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // gl_warp.c -- sky and water polygons
26 void BoundPoly (int numverts, float *verts, vec3_t mins, vec3_t maxs)
31 mins[0] = mins[1] = mins[2] = 9999;
32 maxs[0] = maxs[1] = maxs[2] = -9999;
34 for (i=0 ; i<numverts ; i++)
35 for (j=0 ; j<3 ; j++, v++)
44 void SubdividePolygon (int numverts, float *verts)
50 vec3_t front[64], back[64];
58 Sys_Error ("numverts = %i", numverts);
60 BoundPoly (numverts, verts, mins, maxs);
64 m = (mins[i] + maxs[i]) * 0.5;
65 m = gl_subdivide_size.value * floor (m/gl_subdivide_size.value + 0.5);
73 for (j=0 ; j<numverts ; j++, v+= 3)
79 VectorCopy (verts, v);
83 for (j=0 ; j<numverts ; j++, v+= 3)
87 VectorCopy (v, front[f]);
92 VectorCopy (v, back[b]);
95 if (dist[j] == 0 || dist[j+1] == 0)
97 if ( (dist[j] > 0) != (dist[j+1] > 0) )
100 frac = dist[j] / (dist[j] - dist[j+1]);
101 for (k=0 ; k<3 ; k++)
102 front[f][k] = back[b][k] = v[k] + frac*(v[3+k] - v[k]);
108 SubdividePolygon (f, front[0]);
109 SubdividePolygon (b, back[0]);
113 poly = Hunk_AllocName (sizeof(glpoly_t) + (numverts-4) * VERTEXSIZE*sizeof(float), "surfaces");
114 poly->next = warpface->polys;
115 warpface->polys = poly;
116 poly->numverts = numverts;
117 for (i=0 ; i<numverts ; i++, verts+= 3)
119 VectorCopy (verts, poly->verts[i]);
120 s = DotProduct (verts, warpface->texinfo->vecs[0]);
121 t = DotProduct (verts, warpface->texinfo->vecs[1]);
122 poly->verts[i][3] = s;
123 poly->verts[i][4] = t;
131 Breaks a polygon up along axial 64 unit
132 boundaries so that turbulent and sky warps
133 can be done reasonably.
136 void GL_SubdivideSurface (msurface_t *fa)
147 // convert edges back to a normal polygon
150 for (i=0 ; i<fa->numedges ; i++)
152 lindex = loadmodel->surfedges[fa->firstedge + i];
155 vec = loadmodel->vertexes[loadmodel->edges[lindex].v[0]].position;
157 vec = loadmodel->vertexes[loadmodel->edges[-lindex].v[1]].position;
158 VectorCopy (vec, verts[numverts]);
162 SubdividePolygon (numverts, verts[0]);