================== CM_PatchCollideFromGrid ================== */
| 1015 | ================== |
| 1016 | */ |
| 1017 | static void CM_PatchCollideFromGrid( cGrid_t *grid, patchCollide_t *pf ) { |
| 1018 | int i, j; |
| 1019 | float *p1, *p2, *p3; |
| 1020 | int gridPlanes[CM_MAX_GRID_SIZE][CM_MAX_GRID_SIZE][2]; |
| 1021 | facet_t *facet; |
| 1022 | int borders[4]; |
| 1023 | qboolean noAdjust[4]; |
| 1024 | |
| 1025 | int numFacets; |
| 1026 | facets = (facet_t*) Z_Malloc(MAX_FACETS*sizeof(facet_t), TAG_TEMP_WORKSPACE, qfalse); |
| 1027 | |
| 1028 | numPlanes = 0; |
| 1029 | numFacets = 0; |
| 1030 | |
| 1031 | // find the planes for each triangle of the grid |
| 1032 | for ( i = 0 ; i < grid->width - 1 ; i++ ) { |
| 1033 | for ( j = 0 ; j < grid->height - 1 ; j++ ) { |
| 1034 | p1 = grid->points[i][j]; |
| 1035 | p2 = grid->points[i+1][j]; |
| 1036 | p3 = grid->points[i+1][j+1]; |
| 1037 | gridPlanes[i][j][0] = CM_FindPlane( p1, p2, p3 ); |
| 1038 | |
| 1039 | p1 = grid->points[i+1][j+1]; |
| 1040 | p2 = grid->points[i][j+1]; |
| 1041 | p3 = grid->points[i][j]; |
| 1042 | gridPlanes[i][j][1] = CM_FindPlane( p1, p2, p3 ); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | // create the borders for each facet |
| 1047 | for ( i = 0 ; i < grid->width - 1 ; i++ ) { |
| 1048 | for ( j = 0 ; j < grid->height - 1 ; j++ ) { |
| 1049 | |
| 1050 | borders[EN_TOP] = -1; |
| 1051 | if ( j > 0 ) { |
| 1052 | borders[EN_TOP] = gridPlanes[i][j-1][1]; |
| 1053 | } else if ( grid->wrapHeight ) { |
| 1054 | borders[EN_TOP] = gridPlanes[i][grid->height-2][1]; |
| 1055 | } |
| 1056 | noAdjust[EN_TOP] = (qboolean)( borders[EN_TOP] == gridPlanes[i][j][0] ); |
| 1057 | if ( borders[EN_TOP] == -1 || noAdjust[EN_TOP] ) { |
| 1058 | borders[EN_TOP] = CM_EdgePlaneNum( grid, gridPlanes, i, j, 0 ); |
| 1059 | } |
| 1060 | |
| 1061 | borders[EN_BOTTOM] = -1; |
| 1062 | if ( j < grid->height - 2 ) { |
| 1063 | borders[EN_BOTTOM] = gridPlanes[i][j+1][0]; |
| 1064 | } else if ( grid->wrapHeight ) { |
| 1065 | borders[EN_BOTTOM] = gridPlanes[i][0][0]; |
| 1066 | } |
| 1067 | noAdjust[EN_BOTTOM] = (qboolean)( borders[EN_BOTTOM] == gridPlanes[i][j][1] ); |
| 1068 | if ( borders[EN_BOTTOM] == -1 || noAdjust[EN_BOTTOM] ) { |
| 1069 | borders[EN_BOTTOM] = CM_EdgePlaneNum( grid, gridPlanes, i, j, 2 ); |
| 1070 | } |
| 1071 | |
| 1072 | borders[EN_LEFT] = -1; |
| 1073 | if ( i > 0 ) { |
| 1074 | borders[EN_LEFT] = gridPlanes[i-1][j][0]; |
no test coverage detected