Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

terrain.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

brush_tAddBrushForTerrain (terrainMesh_t *pm, bool bLinkToWorld=true)
bool AnyTerrainSelected (void)
void CalcTriNormal (const vec3_t a, const vec3_t b, const vec3_t c, vec3_t o)
void DrawTerrain (terrainMesh_t *pm, bool bPoints, bool bShade=false)
terrainMesh_tMakeNewTerrain (int width, int height, qtexture_t *texture=NULL)
bool OnlyTerrainSelected (void)
bool RayTriangleIntersect (vec3_t orig, vec3_t dir, vec3_t vert1, vec3_t vert2, vec3_t vert3, float *t)
void RotateTerrainFaceTexture (terrainFace_t *vert, int nAxis, float fDeg)
void Select_TerrainFace (brush_t *brush, terrainFace_t *terraface)
void Select_TerrainFacesFromBrush (brush_t *brush)
void SetTerrainTexdef (brush_t *brush, terrainFace_t *vert, texdef_t *texdef)
terrainMesh_tSingleTerrainSelected (void)
void Terrain_AddMovePoint (vec3_t v, bool bMulti, bool bFull, int buttons)
void Terrain_AddPoint (terrainMesh_t *p, terrainVert_t *v)
void Terrain_ApplyMatrix (terrainMesh_t *p, const vec3_t vOrigin, const vec3_t vMatrix[3], bool bSnap)
void Terrain_BrushToMesh (void)
void Terrain_CalcBounds (terrainMesh_t *p, vec3_t &vMin, vec3_t &vMax)
void Terrain_CalcNormals (terrainMesh_t *p)
void Terrain_CalcVertPos (terrainMesh_t *p, int x, int y, vec3_t vert)
void Terrain_Delete (terrainMesh_t *p)
void Terrain_Deselect (terrainMesh_t *p)
bool Terrain_DragScale (terrainMesh_t *p, vec3_t vAmt, vec3_t vMove)
void Terrain_DrawCam (terrainMesh_t *pm)
void Terrain_DrawFace (brush_t *brush, terrainFace_t *terraface)
void Terrain_DrawXY (terrainMesh_t *pm, entity_t *owner)
terrainMesh_tTerrain_Duplicate (terrainMesh_t *pFrom)
void Terrain_Edit (void)
void Terrain_FindReplaceTexture (terrainMesh_t *p, const char *pFind, const char *pReplace, bool bForce)
const char * Terrain_GetKeyValue (terrainMesh_t *p, const char *pKey)
bool Terrain_HasTexture (terrainMesh_t *p, const char *name)
void Terrain_Init (void)
int Terrain_MemorySize (terrainMesh_t *p)
void Terrain_Move (terrainMesh_t *pm, const vec3_t vMove, bool bRebuild=false)
brush_tTerrain_Parse (void)
int Terrain_PointInMoveList (terrainVert_t *pf)
terrainFace_tTerrain_Ray (vec3_t origin, vec3_t dir, brush_t *b, float *dist)
void Terrain_RemovePointFromMoveList (terrainVert_t *v)
void Terrain_ReplaceQTexture (terrainMesh_t *p, qtexture_t *pOld, qtexture_t *pNew)
void Terrain_Scale (terrainMesh_t *p, const vec3_t vOrigin, const vec3_t vAmt, bool bRebuild=true)
void Terrain_Select (terrainMesh_t *p)
void Terrain_SelectAreaPoints (void)
void Terrain_SelectPointByRay (vec3_t org, vec3_t dir, int buttons)
void Terrain_SetEpair (terrainMesh_t *p, const char *pKey, const char *pValue)
void Terrain_SetTexture (terrainMesh_t *p, texdef_t *tex_def)
void Terrain_UpdateSelected (vec3_t vMove)
void Terrain_Write (terrainMesh_t *p, FILE *file)
void Terrain_Write (terrainMesh_t *p, CMemFile *file)
void TerrainFace_FitTexture (terrainFace_t *vert)
void UpdateTerrainInspector (void)


Function Documentation

brush_t* AddBrushForTerrain terrainMesh_t pm,
bool  bLinkToWorld = true
 

Definition at line 277 of file terrain.cpp.

References active_brushes, b, Brush_AddToList(), Brush_Build(), Brush_Create(), brush_s::brush_faces, brush_t, Entity_LinkBrush(), f, face_t, j, face_s::next, pm, brush_s::pTerrain, Terrain_CalcBounds(), Terrain_CalcNormals(), brush_s::terrainBrush, face_s::texdef, vec3_t, and world_entity.

Referenced by Terrain_BrushToMesh(), Terrain_Duplicate(), and Terrain_Parse().

