| 266 | } |
| 267 | |
| 268 | void BoundingBoxProject( Vector3& min, Vector3& max, const Matrix& view, const Matrix& proj, const TriViewport& vp ) |
| 269 | { |
| 270 | Vector3 corners[8]; |
| 271 | |
| 272 | corners[0] = min; |
| 273 | |
| 274 | corners[1].x = min.x; |
| 275 | corners[1].y = min.y; |
| 276 | corners[1].z = max.z; |
| 277 | |
| 278 | corners[2].x = max.x; |
| 279 | corners[2].y = min.y; |
| 280 | corners[2].z = min.z; |
| 281 | |
| 282 | corners[3].x = max.x; |
| 283 | corners[3].y = min.y; |
| 284 | corners[3].z = max.z; |
| 285 | |
| 286 | corners[4] = max; |
| 287 | |
| 288 | corners[5].x = max.x; |
| 289 | corners[5].y = max.y; |
| 290 | corners[5].z = min.z; |
| 291 | |
| 292 | corners[6].x = min.x; |
| 293 | corners[6].y = max.y; |
| 294 | corners[6].z = max.z; |
| 295 | |
| 296 | corners[7].x = min.x; |
| 297 | corners[7].y = max.y; |
| 298 | corners[7].z = min.z; |
| 299 | |
| 300 | Matrix viewProj = view * proj; |
| 301 | for( int i = 0; i < 8; ++i ) |
| 302 | { |
| 303 | corners[i] = TransformCoord( corners[i], viewProj ); |
| 304 | Vec3TransformByViewport( corners[i], vp ); |
| 305 | } |
| 306 | |
| 307 | min = corners[0]; |
| 308 | max = corners[0]; |
| 309 | float* pMin = (float*)&min; |
| 310 | float* pMax = (float*)&max; |
| 311 | |
| 312 | for( int i = 1; i < 8; ++i ) |
| 313 | { |
| 314 | float* pCorner = (float*)&corners[i]; |
| 315 | |
| 316 | for( int component = 0; component < 3; ++component ) |
| 317 | { |
| 318 | if( pCorner[component] < pMin[component] ) |
| 319 | { |
| 320 | pMin[component] = pCorner[component]; |
| 321 | } |
| 322 | if( pCorner[component] > pMax[component] ) |
| 323 | { |
| 324 | pMax[component] = pCorner[component]; |
| 325 | } |
no test coverage detected