Sync code style in sky warp functions

This commit is contained in:
Denis Pauk 2023-10-11 20:14:07 +03:00
parent 3e7b568ec9
commit 8fb649709e
8 changed files with 232 additions and 186 deletions

View file

@ -34,7 +34,7 @@ static float skyrotate;
static int skyautorotate; static int skyautorotate;
static vec3_t skyaxis; static vec3_t skyaxis;
static image_t *sky_images[6]; static image_t *sky_images[6];
static int skytexorder[6] = {0, 2, 1, 3, 4, 5}; static const int skytexorder[6] = {0, 2, 1, 3, 4, 5};
GLfloat vtx_sky[12]; GLfloat vtx_sky[12];
GLfloat tex_sky[8]; GLfloat tex_sky[8];
@ -42,13 +42,13 @@ unsigned int index_vtx = 0;
unsigned int index_tex = 0; unsigned int index_tex = 0;
/* 3dstudio environment map names */ /* 3dstudio environment map names */
char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"}; static const char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
float r_turbsin[] = { float r_turbsin[] = {
#include "../constants/warpsin.h" #include "../constants/warpsin.h"
}; };
static vec3_t skyclip[6] = { static const vec3_t skyclip[6] = {
{1, 1, 0}, {1, 1, 0},
{1, -1, 0}, {1, -1, 0},
{0, -1, 1}, {0, -1, 1},
@ -56,9 +56,8 @@ static vec3_t skyclip[6] = {
{1, 0, 1}, {1, 0, 1},
{-1, 0, 1} {-1, 0, 1}
}; };
int c_sky;
static int st_to_vec[6][3] = { static const int st_to_vec[6][3] = {
{3, -1, 2}, {3, -1, 2},
{-3, 1, 2}, {-3, 1, 2},
@ -69,7 +68,7 @@ static int st_to_vec[6][3] = {
{2, -1, -3} /* look straight down */ {2, -1, -3} /* look straight down */
}; };
static int vec_to_st[6][3] = { static const int vec_to_st[6][3] = {
{-2, 3, 1}, {-2, 3, 1},
{2, 3, -1}, {2, 3, -1},
@ -157,14 +156,12 @@ R_EmitWaterPolys(msurface_t *fa)
static void static void
R_DrawSkyPolygon(int nump, vec3_t vecs) R_DrawSkyPolygon(int nump, vec3_t vecs)
{ {
int i, j; int i;
vec3_t v, av; vec3_t v, av;
float s, t, dv; float s, t, dv;
int axis; int axis;
float *vp; float *vp;
c_sky++;
/* decide which face it maps to */ /* decide which face it maps to */
VectorCopy(vec3_origin, v); VectorCopy(vec3_origin, v);
@ -214,6 +211,8 @@ R_DrawSkyPolygon(int nump, vec3_t vecs)
/* project new texture coords */ /* project new texture coords */
for (i = 0; i < nump; i++, vecs += 3) for (i = 0; i < nump; i++, vecs += 3)
{ {
int j;
j = vec_to_st[axis][2]; j = vec_to_st[axis][2];
if (j > 0) if (j > 0)
@ -274,10 +273,10 @@ R_DrawSkyPolygon(int nump, vec3_t vecs)
} }
} }
void static void
R_ClipSkyPolygon(int nump, vec3_t vecs, int stage) R_ClipSkyPolygon(int nump, vec3_t vecs, int stage)
{ {
float *norm; const float *norm;
float *v; float *v;
qboolean front, back; qboolean front, back;
float d, e; float d, e;
@ -289,7 +288,7 @@ R_ClipSkyPolygon(int nump, vec3_t vecs, int stage)
if (nump > MAX_CLIP_VERTS - 2) if (nump > MAX_CLIP_VERTS - 2)
{ {
Com_Error(ERR_DROP, "R_ClipSkyPolygon: MAX_CLIP_VERTS"); Com_Error(ERR_DROP, "%s: MAX_CLIP_VERTS", __func__);
} }
if (stage == 6) if (stage == 6)
@ -413,27 +412,22 @@ R_ClearSkyBox(void)
} }
} }
void static void
R_MakeSkyVec(float s, float t, int axis) R_MakeSkyVec(float s, float t, int axis)
{ {
vec3_t v, b; vec3_t v, b;
int j, k; int j;
if (r_farsee->value == 0) float dist = (r_farsee->value == 0) ? 2300.0f : 4096.0f;
{
b[0] = s * 2300; b[0] = s * dist;
b[1] = t * 2300; b[1] = t * dist;
b[2] = 2300; b[2] = dist;
}
else
{
b[0] = s * 4096;
b[1] = t * 4096;
b[2] = 4096;
}
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
{ {
int k;
k = st_to_vec[axis][j]; k = st_to_vec[axis][j];
if (k < 0) if (k < 0)
@ -488,7 +482,7 @@ R_DrawSkyBox(void)
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
{ {
if ((skymins[0][i] < skymaxs[0][i]) && if ((skymins[0][i] < skymaxs[0][i]) &&
(skymins[1][i] < skymaxs[1][i])) (skymins[1][i] < skymaxs[1][i]))
{ {
break; break;
} }
@ -516,7 +510,7 @@ R_DrawSkyBox(void)
} }
if ((skymins[0][i] >= skymaxs[0][i]) || if ((skymins[0][i] >= skymaxs[0][i]) ||
(skymins[1][i] >= skymaxs[1][i])) (skymins[1][i] >= skymaxs[1][i]))
{ {
continue; continue;
} }
@ -576,4 +570,3 @@ RI_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis)
sky_min = 1.0 / 512; sky_min = 1.0 / 512;
sky_max = 511.0 / 512; sky_max = 511.0 / 512;
} }

View file

@ -723,7 +723,7 @@ RecursiveWorldNode(entity_t *currententity, mnode_t *node)
if (surf->texinfo->flags & SURF_SKY) if (surf->texinfo->flags & SURF_SKY)
{ {
/* just adds to visible sky bounds */ /* just adds to visible sky bounds */
GL3_AddSkySurface(surf); R_AddSkySurface(surf);
} }
else if (surf->texinfo->flags & (SURF_TRANS33 | SURF_TRANS66)) else if (surf->texinfo->flags & (SURF_TRANS33 | SURF_TRANS66))
{ {
@ -780,7 +780,7 @@ GL3_DrawWorld(void)
gl3state.currenttexture = -1; gl3state.currenttexture = -1;
GL3_ClearSkyBox(); R_ClearSkyBox();
RecursiveWorldNode(&ent, gl3_worldmodel->nodes); RecursiveWorldNode(&ent, gl3_worldmodel->nodes);
DrawTextureChains(&ent); DrawTextureChains(&ent);
GL3_DrawSkyBox(); GL3_DrawSkyBox();

View file

@ -83,21 +83,16 @@ GL3_EmitWaterPolys(msurface_t *fa)
#define ON_EPSILON 0.1 /* point on plane side epsilon */ #define ON_EPSILON 0.1 /* point on plane side epsilon */
enum { MAX_CLIP_VERTS = 64 }; enum { MAX_CLIP_VERTS = 64 };
static const int skytexorder[6] = {0, 2, 1, 3, 4, 5};
static float skymins[2][6], skymaxs[2][6];
static float sky_min, sky_max;
static float skyrotate; static float skyrotate;
static int skyautorotate; static int skyautorotate;
static vec3_t skyaxis; static vec3_t skyaxis;
static gl3image_t* sky_images[6]; static gl3image_t *sky_images[6];
static const int skytexorder[6] = {0, 2, 1, 3, 4, 5};
/* 3dstudio environment map names */ /* 3dstudio environment map names */
static const char* suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"}; static const char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
vec3_t skyclip[6] = { static const vec3_t skyclip[6] = {
{1, 1, 0}, {1, 1, 0},
{1, -1, 0}, {1, -1, 0},
{0, -1, 1}, {0, -1, 1},
@ -105,9 +100,8 @@ vec3_t skyclip[6] = {
{1, 0, 1}, {1, 0, 1},
{-1, 0, 1} {-1, 0, 1}
}; };
int c_sky;
int st_to_vec[6][3] = { static const int st_to_vec[6][3] = {
{3, -1, 2}, {3, -1, 2},
{-3, 1, 2}, {-3, 1, 2},
@ -118,7 +112,7 @@ int st_to_vec[6][3] = {
{2, -1, -3} /* look straight down */ {2, -1, -3} /* look straight down */
}; };
int vec_to_st[6][3] = { static const int vec_to_st[6][3] = {
{-2, 3, 1}, {-2, 3, 1},
{2, 3, -1}, {2, 3, -1},
@ -129,6 +123,8 @@ int vec_to_st[6][3] = {
{-2, 1, -3} {-2, 1, -3}
}; };
static float skymins[2][6], skymaxs[2][6];
static float sky_min, sky_max;
void void
GL3_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis) GL3_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis)
@ -163,16 +159,14 @@ GL3_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis)
} }
static void static void
DrawSkyPolygon(int nump, vec3_t vecs) R_DrawSkyPolygon(int nump, vec3_t vecs)
{ {
int i, j; int i;
vec3_t v, av; vec3_t v, av;
float s, t, dv; float s, t, dv;
int axis; int axis;
float *vp; float *vp;
c_sky++;
/* decide which face it maps to */ /* decide which face it maps to */
VectorCopy(vec3_origin, v); VectorCopy(vec3_origin, v);
@ -222,6 +216,8 @@ DrawSkyPolygon(int nump, vec3_t vecs)
/* project new texture coords */ /* project new texture coords */
for (i = 0; i < nump; i++, vecs += 3) for (i = 0; i < nump; i++, vecs += 3)
{ {
int j;
j = vec_to_st[axis][2]; j = vec_to_st[axis][2];
if (j > 0) if (j > 0)
@ -283,9 +279,9 @@ DrawSkyPolygon(int nump, vec3_t vecs)
} }
static void static void
ClipSkyPolygon(int nump, vec3_t vecs, int stage) R_ClipSkyPolygon(int nump, vec3_t vecs, int stage)
{ {
float *norm; const float *norm;
float *v; float *v;
qboolean front, back; qboolean front, back;
float d, e; float d, e;
@ -297,13 +293,13 @@ ClipSkyPolygon(int nump, vec3_t vecs, int stage)
if (nump > MAX_CLIP_VERTS - 2) if (nump > MAX_CLIP_VERTS - 2)
{ {
Com_Error(ERR_DROP, "R_ClipSkyPolygon: MAX_CLIP_VERTS"); Com_Error(ERR_DROP, "%s: MAX_CLIP_VERTS", __func__);
} }
if (stage == 6) if (stage == 6)
{ {
/* fully clipped, so draw it */ /* fully clipped, so draw it */
DrawSkyPolygon(nump, vecs); R_DrawSkyPolygon(nump, vecs);
return; return;
} }
@ -335,7 +331,7 @@ ClipSkyPolygon(int nump, vec3_t vecs, int stage)
if (!front || !back) if (!front || !back)
{ {
/* not clipped */ /* not clipped */
ClipSkyPolygon(nump, vecs, stage + 1); R_ClipSkyPolygon(nump, vecs, stage + 1);
return; return;
} }
@ -386,12 +382,12 @@ ClipSkyPolygon(int nump, vec3_t vecs, int stage)
} }
/* continue */ /* continue */
ClipSkyPolygon(newc[0], newv[0][0], stage + 1); R_ClipSkyPolygon(newc[0], newv[0][0], stage + 1);
ClipSkyPolygon(newc[1], newv[1][0], stage + 1); R_ClipSkyPolygon(newc[1], newv[1][0], stage + 1);
} }
void void
GL3_AddSkySurface(msurface_t *fa) R_AddSkySurface(msurface_t *fa)
{ {
int i; int i;
vec3_t verts[MAX_CLIP_VERTS]; vec3_t verts[MAX_CLIP_VERTS];
@ -405,12 +401,12 @@ GL3_AddSkySurface(msurface_t *fa)
VectorSubtract(p->verts[i].pos, gl3_origin, verts[i]); VectorSubtract(p->verts[i].pos, gl3_origin, verts[i]);
} }
ClipSkyPolygon(p->numverts, verts[0], 0); R_ClipSkyPolygon(p->numverts, verts[0], 0);
} }
} }
void void
GL3_ClearSkyBox(void) R_ClearSkyBox(void)
{ {
int i; int i;
@ -425,7 +421,7 @@ static void
MakeSkyVec(float s, float t, int axis, mvtx_t* vert) MakeSkyVec(float s, float t, int axis, mvtx_t* vert)
{ {
vec3_t v, b; vec3_t v, b;
int j, k; int j;
float dist = (r_farsee->value == 0) ? 2300.0f : 4096.0f; float dist = (r_farsee->value == 0) ? 2300.0f : 4096.0f;
@ -435,6 +431,8 @@ MakeSkyVec(float s, float t, int axis, mvtx_t* vert)
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
{ {
int k;
k = st_to_vec[axis][j]; k = st_to_vec[axis][j];
if (k < 0) if (k < 0)

View file

@ -477,8 +477,8 @@ extern void GL3_EmitWaterPolys(msurface_t *fa);
extern void GL3_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis); extern void GL3_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis);
extern void GL3_DrawSkyBox(void); extern void GL3_DrawSkyBox(void);
extern void GL3_ClearSkyBox(void); extern void R_ClearSkyBox(void);
extern void GL3_AddSkySurface(msurface_t *fa); extern void R_AddSkySurface(msurface_t *fa);
// gl3_surf.c // gl3_surf.c

View file

@ -780,7 +780,7 @@ GL4_DrawWorld(void)
gl4state.currenttexture = -1; gl4state.currenttexture = -1;
GL4_ClearSkyBox(); R_ClearSkyBox();
RecursiveWorldNode(&ent, gl4_worldmodel->nodes); RecursiveWorldNode(&ent, gl4_worldmodel->nodes);
DrawTextureChains(&ent); DrawTextureChains(&ent);
GL4_DrawSkyBox(); GL4_DrawSkyBox();

View file

@ -83,21 +83,16 @@ GL4_EmitWaterPolys(msurface_t *fa)
#define ON_EPSILON 0.1 /* point on plane side epsilon */ #define ON_EPSILON 0.1 /* point on plane side epsilon */
enum { MAX_CLIP_VERTS = 64 }; enum { MAX_CLIP_VERTS = 64 };
static const int skytexorder[6] = {0, 2, 1, 3, 4, 5};
static float skymins[2][6], skymaxs[2][6];
static float sky_min, sky_max;
static float skyrotate; static float skyrotate;
static int skyautorotate; static int skyautorotate;
static vec3_t skyaxis; static vec3_t skyaxis;
static gl4image_t* sky_images[6]; static gl4image_t *sky_images[6];
static const int skytexorder[6] = {0, 2, 1, 3, 4, 5};
/* 3dstudio environment map names */ /* 3dstudio environment map names */
static const char* suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"}; static const char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
vec3_t skyclip[6] = { static const vec3_t skyclip[6] = {
{1, 1, 0}, {1, 1, 0},
{1, -1, 0}, {1, -1, 0},
{0, -1, 1}, {0, -1, 1},
@ -105,9 +100,8 @@ vec3_t skyclip[6] = {
{1, 0, 1}, {1, 0, 1},
{-1, 0, 1} {-1, 0, 1}
}; };
int c_sky;
int st_to_vec[6][3] = { static const int st_to_vec[6][3] = {
{3, -1, 2}, {3, -1, 2},
{-3, 1, 2}, {-3, 1, 2},
@ -118,7 +112,7 @@ int st_to_vec[6][3] = {
{2, -1, -3} /* look straight down */ {2, -1, -3} /* look straight down */
}; };
int vec_to_st[6][3] = { static const int vec_to_st[6][3] = {
{-2, 3, 1}, {-2, 3, 1},
{2, 3, -1}, {2, 3, -1},
@ -129,6 +123,8 @@ int vec_to_st[6][3] = {
{-2, 1, -3} {-2, 1, -3}
}; };
static float skymins[2][6], skymaxs[2][6];
static float sky_min, sky_max;
void void
GL4_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis) GL4_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis)
@ -163,16 +159,14 @@ GL4_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis)
} }
static void static void
DrawSkyPolygon(int nump, vec3_t vecs) R_DrawSkyPolygon(int nump, vec3_t vecs)
{ {
int i, j; int i;
vec3_t v, av; vec3_t v, av;
float s, t, dv; float s, t, dv;
int axis; int axis;
float *vp; float *vp;
c_sky++;
/* decide which face it maps to */ /* decide which face it maps to */
VectorCopy(vec3_origin, v); VectorCopy(vec3_origin, v);
@ -222,6 +216,8 @@ DrawSkyPolygon(int nump, vec3_t vecs)
/* project new texture coords */ /* project new texture coords */
for (i = 0; i < nump; i++, vecs += 3) for (i = 0; i < nump; i++, vecs += 3)
{ {
int j;
j = vec_to_st[axis][2]; j = vec_to_st[axis][2];
if (j > 0) if (j > 0)
@ -283,9 +279,9 @@ DrawSkyPolygon(int nump, vec3_t vecs)
} }
static void static void
ClipSkyPolygon(int nump, vec3_t vecs, int stage) R_ClipSkyPolygon(int nump, vec3_t vecs, int stage)
{ {
float *norm; const float *norm;
float *v; float *v;
qboolean front, back; qboolean front, back;
float d, e; float d, e;
@ -297,13 +293,13 @@ ClipSkyPolygon(int nump, vec3_t vecs, int stage)
if (nump > MAX_CLIP_VERTS - 2) if (nump > MAX_CLIP_VERTS - 2)
{ {
Com_Error(ERR_DROP, "R_ClipSkyPolygon: MAX_CLIP_VERTS"); Com_Error(ERR_DROP, "%s: MAX_CLIP_VERTS", __func__);
} }
if (stage == 6) if (stage == 6)
{ {
/* fully clipped, so draw it */ /* fully clipped, so draw it */
DrawSkyPolygon(nump, vecs); R_DrawSkyPolygon(nump, vecs);
return; return;
} }
@ -335,7 +331,7 @@ ClipSkyPolygon(int nump, vec3_t vecs, int stage)
if (!front || !back) if (!front || !back)
{ {
/* not clipped */ /* not clipped */
ClipSkyPolygon(nump, vecs, stage + 1); R_ClipSkyPolygon(nump, vecs, stage + 1);
return; return;
} }
@ -386,8 +382,8 @@ ClipSkyPolygon(int nump, vec3_t vecs, int stage)
} }
/* continue */ /* continue */
ClipSkyPolygon(newc[0], newv[0][0], stage + 1); R_ClipSkyPolygon(newc[0], newv[0][0], stage + 1);
ClipSkyPolygon(newc[1], newv[1][0], stage + 1); R_ClipSkyPolygon(newc[1], newv[1][0], stage + 1);
} }
void void
@ -405,12 +401,12 @@ GL4_AddSkySurface(msurface_t *fa)
VectorSubtract(p->verts[i].pos, gl4_origin, verts[i]); VectorSubtract(p->verts[i].pos, gl4_origin, verts[i]);
} }
ClipSkyPolygon(p->numverts, verts[0], 0); R_ClipSkyPolygon(p->numverts, verts[0], 0);
} }
} }
void void
GL4_ClearSkyBox(void) R_ClearSkyBox(void)
{ {
int i; int i;
@ -425,7 +421,7 @@ static void
MakeSkyVec(float s, float t, int axis, mvtx_t* vert) MakeSkyVec(float s, float t, int axis, mvtx_t* vert)
{ {
vec3_t v, b; vec3_t v, b;
int j, k; int j;
float dist = (r_farsee->value == 0) ? 2300.0f : 4096.0f; float dist = (r_farsee->value == 0) ? 2300.0f : 4096.0f;
@ -435,6 +431,8 @@ MakeSkyVec(float s, float t, int axis, mvtx_t* vert)
for (j = 0; j < 3; j++) for (j = 0; j < 3; j++)
{ {
int k;
k = st_to_vec[axis][j]; k = st_to_vec[axis][j];
if (k < 0) if (k < 0)

View file

@ -477,7 +477,7 @@ extern void GL4_EmitWaterPolys(msurface_t *fa);
extern void GL4_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis); extern void GL4_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis);
extern void GL4_DrawSkyBox(void); extern void GL4_DrawSkyBox(void);
extern void GL4_ClearSkyBox(void); extern void R_ClearSkyBox(void);
extern void GL4_AddSkySurface(msurface_t *fa); extern void GL4_AddSkySurface(msurface_t *fa);

View file

@ -34,9 +34,12 @@ static float skyrotate;
static int skyautorotate; static int skyautorotate;
static vec3_t skyaxis; static vec3_t skyaxis;
static image_t *sky_images[6]; static image_t *sky_images[6];
static int skytexorder[6] = {0, 2, 1, 3, 4, 5}; static const int skytexorder[6] = {0, 2, 1, 3, 4, 5};
static vec3_t skyclip[6] = { /* 3dstudio environment map names */
static const char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
static const vec3_t skyclip[6] = {
{1, 1, 0}, {1, 1, 0},
{1, -1, 0}, {1, -1, 0},
{0, -1, 1}, {0, -1, 1},
@ -45,7 +48,7 @@ static vec3_t skyclip[6] = {
{-1, 0, 1} {-1, 0, 1}
}; };
static int st_to_vec[6][3] = { static const int st_to_vec[6][3] = {
{3, -1, 2}, {3, -1, 2},
{-3, 1, 2}, {-3, 1, 2},
@ -56,7 +59,7 @@ static int st_to_vec[6][3] = {
{2, -1, -3} /* look straight down */ {2, -1, -3} /* look straight down */
}; };
static int vec_to_st[6][3] = { static const int vec_to_st[6][3] = {
{-2, 3, 1}, {-2, 3, 1},
{2, 3, -1}, {2, 3, -1},
@ -179,87 +182,130 @@ EmitWaterPolys(msurface_t *fa, image_t *texture, float *modelMatrix,
} }
} }
//===================================================================
static void static void
DrawSkyPolygon(int nump, vec3_t vecs) R_DrawSkyPolygon(int nump, vec3_t vecs)
{ {
int i; int i;
vec3_t v, av; vec3_t v, av;
float s, t, dv; float s, t, dv;
int axis; int axis;
float *vp; float *vp;
// decide which face it maps to /* decide which face it maps to */
VectorCopy(vec3_origin, v); VectorCopy(vec3_origin, v);
for (i=0, vp=vecs ; i<nump ; i++, vp+=3)
for (i = 0, vp = vecs; i < nump; i++, vp += 3)
{ {
VectorAdd (vp, v, v); VectorAdd(vp, v, v);
} }
av[0] = fabs(v[0]); av[0] = fabs(v[0]);
av[1] = fabs(v[1]); av[1] = fabs(v[1]);
av[2] = fabs(v[2]); av[2] = fabs(v[2]);
if (av[0] > av[1] && av[0] > av[2])
if ((av[0] > av[1]) && (av[0] > av[2]))
{ {
if (v[0] < 0) if (v[0] < 0)
{
axis = 1; axis = 1;
}
else else
{
axis = 0; axis = 0;
}
} }
else if (av[1] > av[2] && av[1] > av[0]) else if ((av[1] > av[2]) && (av[1] > av[0]))
{ {
if (v[1] < 0) if (v[1] < 0)
{
axis = 3; axis = 3;
}
else else
{
axis = 2; axis = 2;
}
} }
else else
{ {
if (v[2] < 0) if (v[2] < 0)
{
axis = 5; axis = 5;
}
else else
{
axis = 4; axis = 4;
}
} }
// project new texture coords /* project new texture coords */
for (i=0 ; i<nump ; i++, vecs+=3) for (i = 0; i < nump; i++, vecs += 3)
{ {
int j; int j;
j = vec_to_st[axis][2]; j = vec_to_st[axis][2];
if (j > 0) if (j > 0)
{
dv = vecs[j - 1]; dv = vecs[j - 1];
}
else else
{
dv = -vecs[-j - 1]; dv = -vecs[-j - 1];
}
if (dv < 0.001) if (dv < 0.001)
continue; // don't divide by zero {
continue; /* don't divide by zero */
}
j = vec_to_st[axis][0]; j = vec_to_st[axis][0];
if (j < 0) if (j < 0)
s = -vecs[-j -1] / dv; {
s = -vecs[-j - 1] / dv;
}
else else
s = vecs[j-1] / dv; {
s = vecs[j - 1] / dv;
}
j = vec_to_st[axis][1]; j = vec_to_st[axis][1];
if (j < 0) if (j < 0)
t = -vecs[-j -1] / dv; {
t = -vecs[-j - 1] / dv;
}
else else
t = vecs[j-1] / dv; {
t = vecs[j - 1] / dv;
}
if (s < skymins[0][axis]) if (s < skymins[0][axis])
{
skymins[0][axis] = s; skymins[0][axis] = s;
}
if (t < skymins[1][axis]) if (t < skymins[1][axis])
{
skymins[1][axis] = t; skymins[1][axis] = t;
}
if (s > skymaxs[0][axis]) if (s > skymaxs[0][axis])
{
skymaxs[0][axis] = s; skymaxs[0][axis] = s;
}
if (t > skymaxs[1][axis]) if (t > skymaxs[1][axis])
{
skymaxs[1][axis] = t; skymaxs[1][axis] = t;
}
} }
} }
static void static void
ClipSkyPolygon(int nump, vec3_t vecs, int stage) R_ClipSkyPolygon(int nump, vec3_t vecs, int stage)
{ {
float *norm; const float *norm;
float *v; float *v;
qboolean front, back; qboolean front, back;
float d, e; float d, e;
@ -270,17 +316,21 @@ ClipSkyPolygon(int nump, vec3_t vecs, int stage)
int i, j; int i, j;
if (nump > MAX_CLIP_VERTS - 2) if (nump > MAX_CLIP_VERTS - 2)
{
Com_Error(ERR_DROP, "%s: MAX_CLIP_VERTS", __func__); Com_Error(ERR_DROP, "%s: MAX_CLIP_VERTS", __func__);
}
if (stage == 6) if (stage == 6)
{ {
/* fully clipped, so draw it */ /* fully clipped, so draw it */
DrawSkyPolygon(nump, vecs); R_DrawSkyPolygon(nump, vecs);
return; return;
} }
front = back = false; front = back = false;
norm = skyclip[stage]; norm = skyclip[stage];
for (i=0, v = vecs ; i<nump ; i++, v+=3)
for (i = 0, v = vecs; i < nump; i++, v += 3)
{ {
d = DotProduct(v, norm); d = DotProduct(v, norm);
@ -303,100 +353,99 @@ ClipSkyPolygon(int nump, vec3_t vecs, int stage)
} }
if (!front || !back) if (!front || !back)
{ // not clipped {
ClipSkyPolygon(nump, vecs, stage + 1); /* not clipped */
R_ClipSkyPolygon(nump, vecs, stage + 1);
return; return;
} }
// clip it /* clip it */
sides[i] = sides[0]; sides[i] = sides[0];
dists[i] = dists[0]; dists[i] = dists[0];
VectorCopy(vecs, (vecs+(i*3)) ); VectorCopy(vecs, (vecs + (i * 3)));
newc[0] = newc[1] = 0; newc[0] = newc[1] = 0;
for (i=0, v = vecs ; i<nump ; i++, v+=3) for (i = 0, v = vecs; i < nump; i++, v += 3)
{ {
switch (sides[i]) switch (sides[i])
{ {
case SIDE_FRONT: case SIDE_FRONT:
VectorCopy(v, newv[0][newc[0]]); VectorCopy(v, newv[0][newc[0]]);
newc[0]++; newc[0]++;
break; break;
case SIDE_BACK: case SIDE_BACK:
VectorCopy(v, newv[1][newc[1]]); VectorCopy(v, newv[1][newc[1]]);
newc[1]++; newc[1]++;
break; break;
case SIDE_ON: case SIDE_ON:
VectorCopy(v, newv[0][newc[0]]); VectorCopy(v, newv[0][newc[0]]);
newc[0]++; newc[0]++;
VectorCopy(v, newv[1][newc[1]]); VectorCopy(v, newv[1][newc[1]]);
newc[1]++; newc[1]++;
break; break;
} }
if (sides[i] == SIDE_ON || sides[i+1] == SIDE_ON || sides[i+1] == sides[i]) if ((sides[i] == SIDE_ON) ||
continue; (sides[i + 1] == SIDE_ON) ||
(sides[i + 1] == sides[i]))
d = dists[i] / (dists[i] - dists[i+1]);
for (j=0 ; j<3 ; j++)
{ {
e = v[j] + d*(v[j+3] - v[j]); continue;
}
d = dists[i] / (dists[i] - dists[i + 1]);
for (j = 0; j < 3; j++)
{
e = v[j] + d * (v[j + 3] - v[j]);
newv[0][newc[0]][j] = e; newv[0][newc[0]][j] = e;
newv[1][newc[1]][j] = e; newv[1][newc[1]][j] = e;
} }
newc[0]++; newc[0]++;
newc[1]++; newc[1]++;
} }
// continue /* continue */
ClipSkyPolygon (newc[0], newv[0][0], stage+1); R_ClipSkyPolygon(newc[0], newv[0][0], stage + 1);
ClipSkyPolygon (newc[1], newv[1][0], stage+1); R_ClipSkyPolygon(newc[1], newv[1][0], stage + 1);
} }
/* void
================= R_AddSkySurface(msurface_t *fa)
R_AddSkySurface
=================
*/
void R_AddSkySurface (msurface_t *fa)
{ {
int i; int i;
vec3_t verts[MAX_CLIP_VERTS]; vec3_t verts[MAX_CLIP_VERTS];
mpoly_t *p; mpoly_t *p;
// calculate vertex values for sky box /* calculate vertex values for sky box */
for (p=fa->polys ; p ; p=p->next) for (p = fa->polys; p; p = p->next)
{ {
for (i = 0; i < p->numverts; i++) for (i = 0; i < p->numverts; i++)
{ {
VectorSubtract(p->verts[i].pos, r_origin, verts[i]); VectorSubtract(p->verts[i].pos, r_origin, verts[i]);
} }
ClipSkyPolygon(p->numverts, verts[0], 0);
R_ClipSkyPolygon(p->numverts, verts[0], 0);
} }
} }
void
/* R_ClearSkyBox(void)
==============
R_ClearSkyBox
==============
*/
void R_ClearSkyBox (void)
{ {
int i; int i;
for (i=0 ; i<6 ; i++) for (i = 0; i < 6; i++)
{ {
skymins[0][i] = skymins[1][i] = 9999; skymins[0][i] = skymins[1][i] = 9999;
skymaxs[0][i] = skymaxs[1][i] = -9999; skymaxs[0][i] = skymaxs[1][i] = -9999;
} }
} }
static void
static void MakeSkyVec (float s, float t, int axis, float *vertexData) MakeSkyVec(float s, float t, int axis, float *vertexData)
{ {
vec3_t v, b; vec3_t v, b;
int j; int j;
float dist = (r_farsee->value == 0) ? 2300.0f : 4096.0f; float dist = (r_farsee->value == 0) ? 2300.0f : 4096.0f;
@ -404,29 +453,43 @@ static void MakeSkyVec (float s, float t, int axis, float *vertexData)
b[1] = t * dist; b[1] = t * dist;
b[2] = dist; b[2] = dist;
for (j = 0; j<3; j++) for (j = 0; j < 3; j++)
{ {
int k; int k;
k = st_to_vec[axis][j]; k = st_to_vec[axis][j];
if (k < 0) if (k < 0)
{
v[j] = -b[-k - 1]; v[j] = -b[-k - 1];
}
else else
{
v[j] = b[k - 1]; v[j] = b[k - 1];
}
} }
// avoid bilerp seam /* avoid bilerp seam */
s = (s + 1)*0.5; s = (s + 1) * 0.5;
t = (t + 1)*0.5; t = (t + 1) * 0.5;
if (s < sky_min) if (s < sky_min)
{
s = sky_min; s = sky_min;
}
else if (s > sky_max) else if (s > sky_max)
{
s = sky_max; s = sky_max;
}
if (t < sky_min) if (t < sky_min)
{
t = sky_min; t = sky_min;
}
else if (t > sky_max) else if (t > sky_max)
{
t = sky_max; t = sky_max;
}
t = 1.0 - t; t = 1.0 - t;
@ -447,7 +510,7 @@ R_DrawSkyBox(void)
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
{ {
if ((skymins[0][i] < skymaxs[0][i]) && if ((skymins[0][i] < skymaxs[0][i]) &&
(skymins[1][i] < skymaxs[1][i])) (skymins[1][i] < skymaxs[1][i]))
{ {
break; break;
} }
@ -486,7 +549,7 @@ R_DrawSkyBox(void)
} }
if ((skymins[0][i] >= skymaxs[0][i]) || if ((skymins[0][i] >= skymaxs[0][i]) ||
(skymins[1][i] >= skymaxs[1][i])) (skymins[1][i] >= skymaxs[1][i]))
{ {
continue; continue;
} }
@ -524,24 +587,18 @@ R_DrawSkyBox(void)
} }
} }
/* void
============ RE_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis)
RE_SetSky
============
*/
// 3dstudio environment map names
static char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
void RE_SetSky(const char *name, float rotate, int autorotate, const vec3_t axis)
{ {
char skyname[MAX_QPATH]; char skyname[MAX_QPATH];
int i; int i;
strncpy(skyname, name, sizeof(skyname) - 1); Q_strlcpy(skyname, name, sizeof(skyname));
skyrotate = rotate; skyrotate = rotate;
skyautorotate = autorotate; skyautorotate = autorotate;
VectorCopy(axis, skyaxis); VectorCopy(axis, skyaxis);
for (i = 0; i<6; i++) for (i = 0; i < 6; i++)
{ {
image_t *image; image_t *image;