00277                                                                     {
00278     int     j;
00279     vec3_t  vMin;
00280     vec3_t  vMax;
00281     brush_t *b;
00282     face_t  *f;
00283 
00284     // calculate the face normals
00285     Terrain_CalcNormals( pm );
00286    
00287     // find the farthest points in x,y,z
00288     Terrain_CalcBounds( pm, vMin, vMax );
00289 
00290     for( j = 0; j < 3; j++ ) {
00291         if ( vMin[ j ] == vMax[ j ] ) {
00292             vMin[ j ] -= 4;
00293             vMax[ j ] += 4;
00294         }
00295     }
00296 
00297     b = Brush_Create( vMin, vMax, &pm->heightmap->tri.texdef );
00298 
00299     for( f = b->brush_faces; f != NULL; f = f->next ) {
00300         // copy the texdef to the brush faces texdef
00301         f->texdef = pm->heightmap->tri.texdef;
00302     }
00303 
00304     // FIXME: this entire type of linkage needs to be fixed
00305     b->pTerrain     = pm;
00306     b->terrainBrush = true;
00307     pm->pSymbiot    = b;
00308     pm->bSelected   = false;
00309     pm->bDirty      = true;
00310     pm->nListID     = -1;
00311 
00312     if ( bLinkToWorld ) {
00313         Brush_AddToList( b, &active_brushes );
00314         Entity_LinkBrush( world_entity, b );
00315         Brush_Build( b, true );
00316     }
00317   
00318     return b;
00319 }

Here is the call graph for this function:

bool AnyTerrainSelected void   ) 
 

Definition at line 1291 of file terrain.cpp.

References brush_t, brush_s::next, selected_brushes, and brush_s::terrainBrush.

Referenced by CMainFrame::OnSelectionDragvertecies().

01291                                 {
01292     brush_t *pb;
01293 
01294     //if ( numselfaces || selected_brushes.next == &selected_brushes )
01295     if ( selected_brushes.next == &selected_brushes ) {
01296         return false;
01297     }
01298 
01299     for( pb = selected_brushes.next; pb != &selected_brushes; pb = pb->next ) {
01300         if ( pb->terrainBrush ) {
01301             return true;
01302         }
01303     }
01304   
01305     return false;
01306 }

void CalcTriNormal const vec3_t  a,
const vec3_t  b,
const vec3_t  c,
vec3_t  o
 

Definition at line 615 of file terrain.cpp.

References a, b, c, CrossProduct(), vec3_t, VectorNormalize(), and VectorSubtract.

Referenced by Terrain_CalcNormals().

00615                                                                                {
00616     vec3_t a1;
00617     vec3_t b1;
00618 
00619     VectorSubtract( b, a, a1 );
00620     VectorNormalize( a1 );
00621 
00622     VectorSubtract( c, a, b1 );
00623     VectorNormalize( b1 );
00624 
00625     CrossProduct( a1, b1, o );
00626     VectorNormalize( o );
00627 }

Here is the call graph for this function:

void DrawTerrain terrainMesh_t pm,
bool  bPoints,
bool  bShade = false
 

Definition at line 917 of file terrain.cpp.

References active_brushes, brush_t, QEGlobals_t::d_numterrapoints, QEGlobals_t::d_select_mode, QEGlobals_t::d_terrapoints, f, g_qeglobals, h(), terrainVert_t::height, i, terrainFace_t::index, n, brush_s::next, terrainVert_t::normal, pm, brush_s::pTerrain, qglBegin, qglBindTexture, qglColor3f, qglColor4f, qglColor4fv, qglDisable, qglEnable, qglEnd, qglIsEnabled, qglPointSize, qglPushAttrib, qglShadeModel, qglTexCoord2fv, qglVertex3f, qglVertex3fv, qtexture_t, terravert_t::rgba, terrainVert_t::scale, sel_terrainpoint, terravert_t::tc, Terrain_GetTriangle(), Terrain_GetTriangles(), Terrain_PointInMoveList(), brush_s::terrainBrush, texture, qtexture_s::texture_number, terrainVert_t::tri, VectorSet, w, x, x2, terrainVert_t::xyz, terravert_t::xyz, y, y1, and y2.

Referenced by Terrain_DrawCam(), and Terrain_DrawXY().

