1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 ----------------------------------------------------------------------------------
24 This code has been altered significantly from its original form, to support
25 several games based on the Quake III Arena engine, in the form of "Q3Map2."
27 ------------------------------------------------------------------------------- */
45 #define Vector2Copy( a, b ) ((b)[ 0 ] = (a)[ 0 ], (b)[ 1 ] = (a)[ 1 ])
46 #define Vector4Copy( a, b ) ((b)[ 0 ] = (a)[ 0 ], (b)[ 1 ] = (a)[ 1 ], (b)[ 2 ] = (a)[ 2 ], (b)[ 3 ] = (a)[ 3 ])
48 #define MAX_NODE_ITEMS 5
49 #define MAX_NODE_TRIANGLES 5
50 #define MAX_TRACE_DEPTH 32
51 #define MIN_NODE_SIZE 32.0f
53 #define GROW_TRACE_INFOS 32768 //% 4096
54 #define GROW_TRACE_WINDINGS 65536 //% 32768
55 #define GROW_TRACE_TRIANGLES 131072 //% 32768
56 #define GROW_TRACE_NODES 16384 //% 16384
57 #define GROW_NODE_ITEMS 16 //% 256
59 #define MAX_TW_VERTS 24 // vortex: increased from 12 to 24 for ability co compile some insane maps with large curve count
61 #define TRACE_ON_EPSILON 0.1f
64 #define TRACE_LEAF_SOLID -2
66 typedef struct traceVert_s
73 typedef struct traceInfo_s
76 int surfaceNum, castShadows;
80 typedef struct traceWinding_s
83 int infoNum, numVerts;
84 traceVert_t v[ MAX_TW_VERTS ];
88 typedef struct traceTriangle_s
96 typedef struct traceNode_s
102 int numItems, maxItems;
108 int noDrawContentFlags, noDrawSurfaceFlags, noDrawCompileFlags;
110 int numTraceInfos = 0, maxTraceInfos = 0, firstTraceInfo = 0;
111 traceInfo_t *traceInfos = NULL;
113 int numTraceWindings = 0, maxTraceWindings = 0, deadWinding = -1;
114 traceWinding_t *traceWindings = NULL;
116 int numTraceTriangles = 0, maxTraceTriangles = 0, deadTriangle = -1;
117 traceTriangle_t *traceTriangles = NULL;
119 int headNodeNum = 0, skyboxNodeNum = 0, maxTraceDepth = 0, numTraceLeafNodes = 0;
120 int numTraceNodes = 0, maxTraceNodes = 0;
121 traceNode_t *traceNodes = NULL;
125 /* -------------------------------------------------------------------------------
127 allocation and list management
129 ------------------------------------------------------------------------------- */
132 AddTraceInfo() - ydnar
133 adds a trace info structure to the pool
136 static int AddTraceInfo( traceInfo_t *ti )
142 /* find an existing info */
143 for( num = firstTraceInfo; num < numTraceInfos; num++ )
145 if( traceInfos[ num ].si == ti->si &&
146 traceInfos[ num ].surfaceNum == ti->surfaceNum &&
147 traceInfos[ num ].castShadows == ti->castShadows )
152 if( numTraceInfos >= maxTraceInfos )
154 /* allocate more room */
155 maxTraceInfos += GROW_TRACE_INFOS;
156 temp = safe_malloc( maxTraceInfos * sizeof( *traceInfos ) );
157 if( traceInfos != NULL )
159 memcpy( temp, traceInfos, numTraceInfos * sizeof( *traceInfos ) );
162 traceInfos = (traceInfo_t*) temp;
166 memcpy( &traceInfos[ num ], ti, sizeof( *traceInfos ) );
167 if( num == numTraceInfos )
170 /* return the ti number */
177 AllocTraceNode() - ydnar
178 allocates a new trace node
181 static int AllocTraceNode( void )
187 if( numTraceNodes >= maxTraceNodes )
189 /* reallocate more room */
190 maxTraceNodes += GROW_TRACE_NODES;
191 temp = safe_malloc( maxTraceNodes * sizeof( traceNode_t ) );
192 if( traceNodes != NULL )
194 memcpy( temp, traceNodes, numTraceNodes * sizeof( traceNode_t ) );
201 memset( &traceNodes[ numTraceNodes ], 0, sizeof( traceNode_t ) );
202 traceNodes[ numTraceNodes ].type = TRACE_LEAF;
203 ClearBounds( traceNodes[ numTraceNodes ].mins, traceNodes[ numTraceNodes ].maxs );
205 /* Sys_Printf("alloc node %d\n", numTraceNodes); */
209 /* return the count */
210 return (numTraceNodes - 1);
216 AddTraceWinding() - ydnar
217 adds a winding to the raytracing pool
220 static int AddTraceWinding( traceWinding_t *tw )
226 /* check for a dead winding */
227 if( deadWinding >= 0 && deadWinding < numTraceWindings )
231 /* put winding at the end of the list */
232 num = numTraceWindings;
235 if( numTraceWindings >= maxTraceWindings )
237 /* allocate more room */
238 maxTraceWindings += GROW_TRACE_WINDINGS;
239 temp = safe_malloc( maxTraceWindings * sizeof( *traceWindings ) );
240 if( traceWindings != NULL )
242 memcpy( temp, traceWindings, numTraceWindings * sizeof( *traceWindings ) );
243 free( traceWindings );
245 traceWindings = (traceWinding_t*) temp;
249 /* add the winding */
250 memcpy( &traceWindings[ num ], tw, sizeof( *traceWindings ) );
251 if( num == numTraceWindings )
255 /* return the winding number */
262 AddTraceTriangle() - ydnar
263 adds a triangle to the raytracing pool
266 static int AddTraceTriangle( traceTriangle_t *tt )
272 /* check for a dead triangle */
273 if( deadTriangle >= 0 && deadTriangle < numTraceTriangles )
277 /* put triangle at the end of the list */
278 num = numTraceTriangles;
281 if( numTraceTriangles >= maxTraceTriangles )
283 /* allocate more room */
284 maxTraceTriangles += GROW_TRACE_TRIANGLES;
285 temp = safe_malloc( maxTraceTriangles * sizeof( *traceTriangles ) );
286 if( traceTriangles != NULL )
288 memcpy( temp, traceTriangles, numTraceTriangles * sizeof( *traceTriangles ) );
289 free( traceTriangles );
291 traceTriangles = (traceTriangle_t*) temp;
295 /* find vectors for two edges sharing the first vert */
296 VectorSubtract( tt->v[ 1 ].xyz, tt->v[ 0 ].xyz, tt->edge1 );
297 VectorSubtract( tt->v[ 2 ].xyz, tt->v[ 0 ].xyz, tt->edge2 );
299 /* add the triangle */
300 memcpy( &traceTriangles[ num ], tt, sizeof( *traceTriangles ) );
301 if( num == numTraceTriangles )
305 /* return the triangle number */
312 AddItemToTraceNode() - ydnar
313 adds an item reference (winding or triangle) to a trace node
316 static int AddItemToTraceNode( traceNode_t *node, int num )
326 if( node->numItems >= node->maxItems )
328 /* allocate more room */
329 if( node == traceNodes )
332 node->maxItems += GROW_NODE_ITEMS;
333 if( node->maxItems <= 0 )
334 node->maxItems = GROW_NODE_ITEMS;
335 temp = safe_malloc( node->maxItems * sizeof( *node->items ) );
336 if( node->items != NULL )
338 memcpy( temp, node->items, node->numItems * sizeof( *node->items ) );
341 node->items = (int*) temp;
345 node->items[ node->numItems ] = num;
348 /* return the count */
349 return (node->numItems - 1);
355 /* -------------------------------------------------------------------------------
359 ------------------------------------------------------------------------------- */
362 SetupTraceNodes_r() - ydnar
363 recursively create the initial trace node structure from the bsp tree
366 static int SetupTraceNodes_r( int bspNodeNum )
368 int i, nodeNum, bspLeafNum, newNode;
373 /* get bsp node and plane */
374 bspNode = &bspNodes[ bspNodeNum ];
375 plane = &bspPlanes[ bspNode->planeNum ];
377 /* allocate a new trace node */
378 nodeNum = AllocTraceNode();
380 /* setup trace node */
381 traceNodes[ nodeNum ].type = PlaneTypeForNormal( plane->normal );
382 VectorCopy( plane->normal, traceNodes[ nodeNum ].plane );
383 traceNodes[ nodeNum ].plane[ 3 ] = plane->dist;
386 for( i = 0; i < 2; i++ )
389 if( bspNode->children[ i ] < 0 )
391 bspLeafNum = -bspNode->children[ i ] - 1;
394 newNode = AllocTraceNode();
395 traceNodes[ nodeNum ].children[ i ] = newNode;
396 /* have to do this separately, as gcc first executes LHS, then RHS, and if a realloc took place, this fails */
398 if( bspLeafs[ bspLeafNum ].cluster == -1 )
399 traceNodes[ traceNodes[ nodeNum ].children[ i ] ].type = TRACE_LEAF_SOLID;
404 traceNodes[ nodeNum ].children[ i ] = SetupTraceNodes_r( bspNode->children[ i ] );
407 /* Sys_Printf("node %d children: %d %d\n", nodeNum, traceNodes[ nodeNum ].children[0], traceNodes[ nodeNum ].children[1]); */
409 /* return node number */
416 ClipTraceWinding() - ydnar
417 clips a trace winding against a plane into one or two parts
420 #define TW_ON_EPSILON 0.25f
422 void ClipTraceWinding( traceWinding_t *tw, vec4_t plane, traceWinding_t *front, traceWinding_t *back )
425 int sides[ MAX_TW_VERTS ], counts[ 3 ] = { 0, 0, 0 };
426 float dists[ MAX_TW_VERTS ];
428 traceVert_t *a, *b, mid;
431 /* clear front and back */
435 /* classify points */
436 for( i = 0; i < tw->numVerts; i++ )
438 dists[ i ] = DotProduct( tw->v[ i ].xyz, plane ) - plane[ 3 ];
439 if( dists[ i ] < -TW_ON_EPSILON )
440 sides[ i ] = SIDE_BACK;
441 else if( dists[ i ] > TW_ON_EPSILON )
442 sides[ i ] = SIDE_FRONT;
444 sides[ i ] = SIDE_ON;
445 counts[ sides[ i ] ]++;
448 /* entirely on front? */
449 if( counts[ SIDE_BACK ] == 0 )
450 memcpy( front, tw, sizeof( *front ) );
452 /* entirely on back? */
453 else if( counts[ SIDE_FRONT ] == 0 )
454 memcpy( back, tw, sizeof( *back ) );
456 /* straddles the plane */
459 /* setup front and back */
460 memcpy( front, tw, sizeof( *front ) );
462 memcpy( back, tw, sizeof( *back ) );
465 /* split the winding */
466 for( i = 0; i < tw->numVerts; i++ )
469 j = (i + 1) % tw->numVerts;
475 /* handle points on the splitting plane */
479 if( front->numVerts >= MAX_TW_VERTS )
480 Error( "MAX_TW_VERTS (%d) exceeded", MAX_TW_VERTS );
481 front->v[ front->numVerts++ ] = *a;
485 if( back->numVerts >= MAX_TW_VERTS )
486 Error( "MAX_TW_VERTS (%d) exceeded", MAX_TW_VERTS );
487 back->v[ back->numVerts++ ] = *a;
491 if( front->numVerts >= MAX_TW_VERTS || back->numVerts >= MAX_TW_VERTS )
492 Error( "MAX_TW_VERTS (%d) exceeded", MAX_TW_VERTS );
493 front->v[ front->numVerts++ ] = *a;
494 back->v[ back->numVerts++ ] = *a;
498 /* check next point to see if we need to split the edge */
499 if( sides[ j ] == SIDE_ON || sides[ j ] == sides[ i ] )
503 if( front->numVerts >= MAX_TW_VERTS || back->numVerts >= MAX_TW_VERTS )
504 Error( "MAX_TW_VERTS (%d) exceeded", MAX_TW_VERTS );
506 /* generate a split point */
507 frac = dists[ i ] / (dists[ i ] - dists[ j ]);
508 for( k = 0; k < 3; k++ )
510 /* minimize fp precision errors */
511 if( plane[ k ] == 1.0f )
512 mid.xyz[ k ] = plane[ 3 ];
513 else if( plane[ k ] == -1.0f )
514 mid.xyz[ k ] = -plane[ 3 ];
516 mid.xyz[ k ] = a->xyz[ k ] + frac * (b->xyz[ k ] - a->xyz[ k ]);
518 /* set texture coordinates */
521 mid.st[ 0 ] = a->st[ 0 ] + frac * (b->st[ 0 ] - a->st[ 0 ]);
522 mid.st[ 1 ] = a->st[ 1 ] + frac * (b->st[ 1 ] - a->st[ 1 ]);
525 /* copy midpoint to front and back polygons */
526 front->v[ front->numVerts++ ] = mid;
527 back->v[ back->numVerts++ ] = mid;
535 FilterPointToTraceNodes_r() - ydnar
539 static int FilterPointToTraceNodes_r( vec3_t pt, int nodeNum )
545 if( nodeNum < 0 || nodeNum >= numTraceNodes )
548 node = &traceNodes[ nodeNum ];
550 if( node->type >= 0 )
552 dot = DotProduct( pt, node->plane ) - node->plane[ 3 ];
554 FilterPointToTraceNodes_r( pt, node->children[ 0 ] );
556 FilterPointToTraceNodes_r( pt, node->children[ 1 ] );
560 Sys_Printf( "%d ", nodeNum );
568 FilterTraceWindingIntoNodes_r() - ydnar
569 filters a trace winding into the raytracing tree
572 static void FilterTraceWindingIntoNodes_r( traceWinding_t *tw, int nodeNum )
575 vec4_t plane1, plane2, reverse;
577 traceWinding_t front, back;
580 /* don't filter if passed a bogus node (solid, etc) */
581 if( nodeNum < 0 || nodeNum >= numTraceNodes )
585 node = &traceNodes[ nodeNum ];
587 /* is this a decision node? */
588 if( node->type >= 0 )
590 /* create winding plane if necessary, filtering out bogus windings as well */
591 if( nodeNum == headNodeNum )
593 if( !PlaneFromPoints( tw->plane, tw->v[ 0 ].xyz, tw->v[ 1 ].xyz, tw->v[ 2 ].xyz ) )
597 /* validate the node */
598 if( node->children[ 0 ] == 0 || node->children[ 1 ] == 0 )
599 Error( "Invalid tracenode: %d", nodeNum );
602 Vector4Copy( node->plane, plane1 );
604 /* get winding plane */
605 Vector4Copy( tw->plane, plane2 );
607 /* invert surface plane */
608 VectorSubtract( vec3_origin, plane2, reverse );
609 reverse[ 3 ] = -plane2[ 3 ];
612 if( DotProduct( plane1, plane2 ) > 0.999f && fabs( plane1[ 3 ] - plane2[ 3 ] ) < 0.001f )
614 FilterTraceWindingIntoNodes_r( tw, node->children[ 0 ] );
619 if( DotProduct( plane1, reverse ) > 0.999f && fabs( plane1[ 3 ] - reverse[ 3 ] ) < 0.001f )
621 FilterTraceWindingIntoNodes_r( tw, node->children[ 1 ] );
625 /* clip the winding by node plane */
626 ClipTraceWinding( tw, plane1, &front, &back );
628 /* filter by node plane */
629 if( front.numVerts >= 3 )
630 FilterTraceWindingIntoNodes_r( &front, node->children[ 0 ] );
631 if( back.numVerts >= 3 )
632 FilterTraceWindingIntoNodes_r( &back, node->children[ 1 ] );
634 /* return to caller */
638 /* add winding to leaf node */
639 num = AddTraceWinding( tw );
640 AddItemToTraceNode( node, num );
646 SubdivideTraceNode_r() - ydnar
647 recursively subdivides a tracing node until it meets certain size and complexity criteria
650 static void SubdivideTraceNode_r( int nodeNum, int depth )
652 int i, j, count, num, frontNum, backNum, type;
656 traceNode_t *node, *frontNode, *backNode;
657 traceWinding_t *tw, front, back;
661 if( nodeNum < 0 || nodeNum >= numTraceNodes )
665 node = &traceNodes[ nodeNum ];
667 /* runaway recursion check */
668 if( depth >= MAX_TRACE_DEPTH )
670 //% Sys_Printf( "Depth: (%d items)\n", node->numItems );
676 /* is this a decision node? */
677 if( node->type >= 0 )
679 /* subdivide children */
680 frontNum = node->children[ 0 ];
681 backNum = node->children[ 1 ];
682 SubdivideTraceNode_r( frontNum, depth );
683 SubdivideTraceNode_r( backNum, depth );
688 ClearBounds( node->mins, node->maxs );
689 VectorClear( average );
691 for( i = 0; i < node->numItems; i++ )
694 tw = &traceWindings[ node->items[ i ] ];
697 for( j = 0; j < tw->numVerts; j++ )
699 AddPointToBounds( tw->v[ j ].xyz, node->mins, node->maxs );
700 average[ 0 ] += tw->v[ j ].xyz[ 0 ];
701 average[ 1 ] += tw->v[ j ].xyz[ 1 ];
702 average[ 2 ] += tw->v[ j ].xyz[ 2 ];
707 /* check triangle limit */
708 //% if( node->numItems <= MAX_NODE_ITEMS )
709 if( (count - (node->numItems * 2)) < MAX_NODE_TRIANGLES )
711 //% Sys_Printf( "Limit: (%d triangles)\n", (count - (node->numItems * 2)) );
716 /* the largest dimension of the bounding box will be the split axis */
717 VectorSubtract( node->maxs, node->mins, size );
718 if( size[ 0 ] >= size[ 1 ] && size[ 0 ] >= size[ 2 ] )
720 else if( size[ 1 ] >= size[ 0 ] && size[ 1 ] >= size[ 2 ] )
725 /* don't split small nodes */
726 if( size[ type ] <= MIN_NODE_SIZE )
728 //% Sys_Printf( "Limit: %f %f %f (%d items)\n", size[ 0 ], size[ 1 ], size[ 2 ], node->numItems );
733 /* set max trace depth */
734 if( depth > maxTraceDepth )
735 maxTraceDepth = depth;
737 /* snap the average */
738 dist = floor( average[ type ] / count );
741 if( dist <= node->mins[ type ] || dist >= node->maxs[ type ] )
742 dist = floor( 0.5f * (node->mins[ type ] + node->maxs[ type ]) );
744 /* allocate child nodes */
745 frontNum = AllocTraceNode();
746 backNum = AllocTraceNode();
749 node = &traceNodes[ nodeNum ];
750 frontNode = &traceNodes[ frontNum ];
751 backNode = &traceNodes[ backNum ];
753 /* attach children */
755 node->plane[ type ] = 1.0f;
756 node->plane[ 3 ] = dist;
757 node->children[ 0 ] = frontNum;
758 node->children[ 1 ] = backNum;
760 /* setup front node */
761 frontNode->maxItems = (node->maxItems >> 1);
762 frontNode->items = safe_malloc( frontNode->maxItems * sizeof( *frontNode->items ) );
764 /* setup back node */
765 backNode->maxItems = (node->maxItems >> 1);
766 backNode->items = safe_malloc( backNode->maxItems * sizeof( *backNode->items ) );
768 /* filter windings into child nodes */
769 for( i = 0; i < node->numItems; i++ )
772 tw = &traceWindings[ node->items[ i ] ];
774 /* clip the winding by the new split plane */
775 ClipTraceWinding( tw, node->plane, &front, &back );
777 /* kill the existing winding */
778 if( front.numVerts >= 3 || back.numVerts >= 3 )
779 deadWinding = node->items[ i ];
781 /* add front winding */
782 if( front.numVerts >= 3 )
784 num = AddTraceWinding( &front );
785 AddItemToTraceNode( frontNode, num );
788 /* add back winding */
789 if( back.numVerts >= 3 )
791 num = AddTraceWinding( &back );
792 AddItemToTraceNode( backNode, num );
796 /* free original node winding list */
803 if( frontNode->numItems <= 0 )
805 frontNode->maxItems = 0;
806 free( frontNode->items );
807 frontNode->items = NULL;
810 if( backNode->numItems <= 0 )
812 backNode->maxItems = 0;
813 free( backNode->items );
814 backNode->items = NULL;
817 /* subdivide children */
818 SubdivideTraceNode_r( frontNum, depth );
819 SubdivideTraceNode_r( backNum, depth );
825 TriangulateTraceNode_r()
826 optimizes the tracing data by changing trace windings into triangles
829 static int TriangulateTraceNode_r( int nodeNum )
831 int i, j, num, frontNum, backNum, numWindings, *windings;
838 if( nodeNum < 0 || nodeNum >= numTraceNodes )
842 node = &traceNodes[ nodeNum ];
844 /* is this a decision node? */
845 if( node->type >= 0 )
847 /* triangulate children */
848 frontNum = node->children[ 0 ];
849 backNum = node->children[ 1 ];
850 node->numItems = TriangulateTraceNode_r( frontNum );
851 node->numItems += TriangulateTraceNode_r( backNum );
852 return node->numItems;
856 if( node->numItems == 0 )
859 if( node->items != NULL )
861 return node->numItems;
864 /* store off winding data */
865 numWindings = node->numItems;
866 windings = node->items;
870 node->maxItems = numWindings * 2;
871 node->items = safe_malloc( node->maxItems * sizeof( tt ) );
873 /* walk winding list */
874 for( i = 0; i < numWindings; i++ )
877 tw = &traceWindings[ windings[ i ] ];
880 tt.infoNum = tw->infoNum;
881 tt.v[ 0 ] = tw->v[ 0 ];
883 /* walk vertex list */
884 for( j = 1; j + 1 < tw->numVerts; j++ )
887 tt.v[ 1 ] = tw->v[ j ];
888 tt.v[ 2 ] = tw->v[ j + 1 ];
890 /* find vectors for two edges sharing the first vert */
891 VectorSubtract( tt.v[ 1 ].xyz, tt.v[ 0 ].xyz, tt.edge1 );
892 VectorSubtract( tt.v[ 2 ].xyz, tt.v[ 0 ].xyz, tt.edge2 );
894 /* add it to the node */
895 num = AddTraceTriangle( &tt );
896 AddItemToTraceNode( node, num );
901 if( windings != NULL )
904 /* return item count */
905 return node->numItems;
910 /* -------------------------------------------------------------------------------
912 shadow casting item setup (triangles, patches, entities)
914 ------------------------------------------------------------------------------- */
917 PopulateWithBSPModel() - ydnar
918 filters a bsp model's surfaces into the raytracing tree
921 static void PopulateWithBSPModel( bspModel_t *model, m4x4_t transform )
923 int i, j, x, y, pw[ 5 ], r, nodeNum;
924 bspDrawSurface_t *ds;
926 bspDrawVert_t *verts;
928 mesh_t srcMesh, *mesh, *subdivided;
934 if( model == NULL || transform == NULL )
937 /* walk the list of surfaces in this model and fill out the info structs */
938 for( i = 0; i < model->numBSPSurfaces; i++ )
940 /* get surface and info */
941 ds = &bspDrawSurfaces[ model->firstBSPSurface + i ];
942 info = &surfaceInfos[ model->firstBSPSurface + i ];
943 if( info->si == NULL )
947 if( !info->castShadows )
951 if( ds->surfaceType == MST_PATCH && patchShadows == qfalse )
954 /* some surfaces in the bsp might have been tagged as nodraw, with a bogus shader */
955 if( (bspShaders[ ds->shaderNum ].contentFlags & noDrawContentFlags) ||
956 (bspShaders[ ds->shaderNum ].surfaceFlags & noDrawSurfaceFlags) )
959 /* translucent surfaces that are neither alphashadow or lightfilter don't cast shadows */
960 if( (info->si->compileFlags & C_NODRAW) )
962 if( (info->si->compileFlags & C_TRANSLUCENT) &&
963 !(info->si->compileFlags & C_ALPHASHADOW) &&
964 !(info->si->compileFlags & C_LIGHTFILTER) )
967 /* setup trace info */
969 ti.castShadows = info->castShadows;
970 ti.surfaceNum = model->firstBSPBrush + i;
972 /* choose which node (normal or skybox) */
973 if( info->parentSurfaceNum >= 0 )
975 nodeNum = skyboxNodeNum;
977 /* sky surfaces in portal skies are ignored */
978 if( info->si->compileFlags & C_SKY )
982 nodeNum = headNodeNum;
984 /* setup trace winding */
985 memset( &tw, 0, sizeof( tw ) );
986 tw.infoNum = AddTraceInfo( &ti );
990 switch( ds->surfaceType )
994 /* subdivide the surface */
995 srcMesh.width = ds->patchWidth;
996 srcMesh.height = ds->patchHeight;
997 srcMesh.verts = &bspDrawVerts[ ds->firstVert ];
998 //% subdivided = SubdivideMesh( srcMesh, 8, 512 );
999 subdivided = SubdivideMesh2( srcMesh, info->patchIterations );
1001 /* fit it to the curve and remove colinear verts on rows/columns */
1002 PutMeshOnCurve( *subdivided );
1003 mesh = RemoveLinearMeshColumnsRows( subdivided );
1004 FreeMesh( subdivided );
1007 verts = mesh->verts;
1009 /* subdivide each quad to place the models */
1010 for( y = 0; y < (mesh->height - 1); y++ )
1012 for( x = 0; x < (mesh->width - 1); x++ )
1015 pw[ 0 ] = x + (y * mesh->width);
1016 pw[ 1 ] = x + ((y + 1) * mesh->width);
1017 pw[ 2 ] = x + 1 + ((y + 1) * mesh->width);
1018 pw[ 3 ] = x + 1 + (y * mesh->width);
1019 pw[ 4 ] = x + (y * mesh->width); /* same as pw[ 0 ] */
1024 /* make first triangle */
1025 VectorCopy( verts[ pw[ r + 0 ] ].xyz, tw.v[ 0 ].xyz );
1026 Vector2Copy( verts[ pw[ r + 0 ] ].st, tw.v[ 0 ].st );
1027 VectorCopy( verts[ pw[ r + 1 ] ].xyz, tw.v[ 1 ].xyz );
1028 Vector2Copy( verts[ pw[ r + 1 ] ].st, tw.v[ 1 ].st );
1029 VectorCopy( verts[ pw[ r + 2 ] ].xyz, tw.v[ 2 ].xyz );
1030 Vector2Copy( verts[ pw[ r + 2 ] ].st, tw.v[ 2 ].st );
1031 m4x4_transform_point( transform, tw.v[ 0 ].xyz );
1032 m4x4_transform_point( transform, tw.v[ 1 ].xyz );
1033 m4x4_transform_point( transform, tw.v[ 2 ].xyz );
1034 FilterTraceWindingIntoNodes_r( &tw, nodeNum );
1036 /* make second triangle */
1037 VectorCopy( verts[ pw[ r + 0 ] ].xyz, tw.v[ 0 ].xyz );
1038 Vector2Copy( verts[ pw[ r + 0 ] ].st, tw.v[ 0 ].st );
1039 VectorCopy( verts[ pw[ r + 2 ] ].xyz, tw.v[ 1 ].xyz );
1040 Vector2Copy( verts[ pw[ r + 2 ] ].st, tw.v[ 1 ].st );
1041 VectorCopy( verts[ pw[ r + 3 ] ].xyz, tw.v[ 2 ].xyz );
1042 Vector2Copy( verts[ pw[ r + 3 ] ].st, tw.v[ 2 ].st );
1043 m4x4_transform_point( transform, tw.v[ 0 ].xyz );
1044 m4x4_transform_point( transform, tw.v[ 1 ].xyz );
1045 m4x4_transform_point( transform, tw.v[ 2 ].xyz );
1046 FilterTraceWindingIntoNodes_r( &tw, nodeNum );
1050 /* free the subdivided mesh */
1054 /* handle triangle surfaces */
1055 case MST_TRIANGLE_SOUP:
1057 /* set verts and indexes */
1058 verts = &bspDrawVerts[ ds->firstVert ];
1059 indexes = &bspDrawIndexes[ ds->firstIndex ];
1061 /* walk the triangle list */
1062 for( j = 0; j < ds->numIndexes; j += 3 )
1064 VectorCopy( verts[ indexes[ j ] ].xyz, tw.v[ 0 ].xyz );
1065 Vector2Copy( verts[ indexes[ j ] ].st, tw.v[ 0 ].st );
1066 VectorCopy( verts[ indexes[ j + 1 ] ].xyz, tw.v[ 1 ].xyz );
1067 Vector2Copy( verts[ indexes[ j + 1 ] ].st, tw.v[ 1 ].st );
1068 VectorCopy( verts[ indexes[ j + 2 ] ].xyz, tw.v[ 2 ].xyz );
1069 Vector2Copy( verts[ indexes[ j + 2 ] ].st, tw.v[ 2 ].st );
1070 m4x4_transform_point( transform, tw.v[ 0 ].xyz );
1071 m4x4_transform_point( transform, tw.v[ 1 ].xyz );
1072 m4x4_transform_point( transform, tw.v[ 2 ].xyz );
1073 FilterTraceWindingIntoNodes_r( &tw, nodeNum );
1077 /* other surface types do not cast shadows */
1087 PopulateWithPicoModel() - ydnar
1088 filters a picomodel's surfaces into the raytracing tree
1091 static void PopulateWithPicoModel( int castShadows, picoModel_t *model, m4x4_t transform )
1093 int i, j, k, numSurfaces, numIndexes;
1094 picoSurface_t *surface;
1095 picoShader_t *shader;
1096 picoVec_t *xyz, *st;
1097 picoIndex_t *indexes;
1103 if( model == NULL || transform == NULL )
1107 numSurfaces = PicoGetModelNumSurfaces( model );
1109 /* walk the list of surfaces in this model and fill out the info structs */
1110 for( i = 0; i < numSurfaces; i++ )
1113 surface = PicoGetModelSurface( model, i );
1114 if( surface == NULL )
1117 /* only handle triangle surfaces initially (fixme: support patches) */
1118 if( PicoGetSurfaceType( surface ) != PICO_TRIANGLES )
1121 /* get shader (fixme: support shader remapping) */
1122 shader = PicoGetSurfaceShader( surface );
1123 if( shader == NULL )
1125 ti.si = ShaderInfoForShader( PicoGetShaderName( shader ) );
1129 /* translucent surfaces that are neither alphashadow or lightfilter don't cast shadows */
1130 if( (ti.si->compileFlags & C_NODRAW) )
1132 if( (ti.si->compileFlags & C_TRANSLUCENT) &&
1133 !(ti.si->compileFlags & C_ALPHASHADOW) &&
1134 !(ti.si->compileFlags & C_LIGHTFILTER) )
1137 /* setup trace info */
1138 ti.castShadows = castShadows;
1141 /* setup trace winding */
1142 memset( &tw, 0, sizeof( tw ) );
1143 tw.infoNum = AddTraceInfo( &ti );
1147 numIndexes = PicoGetSurfaceNumIndexes( surface );
1148 indexes = PicoGetSurfaceIndexes( surface, 0 );
1150 /* walk the triangle list */
1151 for( j = 0; j < numIndexes; j += 3, indexes += 3 )
1153 for( k = 0; k < 3; k++ )
1155 xyz = PicoGetSurfaceXYZ( surface, indexes[ k ] );
1156 st = PicoGetSurfaceST( surface, 0, indexes[ k ] );
1157 VectorCopy( xyz, tw.v[ k ].xyz );
1158 Vector2Copy( st, tw.v[ k ].st );
1159 m4x4_transform_point( transform, tw.v[ k ].xyz );
1161 FilterTraceWindingIntoNodes_r( &tw, headNodeNum );
1169 PopulateTraceNodes() - ydnar
1170 fills the raytracing tree with world and entity occluders
1173 static void PopulateTraceNodes( void )
1175 int i, m, frame, castShadows;
1180 vec3_t origin, scale, angles;
1184 /* add worldspawn triangles */
1185 m4x4_identity( transform );
1186 PopulateWithBSPModel( &bspModels[ 0 ], transform );
1188 /* walk each entity list */
1189 for( i = 1; i < numEntities; i++ )
1194 /* get shadow flags */
1195 castShadows = ENTITY_CAST_SHADOWS;
1196 GetEntityShadowFlags( e, NULL, &castShadows, NULL );
1202 /* get entity origin */
1203 GetVectorForKey( e, "origin", origin );
1206 scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f;
1207 temp = FloatForKey( e, "modelscale" );
1209 scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp;
1210 value = ValueForKey( e, "modelscale_vec" );
1211 if( value[ 0 ] != '\0' )
1212 sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
1214 /* get "angle" (yaw) or "angles" (pitch yaw roll) */
1215 angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f;
1216 angles[ 2 ] = FloatForKey( e, "angle" );
1217 value = ValueForKey( e, "angles" );
1218 if( value[ 0 ] != '\0' )
1219 sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
1221 /* set transform matrix (thanks spog) */
1222 m4x4_identity( transform );
1223 m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin );
1225 /* hack: Stable-1_2 and trunk have differing row/column major matrix order
1226 this transpose is necessary with Stable-1_2
1227 uncomment the following line with old m4x4_t (non 1.3/spog_branch) code */
1228 //% m4x4_transpose( transform );
1231 value = ValueForKey( e, "model" );
1233 /* switch on model type */
1234 switch( value[ 0 ] )
1242 m = atoi( &value[ 1 ] );
1243 if( m <= 0 || m >= numBSPModels )
1245 PopulateWithBSPModel( &bspModels[ m ], transform );
1248 /* external model */
1250 frame = IntForKey( e, "_frame" );
1251 model = LoadModel( (char*) value, frame );
1254 PopulateWithPicoModel( castShadows, model, transform );
1259 value = ValueForKey( e, "model2" );
1261 /* switch on model type */
1262 switch( value[ 0 ] )
1270 m = atoi( &value[ 1 ] );
1271 if( m <= 0 || m >= numBSPModels )
1273 PopulateWithBSPModel( &bspModels[ m ], transform );
1276 /* external model */
1278 frame = IntForKey( e, "_frame2" );
1279 model = LoadModel( (char*) value, frame );
1282 PopulateWithPicoModel( castShadows, model, transform );
1291 /* -------------------------------------------------------------------------------
1293 trace initialization
1295 ------------------------------------------------------------------------------- */
1298 SetupTraceNodes() - ydnar
1299 creates a balanced bsp with axis-aligned splits for efficient raytracing
1302 void SetupTraceNodes( void )
1305 Sys_FPrintf( SYS_VRB, "--- SetupTraceNodes ---\n" );
1307 /* find nodraw bit */
1308 noDrawContentFlags = noDrawSurfaceFlags = noDrawCompileFlags = 0;
1309 ApplySurfaceParm( "nodraw", &noDrawContentFlags, &noDrawSurfaceFlags, &noDrawCompileFlags );
1311 /* create the baseline raytracing tree from the bsp tree */
1312 headNodeNum = SetupTraceNodes_r( 0 );
1314 /* create outside node for skybox surfaces */
1315 skyboxNodeNum = AllocTraceNode();
1317 /* populate the tree with triangles from the world and shadow casting entities */
1318 PopulateTraceNodes();
1320 /* create the raytracing bsp */
1321 if( loMem == qfalse )
1323 SubdivideTraceNode_r( headNodeNum, 0 );
1324 SubdivideTraceNode_r( skyboxNodeNum, 0 );
1327 /* create triangles from the trace windings */
1328 TriangulateTraceNode_r( headNodeNum );
1329 TriangulateTraceNode_r( skyboxNodeNum );
1331 /* emit some stats */
1332 //% Sys_FPrintf( SYS_VRB, "%9d original triangles\n", numOriginalTriangles );
1333 Sys_FPrintf( SYS_VRB, "%9d trace windings (%.2fMB)\n", numTraceWindings, (float) (numTraceWindings * sizeof( *traceWindings )) / (1024.0f * 1024.0f) );
1334 Sys_FPrintf( SYS_VRB, "%9d trace triangles (%.2fMB)\n", numTraceTriangles, (float) (numTraceTriangles * sizeof( *traceTriangles )) / (1024.0f * 1024.0f) );
1335 Sys_FPrintf( SYS_VRB, "%9d trace nodes (%.2fMB)\n", numTraceNodes, (float) (numTraceNodes * sizeof( *traceNodes )) / (1024.0f * 1024.0f) );
1336 Sys_FPrintf( SYS_VRB, "%9d leaf nodes (%.2fMB)\n", numTraceLeafNodes, (float) (numTraceLeafNodes * sizeof( *traceNodes )) / (1024.0f * 1024.0f) );
1337 //% Sys_FPrintf( SYS_VRB, "%9d average triangles per leaf node\n", numTraceTriangles / numTraceLeafNodes );
1338 Sys_FPrintf( SYS_VRB, "%9d average windings per leaf node\n", numTraceWindings / (numTraceLeafNodes + 1) );
1339 Sys_FPrintf( SYS_VRB, "%9d max trace depth\n", maxTraceDepth );
1341 /* free trace windings */
1342 free( traceWindings );
1343 numTraceWindings = 0;
1344 maxTraceWindings = 0;
1347 /* debug code: write out trace triangles to an alias obj file */
1352 char filename[ 1024 ];
1357 strcpy( filename, source );
1358 StripExtension( filename );
1359 strcat( filename, ".lin" );
1360 Sys_Printf( "Opening light trace file %s...\n", filename );
1361 file = fopen( filename, "w" );
1363 Error( "Error opening %s for writing", filename );
1365 /* walk node list */
1366 for( i = 0; i < numTraceWindings; i++ )
1368 tw = &traceWindings[ i ];
1369 for( j = 0; j < tw->numVerts + 1; j++ )
1370 fprintf( file, "%f %f %f\n",
1371 tw->v[ j % tw->numVerts ].xyz[ 0 ], tw->v[ j % tw->numVerts ].xyz[ 1 ], tw->v[ j % tw->numVerts ].xyz[ 2 ] );
1382 /* -------------------------------------------------------------------------------
1386 ------------------------------------------------------------------------------- */
1390 based on code written by william 'spog' joseph
1391 based on code originally written by tomas moller and ben trumbore, journal of graphics tools, 2(1):21-28, 1997
1394 #define BARY_EPSILON 0.01f
1395 #define ASLF_EPSILON 0.0001f /* so to not get double shadows */
1396 #define COPLANAR_EPSILON 0.25f //% 0.000001f
1397 #define NEAR_SHADOW_EPSILON 1.5f //% 1.25f
1398 #define SELF_SHADOW_EPSILON 0.5f
1400 qboolean TraceTriangle( traceInfo_t *ti, traceTriangle_t *tt, trace_t *trace )
1403 float tvec[ 3 ], pvec[ 3 ], qvec[ 3 ];
1404 float det, invDet, depth;
1405 float u, v, w, s, t;
1412 /* don't double-trace against sky */
1414 if( trace->compileFlags & si->compileFlags & C_SKY )
1417 /* receive shadows from worldspawn group only */
1418 if( trace->recvShadows == 1 )
1420 if( ti->castShadows != 1 )
1424 /* receive shadows from same group and worldspawn group */
1425 else if( trace->recvShadows > 1 )
1427 if( ti->castShadows != 1 && abs( ti->castShadows ) != abs( trace->recvShadows ) )
1429 //% Sys_Printf( "%d:%d ", tt->castShadows, trace->recvShadows );
1432 /* receive shadows from the same group only (< 0) */
1435 if( abs( ti->castShadows ) != abs( trace->recvShadows ) )
1439 /* begin calculating determinant - also used to calculate u parameter */
1440 CrossProduct( trace->direction, tt->edge2, pvec );
1442 /* if determinant is near zero, trace lies in plane of triangle */
1443 det = DotProduct( tt->edge1, pvec );
1445 /* the non-culling branch */
1446 if( fabs( det ) < COPLANAR_EPSILON )
1448 invDet = 1.0f / det;
1450 /* calculate distance from first vertex to ray origin */
1451 VectorSubtract( trace->origin, tt->v[ 0 ].xyz, tvec );
1453 /* calculate u parameter and test bounds */
1454 u = DotProduct( tvec, pvec ) * invDet;
1455 if( u < -BARY_EPSILON || u > (1.0f + BARY_EPSILON) )
1458 /* prepare to test v parameter */
1459 CrossProduct( tvec, tt->edge1, qvec );
1461 /* calculate v parameter and test bounds */
1462 v = DotProduct( trace->direction, qvec ) * invDet;
1463 if( v < -BARY_EPSILON || (u + v) > (1.0f + BARY_EPSILON) )
1466 /* calculate t (depth) */
1467 depth = DotProduct( tt->edge2, qvec ) * invDet;
1468 if( depth <= trace->inhibitRadius || depth >= trace->distance )
1471 /* if hitpoint is really close to trace origin (sample point), then check for self-shadowing */
1472 if( depth <= SELF_SHADOW_EPSILON )
1474 /* don't self-shadow */
1475 for( i = 0; i < trace->numSurfaces; i++ )
1477 if( ti->surfaceNum == trace->surfaces[ i ] )
1482 /* stack compile flags */
1483 trace->compileFlags |= si->compileFlags;
1485 /* don't trace against sky */
1486 if( si->compileFlags & C_SKY )
1489 /* most surfaces are completely opaque */
1490 if( !(si->compileFlags & (C_ALPHASHADOW | C_LIGHTFILTER)) ||
1491 si->lightImage == NULL || si->lightImage->pixels == NULL )
1493 VectorMA( trace->origin, depth, trace->direction, trace->hit );
1494 VectorClear( trace->color );
1495 trace->opaque = qtrue;
1499 /* try to avoid double shadows near triangle seams */
1500 if( u < -ASLF_EPSILON || u > (1.0f + ASLF_EPSILON) ||
1501 v < -ASLF_EPSILON || (u + v) > (1.0f + ASLF_EPSILON) )
1504 /* calculate w parameter */
1507 /* calculate st from uvw (barycentric) coordinates */
1508 s = w * tt->v[ 0 ].st[ 0 ] + u * tt->v[ 1 ].st[ 0 ] + v * tt->v[ 2 ].st[ 0 ];
1509 t = w * tt->v[ 0 ].st[ 1 ] + u * tt->v[ 1 ].st[ 1 ] + v * tt->v[ 2 ].st[ 1 ];
1512 is = s * si->lightImage->width;
1513 it = t * si->lightImage->height;
1516 pixel = si->lightImage->pixels + 4 * (it * si->lightImage->width + is);
1518 /* ydnar: color filter */
1519 if( si->compileFlags & C_LIGHTFILTER )
1521 /* filter by texture color */
1522 trace->color[ 0 ] *= ((1.0f / 255.0f) * pixel[ 0 ]);
1523 trace->color[ 1 ] *= ((1.0f / 255.0f) * pixel[ 1 ]);
1524 trace->color[ 2 ] *= ((1.0f / 255.0f) * pixel[ 2 ]);
1527 /* ydnar: alpha filter */
1528 if( si->compileFlags & C_ALPHASHADOW )
1530 /* filter by inverse texture alpha */
1531 shadow = (1.0f / 255.0f) * (255 - pixel[ 3 ]);
1532 trace->color[ 0 ] *= shadow;
1533 trace->color[ 1 ] *= shadow;
1534 trace->color[ 2 ] *= shadow;
1537 /* check filter for opaque */
1538 if( trace->color[ 0 ] <= 0.001f && trace->color[ 1 ] <= 0.001f && trace->color[ 2 ] <= 0.001f )
1540 VectorMA( trace->origin, depth, trace->direction, trace->hit );
1541 trace->opaque = qtrue;
1545 /* continue tracing */
1552 TraceWinding() - ydnar
1556 qboolean TraceWinding( traceWinding_t *tw, trace_t *trace )
1563 tt.infoNum = tw->infoNum;
1564 tt.v[ 0 ] = tw->v[ 0 ];
1566 /* walk vertex list */
1567 for( i = 1; i + 1 < tw->numVerts; i++ )
1570 tt.v[ 1 ] = tw->v[ i ];
1571 tt.v[ 2 ] = tw->v[ i + 1 ];
1573 /* find vectors for two edges sharing the first vert */
1574 VectorSubtract( tt.v[ 1 ].xyz, tt.v[ 0 ].xyz, tt.edge1 );
1575 VectorSubtract( tt.v[ 2 ].xyz, tt.v[ 0 ].xyz, tt.edge2 );
1578 if( TraceTriangle( &traceInfos[ tt.infoNum ], &tt, trace ) )
1591 returns qtrue if something is hit and tracing can stop
1594 static qboolean TraceLine_r( int nodeNum, vec3_t origin, vec3_t end, trace_t *trace )
1598 float front, back, frac;
1603 /* bogus node number means solid, end tracing unless testing all */
1606 VectorCopy( origin, trace->hit );
1607 trace->passSolid = qtrue;
1612 node = &traceNodes[ nodeNum ];
1615 if( node->type == TRACE_LEAF_SOLID )
1617 VectorCopy( origin, trace->hit );
1618 trace->passSolid = qtrue;
1623 if( node->type < 0 )
1625 /* note leaf and return */
1626 if( node->numItems > 0 && trace->numTestNodes < MAX_TRACE_TEST_NODES )
1627 trace->testNodes[ trace->numTestNodes++ ] = nodeNum;
1631 /* ydnar 2003-09-07: don't test branches of the bsp with nothing in them when testall is enabled */
1632 if( trace->testAll && node->numItems == 0 )
1635 /* classify beginning and end points */
1636 switch( node->type )
1639 front = origin[ 0 ] - node->plane[ 3 ];
1640 back = end[ 0 ] - node->plane[ 3 ];
1644 front = origin[ 1 ] - node->plane[ 3 ];
1645 back = end[ 1 ] - node->plane[ 3 ];
1649 front = origin[ 2 ] - node->plane[ 3 ];
1650 back = end[ 2 ] - node->plane[ 3 ];
1654 front = DotProduct( origin, node->plane ) - node->plane[ 3 ];
1655 back = DotProduct( end, node->plane ) - node->plane[ 3 ];
1659 /* entirely in front side? */
1660 if( front >= -TRACE_ON_EPSILON && back >= -TRACE_ON_EPSILON )
1661 return TraceLine_r( node->children[ 0 ], origin, end, trace );
1663 /* entirely on back side? */
1664 if( front < TRACE_ON_EPSILON && back < TRACE_ON_EPSILON )
1665 return TraceLine_r( node->children[ 1 ], origin, end, trace );
1670 /* calculate intercept point */
1671 frac = front / (front - back);
1672 mid[ 0 ] = origin[ 0 ] + (end[ 0 ] - origin[ 0 ]) * frac;
1673 mid[ 1 ] = origin[ 1 ] + (end[ 1 ] - origin[ 1 ]) * frac;
1674 mid[ 2 ] = origin[ 2 ] + (end[ 2 ] - origin[ 2 ]) * frac;
1676 /* fixme: check inhibit radius, then solid nodes and ignore */
1678 /* set trace hit here */
1679 //% VectorCopy( mid, trace->hit );
1681 /* trace first side */
1682 r = TraceLine_r( node->children[ side ], origin, mid, trace );
1686 /* trace other side */
1687 return TraceLine_r( node->children[ !side ], mid, end, trace );
1694 rewrote this function a bit :)
1697 void TraceLine( trace_t *trace )
1701 traceTriangle_t *tt;
1705 /* setup output (note: this code assumes the input data is completely filled out) */
1706 trace->passSolid = qfalse;
1707 trace->opaque = qfalse;
1708 trace->compileFlags = 0;
1709 trace->numTestNodes = 0;
1712 if( !trace->recvShadows || !trace->testOcclusion || trace->distance <= 0.00001f )
1715 /* trace through nodes */
1716 TraceLine_r( headNodeNum, trace->origin, trace->end, trace );
1717 if( trace->passSolid && !trace->testAll )
1719 trace->opaque = qtrue;
1723 /* skip surfaces? */
1727 /* testall means trace through sky */
1728 if( trace->testAll && trace->numTestNodes < MAX_TRACE_TEST_NODES &&
1729 trace->compileFlags & C_SKY &&
1730 (trace->numSurfaces == 0 || surfaceInfos[ trace->surfaces[ 0 ] ].childSurfaceNum < 0) )
1732 //% trace->testNodes[ trace->numTestNodes++ ] = skyboxNodeNum;
1733 TraceLine_r( skyboxNodeNum, trace->origin, trace->end, trace );
1736 /* walk node list */
1737 for( i = 0; i < trace->numTestNodes; i++ )
1740 node = &traceNodes[ trace->testNodes[ i ] ];
1742 /* walk node item list */
1743 for( j = 0; j < node->numItems; j++ )
1745 tt = &traceTriangles[ node->items[ j ] ];
1746 ti = &traceInfos[ tt->infoNum ];
1747 if( TraceTriangle( ti, tt, trace ) )
1749 //% if( TraceWinding( &traceWindings[ node->items[ j ] ], trace ) )
1758 SetupTrace() - ydnar
1759 sets up certain trace values
1762 float SetupTrace( trace_t *trace )
1764 VectorSubtract( trace->end, trace->origin, trace->displacement );
1765 trace->distance = VectorNormalize( trace->displacement, trace->direction );
1766 VectorCopy( trace->origin, trace->hit );
1767 return trace->distance;