11 May 2011

This commit is contained in:
g-cont 2011-05-11 00:00:00 +04:00 committed by Alibek Omarov
parent 8f8e9a4013
commit 3296d44539
3 changed files with 183 additions and 52 deletions

View File

@ -67,9 +67,9 @@ static void SubdividePolygon_r( msurface_t *warpface, int numverts, float *verts
{
int i, j, k, f, b;
vec3_t mins, maxs;
float m, frac, s, t, *v;
float m, frac, s, t, *v, vertsDiv;
vec3_t front[SUBDIVIDE_SIZE], back[SUBDIVIDE_SIZE], total;
float dist[SUBDIVIDE_SIZE], total_s, total_t;
float dist[SUBDIVIDE_SIZE], total_s, total_t, total_ls, total_lt;
glpoly_t *poly;
if( numverts > ( SUBDIVIDE_SIZE - 4 ))
@ -136,26 +136,63 @@ static void SubdividePolygon_r( msurface_t *warpface, int numverts, float *verts
warpface->polys = poly;
poly->numverts = numverts + 2;
VectorClear( total );
total_s = 0;
total_t = 0;
total_s = total_ls = 0.0f;
total_t = total_lt = 0.0f;
for( i = 0; i < numverts; i++, verts += 3 )
{
VectorCopy( verts, poly->verts[i+1] );
s = DotProduct( verts, warpface->texinfo->vecs[0] );
t = DotProduct( verts, warpface->texinfo->vecs[1] );
total_s += s;
total_t += t;
VectorAdd( total, verts, total );
if( warpface->flags & SURF_DRAWTURB )
{
s = DotProduct( verts, warpface->texinfo->vecs[0] );
t = DotProduct( verts, warpface->texinfo->vecs[1] );
}
else
{
s = DotProduct( verts, warpface->texinfo->vecs[0] ) + warpface->texinfo->vecs[0][3];
t = DotProduct( verts, warpface->texinfo->vecs[1] ) + warpface->texinfo->vecs[1][3];
s /= warpface->texinfo->texture->width;
t /= warpface->texinfo->texture->height;
}
poly->verts[i+1][3] = s;
poly->verts[i+1][4] = t;
total_s += s;
total_t += t;
if(!( warpface->flags & SURF_DRAWTURB ))
{
// lightmap texture coordinates
s = DotProduct( verts, warpface->texinfo->vecs[0] ) + warpface->texinfo->vecs[0][3];
s -= warpface->texturemins[0];
s += warpface->light_s * LM_SAMPLE_SIZE;
s += 8;
s /= BLOCK_WIDTH * LM_SAMPLE_SIZE; //fa->texinfo->texture->width;
t = DotProduct( verts, warpface->texinfo->vecs[1] ) + warpface->texinfo->vecs[1][3];
t -= warpface->texturemins[1];
t += warpface->light_t * LM_SAMPLE_SIZE;
t += 8;
t /= BLOCK_HEIGHT * LM_SAMPLE_SIZE; //fa->texinfo->texture->height;
poly->verts[i+1][5] = s;
poly->verts[i+1][6] = t;
total_ls += s;
total_lt += t;
}
}
VectorScale( total, ( 1.0f / numverts ), poly->verts[0] );
poly->verts[0][3] = total_s / numverts;
poly->verts[0][4] = total_t / numverts;
vertsDiv = ( 1.0f / (float)numverts );
VectorScale( total, vertsDiv, poly->verts[0] );
poly->verts[0][3] = total_s * vertsDiv;
poly->verts[0][4] = total_t * vertsDiv;
poly->verts[0][5] = total_ls * vertsDiv;
poly->verts[0][6] = total_lt * vertsDiv;
// copy first vertex to last
Q_memcpy( poly->verts[i+1], poly->verts[1], sizeof( poly->verts[0] ));
@ -185,7 +222,7 @@ void GL_SubdivideSurface( msurface_t *fa )
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]);
VectorCopy( vec, verts[numverts] );
numverts++;
}
@ -213,6 +250,13 @@ void GL_BuildPolygonFromSurface( msurface_t *fa )
if( !fa->texinfo || !fa->texinfo->texture )
return; // bad polygon ?
if( fa->texinfo->texture->anim_total < 0 )
{
// random tileing. subdivide the polygon
GL_SubdivideSurface( fa );
return;
}
// reconstruct the polygon
pedges = loadmodel->edges;
lnumverts = fa->numedges;
@ -275,11 +319,26 @@ R_TextureAnimation
Returns the proper texture for a given time and base texture
===============
*/
texture_t *R_TextureAnimation( texture_t *base )
texture_t *R_TextureAnimation( texture_t *base, int surfacenum )
{
int reletive;
int count, speed;
// random tileng textures
if( base->anim_total < 0 )
{
reletive = surfacenum % abs( base->anim_total );
count = 0;
while( base->anim_min > reletive || base->anim_max <= reletive )
{
base = base->anim_next;
if( !base ) Host_Error( "R_TextureAnimation: broken loop\n" );
if( ++count > 100 ) Host_Error( "R_TextureAnimation: infinite loop\n" );
}
return base;
}
if( RI.currententity->curstate.frame )
{
if( base->alternate_anims )
@ -559,13 +618,14 @@ static void R_BuildLightMap( msurface_t *surf, byte *dest, int stride )
DrawGLPoly
================
*/
void DrawGLPoly( glpoly_t *p )
void DrawGLPoly( glpoly_t *p, texture_t *tex )
{
float *v;
float sOffset, sy;
float tOffset, cy;
cl_entity_t *e = RI.currententity;
int i;
qboolean random_tiles = false;
texture_t *t;
glpoly_t *base;
if( p->flags & SURF_CONVEYOR )
{
@ -597,16 +657,29 @@ void DrawGLPoly( glpoly_t *p )
sOffset = tOffset = 0.0f;
}
pglBegin( GL_POLYGON );
if( p && p->next ) random_tiles = true;
v = p->verts[0];
for( i = 0; i < p->numverts; i++, v += VERTEXSIZE )
for( base = p; p != NULL; p = p->next )
{
pglTexCoord2f( v[3] + sOffset, v[4] + tOffset );
pglVertex3fv( v );
}
float *v;
int i;
pglEnd();
if( random_tiles && tex )
{
t = R_TextureAnimation( tex, base - p );
GL_MBind( t->gl_texturenum );
}
pglBegin( GL_POLYGON );
for( i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE )
{
pglTexCoord2f( v[3] + sOffset, v[4] + tOffset );
pglVertex3fv( v );
}
pglEnd();
}
}
/*
@ -625,19 +698,23 @@ void DrawGLPolyChain( glpoly_t *p, float soffset, float toffset )
for( ; p != NULL; p = p->chain )
{
glpoly_t *p2;
float *v;
int i;
pglBegin( GL_POLYGON );
v = p->verts[0];
for( i = 0; i < p->numverts; i++, v += VERTEXSIZE )
for( p2 = p; p2 != NULL; p2 = p2->next )
{
if( !dynamic ) pglTexCoord2f( v[5], v[6] );
else pglTexCoord2f( v[5] - soffset, v[6] - toffset );
pglVertex3fv( v );
pglBegin( GL_POLYGON );
v = p2->verts[0];
for( i = 0; i < p2->numverts; i++, v += VERTEXSIZE )
{
if( !dynamic ) pglTexCoord2f( v[5], v[6] );
else pglTexCoord2f( v[5] - soffset, v[6] - toffset );
pglVertex3fv( v );
}
pglEnd ();
}
pglEnd ();
}
}
@ -810,7 +887,7 @@ void R_RenderFullbrights( void )
{
if( p->flags & SURF_DRAWTURB )
EmitWaterPolys( p, ( p->flags & SURF_NOCULL ));
else DrawGLPoly( p );
else DrawGLPoly( p, NULL ); // disable random tiling (chain is already used)
}
fullbright_polys[i] = NULL;
@ -849,7 +926,7 @@ void R_RenderBrushPoly( msurface_t *fa )
return;
}
t = R_TextureAnimation( fa->texinfo->texture );
t = R_TextureAnimation( fa->texinfo->texture, 0 );
GL_MBind( t->gl_texturenum );
if( fa->flags & SURF_DRAWTURB )
@ -867,7 +944,7 @@ void R_RenderBrushPoly( msurface_t *fa )
draw_fullbrights = true;
}
DrawGLPoly( fa->polys );
DrawGLPoly( fa->polys, fa->texinfo->texture );
DrawSurfaceDecals( fa );
// check for lightmap modification
@ -1587,7 +1664,7 @@ R_DrawTriangleOutlines
void R_DrawTriangleOutlines( void )
{
int i, j;
glpoly_t *p;
glpoly_t *p, *p2;
if( !gl_wireframe->integer )
return;
@ -1605,13 +1682,18 @@ void R_DrawTriangleOutlines( void )
for( surf = gl_lms.lightmap_surfaces[i]; surf != NULL; surf = surf->lightmapchain )
{
p = surf->polys;
for( ; p != NULL; p = p->chain )
// for( ; p != NULL; p = p->chain )
{
pglBegin( GL_POLYGON );
v = p->verts[0];
for( j = 0; j < p->numverts; j++, v += VERTEXSIZE )
pglVertex3fv( v );
pglEnd ();
p2 = p;
for( p2 = p; p2; p2 = p2->next )
{
pglBegin( GL_POLYGON );
for( j = 0, v = p2->verts[0]; j < p2->numverts; j++, v += VERTEXSIZE )
pglVertex3fv( v );
pglEnd ();
}
}
}
}

View File

@ -669,6 +669,62 @@ static void Mod_LoadTextures( const dlump_t *l )
if( max ) tx2->alternate_anims = anims[0];
}
}
// sequence the detail textures
for( i = 0; i < loadmodel->numtextures; i++ )
{
tx = loadmodel->textures[i];
if( !tx || tx->name[0] != '-' )
continue;
if( tx->anim_next )
continue; // allready sequenced
// find the number of frames in the sequence
Q_memset( anims, 0, sizeof( anims ));
max = tx->name[1];
if( max >= '0' && max <= '9' )
{
max -= '0';
anims[max] = tx;
max++;
}
else Host_Error( "Mod_LoadTextures: bad detail texture %s\n", tx->name );
for( j = i + 1; j < loadmodel->numtextures; j++ )
{
tx2 = loadmodel->textures[j];
if( !tx2 || tx2->name[0] != '-' )
continue;
if( Q_strcmp( tx2->name + 2, tx->name + 2 ))
continue;
num = tx2->name[1];
if( num >= '0' && num <= '9' )
{
num -= '0';
anims[num] = tx2;
if( num+1 > max )
max = num + 1;
}
else Host_Error( "Mod_LoadTextures: bad detail texture %s\n", tx->name );
}
// link them all together
for( j = 0; j < max; j++ )
{
tx2 = anims[j];
if( !tx2 ) Host_Error( "Mod_LoadTextures: missing frame %i of %s\n", j, tx->name );
tx2->anim_total = -( max * ANIM_CYCLE ); // to differentiate from animations
tx2->anim_min = j * ANIM_CYCLE;
tx2->anim_max = (j + 1) * ANIM_CYCLE;
tx2->anim_next = anims[(j + 1) % max];
}
}
}
/*

View File

@ -208,7 +208,7 @@ qboolean PM_RecursiveHullCheck( hull_t *hull, int num, float p1f, float p2f, vec
float frac, midf;
int side;
vec3_t mid;
loc0:
// check for empty
if( num < 0 )
{
@ -242,16 +242,9 @@ loc0:
}
if( t1 >= 0 && t2 >= 0 )
{
num = node->children[0];
goto loc0;
}
return PM_RecursiveHullCheck( hull, node->children[0], p1f, p2f, p1, p2, trace );
if( t1 < 0 && t2 < 0 )
{
num = node->children[1];
goto loc0;
}
return PM_RecursiveHullCheck( hull, node->children[1], p1f, p2f, p1, p2, trace );
// put the crosspoint DIST_EPSILON pixels on the near side
side = (t1 < 0);