00917                                                                  {
00918     int             i;
00919     int             w;
00920     int             h;
00921     int             x;
00922     int             y;
00923     //int           n;
00924     //float         x1;
00925     //float         y1;
00926     float           scale_x;
00927     float           scale_y;
00928     //vec3_t        pSelectedPoints[ MAX_TERRA_POINTS ];
00929     //int           nIndex;
00930     terravert_t     a0;
00931     terravert_t     a1;
00932     terravert_t     a2;
00933     terravert_t     b0;
00934     terravert_t     b1;
00935     terravert_t     b2;
00936     terrainVert_t   *vert;
00937     qtexture_t      *texture;
00938 
00939     h = pm->height - 1;
00940     w = pm->width - 1;
00941    
00942     scale_x = pm->scale_x;
00943     scale_y = pm->scale_y;
00944 
00945     qglShadeModel (GL_SMOOTH);
00946 
00947     if ( bShade ) {
00948         for( i = 0; i < pm->numtextures; i++ ) {
00949             texture = pm->textures[ i ];
00950 
00951             qglBindTexture( GL_TEXTURE_2D, texture->texture_number );
00952 
00953             vert = pm->heightmap;
00954             for( y = 0; y < h; y++ ) {
00955                 qglBegin( GL_TRIANGLES );
00956 
00957                 for( x = 0; x < w; x++, vert++ ) {
00958                     Terrain_GetTriangles( pm, x, y, &a0, &a1, &a2, &b0, &b1, &b2, texture );
00959 
00960                     // first tri
00961                     if ( a0.rgba[ 3 ] || a1.rgba[ 3 ] || a2.rgba[ 3 ] ) {
00962                         qglColor4fv( a0.rgba );
00963                         qglTexCoord2fv( a0.tc );
00964                         qglVertex3fv( a0.xyz );
00965 
00966                         qglColor4fv( a1.rgba );
00967                         qglTexCoord2fv( a1.tc );
00968                         qglVertex3fv( a1.xyz );
00969 
00970                         qglColor4fv( a2.rgba );
00971                         qglTexCoord2fv( a2.tc );
00972                         qglVertex3fv( a2.xyz );
00973                     }
00974 
00975                     // second tri
00976                     if ( b0.rgba[ 3 ] || b1.rgba[ 3 ] || b2.rgba[ 3 ] ) {
00977                         qglColor4fv( b0.rgba );
00978                         qglTexCoord2fv( b0.tc );
00979                         qglVertex3fv( b0.xyz );
00980 
00981                         qglColor4fv( b1.rgba );
00982                         qglTexCoord2fv( b1.tc );
00983                         qglVertex3fv( b1.xyz );
00984 
00985                         qglColor4fv( b2.rgba );
00986                         qglTexCoord2fv( b2.tc );
00987                         qglVertex3fv( b2.xyz );
00988                     }
00989                 }
00990 
00991             qglEnd ();
00992             }
00993         }
00994     } else {
00995         for( i = 0; i < pm->numtextures; i++ ) {
00996             texture = pm->textures[ i ];
00997 
00998             qglBindTexture( GL_TEXTURE_2D, texture->texture_number );
00999 
01000             vert = pm->heightmap;
01001             for( y = 0; y < h; y++ ) {
01002                 qglBegin( GL_TRIANGLES );
01003 
01004                 for( x = 0; x < w; x++, vert++ ) {
01005                     Terrain_GetTriangles( pm, x, y, &a0, &a1, &a2, &b0, &b1, &b2, texture );
01006 
01007                     // first tri
01008                     if ( a0.rgba[ 3 ] || a1.rgba[ 3 ] || a2.rgba[ 3 ] ) {
01009                         qglColor4fv( a0.rgba );
01010                         qglTexCoord2fv( a0.tc );
01011                         qglVertex3fv( a0.xyz );
01012 
01013                         qglColor4fv( a1.rgba );
01014                         qglTexCoord2fv( a1.tc );
01015                         qglVertex3fv( a1.xyz );
01016 
01017                         qglColor4fv( a2.rgba );
01018                         qglTexCoord2fv( a2.tc );
01019                         qglVertex3fv( a2.xyz );
01020                     }
01021 
01022                     // second tri
01023                     if ( b0.rgba[ 3 ] || b1.rgba[ 3 ] || b2.rgba[ 3 ] ) {
01024                         qglColor4fv( b0.rgba );
01025                         qglTexCoord2fv( b0.tc );
01026                         qglVertex3fv( b0.xyz );
01027 
01028                         qglColor4fv( b1.rgba );
01029                         qglTexCoord2fv( b1.tc );
01030                         qglVertex3fv( b1.xyz );
01031 
01032                         qglColor4fv( b2.rgba );
01033                         qglTexCoord2fv( b2.tc );
01034                         qglVertex3fv( b2.xyz );
01035                     }
01036                 }
01037                 qglEnd ();
01038             }
01039         }
01040     }
01041 
01042     qglPushAttrib( GL_CURRENT_BIT );
01043 
01044     bool bDisabledLighting = qglIsEnabled( GL_LIGHTING );
01045     if ( bDisabledLighting ) {
01046         qglDisable( GL_LIGHTING );
01047     }
01048 
01049 #if 0
01050     terrainVert_t   *currentrow;
01051     terrainVert_t   *nextrow;
01052     float           x2;
01053     float           y2;
01054 
01055     // Draw normals
01056     qglDisable( GL_TEXTURE_2D );
01057     qglDisable( GL_BLEND );
01058     qglColor3f( 1, 1, 1 );
01059     qglBegin( GL_LINES );
01060 
01061     y2 = pm->origin[ 1 ];
01062     nextrow = pm->heightmap;
01063     for( y = 0; y < h; y++ ) {
01064         y1 = y2;
01065         y2 += scale_y;
01066 
01067         x2 = pm->origin[ 0 ];
01068         currentrow = nextrow;
01069         nextrow = currentrow + pm->width;
01070         for( x = 0; x < w; x++ ) {
01071             x1 = x2;
01072             x2 += scale_x;
01073 
01074             // normals
01075             qglVertex3f( x1, y1, pm->origin[ 2 ] + currentrow[ x ].height );
01076             qglVertex3f( x1 + currentrow[ x ].normal[ 0 ] * 16.0f, y1 + currentrow[ x ].normal[ 1 ] * 16.0f, pm->origin[ 2 ] + currentrow[ x ].height + currentrow[ x ].normal[ 2 ] * 16.0f );
01077 
01078             qglVertex3f( x2, y1, pm->origin[ 2 ] + currentrow[ x + 1 ].height );
01079             qglVertex3f( x2 + currentrow[ x + 1 ].normal[ 0 ] * 16.0f, y1 + currentrow[ x + 1 ].normal[ 1 ] * 16.0f, pm->origin[ 2 ] + currentrow[ x + 1 ].height + currentrow[ x + 1 ].normal[ 2 ] * 16.0f );
01080 
01081             qglVertex3f( x1, y2, pm->origin[ 2 ] + nextrow[ x ].height );
01082             qglVertex3f( x1 + nextrow[ x ].normal[ 0 ] * 16.0f, y2 + nextrow[ x ].normal[ 1 ] * 16.0f, pm->origin[ 2 ] + nextrow[ x ].height + nextrow[ x ].normal[ 2 ] * 16.0f );
01083 
01084             qglVertex3f( x2, y2, pm->origin[ 2 ] + nextrow[ x + 1 ].height );
01085             qglVertex3f( x2 + nextrow[ x + 1 ].normal[ 0 ] * 16.0f, y2 + nextrow[ x + 1 ].normal[ 1 ] * 16.0f, pm->origin[ 2 ] + nextrow[ x + 1 ].height + nextrow[ x + 1 ].normal[ 2 ] * 16.0f );
01086         }
01087     }
01088 
01089     qglEnd ();
01090     qglEnable( GL_TEXTURE_2D );
01091 #endif
01092 
01093 #if 0
01094     if ( bPoints && ( g_qeglobals.d_select_mode == sel_terrainpoint || g_qeglobals.d_select_mode == sel_area ) ) {
01095         qglPointSize( 6 );
01096         qglDisable( GL_TEXTURE_2D );
01097         qglDisable( GL_BLEND );
01098 
01099         qglBegin( GL_POINTS );
01100 
01101         nIndex = 0;
01102 
01103         qglColor4f( 1, 0, 1, 1 );
01104 
01105         y1 = pm->origin[ 1 ];
01106         for ( y = 0; y < pm->height; y++, y1 += pm->scale_y ) {
01107             x1 = pm->origin[ 0 ];
01108             for( x = 0; x < pm->width; x++, x1 += pm->scale_x ) {
01109                 // FIXME: need to not do loop lookups inside here
01110                 n = Terrain_PointInMoveList( &pm->heightmap[ x + y * pm->width ] );
01111                 if ( n >= 0 ) {
01112                     VectorSet( pSelectedPoints[ nIndex ], x1, y1, pm->heightmap[ x + y * pm->width ].height + pm->origin[ 2 ] );
01113                     nIndex++;
01114                 } else {
01115                     qglVertex3f( x1, y1, pm->origin[ 2 ] + pm->heightmap[ x + y * pm->width ].height );
01116                 }
01117             }
01118         }
01119 
01120         qglEnd();
01121         
01122         qglEnable( GL_TEXTURE_2D );
01123 
01124         if ( nIndex > 0 ) {
01125             qglBegin( GL_POINTS );
01126             qglColor4f( 0, 0, 1, 1 );
01127             while( nIndex-- > 0 ) {
01128                 qglVertex3fv( pSelectedPoints[ nIndex ] );
01129             }
01130         
01131             qglEnd();
01132         }
01133     }
01134 #endif
01135 
01136     if ( g_qeglobals.d_numterrapoints && ( ( g_qeglobals.d_select_mode == sel_terrainpoint ) || ( g_qeglobals.d_select_mode == sel_terraintexture ) ) ) {
01137 #if 0 
01138         qglPointSize( 6 );
01139         qglDisable( GL_TEXTURE_2D );
01140         qglDisable( GL_BLEND );
01141 
01142         qglBegin( GL_POINTS );
01143 
01144         qglColor4f( 1, 0, 1, 1 );
01145 
01146         for( i = 0; i < g_qeglobals.d_numterrapoints; i++ ) {
01147             qglVertex3fv( g_qeglobals.d_terrapoints[ i ]->xyz );
01148         }
01149 
01150         qglEnd();
01151             
01152         qglEnable( GL_TEXTURE_2D );
01153 #endif
01154 
01155         brush_t         *pb;
01156         terrainMesh_t   *pm;
01157 
01158         pm = NULL;
01159         for( pb = active_brushes .next; pb != &active_brushes; pb = pb->next ) {
01160             if ( pb->terrainBrush ) {
01161                 pm = pb->pTerrain;
01162                 break;
01163             }
01164         }
01165 
01166         if ( pm ) {
01167             qglDisable( GL_TEXTURE_2D );
01168             qglBegin( GL_TRIANGLES );
01169             qglEnable( GL_BLEND );
01170 
01171             qglColor4f( 0.25, 0.5, 1, 0.35 );
01172 
01173             for( i = 0; i < g_qeglobals.d_numterrapoints; i++ ) {
01174                 terravert_t     a0;
01175                 terravert_t     a1;
01176                 terravert_t     a2;
01177 
01178                 qglColor4f( 0.25, 0.5, 1, g_qeglobals.d_terrapoints[ i ]->scale * 0.75 + 0.25 );
01179                 Terrain_GetTriangle( pm, g_qeglobals.d_terrapoints[ i ]->tri.index * 2, &a0, &a1, &a2 );
01180 
01181                 qglVertex3fv( a0.xyz );
01182                 qglVertex3fv( a1.xyz );
01183                 qglVertex3fv( a2.xyz );
01184 
01185                 Terrain_GetTriangle( pm, g_qeglobals.d_terrapoints[ i ]->tri.index * 2 + 1, &a0, &a1, &a2 );
01186 
01187                 qglVertex3fv( a0.xyz );
01188                 qglVertex3fv( a1.xyz );
01189                 qglVertex3fv( a2.xyz );
01190             }
01191             qglEnd();
01192             
01193             qglDisable( GL_BLEND );
01194             qglEnable( GL_TEXTURE_2D );
01195         }
01196     }
01197 }

