/* Copyright (C) 1996-2001 Id Software, Inc. Copyright (C) 2002-2009 John Fitzgibbons and others Copyright (C) 2010-2014 QuakeSpasm developers 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. */ //gl_warp.c -- warping animation support #include "quakedef.h" extern cvar_t r_drawflat; cvar_t r_waterwarp = {"r_waterwarp", "1", CVAR_NONE}; int gl_warpimagesize; float load_subdivide_size; //johnfitz -- remember what subdivide_size value was when this map was loaded float turbsin[] = { #include "gl_warp_sin.h" }; #define WARPCALC(s,t) ((s + turbsin[(int)((t*2)+(cl.time*(128.0/M_PI))) & 255]) * (1.0/64)) //johnfitz -- correct warp #define WARPCALC2(s,t) ((s + turbsin[(int)((t*0.125+cl.time)*(128.0/M_PI)) & 255]) * (1.0/64)) //johnfitz -- old warp //============================================================================== // // OLD-STYLE WATER // //============================================================================== msurface_t *warpface; cvar_t gl_subdivide_size = {"gl_subdivide_size", "128", CVAR_ARCHIVE}; void BoundPoly (int numverts, float *verts, vec3_t mins, vec3_t maxs) { int i, j; float *v; mins[0] = mins[1] = mins[2] = FLT_MAX; maxs[0] = maxs[1] = maxs[2] = -FLT_MAX; v = verts; for (i=0 ; i maxs[j]) maxs[j] = *v; } } void SubdividePolygon (int numverts, float *verts) { int i, j, k; vec3_t mins, maxs; float m; float *v; vec3_t front[64], back[64]; int f, b; float dist[64]; float frac; glpoly_t *poly; float s, t; if (numverts > 60) Sys_Error ("numverts = %i", numverts); BoundPoly (numverts, verts, mins, maxs); for (i=0 ; i<3 ; i++) { m = (mins[i] + maxs[i]) * 0.5; m = gl_subdivide_size.value * floor (m/gl_subdivide_size.value + 0.5); if (maxs[i] - m < 8) continue; if (m - mins[i] < 8) continue; // cut it v = verts + i; for (j=0 ; j= 0) { VectorCopy (v, front[f]); f++; } if (dist[j] <= 0) { VectorCopy (v, back[b]); b++; } if (dist[j] == 0 || dist[j+1] == 0) continue; if ( (dist[j] > 0) != (dist[j+1] > 0) ) { // clip point frac = dist[j] / (dist[j] - dist[j+1]); for (k=0 ; k<3 ; k++) front[f][k] = back[b][k] = v[k] + frac*(v[3+k] - v[k]); f++; b++; } } SubdividePolygon (f, front[0]); SubdividePolygon (b, back[0]); return; } poly = (glpoly_t *) Hunk_Alloc (sizeof(glpoly_t) + (numverts-4) * VERTEXSIZE*sizeof(float)); poly->next = warpface->polys->next; warpface->polys->next = poly; poly->numverts = numverts; for (i=0 ; iverts[i]); s = DotProduct (verts, warpface->texinfo->vecs[0]); t = DotProduct (verts, warpface->texinfo->vecs[1]); poly->verts[i][3] = s; poly->verts[i][4] = t; } } /* ================ GL_SubdivideSurface ================ */ void GL_SubdivideSurface (msurface_t *fa) { vec3_t verts[64]; int i; warpface = fa; //the first poly in the chain is the undivided poly for newwater rendering. //grab the verts from that. for (i=0; ipolys->numverts; i++) VectorCopy (fa->polys->verts[i], verts[i]); SubdividePolygon (fa->polys->numverts, verts[0]); } /* ================ DrawWaterPoly -- johnfitz ================ */ void DrawWaterPoly (glpoly_t *p) { float *v; int i; if (load_subdivide_size > 48) { glBegin (GL_POLYGON); v = p->verts[0]; for (i=0 ; inumverts ; i++, v+= VERTEXSIZE) { glTexCoord2f (WARPCALC2(v[3],v[4]), WARPCALC2(v[4],v[3])); glVertex3fv (v); } glEnd (); } else { glBegin (GL_POLYGON); v = p->verts[0]; for (i=0 ; inumverts ; i++, v+= VERTEXSIZE) { glTexCoord2f (WARPCALC(v[3],v[4]), WARPCALC(v[4],v[3])); glVertex3fv (v); } glEnd (); } }