2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
gl_warp.c
|
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
water polygons
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/sys.h"
|
2001-04-15 21:11:41 +00:00
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "r_cvar.h"
|
2001-09-01 08:57:04 +00:00
|
|
|
#include "r_shared.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
|
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
msurface_t *warpface;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
extern cvar_t *gl_subdivide_size;
|
2001-09-01 08:57:04 +00:00
|
|
|
extern model_t *loadmodel;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
BoundPoly (int numverts, float *verts, vec3_t mins, vec3_t maxs)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float *v;
|
2001-09-01 08:57:04 +00:00
|
|
|
int i, j;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
mins[0] = mins[1] = mins[2] = 9999;
|
|
|
|
maxs[0] = maxs[1] = maxs[2] = -9999;
|
|
|
|
v = verts;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < numverts; i++)
|
|
|
|
for (j = 0; j < 3; j++, v++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (*v < mins[j])
|
|
|
|
mins[j] = *v;
|
|
|
|
if (*v > maxs[j])
|
|
|
|
maxs[j] = *v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SubdividePolygon (int numverts, float *verts)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-01 08:57:04 +00:00
|
|
|
float frac, m, s, t;
|
2001-02-26 06:48:02 +00:00
|
|
|
float dist[64];
|
2001-09-01 08:57:04 +00:00
|
|
|
float *v;
|
|
|
|
int b, f, i, j, k;
|
2001-02-26 06:48:02 +00:00
|
|
|
glpoly_t *poly;
|
2001-09-01 08:57:04 +00:00
|
|
|
vec3_t mins, maxs;
|
|
|
|
vec3_t front[64], back[64];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (numverts > 60)
|
|
|
|
Sys_Error ("numverts = %i", numverts);
|
|
|
|
|
|
|
|
BoundPoly (numverts, verts, mins, maxs);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
m = (mins[i] + maxs[i]) * 0.5;
|
2001-09-01 08:57:04 +00:00
|
|
|
m = gl_subdivide_size->value * floor (m / gl_subdivide_size->value +
|
2001-02-26 06:48:02 +00:00
|
|
|
0.5);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (maxs[i] - m < 8)
|
|
|
|
continue;
|
|
|
|
if (m - mins[i] < 8)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// cut it
|
|
|
|
v = verts + i;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 0; j < numverts; j++, v += 3)
|
2001-02-19 21:15:25 +00:00
|
|
|
dist[j] = *v - m;
|
|
|
|
|
|
|
|
// wrap cases
|
|
|
|
dist[j] = dist[0];
|
2001-02-26 06:48:02 +00:00
|
|
|
v -= i;
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (verts, v);
|
|
|
|
|
|
|
|
f = b = 0;
|
|
|
|
v = verts;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 0; j < numverts; j++, v += 3) {
|
|
|
|
if (dist[j] >= 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (v, front[f]);
|
|
|
|
f++;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dist[j] <= 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (v, back[b]);
|
|
|
|
b++;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dist[j] == 0 || dist[j + 1] == 0)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((dist[j] > 0) != (dist[j + 1] > 0)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// clip point
|
2001-02-26 06:48:02 +00:00
|
|
|
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]);
|
2001-02-19 21:15:25 +00:00
|
|
|
f++;
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SubdividePolygon (f, front[0]);
|
|
|
|
SubdividePolygon (b, back[0]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-22 11:00:25 +00:00
|
|
|
poly = Hunk_Alloc (sizeof (glpoly_t) + (numverts - 4) * VERTEXSIZE *
|
|
|
|
sizeof (float));
|
2001-02-19 21:15:25 +00:00
|
|
|
poly->next = warpface->polys;
|
|
|
|
warpface->polys = poly;
|
|
|
|
poly->numverts = numverts;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < numverts; i++, verts += 3) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (verts, poly->verts[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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-11 01:01:27 +00:00
|
|
|
GL_SubdivideSurface
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
Breaks a polygon up along axial 64 unit
|
|
|
|
boundaries so that turbulent and sky warps
|
|
|
|
can be done reasonably.
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
GL_SubdivideSurface (msurface_t *fa)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float *vec;
|
2001-09-01 08:57:04 +00:00
|
|
|
int lindex, numverts, i;
|
|
|
|
vec3_t verts[64];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
warpface = fa;
|
|
|
|
|
|
|
|
// convert edges back to a normal polygon
|
|
|
|
numverts = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < fa->numedges; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lindex = loadmodel->surfedges[fa->firstedge + i];
|
|
|
|
|
|
|
|
if (lindex > 0)
|
|
|
|
vec = loadmodel->vertexes[loadmodel->edges[lindex].v[0]].position;
|
|
|
|
else
|
|
|
|
vec = loadmodel->vertexes[loadmodel->edges[-lindex].v[1]].position;
|
|
|
|
VectorCopy (vec, verts[numverts]);
|
|
|
|
numverts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubdividePolygon (numverts, verts[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// speed up sin calculations - Ed
|
2001-02-26 06:48:02 +00:00
|
|
|
float turbsin[] = {
|
2001-05-09 18:45:38 +00:00
|
|
|
# include "gl_warp_sin.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
};
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
#define TURBSCALE (256.0 / (2 * M_PI))
|
2001-05-09 05:41:34 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-05-11 01:01:27 +00:00
|
|
|
EmitWaterPolys
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
Does a water warp on the pre-fragmented glpoly_t chain
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
EmitWaterPolys (msurface_t *fa)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-01 08:57:04 +00:00
|
|
|
float os, ot, s, t;
|
2001-02-26 06:48:02 +00:00
|
|
|
float *v;
|
|
|
|
int i;
|
2001-09-01 08:57:04 +00:00
|
|
|
glpoly_t *p;
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t nv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (p = fa->polys; p; p = p->next) {
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglBegin (GL_POLYGON);
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE) {
|
2001-02-19 21:15:25 +00:00
|
|
|
os = v[3];
|
|
|
|
ot = v[4];
|
|
|
|
|
2001-10-05 18:55:40 +00:00
|
|
|
s = (os + turbsin[(int) ((ot * 0.125 + r_realtime) * TURBSCALE) &
|
|
|
|
255]) * (1.0 / 64.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-10-05 18:55:40 +00:00
|
|
|
t = (ot + turbsin[(int) ((os * 0.125 + r_realtime) * TURBSCALE) &
|
|
|
|
255]) * (1.0 / 64.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTexCoord2f (s, t);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VectorCopy (v, nv);
|
|
|
|
nv[2] += r_waterripple->value
|
2001-08-22 11:00:25 +00:00
|
|
|
* turbsin[(int) ((v[3] * 0.125 + r_realtime) * TURBSCALE) &
|
|
|
|
255]
|
|
|
|
* turbsin[(int) ((v[4] * 0.125 + r_realtime) * TURBSCALE) &
|
2001-10-05 18:55:40 +00:00
|
|
|
255] * (1.0 / 64.0);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglVertex3fv (nv);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnd ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|