Here is the call graph for this function:

terrainMesh_t* MakeNewTerrain int  width,
int  height,
qtexture_t texture = NULL
 

Definition at line 231 of file terrain.cpp.

References h(), terrainVert_t::height, terrainFace_t::index, memset(), qtexture_s::name, terrainVert_t::normal, pm, qmalloc(), qtexture_t, terrainVert_t::rgba, texdef_t::SetName(), size_t, Terrain_AddTexture(), terrainFace_t::texdef, terrainFace_t::texture, texture, terrainVert_t::tri, VectorClear, VectorSet, w, and width.

Referenced by Terrain_BrushToMesh(), Terrain_Duplicate(), and Terrain_Parse().

00231                                                                             {
00232     int             h;
00233     int             w;
00234     terrainMesh_t   *pm;
00235     size_t          size;
00236     size_t          heightmapsize;
00237     terrainVert_t   *vert;
00238     int             index;
00239 
00240     heightmapsize  = sizeof( terrainVert_t ) * width * height;
00241     size           = sizeof( terrainMesh_t ) + heightmapsize;
00242    
00243     pm = reinterpret_cast< terrainMesh_t * >( qmalloc( size ) );
00244    
00245     memset( pm, 0x00, size );
00246 
00247     pm->numtextures = 0;
00248     pm->width      = width;
00249     pm->height     = height;
00250     pm->heightmap  = reinterpret_cast< terrainVert_t * >( pm + 1 );
00251 
00252     if ( texture ) {
00253         Terrain_AddTexture( pm, texture );
00254     }
00255 
00256     index = 0;
00257     vert = pm->heightmap;
00258     for( h = 0; h < pm->height; h++ ) {
00259         for( w = 0; w < pm->width; w++, vert++ ) {
00260             vert->tri.index = index++;
00261             vert->tri.texture = texture;
00262             if ( texture ) {
00263                 vert->tri.texdef.SetName( texture->name );
00264             }
00265 
00266             vert->height = 0;
00267 
00268             VectorClear( vert->normal );
00269             VectorSet( vert->rgba, 1.0f, 1.0f, 1.0f );
00270             vert->rgba[ 3 ] = 1.0f;
00271         }
00272     }
00273    
00274     return pm;
00275 }

