mirror of
https://git.code.sf.net/p/quake/newtree
synced 2024-11-26 05:51:36 +00:00
very close to having working slipped skybox. framed box faces now work, but not
the surrounding faces within the frame. (frame = sky poly surrounding the face) Also, faces with only to vertexes from clipping don't work yet.
This commit is contained in:
parent
619cb49fca
commit
d616ad745f
1 changed files with 62 additions and 35 deletions
|
@ -353,36 +353,42 @@ find_intersect (int face1, vec3_t x1, int face2, vec3_t x2, vec3_t y)
|
||||||
VectorSubtract (x, t, y);
|
VectorSubtract (x, t, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct box_def {
|
||||||
|
int tex, enter, leave;
|
||||||
|
glpoly_t poly;
|
||||||
|
float verts[32][VERTEXSIZE];
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_vertex (glpoly_t *p, vec3_t v, int face)
|
set_vertex (struct box_def *box, vec3_t v, int face)
|
||||||
{
|
{
|
||||||
int ind = p->numverts++;
|
int ind = box[face].poly.numverts++;
|
||||||
VectorCopy (v, p->verts[ind]);
|
VectorCopy (v, box[face].poly.verts[ind]);
|
||||||
VectorAdd (v, r_refdef.vieworg, p->verts[ind]);
|
VectorAdd (v, r_refdef.vieworg, box[face].poly.verts[ind]);
|
||||||
switch (face) {
|
switch (face) {
|
||||||
case 0:
|
case 0:
|
||||||
p->verts[ind][3] = (1024 - v[1]) / 2048;
|
box[face].poly.verts[ind][3] = (1024 - v[1]) / 2048;
|
||||||
p->verts[ind][4] = (1024 - v[2]) / 2048;
|
box[face].poly.verts[ind][4] = (1024 - v[2]) / 2048;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
p->verts[ind][3] = (1024 + v[0]) / 2048;
|
box[face].poly.verts[ind][3] = (1024 + v[0]) / 2048;
|
||||||
p->verts[ind][4] = (1024 - v[2]) / 2048;
|
box[face].poly.verts[ind][4] = (1024 - v[2]) / 2048;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
p->verts[ind][3] = (1024 + v[0]) / 2048;
|
box[face].poly.verts[ind][3] = (1024 + v[0]) / 2048;
|
||||||
p->verts[ind][4] = (1024 + v[1]) / 2048;
|
box[face].poly.verts[ind][4] = (1024 + v[1]) / 2048;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
p->verts[ind][3] = (1024 + v[1]) / 2048;
|
box[face].poly.verts[ind][3] = (1024 + v[1]) / 2048;
|
||||||
p->verts[ind][4] = (1024 - v[2]) / 2048;
|
box[face].poly.verts[ind][4] = (1024 - v[2]) / 2048;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
p->verts[ind][3] = (1024 - v[0]) / 2048;
|
box[face].poly.verts[ind][3] = (1024 - v[0]) / 2048;
|
||||||
p->verts[ind][4] = (1024 - v[2]) / 2048;
|
box[face].poly.verts[ind][4] = (1024 - v[2]) / 2048;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
p->verts[ind][3] = (1024 - v[0]) / 2048;
|
box[face].poly.verts[ind][3] = (1024 - v[0]) / 2048;
|
||||||
p->verts[ind][4] = (1024 - v[1]) / 2048;
|
box[face].poly.verts[ind][4] = (1024 - v[1]) / 2048;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,19 +408,13 @@ find_cube_vertex (int face1, int face2, int face3, vec3_t v)
|
||||||
v[face3 % 3] = 1024 * (1 - 2 * (face3 / 3));
|
v[face3 % 3] = 1024 * (1 - 2 * (face3 / 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct box_def {
|
|
||||||
int tex, enter, leave;
|
|
||||||
glpoly_t poly;
|
|
||||||
float verts[32][VERTEXSIZE];
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enter_face (struct box_def *box, int prev_face, int face)
|
enter_face (struct box_def *box, int prev_face, int face)
|
||||||
{
|
{
|
||||||
if (box[face].leave >=0 && (box[face].leave % 3) != (prev_face % 3)) {
|
if (box[face].leave >=0 && (box[face].leave % 3) != (prev_face % 3)) {
|
||||||
vec3_t t;
|
vec3_t t;
|
||||||
find_cube_vertex (prev_face, face, box[face].leave, t);
|
find_cube_vertex (prev_face, face, box[face].leave, t);
|
||||||
set_vertex(&box[face].poly, t, face);
|
set_vertex(box, t, face);
|
||||||
box[face].enter = -1;
|
box[face].enter = -1;
|
||||||
} else {
|
} else {
|
||||||
box[face].enter = prev_face;
|
box[face].enter = prev_face;
|
||||||
|
@ -428,7 +428,7 @@ leave_face (struct box_def *box, int prev_face, int face)
|
||||||
if (box[prev_face].enter >=0 && (box[prev_face].enter) % 3 != (face % 3)) {
|
if (box[prev_face].enter >=0 && (box[prev_face].enter) % 3 != (face % 3)) {
|
||||||
vec3_t t;
|
vec3_t t;
|
||||||
find_cube_vertex (prev_face, face, box[prev_face].enter, t);
|
find_cube_vertex (prev_face, face, box[prev_face].enter, t);
|
||||||
set_vertex(&box[prev_face].poly, t, prev_face);
|
set_vertex(box, t, prev_face);
|
||||||
box[prev_face].leave = -1;
|
box[prev_face].leave = -1;
|
||||||
} else {
|
} else {
|
||||||
box[prev_face].leave = face;
|
box[prev_face].leave = face;
|
||||||
|
@ -459,9 +459,10 @@ R_DrawSkyBoxPoly (glpoly_t *poly)
|
||||||
{
|
{
|
||||||
static int skytex_offs[] = {3, 0, 4, 1, 2, 5};
|
static int skytex_offs[] = {3, 0, 4, 1, 2, 5};
|
||||||
vec3_t v, last_v;
|
vec3_t v, last_v;
|
||||||
|
vec3_t center = {0, 0, 0};
|
||||||
struct box_def box[6];
|
struct box_def box[6];
|
||||||
int i;
|
int i;
|
||||||
int face, prev_face;
|
int face, prev_face, c_face;
|
||||||
|
|
||||||
memset (box, 0, sizeof (box));
|
memset (box, 0, sizeof (box));
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
|
@ -474,6 +475,13 @@ R_DrawSkyBoxPoly (glpoly_t *poly)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < poly->numverts; i++) {
|
||||||
|
VectorAdd (poly->verts[i], center, center);
|
||||||
|
VectorSubtract (center, r_refdef.vieworg, center);
|
||||||
|
}
|
||||||
|
VectorScale (center, 1.0/poly->numverts, center);
|
||||||
|
c_face = determine_face (center);
|
||||||
|
|
||||||
VectorSubtract (poly->verts[poly->numverts - 1], r_refdef.vieworg, v);
|
VectorSubtract (poly->verts[poly->numverts - 1], r_refdef.vieworg, v);
|
||||||
prev_face = determine_face (v);
|
prev_face = determine_face (v);
|
||||||
VectorCopy (v, last_v);
|
VectorCopy (v, last_v);
|
||||||
|
@ -482,43 +490,62 @@ R_DrawSkyBoxPoly (glpoly_t *poly)
|
||||||
VectorSubtract (poly->verts[i], r_refdef.vieworg, v);
|
VectorSubtract (poly->verts[i], r_refdef.vieworg, v);
|
||||||
face = determine_face (v);
|
face = determine_face (v);
|
||||||
if (face != prev_face) {
|
if (face != prev_face) {
|
||||||
if (face % 3 == prev_face % 3) {
|
if ((face % 3) == (prev_face % 3)) {
|
||||||
vec3_t l, x;
|
vec3_t l, x;
|
||||||
int x_face;
|
int x_face;
|
||||||
|
|
||||||
VectorSubtract (v, last_v, x);
|
VectorAdd (v, last_v, x);
|
||||||
VectorScale (x, 0.5, x);
|
VectorScale (x, 0.5, x);
|
||||||
VectorAdd (last_v, x, x);
|
|
||||||
|
|
||||||
x_face = determine_face (x);
|
x_face = determine_face (x);
|
||||||
|
|
||||||
find_intersect (prev_face, last_v, x_face, v, l);
|
find_intersect (prev_face, last_v, x_face, v, l);
|
||||||
|
|
||||||
set_vertex(&box[prev_face].poly, l, prev_face);
|
set_vertex(box, l, prev_face);
|
||||||
leave_face (box, prev_face, x_face);
|
leave_face (box, prev_face, x_face);
|
||||||
//enter_face (box, prev_face, x_face);
|
enter_face (box, prev_face, x_face);
|
||||||
|
|
||||||
find_intersect (x_face, last_v, face, v, l);
|
find_intersect (x_face, last_v, face, v, l);
|
||||||
|
|
||||||
//leave_face (box, x_face, face);
|
leave_face (box, x_face, face);
|
||||||
enter_face (box, x_face, face);
|
enter_face (box, x_face, face);
|
||||||
set_vertex(&box[face].poly, l, face);
|
set_vertex(box, l, face);
|
||||||
} else {
|
} else {
|
||||||
vec3_t l;
|
vec3_t l;
|
||||||
find_intersect (prev_face, last_v, face, v, l);
|
find_intersect (prev_face, last_v, face, v, l);
|
||||||
|
|
||||||
set_vertex(&box[prev_face].poly, l, prev_face);
|
set_vertex(box, l, prev_face);
|
||||||
leave_face (box, prev_face, face);
|
leave_face (box, prev_face, face);
|
||||||
enter_face (box, prev_face, face);
|
enter_face (box, prev_face, face);
|
||||||
set_vertex(&box[face].poly, l, face);
|
set_vertex(box, l, face);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_vertex(&box[face].poly, v, face);
|
set_vertex(box, v, face);
|
||||||
|
|
||||||
VectorCopy (v, last_v);
|
VectorCopy (v, last_v);
|
||||||
prev_face = face;
|
prev_face = face;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (box[c_face].poly.numverts == 0) {
|
||||||
|
vec3_t v;
|
||||||
|
find_cube_vertex (c_face, c_face + 1, c_face + 2, v);
|
||||||
|
set_vertex(box, v, c_face);
|
||||||
|
set_vertex(box, v, (c_face + 1) % 6);
|
||||||
|
set_vertex(box, v, (c_face + 2) % 6);
|
||||||
|
find_cube_vertex (c_face, c_face + 2, c_face + 4, v);
|
||||||
|
set_vertex(box, v, c_face);
|
||||||
|
set_vertex(box, v, (c_face + 2) % 6);
|
||||||
|
set_vertex(box, v, (c_face + 4) % 6);
|
||||||
|
find_cube_vertex (c_face, c_face + 4, c_face + 5, v);
|
||||||
|
set_vertex(box, v, c_face);
|
||||||
|
set_vertex(box, v, (c_face + 4) % 6);
|
||||||
|
set_vertex(box, v, (c_face + 5) % 6);
|
||||||
|
find_cube_vertex (c_face, c_face + 5, c_face + 1, v);
|
||||||
|
set_vertex(box, v, c_face);
|
||||||
|
set_vertex(box, v, (c_face + 5) % 6);
|
||||||
|
set_vertex(box, v, (c_face + 1) % 6);
|
||||||
|
}
|
||||||
|
|
||||||
render_box (box);
|
render_box (box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue