================= BaseWindingForPlane ================= */
| 99 | ================= |
| 100 | */ |
| 101 | winding_t *BaseWindingForPlane (vec3_t normal, vec_t dist) |
| 102 | { |
| 103 | int i, x; |
| 104 | vec_t max, v; |
| 105 | vec3_t org, vright, vup; |
| 106 | winding_t *w; |
| 107 | |
| 108 | // find the major axis |
| 109 | |
| 110 | max = -MAX_MAP_BOUNDS; |
| 111 | x = -1; |
| 112 | for (i=0 ; i<3; i++) |
| 113 | { |
| 114 | v = fabs(normal[i]); |
| 115 | if (v > max) |
| 116 | { |
| 117 | x = i; |
| 118 | max = v; |
| 119 | } |
| 120 | } |
| 121 | if (x==-1) |
| 122 | Com_Error (ERR_DROP, "BaseWindingForPlane: no axis found"); |
| 123 | |
| 124 | VectorCopy (vec3_origin, vup); |
| 125 | switch (x) |
| 126 | { |
| 127 | case 0: |
| 128 | case 1: |
| 129 | vup[2] = 1; |
| 130 | break; |
| 131 | case 2: |
| 132 | vup[0] = 1; |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | v = DotProduct (vup, normal); |
| 137 | VectorMA (vup, -v, normal, vup); |
| 138 | VectorNormalize2(vup, vup); |
| 139 | |
| 140 | VectorScale (normal, dist, org); |
| 141 | |
| 142 | CrossProduct (vup, normal, vright); |
| 143 | |
| 144 | VectorScale (vup, MAX_MAP_BOUNDS, vup); |
| 145 | VectorScale (vright, MAX_MAP_BOUNDS, vright); |
| 146 | |
| 147 | // project a really big axis aligned box onto the plane |
| 148 | w = AllocWinding (4); |
| 149 | |
| 150 | VectorSubtract (org, vright, w->p[0]); |
| 151 | VectorAdd (w->p[0], vup, w->p[0]); |
| 152 | |
| 153 | VectorAdd (org, vright, w->p[1]); |
| 154 | VectorAdd (w->p[1], vup, w->p[1]); |
| 155 | |
| 156 | VectorAdd (org, vright, w->p[2]); |
| 157 | VectorSubtract (w->p[2], vup, w->p[2]); |
| 158 |
no test coverage detected