Here is the call graph for this function:

bool OnlyTerrainSelected void   ) 
 

Definition at line 1274 of file terrain.cpp.

References brush_t, brush_s::next, selected_brushes, and brush_s::terrainBrush.

Referenced by Drag_MouseUp(), and CMainFrame::OnSelectionDragvertecies().

01274                                  {
01275     brush_t *pb;
01276 
01277     //if ( numselfaces || selected_brushes.next == &selected_brushes )
01278     if ( selected_brushes.next == &selected_brushes ) {
01279         return false;
01280     }
01281 
01282     for( pb = selected_brushes.next; pb != &selected_brushes; pb = pb->next ) {
01283         if ( !pb->terrainBrush ) {
01284             return false;
01285         }
01286     }
01287    
01288     return true;
01289 }

bool RayTriangleIntersect vec3_t  orig,
vec3_t  dir,
vec3_t  vert1,
vec3_t  vert2,
vec3_t  vert3,
float *  t
 

Definition at line 1553 of file terrain.cpp.

References CrossProduct(), DotProduct, t, v, vec3_t, and VectorSubtract.

Referenced by Terrain_Ray().

01553                                                                                                          {
01554     float   u;
01555     float   v;
01556     vec3_t  edge1;
01557     vec3_t  edge2;
01558     vec3_t  tvec;
01559     vec3_t  pvec;
01560     vec3_t  qvec;
01561     float   det;
01562 
01563     VectorSubtract( vert2, vert1, edge1 );
01564     VectorSubtract( vert3, vert1, edge2 );
01565 
01566     // begin calculating determinant - also used to calculate U parameter
01567     CrossProduct( dir, edge2, pvec );
01568 
01569     // if determinant is near zero, ray lies in plane of triangle
01570     det = DotProduct( edge1, pvec );
01571     if ( det < EPSILON ) {
01572         return false;
01573     }
01574 
01575     // calculate distance from vert1 to ray origin
01576     VectorSubtract( orig, vert1, tvec );
01577 
01578     // calculate U parameter and test bounds
01579     u = DotProduct( tvec, pvec );
01580     if ( ( u < 0.0f ) || ( u > det ) ) {
01581         return false;
01582     }
01583 
01584     // prepare to test V parameter
01585     CrossProduct( tvec, edge1, qvec );
01586 
01587     // calculate V parameter and test bounds
01588     v = DotProduct( dir, qvec );
01589     if ( ( v < 0.0f ) || ( u + v > det ) ) {
01590         return false;
01591     }
01592 
01593     // calculate t, scale parameters, ray intersects triangle
01594     *t = DotProduct( edge2, qvec ) / det;
01595 
01596     return true;
01597 }

