#include "qbsp.h"
#include <assert.h>
Include dependency graph for terrain.c:

Go to the source code of this file.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 26 of file terrain.c. Referenced by ParseTerrain(), and SetTerrainTextures(). |
|
|
Definition at line 25 of file terrain.c. Referenced by ParseTerrain(), and SetTerrainTextures(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||||
|
Definition at line 864 of file terrain.c. References buildBrush, MapPlaneFromPoints(), memset(), bspbrush_s::numsides, shaderInfo_t, side_t, bspbrush_s::sides, v1, and v2. Referenced by MakeBrushFromTriangle(). 00864 {
00865 side_t *side;
00866 int planenum;
00867
00868 side = &buildBrush->sides[ buildBrush->numsides ];
00869 memset( side, 0, sizeof( *side ) );
00870 buildBrush->numsides++;
00871
00872 side->shaderInfo = terrainShader;
00873
00874 // find the plane number
00875 planenum = MapPlaneFromPoints( v1, v2, v3 );
00876 side->planenum = planenum;
00877 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 159 of file terrain.c. References AddPointToBounds(), entity_t::brushes, bspbrush_t, ClearBounds(), Error(), floor(), GetVectorForKey(), i, mapent, bspbrush_s::maxs, bspbrush_s::mins, bspbrush_s::next, ValueForKey(), and VectorSubtract. Referenced by SetTerrainTextures(). 00159 {
00160 bspbrush_t *brush;
00161 int i;
00162 const char *key;
00163
00164 // calculate the size of the terrain
00165 ClearBounds( mins, maxs );
00166 for( brush = mapent->brushes; brush != NULL; brush = brush->next ) {
00167 AddPointToBounds( brush->mins, mins, maxs );
00168 AddPointToBounds( brush->maxs, mins, maxs );
00169 }
00170
00171 key = ValueForKey( mapent, "min" );
00172 if ( key[ 0 ] ) {
00173 GetVectorForKey( mapent, "min", mins );
00174 }
00175
00176 key = ValueForKey( mapent, "max" );
00177 if ( key[ 0 ] ) {
00178 GetVectorForKey( mapent, "max", maxs );
00179 }
00180
00181 for( i = 0; i < 3; i++ ) {
00182 mins[ i ] = floor( mins[ i ] + 0.1 );
00183 maxs[ i ] = floor( maxs[ i ] + 0.1 );
00184 }
00185
00186 VectorSubtract( maxs, mins, size );
00187
00188 if ( ( size[ 0 ] <= 0 ) || ( size[ 1 ] <= 0 ) ) {
00189 Error ("CalcTerrainSize: Invalid terrain size: %fx%f", size[ 0 ], size[ 1 ] );
00190 }
00191 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 76 of file terrain.c. References floor(), i, qboolean, drawVert_t::st, v1, v2, and drawVert_t::xyz. Referenced by CreateTerrainSurface(), EmitTerrainVerts(), and EmitTerrainVerts2(). 00076 {
00077 int i;
00078
00079 for( i = 0; i < 3; i++ ) {
00080 if ( floor( v1->xyz[ i ] + 0.1 ) != floor( v2->xyz[ i ] + 0.1 ) ) {
00081 return qfalse;
00082 }
00083 if ( checkst && ( ( v1->st[ 0 ] != v2->st[ 0 ] ) || ( v1->st[ 1 ] != v2->st[ 1 ] ) ) ) {
00084 return qfalse;
00085 }
00086 }
00087
00088 return qtrue;
00089 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 363 of file terrain.c. References AllocDrawSurf(), drawVert_t::color, CompareVert(), drawsurf_s::fogNum, i, in, terrainSurf_t::indexes, drawsurf_s::indexes, j, k, drawsurf_s::lightmapNum, malloc(), mapDrawSurface_t, memcpy(), memset(), drawsurf_s::miscModel, drawVert_t::normal, terrainSurf_t::numIndexes, drawsurf_s::numIndexes, terrainSurf_t::numVerts, drawsurf_s::numVerts, qfalse, drawsurf_s::shaderInfo, shaderInfo_t, drawVert_t::st, surfaces, VectorAdd, VectorClear, VectorCopy, VectorNormalize(), terrainSurf_t::verts, drawsurf_s::verts, and drawVert_t::xyz. Referenced by ParseTerrain(), and SetTerrainTextures(). 00363 {
00364 int i, j, k;
00365 drawVert_t *out;
00366 drawVert_t *in;
00367 mapDrawSurface_t *newsurf;
00368
00369 newsurf = AllocDrawSurf();
00370
00371 newsurf->miscModel = qtrue;
00372 newsurf->shaderInfo = shader;
00373 newsurf->lightmapNum = -1;
00374 newsurf->fogNum = -1;
00375 newsurf->numIndexes = surf->numIndexes;
00376 newsurf->numVerts = surf->numVerts;
00377
00378 // copy the indices
00379 newsurf->indexes = malloc( surf->numIndexes * sizeof( *newsurf->indexes ) );
00380 memcpy( newsurf->indexes, surf->indexes, surf->numIndexes * sizeof( *newsurf->indexes ) );
00381
00382 // allocate the vertices
00383 newsurf->verts = malloc( surf->numVerts * sizeof( *newsurf->verts ) );
00384 memset( newsurf->verts, 0, surf->numVerts * sizeof( *newsurf->verts ) );
00385
00386 // calculate the surface verts
00387 out = newsurf->verts;
00388 for( i = 0; i < newsurf->numVerts; i++, out++ ) {
00389 VectorCopy( surf->verts[ i ].xyz, out->xyz );
00390
00391 // set the texture coordinates
00392 out->st[ 0 ] = surf->verts[ i ].st[ 0 ];
00393 out->st[ 1 ] = surf->verts[ i ].st[ 1 ];
00394
00395 // the colors will be set by the lighting pass
00396 out->color[0] = 255;
00397 out->color[1] = 255;
00398 out->color[2] = 255;
00399 out->color[3] = surf->verts[ i ].color[ 3 ];
00400
00401 // calculate the vertex normal
00402 VectorClear( out->normal );
00403 for( j = 0; j < numsurfaces; j++ ) {
00404 in = surfaces[ j ].verts;
00405 for( k = 0; k < surfaces[ j ].numVerts; k++, in++ ) {
00406 if ( CompareVert( out, in, qfalse ) ) {
00407 VectorAdd( out->normal, in->normal, out->normal );
00408 }
00409 }
00410 }
00411
00412 VectorNormalize( out->normal, out->normal );
00413 }
00414 }
|
Here is the call graph for this function:

|
||||||||||||||||||||||||
|
Definition at line 421 of file terrain.c. References alpha, drawVert_t::color, CompareVert(), DotProduct, FindFloatPlane(), floor(), free(), shaderInfo_s::height, i, terrainSurf_t::indexes, indices, j, malloc(), mapplanes, terrainSurf_t::maxIndexes, terrainSurf_t::maxVerts, drawVert_t::normal, terrainSurf_t::numIndexes, winding_t::numpoints, terrainSurf_t::numVerts, winding_t::p, side_s::planenum, qtrue, QuakeTextureVecs(), realloc(), terrainSurf_t::shader, shift, side_t, SideAsTristrip(), drawVert_t::st, vec3_t, vec_t, side_s::vecs, vecs, VectorCopy, terrainSurf_t::verts, shaderInfo_s::width, side_s::winding, and drawVert_t::xyz. Referenced by SetTerrainTextures(). 00421 {
00422 int i;
00423 int j;
00424 drawVert_t *vert;
00425 int *indices;
00426 int numindices;
00427 int maxindices;
00428 int xyplane;
00429 vec3_t xynorm = { 0, 0, 1 };
00430 vec_t shift[ 2 ] = { 0, 0 };
00431 vec_t scale[ 2 ] = { 0.5, 0.5 };
00432 float vecs[ 2 ][ 4 ];
00433 static int numtimes = 0;
00434
00435 numtimes++;
00436
00437 if ( !surf->verts ) {
00438 surf->numVerts = 0;
00439 surf->maxVerts = GROW_VERTS;
00440 surf->verts = malloc( surf->maxVerts * sizeof( *surf->verts ) );
00441
00442 surf->numIndexes = 0;
00443 surf->maxIndexes = GROW_INDICES;
00444 surf->indexes = malloc( surf->maxIndexes * sizeof( *surf->indexes ) );
00445 }
00446
00447 // calculate the texture coordinate vectors
00448 xyplane = FindFloatPlane( xynorm, 0 );
00449 QuakeTextureVecs( &mapplanes[ xyplane ], shift, 0, scale, vecs );
00450
00451 // emit the vertexes
00452 numindices = 0;
00453 maxindices = surf->maxIndexes;
00454 indices = malloc ( maxindices * sizeof( *indices ) );
00455
00456 for ( i = 0; i < side->winding->numpoints; i++ ) {
00457 vert = &surf->verts[ surf->numVerts ];
00458
00459 // set the final alpha value--0 for texture 1, 255 for texture 2
00460 if ( alpha[ i ] < maxlayer ) {
00461 vert->color[3] = 0;
00462 } else {
00463 vert->color[3] = 255;
00464 }
00465
00466 vert->xyz[ 0 ] = floor( side->winding->p[ i ][ 0 ] + 0.1f );
00467 vert->xyz[ 1 ] = floor( side->winding->p[ i ][ 1 ] + 0.1f );
00468 vert->xyz[ 2 ] = floor( side->winding->p[ i ][ 2 ] + 0.1f );
00469
00470 // set the texture coordinates
00471 if ( projecttexture ) {
00472 vert->st[0] = ( vecs[0][3] + DotProduct( vecs[ 0 ], vert->xyz ) ) / surf->shader->width;
00473 vert->st[1] = ( vecs[1][3] + DotProduct( vecs[ 1 ], vert->xyz ) ) / surf->shader->height;
00474 } else {
00475 vert->st[0] = ( side->vecs[0][3] + DotProduct( side->vecs[ 0 ], vert->xyz ) ) / surf->shader->width;
00476 vert->st[1] = ( side->vecs[1][3] + DotProduct( side->vecs[ 1 ], vert->xyz ) ) / surf->shader->height;
00477 }
00478
00479 VectorCopy( mapplanes[ side->planenum ].normal, vert->normal );
00480
00481 for( j = 0; j < surf->numVerts; j++ ) {
00482 if ( CompareVert( vert, &surf->verts[ j ], qtrue ) ) {
00483 break;
00484 }
00485 }
00486
00487 if ( numindices >= maxindices ) {
00488 maxindices += GROW_INDICES;
00489 indices = realloc( indices, maxindices * sizeof( *indices ) );
00490 }
00491
00492 if ( j != surf->numVerts ) {
00493 indices[ numindices++ ] = j;
00494 } else {
00495 indices[ numindices++ ] = surf->numVerts;
00496 surf->numVerts++;
00497 if ( surf->numVerts >= surf->maxVerts ) {
00498 surf->maxVerts += GROW_VERTS;
00499 surf->verts = realloc( surf->verts, surf->maxVerts * sizeof( *surf->verts ) );
00500 }
00501 }
00502 }
00503
00504 SideAsTristrip( surf, indices, numindices );
00505
00506 free( indices );
00507 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 776 of file terrain.c. References alpha, assert, drawVert_t::color, CompareVert(), DotProduct, f, FindFloatPlane(), floor(), free(), shaderInfo_s::height, i, terrainSurf_t::indexes, indices, j, malloc(), mapplanes, terrainSurf_t::maxIndexes, terrainSurf_t::maxVerts, drawVert_t::normal, terrainSurf_t::numIndexes, terrainSurf_t::numVerts, PlaneFromPoints(), qtrue, QuakeTextureVecs(), realloc(), terrainSurf_t::shader, shift, SideAsTristrip(), drawVert_t::st, vec3_t, vec_t, vecs, VectorCopy, terrainSurf_t::verts, shaderInfo_s::width, and drawVert_t::xyz. Referenced by ParseTerrain(). 00776 {
00777 int i;
00778 int j;
00779 drawVert_t *vert;
00780 int *indices;
00781 int numindices;
00782 int maxindices;
00783 int xyplane;
00784 vec3_t xynorm = { 0, 0, 1 };
00785 vec_t shift[ 2 ] = { 0, 0 };
00786 vec_t scale[ 2 ] = { 0.5, 0.5 };
00787 float vecs[ 2 ][ 4 ];
00788 vec4_t plane;
00789
00790 if ( !surf->verts ) {
00791 surf->numVerts = 0;
00792 surf->maxVerts = GROW_VERTS;
00793 surf->verts = malloc( surf->maxVerts * sizeof( *surf->verts ) );
00794
00795 surf->numIndexes = 0;
00796 surf->maxIndexes = GROW_INDICES;
00797 surf->indexes = malloc( surf->maxIndexes * sizeof( *surf->indexes ) );
00798 }
00799
00800 // calculate the texture coordinate vectors
00801 xyplane = FindFloatPlane( xynorm, 0 );
00802 QuakeTextureVecs( &mapplanes[ xyplane ], shift, 0, scale, vecs );
00803
00804 // emit the vertexes
00805 numindices = 0;
00806 maxindices = surf->maxIndexes;
00807 assert( maxindices >= 0 );
00808 indices = malloc ( maxindices * sizeof( *indices ) );
00809
00810 PlaneFromPoints( plane, verts[ 0 ]->xyz, verts[ 1 ]->xyz, verts[ 2 ]->xyz );
00811
00812 for ( i = 0; i < 3; i++ ) {
00813 vert = &surf->verts[ surf->numVerts ];
00814
00815 if ( alpha[ i ] ) {
00816 vert->color[3] = 255;
00817 } else {
00818 vert->color[3] = 0;
00819 }
00820
00821 vert->xyz[ 0 ] = floor( verts[ i ]->xyz[ 0 ] + 0.1f );
00822 vert->xyz[ 1 ] = floor( verts[ i ]->xyz[ 1 ] + 0.1f );
00823 vert->xyz[ 2 ] = floor( verts[ i ]->xyz[ 2 ] + 0.1f );
00824
00825 // set the texture coordinates
00826 vert->st[0] = ( vecs[0][3] + DotProduct( vecs[ 0 ], vert->xyz ) ) / surf->shader->width;
00827 vert->st[1] = ( vecs[1][3] + DotProduct( vecs[ 1 ], vert->xyz ) ) / surf->shader->height;
00828
00829 VectorCopy( plane, vert->normal );
00830
00831 for( j = 0; j < surf->numVerts; j++ ) {
00832 if ( CompareVert( vert, &surf->verts[ j ], qtrue ) ) {
00833 break;
00834 }
00835 }
00836
00837 if ( numindices >= maxindices ) {
00838 maxindices += GROW_INDICES;
00839 indices = realloc( indices, maxindices * sizeof( *indices ) );
00840 }
00841
00842 if ( j != surf->numVerts ) {
00843 indices[ numindices++ ] = j;
00844 } else {
00845 indices[ numindices++ ] = surf->numVerts;
00846 surf->numVerts++;
00847 if ( surf->numVerts >= surf->maxVerts ) {
00848 surf->maxVerts += GROW_VERTS;
00849 surf->verts = realloc( surf->verts, surf->maxVerts * sizeof( *surf->verts ) );
00850 }
00851 }
00852 }
00853
00854 SideAsTristrip( surf, indices, numindices );
00855
00856 free( indices );
00857 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 201 of file terrain.c. References a, b, c, CrossProduct(), d, points, qboolean, v1, v2, vec3_t, VectorLength(), and VectorSubtract. Referenced by SideAsTristrip(), and SurfaceAsTristrip(). 00201 {
00202 vec3_t v1, v2, v3;
00203 float d;
00204
00205 VectorSubtract( points[b].xyz, points[a].xyz, v1 );
00206 VectorSubtract( points[c].xyz, points[a].xyz, v2 );
00207 CrossProduct( v1, v2, v3 );
00208 d = VectorLength( v3 );
00209
00210 // assume all very small or backwards triangles will cause problems
00211 if ( d < COLINEAR_AREA ) {
00212 return qtrue;
00213 }
00214
00215 return qfalse;
00216 }
|
Here is the call graph for this function:

|
|
Definition at line 1029 of file terrain.c. References atoi, i, l, shaderInfo_s::shader, shaderInfo_t, and strlen(). Referenced by ParseTerrain(). 01029 {
01030 int i;
01031 int l;
01032
01033 l = strlen( shader->shader );
01034 for( i = l - 1; i >= 0; i-- ) {
01035 if ( shader->shader[ i ] == '_' ) {
01036 return atoi( &shader->shader[ i + 1 ] );
01037 break;
01038 }
01039 }
01040
01041 return 0;
01042 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 96 of file terrain.c. References assert, atoi, byte, Error(), ExpandGamePath(), ExtractFileExtension(), height, i, Load256Image(), Load32BitImage(), malloc(), mapent, NULL, Q_stricmp(), ValueForKey(), and width. Referenced by SetTerrainTextures(). 00096 {
00097 int *alphamap32;
00098 byte *alphamap;
00099 const char *alphamapname;
00100 char ext[ 128 ];
00101 int width;
00102 int height;
00103 int layers;
00104 int size;
00105 int i;
00106
00107 assert( alphawidth );
00108 assert( alphaheight );
00109 assert( num_layers );
00110
00111 layers = atoi( ValueForKey( mapent, "layers" ) );
00112 if ( layers < 1 ) {
00113 Error ("SetTerrainTextures: invalid value for 'layers' (%d)", layers );
00114 }
00115
00116 alphamapname = ValueForKey( mapent, "alphamap" );
00117 if ( !alphamapname[ 0 ] ) {
00118 Error ("LoadAlphaMap: No alphamap specified on terrain" );
00119 }
00120
00121 ExtractFileExtension( alphamapname, ext);
00122 if ( !Q_stricmp( ext, "tga" ) ) {
00123 Load32BitImage( ExpandGamePath( alphamapname ), &alphamap32, &width, &height );
00124
00125 size = width * height;
00126 alphamap = malloc( size );
00127 for( i = 0; i < size; i++ ) {
00128 alphamap[ i ] = ( ( alphamap32[ i ] & 0xff ) * layers ) / 256;
00129 if ( alphamap[ i ] >= layers ) {
00130 alphamap[ i ] = layers - 1;
00131 }
00132 }
00133 } else {
00134 Load256Image( ExpandGamePath( alphamapname ), &alphamap, NULL, &width, &height );
00135 size = width * height;
00136 for( i = 0; i < size; i++ ) {
00137 if ( alphamap[ i ] >= layers ) {
00138 alphamap[ i ] = layers - 1;
00139 }
00140 }
00141 }
00142
00143 if ( ( width < 2 ) || ( height < 2 ) ) {
00144 Error ("LoadAlphaMap: alphamap width/height must be at least 2x2." );
00145 }
00146
00147 *num_layers = layers;
00148 *alphawidth = width;
00149 *alphaheight = height;
00150
00151 return alphamap;
00152 }
|
Here is the call graph for this function:

|
||||||||||||||||||||
|
Definition at line 879 of file terrain.c. References AddBrushSide(), b, bspbrush_s::brushnum, bspbrush_t, buildBrush, bspbrush_s::contents, bspbrush_s::detail, bspbrush_s::entitynum, FinishBrush(), MIN_WORLD_COORD, num_entities, bspbrush_s::numsides, bspbrush_s::portalareas, RemoveDuplicateBrushPlanes(), SetBrushContents(), shaderInfo_t, v1, v2, vec3_t, and VectorSet. Referenced by MakeTerrainIntoBrushes(). 00879 {
00880 bspbrush_t *b;
00881 vec3_t d1;
00882 vec3_t d2;
00883 vec3_t d3;
00884
00885 VectorSet( d1, v1[ 0 ], v1[ 1 ], MIN_WORLD_COORD + 10 ); //FIXME
00886 VectorSet( d2, v2[ 0 ], v2[ 1 ], MIN_WORLD_COORD + 10 );
00887 VectorSet( d3, v3[ 0 ], v3[ 1 ], MIN_WORLD_COORD + 10 );
00888
00889 buildBrush->numsides = 0;
00890 buildBrush->detail = qfalse;
00891
00892 AddBrushSide( v1, v2, v3, terrainShader );
00893 AddBrushSide( v1, d1, v2, terrainShader );
00894 AddBrushSide( v2, d2, v3, terrainShader );
00895 AddBrushSide( v3, d3, v1, terrainShader );
00896 AddBrushSide( d3, d2, d1, terrainShader );
00897
00898 buildBrush->portalareas[0] = -1;
00899 buildBrush->portalareas[1] = -1;
00900 buildBrush->entitynum = num_entities-1;
00901 buildBrush->brushnum = entitySourceBrushes;
00902
00903 // if there are mirrored planes, the entire brush is invalid
00904 if ( !RemoveDuplicateBrushPlanes( buildBrush ) ) {
00905 return;
00906 }
00907
00908 // get the content for the entire brush
00909 SetBrushContents( buildBrush );
00910 buildBrush->contents |= CONTENTS_DETAIL;
00911
00912 b = FinishBrush();
00913 if ( !b ) {
00914 return;
00915 }
00916 }
|
Here is the call graph for this function:

|
|
Definition at line 918 of file terrain.c. References terrainMesh_t::height, MakeBrushFromTriangle(), shaderInfo_t, ShaderInfoForShader(), terrainMesh_t::width, x, and y. Referenced by ParseTerrain(). 00918 {
00919 int index[ 6 ];
00920 int y;
00921 int x;
00922 terrainVert_t *verts;
00923 shaderInfo_t *terrainShader;
00924
00925 terrainShader = ShaderInfoForShader( "textures/common/terrain" );
00926
00927 verts = tm->map;
00928 for( y = 0; y < tm->height - 1; y++ ) {
00929 for( x = 0; x < tm->width - 1; x++ ) {
00930 if ( ( x + y ) & 1 ) {
00931 // first tri
00932 index[ 0 ] = x + y * tm->width;
00933 index[ 1 ] = x + ( y + 1 ) * tm->width;
00934 index[ 2 ] = ( x + 1 ) + ( y + 1 ) * tm->width;
00935 index[ 3 ] = ( x + 1 ) + ( y + 1 ) * tm->width;
00936 index[ 4 ] = ( x + 1 ) + y * tm->width;
00937 index[ 5 ] = x + y * tm->width;
00938 } else {
00939 // first tri
00940 index[ 0 ] = x + y * tm->width;
00941 index[ 1 ] = x + ( y + 1 ) * tm->width;
00942 index[ 2 ] = ( x + 1 ) + y * tm->width;
00943 index[ 3 ] = ( x + 1 ) + y * tm->width;
00944 index[ 4 ] = x + ( y + 1 ) * tm->width;
00945 index[ 5 ] = ( x + 1 ) + ( y + 1 ) * tm->width;
00946 }
00947
00948 MakeBrushFromTriangle( verts[ index[ 0 ] ].xyz, verts[ index[ 1 ] ].xyz, verts[ index[ 2 ] ].xyz, terrainShader );
00949 MakeBrushFromTriangle( verts[ index[ 3 ] ].xyz, verts[ index[ 4 ] ].xyz, verts[ index[ 5 ] ].xyz, terrainShader );
00950 }
00951 }
00952 }
|
Here is the call graph for this function:

|
||||||||||||||||
|
Definition at line 261 of file map.c. References CrossProduct(), DotProduct, FindFloatPlane(), p2, vec3_t, vec_t, VectorNormalize(), and VectorSubtract. Referenced by AddBrushSide(), and ParseRawBrush(). 00261 {
00262 vec3_t t1, t2, normal;
00263 vec_t dist;
00264
00265 VectorSubtract (p0, p1, t1);
00266 VectorSubtract (p2, p1, t2);
00267 CrossProduct (t1, t2, normal);
00268 VectorNormalize (normal, normal);
00269
00270 dist = DotProduct (p0, normal);
00271
00272 return FindFloatPlane (normal, dist);
00273 }
|
Here is the call graph for this function:
