================== CM_FindPlane ================== */
| 531 | ================== |
| 532 | */ |
| 533 | static int CM_FindPlane( float *p1, float *p2, float *p3 ) { |
| 534 | float plane[4]; |
| 535 | int i; |
| 536 | float d; |
| 537 | |
| 538 | if ( !CM_PlaneFromPoints( plane, p1, p2, p3 ) ) { |
| 539 | return -1; |
| 540 | } |
| 541 | |
| 542 | // see if the points are close enough to an existing plane |
| 543 | for ( i = 0 ; i < numPlanes ; i++ ) { |
| 544 | if ( DotProduct( plane, planes[i].plane ) < 0 ) { |
| 545 | continue; // allow backwards planes? |
| 546 | } |
| 547 | |
| 548 | d = DotProduct( p1, planes[i].plane ) - planes[i].plane[3]; |
| 549 | if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON ) { |
| 550 | continue; |
| 551 | } |
| 552 | |
| 553 | d = DotProduct( p2, planes[i].plane ) - planes[i].plane[3]; |
| 554 | if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON ) { |
| 555 | continue; |
| 556 | } |
| 557 | |
| 558 | d = DotProduct( p3, planes[i].plane ) - planes[i].plane[3]; |
| 559 | if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON ) { |
| 560 | continue; |
| 561 | } |
| 562 | |
| 563 | // found it |
| 564 | return i; |
| 565 | } |
| 566 | |
| 567 | // add a new plane |
| 568 | if ( numPlanes == MAX_PATCH_PLANES ) { |
| 569 | Com_Error( ERR_DROP, "MAX_PATCH_PLANES" ); |
| 570 | } |
| 571 | |
| 572 | VectorCopy4( plane, planes[numPlanes].plane ); |
| 573 | planes[numPlanes].signbits = CM_SignbitsForNormal( plane ); |
| 574 | |
| 575 | numPlanes++; |
| 576 | |
| 577 | return numPlanes-1; |
| 578 | } |
| 579 | |
| 580 | |
| 581 | /* |
no test coverage detected