Here is the call graph for this function:

void RotateTerrainFaceTexture terrainFace_t vert,
int  nAxis,
float  fDeg
 

Definition at line 1720 of file terrain.cpp.

01720                                                                             {
01721 }

void Select_TerrainFace brush_t brush,
terrainFace_t terraface
 

Definition at line 1672 of file terrain.cpp.

References brush_t.

Referenced by Select_TerrainFacesFromBrush().

01672                                                                       {
01673 #if 0
01674     UnSelect_Brush( brush );
01675 
01676     if( numselfaces < MAX_SEL_FACES ) {
01677         selfaces[numselfaces].face = NULL;
01678         selfaces[numselfaces].brush = brush;
01679         selfaces[numselfaces].terraface = terraface;
01680         numselfaces++;
01681     }
01682 #endif
01683 }

void Select_TerrainFacesFromBrush brush_t brush  ) 
 

Definition at line 1685 of file terrain.cpp.

References brush_t, h(), terrainMesh_t::heightmap, pm, brush_s::pTerrain, Select_TerrainFace(), w, x, and y.

01685                                                     {
01686     terrainMesh_t   *pm;
01687     int             h;
01688     int             w;
01689     int             x;
01690     int             y;
01691 
01692     pm = brush->pTerrain;
01693     h = pm->height - 1;
01694     w = pm->width - 1;
01695    
01696     for( y = 0; y < h; y++ ) {
01697         for( x = 0; x < w; x++ ) {
01698             Select_TerrainFace( brush, &brush->pTerrain->heightmap[ x + y * pm->width ].tri );
01699         }
01700     }
01701 }

Here is the call graph for this function:

void SetTerrainTexdef brush_t brush,
terrainFace_t vert,
texdef_t texdef
 

Definition at line 1703 of file terrain.cpp.

References brush_t, texdef_t::contents, texdef_t::flags, texdef_t::name, terrainFace_t::texdef, terrainFace_t::texture, and Texture_ForName().

01703                                                                                {
01704     int oldFlags;
01705     int oldContents;
01706 
01707     oldFlags = face->texdef.flags;
01708     oldContents = face->texdef.contents;
01709 
01710     face->texdef = *texdef;
01711 
01712     face->texdef.flags = ( face->texdef.flags & ~SURF_KEEP ) | ( oldFlags & SURF_KEEP );
01713     face->texdef.contents = ( face->texdef.contents & ~CONTENTS_KEEP ) | ( oldContents & CONTENTS_KEEP );
01714    
01715     face->texture = Texture_ForName( texdef->name );
01716 
01717     //Terrain_AddTexture( face->texture );
01718 }

Here is the call graph for this function:

terrainMesh_t* SingleTerrainSelected void   ) 
 

Definition at line 1308 of file terrain.cpp.

References brush_s::next, brush_s::pTerrain, selected_brushes, and brush_s::terrainBrush.

01308                                              {
01309     if ( selected_brushes.next->terrainBrush ) {
01310         return selected_brushes.next->pTerrain;
01311     }
01312 
01313     return NULL;
01314 }

void Terrain_AddMovePoint vec3_t  v,
bool  bMulti,
bool  bFull,
int  buttons
 

Definition at line 1385 of file terrain.cpp.

References abs(), active_brushes, brush_t, cos(), crandom, QEGlobals_t::d_numterrapoints, QEGlobals_t::d_select_mode, QEGlobals_t::d_terrainBrush, QEGlobals_t::d_terrainBrushSize, QEGlobals_t::d_terrainFalloff, QEGlobals_t::d_terrainNoiseType, QEGlobals_t::d_texturewin, fabs(), g_bSameView, g_qeglobals, terrainMesh_t::height, terrainMesh_t::heightmap, M_PI, qtexture_s::name, texdef_t::name, brush_s::next, NOISE_PLUS, NOISE_PLUSMINUS, terrainMesh_t::origin, p, brush_s::pTerrain, random, terrainVert_t::scale, terrainMesh_t::scale_x, texdef_t::SetName(), sqrt(), Terrain_AddPoint(), Terrain_AddTexture(), brush_s::terrainBrush, terrainFace_t::texdef, texturewin_t::texdef, terrainFace_t::texture, Texture_ForName(), terrainVert_t::tri, v, terrainMesh_t::width, x, y, and y1.

Referenced by Terrain_SelectPointByRay().

01385                                                                              {
01386     brush_t         *pb;
01387     terrainMesh_t   *p;
01388     terrainVert_t   *vert;
01389     int             x;
01390     int             y;
01391     int             x1, y1;
01392     float           dx, dy;
01393     float           dist;
01394     float           pd;
01395 
01396     if ( !g_bSameView && !bMulti && !bFull ) {
01397         g_bSameView = true;
01398         return;
01399     }
01400     
01401     g_qeglobals.d_numterrapoints = 0;
01402     for( pb = active_brushes .next; pb != &active_brushes; pb = pb->next ) {
01403     //for( pb = selected_brushes.next; pb != &selected_brushes; pb = pb->next ) {
01404         if ( pb->terrainBrush ) {
01405             p = pb->pTerrain;
01406         
01407             x = ( v[ 0 ] - p->origin[ 0 ] ) / p->scale_x;
01408             y = ( v[ 1 ] - p->origin[ 1 ] ) / p->scale_x;
01409             if ( ( x < 0 ) || ( x >= p->width ) || ( y < 0 ) || ( y >= p->height ) ) {
01410                 continue;
01411             }
01412 
01413             vert = p->heightmap;
01414             for( y1 = 0; y1 < p->height; y1++ ) {
01415                 for( x1 = 0; x1 < p->width; x1++, vert++ ) {
01416 
01417                     if ( g_qeglobals.d_terrainBrush == TERRAIN_BRUSH_CIRCLE ) {
01418                         dx = x1 - x;
01419                         dy = y1 - y;
01420                         dist = sqrt( dx * dx + dy * dy );
01421                     } else {
01422                         dx = abs( x1 - x );
01423                         dy = abs( y1 - y );
01424                         if ( dx > dy ) {
01425                             dist = dx;
01426                         } else {
01427                             dist = dy;
01428                         }
01429                     }
01430 
01431                     pd = dist * 2.0f / g_qeglobals.d_terrainBrushSize;
01432                     if ( fabs( pd ) <= 1.0f ) {
01433                         Terrain_AddPoint( p, vert );
01434 
01435                         if ( ( buttons & MK_LBUTTON ) && ( g_qeglobals.d_select_mode == sel_terraintexture ) ) {
01436                             vert->tri.texture = Texture_ForName( g_qeglobals.d_texturewin.texdef.name );
01437                             vert->tri.texdef.SetName( vert->tri.texture->name );
01438                             Terrain_AddTexture( p, vert->tri.texture );
01439                             continue;
01440                         }
01441 
01442                         if ( g_qeglobals.d_terrainFalloff == TERRAIN_FALLOFF_CURVED ) {
01443                             if ( g_qeglobals.d_terrainBrush == TERRAIN_BRUSH_CIRCLE ) {
01444                                 vert->scale = ( 0.5f + cos( pd * M_PI ) * 0.5f );
01445                             } else {
01446                                 vert->scale = ( 0.5f + cos( dx/ g_qeglobals.d_terrainBrushSize * M_PI ) * 0.5f ) * ( 0.5f + cos( dy/ g_qeglobals.d_terrainBrushSize * M_PI ) * 0.5f ) - 0.25;
01447                             }
01448                         } else {
01449                             vert->scale = 1.0f - pd;
01450                         }
01451 
01452                         switch( g_qeglobals.d_terrainNoiseType ) {
01453                         case NOISE_PLUS :
01454                             vert->scale *= crandom();
01455                             break;
01456 
01457                         case NOISE_PLUSMINUS :
01458                             vert->scale *= random();
01459                             break;
01460                         }
01461                     }
01462                 }
01463             }
01464         }
01465     }
01466 }

Here is the call graph for this function:

void Terrain_AddPoint terrainMesh_t p,
terrainVert_t v
 

Definition at line 1518 of file terrain.cpp.

References QEGlobals_t::d_numterrapoints, QEGlobals_t::d_terrapoints, and g_qeglobals.

Referenced by Terrain_AddMovePoint().

01518                                                             {
01519     if ( g_qeglobals.d_numterrapoints < MAX_TERRA_POINTS ) {
01520         g_qeglobals.d_terrapoints[ g_qeglobals.d_numterrapoints++ ] = v;
01521     }
01522 }

void Terrain_ApplyMatrix terrainMesh_t p,
const vec3_t  vOrigin,
const vec3_t  vMatrix[3],
bool  bSnap
 

Definition at line 885 of file terrain.cpp.

Referenced by Select_ApplyMatrix().

00885                                                                                                           {
00886 }

void Terrain_BrushToMesh void   ) 
 

Definition at line 357 of file terrain.cpp.

References AddBrushForTerrain(), b, brush_s::brush_faces, brush_t, QEGlobals_t::d_terrainHeight, QEGlobals_t::d_terrainWidth, face_s::d_texture, g_qeglobals, terrainMesh_t::height, MakeNewTerrain(), brush_s::maxs, brush_s::mins, brush_s::next, terrainMesh_t::origin, p, QE_SingleBrush(), terrainMesh_t::scale_x, terrainMesh_t::scale_y, Select_Brush(), Select_Delete(), selected_brushes, VectorCopy, and terrainMesh_t::width.

Referenced by CMainFrame::OnTerrainCreateFromBrush().

00357                                  {
00358     brush_t         *b;
00359     terrainMesh_t   *p;
00360 
00361     if ( !QE_SingleBrush() ) {
00362         return;
00363     }
00364 
00365     b = selected_brushes.next;
00366 
00367     if ( g_qeglobals.d_terrainWidth < 1 ) {
00368         g_qeglobals.d_terrainWidth = 1;
00369     }
00370 
00371     if ( g_qeglobals.d_terrainHeight < 1 ) {
00372         g_qeglobals.d_terrainHeight = 1;
00373     }
00374 
00375     p = MakeNewTerrain( g_qeglobals.d_terrainWidth + 1, g_qeglobals.d_terrainHeight + 1, b->brush_faces->d_texture );
00376     p->scale_x = ( b->maxs[ 0 ] - b->mins[ 0 ] ) / float( p->width - 1 );
00377     p->scale_y = ( b->maxs[ 1 ] - b->mins[ 1 ] ) / float( p->height - 1 );
00378 
00379     VectorCopy( b->mins, p->origin );
00380 
00381     b = AddBrushForTerrain( p );
00382     Select_Delete();
00383     Select_Brush( b );
00384 }

Here is the call graph for this function:

void Terrain_CalcBounds terrainMesh_t p,
vec3_t vMin,
vec3_t vMax
 

Definition at line 585 of file terrain.cpp.

References terrainMesh_t::bDirty, f, h(), terrainVert_t::height, terrainMesh_t::height, terrainMesh_t::heightmap, terrainMesh_t::or