comparison Vis.cpp @ 1050:4b329bf2d197

intersect_face_vertex_coords_list
author Ritor1
date Thu, 23 May 2013 16:36:08 +0600
parents efe228ab5003
children 05c62d166182 958c7372f2d4
comparison
equal deleted inserted replaced
1049:efe228ab5003 1050:4b329bf2d197
367 continue; 367 continue;
368 368
369 auto bmodel = &pOutdoor->pBModels[i]; 369 auto bmodel = &pOutdoor->pBModels[i];
370 for (uint j = 0; j < bmodel->uNumFaces; ++j) 370 for (uint j = 0; j < bmodel->uNumFaces; ++j)
371 { 371 {
372 //if ( i == 1 && j == 30 )//
373 //__debugbreak();//
372 auto face = &bmodel->pFaces[j]; 374 auto face = &bmodel->pFaces[j];
373 if (is_part_of_selection(face, filter)) 375 if (is_part_of_selection(face, filter))
374 { 376 {
375 BLVFace blv_face; 377 BLVFace blv_face;
376 blv_face.FromODM(face); 378 blv_face.FromODM(face);
586 588
587 IntersectPoint.x = (signed __int64)Intersection->vWorldPosition.x; 589 IntersectPoint.x = (signed __int64)Intersection->vWorldPosition.x;
588 IntersectPoint.y = (signed __int64)Intersection->vWorldPosition.y; 590 IntersectPoint.y = (signed __int64)Intersection->vWorldPosition.y;
589 IntersectPoint.z = (signed __int64)Intersection->vWorldPosition.z; 591 IntersectPoint.z = (signed __int64)Intersection->vWorldPosition.z;
590 592
591 if ( !IntersectBModel_sub(pFace, IntersectPoint, pBModelID) ) 593 if ( !CheckIntersectBModel(pFace, IntersectPoint, pBModelID) )
592 return false; 594 return false;
593 595
594 *pDepth = t;//Record the distance from the origin of the ray (Записываем дистанцию от начала луча) 596 *pDepth = t;//Record the distance from the origin of the ray (Записываем дистанцию от начала луча)
595 return true; 597 return true;
596 } 598 }
597 599
598 //----- (004C1D2B) -------------------------------------------------------- 600 //----- (004C1D2B) --------------------------------------------------------
599 bool Vis::IntersectBModel_sub(BLVFace *pFace, Vec3_short_ IntersectPoint, unsigned int uModelID) 601 bool Vis::CheckIntersectBModel(BLVFace *pFace, Vec3_short_ IntersectPoint, unsigned int uModelID)
600 { 602 {
601 int v5; // esi@10 603 int v5; // esi@10
602 bool v6; // edi@10 604 bool v6; // edi@10
603 signed int v10; // ebx@14 605 signed int v10; // ebx@14
604 int v11; // edi@16 606 int v11; // edi@16
606 signed __int64 v13; // qtt@18 608 signed __int64 v13; // qtt@18
607 signed int result; // eax@21 609 signed int result; // eax@21
608 int v15; // [sp+10h] [bp-Ch]@10 610 int v15; // [sp+10h] [bp-Ch]@10
609 signed int v16; // [sp+18h] [bp-4h]@10 611 signed int v16; // [sp+18h] [bp-4h]@10
610 612
611 int a1 = 0, a2 = 0; 613 int a = 0, b = 0;
612 614
613 if (IntersectPoint.x < pFace->pBounding.x1 || IntersectPoint.x > pFace->pBounding.x2 || 615 if (IntersectPoint.x < pFace->pBounding.x1 || IntersectPoint.x > pFace->pBounding.x2 ||
614 IntersectPoint.y < pFace->pBounding.y1 || IntersectPoint.y > pFace->pBounding.y2 || 616 IntersectPoint.y < pFace->pBounding.y1 || IntersectPoint.y > pFace->pBounding.y2 ||
615 IntersectPoint.z < pFace->pBounding.z1 || IntersectPoint.z > pFace->pBounding.z2 ) 617 IntersectPoint.z < pFace->pBounding.z1 || IntersectPoint.z > pFace->pBounding.z2 )
616 return false; 618 return false;
617 619
618 pFace->uAttributes |= 0x80000000; 620 pFace->uAttributes |= 0x80000000;
619 621
620 if (uModelID != -1) 622 if (uModelID != -1)
621 ODM_IntersectBModel(&a1, &a2, word_F8BC48_displaced_face_intersect_plane_coords_a, word_F8BD18_displaced_face_intersect_plane_coords_b, 623 ODM_CreateIntersectFacesVertexCoordList(&a, &b, intersect_face_vertex_coords_list_a, intersect_face_vertex_coords_list_b,
622 &IntersectPoint, pFace, uModelID); 624 &IntersectPoint, pFace, uModelID);
623 else 625 else
624 BLV_IntersectBModel(&a1, &a2, word_F8BC48_displaced_face_intersect_plane_coords_a, word_F8BD18_displaced_face_intersect_plane_coords_b, 626 BLV_CreateIntersectFacesVertexCoordList(&a, &b, intersect_face_vertex_coords_list_a, intersect_face_vertex_coords_list_b,
625 &IntersectPoint, pFace); 627 &IntersectPoint, pFace);
626 v5 = 2 * pFace->uNumVertices; 628 v5 = 2 * pFace->uNumVertices;
627 v16 = 0; 629 v16 = 0;
628 word_F8BC48_displaced_face_intersect_plane_coords_a[v5] = word_F8BC48_displaced_face_intersect_plane_coords_a[0]; 630 intersect_face_vertex_coords_list_a[v5] = intersect_face_vertex_coords_list_a[0];
629 word_F8BD18_displaced_face_intersect_plane_coords_b[v5] = word_F8BD18_displaced_face_intersect_plane_coords_b[0]; 631 intersect_face_vertex_coords_list_b[v5] = intersect_face_vertex_coords_list_b[0];
630 v6 = word_F8BD18_displaced_face_intersect_plane_coords_b[0] >= a2; 632 v6 = intersect_face_vertex_coords_list_b[0] >= b;
631 if (v5 <= 0) 633 if (v5 <= 0)
632 return false; 634 return false;
633 for ( uint i = 0; i < v5; ++i ) 635 for ( uint i = 0; i < v5; ++i )
634 { 636 {
635 if ( v16 >= 2 ) 637 if ( v16 >= 2 )
636 break; 638 break;
637 if ( v6 ^ word_F8BD18_displaced_face_intersect_plane_coords_b[i + 1] >= a2 ) 639 if ( v6 ^ intersect_face_vertex_coords_list_b[i + 1] >= b )
638 { 640 {
639 if ( word_F8BC48_displaced_face_intersect_plane_coords_a[i + 1] >= a1 ) 641 if ( intersect_face_vertex_coords_list_a[i + 1] >= a )
640 v10 = 0; 642 v10 = 0;
641 else 643 else
642 v10 = 2; 644 v10 = 2;
643 v11 = v10 | word_F8BC48_displaced_face_intersect_plane_coords_a[i] < a1; 645 v11 = v10 | intersect_face_vertex_coords_list_a[i] < a;
644 if ( v11 != 3 ) 646 if ( v11 != 3 )
645 { 647 {
646 if ( !v11 648 if ( !v11
647 || (v12 = word_F8BC48_displaced_face_intersect_plane_coords_a[i + 1] - word_F8BC48_displaced_face_intersect_plane_coords_a[i], 649 || (v12 = intersect_face_vertex_coords_list_a[i + 1] - intersect_face_vertex_coords_list_a[i],
648 LODWORD(v13) = v12 << 16, 650 LODWORD(v13) = v12 << 16,
649 HIDWORD(v13) = v12 >> 16, 651 HIDWORD(v13) = v12 >> 16,
650 word_F8BC48_displaced_face_intersect_plane_coords_a[i] 652 intersect_face_vertex_coords_list_a[i]
651 + ((signed int)(((unsigned __int64)(v13 / (word_F8BD18_displaced_face_intersect_plane_coords_b[i + 1] - word_F8BD18_displaced_face_intersect_plane_coords_b[i]) 653 + ((signed int)(((unsigned __int64)(v13 / (intersect_face_vertex_coords_list_b[i + 1] - intersect_face_vertex_coords_list_b[i])
652 * (signed int)((a2 - word_F8BD18_displaced_face_intersect_plane_coords_b[i]) << 16)) >> 16) + 32768) >> 16) >= a1) ) 654 * (signed int)((b - intersect_face_vertex_coords_list_b[i]) << 16)) >> 16) + 32768) >> 16) >= a) )
653 ++v16; 655 ++v16;
654 } 656 }
655 } 657 }
656 v6 = word_F8BD18_displaced_face_intersect_plane_coords_b[i + 1] >= a2; 658 v6 = intersect_face_vertex_coords_list_b[i + 1] >= b;
657 } 659 }
658 result = 1; 660 result = true;
659 if ( v16 != 1 ) 661 if ( v16 != 1 )
660 result = 0; 662 result = false;
661 return result; 663 return result;
662 } 664 }
663 665
664 //----- (004C1EE5) -------------------------------------------------------- 666 //----- (004C1EE5) --------------------------------------------------------
665 bool Vis::BLV_IntersectBModel(int *a1, int *a2, __int16 *displaced_face_intersect_plane_coords_a, __int16 *displaced_face_intersect_plane_coords_b, Vec3_short_ *IntersectPoint, BLVFace *pFace) 667 void Vis::BLV_CreateIntersectFacesVertexCoordList(int *a, int *b, __int16 *intersect_face_vertex_coords_list_a, __int16 *intersect_face_vertex_coords_list_b, Vec3_short_ *IntersectPoint, BLVFace *pFace)
666 { 668 {
667 if (pFace->uAttributes & FACE_XY_PLANE) 669 if (pFace->uAttributes & FACE_XY_PLANE)
668 { 670 {
669 *a1 = IntersectPoint->x; 671 *a = IntersectPoint->x;
670 *a2 = IntersectPoint->y; 672 *b = IntersectPoint->y;
671 673
672 for (uint i = 0; i < pFace->uNumVertices; ++i) 674 for (uint i = 0; i < pFace->uNumVertices; ++i)
673 { 675 {
674 displaced_face_intersect_plane_coords_a[2 * i] = pFace->pXInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].x; 676 intersect_face_vertex_coords_list_a[2 * i] = pFace->pXInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].x;
675 displaced_face_intersect_plane_coords_a[2 * i + 1] = pFace->pXInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].x; 677 intersect_face_vertex_coords_list_a[2 * i + 1] = pFace->pXInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].x;
676 678
677 displaced_face_intersect_plane_coords_b[2 * i] = pFace->pYInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].y; 679 intersect_face_vertex_coords_list_b[2 * i] = pFace->pYInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].y;
678 displaced_face_intersect_plane_coords_b[2 * i + 1] = pFace->pYInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].y; 680 intersect_face_vertex_coords_list_b[2 * i + 1] = pFace->pYInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].y;
679 } 681 }
680 } 682 }
681 else if (pFace->uAttributes & FACE_XZ_PLANE) 683 else if (pFace->uAttributes & FACE_XZ_PLANE)
682 { 684 {
683 *a1 = IntersectPoint->x; 685 *a = IntersectPoint->x;
684 *a2 = IntersectPoint->z; 686 *b = IntersectPoint->z;
685 687
686 for (uint i = 0; i < pFace->uNumVertices; ++i) 688 for (uint i = 0; i < pFace->uNumVertices; ++i)
687 { 689 {
688 displaced_face_intersect_plane_coords_a[2 * i] = pFace->pXInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].x; 690 intersect_face_vertex_coords_list_a[2 * i] = pFace->pXInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].x;
689 displaced_face_intersect_plane_coords_a[2 * i + 1] = pFace->pXInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].x; 691 intersect_face_vertex_coords_list_a[2 * i + 1] = pFace->pXInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].x;
690 692
691 displaced_face_intersect_plane_coords_b[2 * i] = pFace->pZInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].z; 693 intersect_face_vertex_coords_list_b[2 * i] = pFace->pZInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].z;
692 displaced_face_intersect_plane_coords_b[2 * i + 1] = pFace->pZInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].z; 694 intersect_face_vertex_coords_list_b[2 * i + 1] = pFace->pZInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].z;
693 } 695 }
694 } 696 }
695 else if (pFace->uAttributes & FACE_YZ_PLANE) 697 else if (pFace->uAttributes & FACE_YZ_PLANE)
696 { 698 {
697 *a1 = IntersectPoint->y; 699 *a = IntersectPoint->y;
698 *a2 = IntersectPoint->z; 700 *b = IntersectPoint->z;
699 701
700 for (uint i = 0; i < pFace->uNumVertices; ++i) 702 for (uint i = 0; i < pFace->uNumVertices; ++i)
701 { 703 {
702 displaced_face_intersect_plane_coords_a[2 * i] = pFace->pYInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].y; 704 intersect_face_vertex_coords_list_a[2 * i] = pFace->pYInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].y;
703 displaced_face_intersect_plane_coords_a[2 * i + 1] = pFace->pYInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].y; 705 intersect_face_vertex_coords_list_a[2 * i + 1] = pFace->pYInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].y;
704 706
705 displaced_face_intersect_plane_coords_b[2 * i] = pFace->pZInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].z; 707 intersect_face_vertex_coords_list_b[2 * i] = pFace->pZInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].z;
706 displaced_face_intersect_plane_coords_b[2 * i + 1] = pFace->pZInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].z; 708 intersect_face_vertex_coords_list_b[2 * i + 1] = pFace->pZInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].z;
707 } 709 }
708 } 710 }
709 else 711 else assert(false);
710 {
711 assert(false);
712 return false;
713 }
714
715 return true;
716 } 712 }
717 713
718 //----- (004C2186) -------------------------------------------------------- 714 //----- (004C2186) --------------------------------------------------------
719 bool Vis::ODM_IntersectBModel(int *a1, int *a2, __int16 *displaced_face_intersect_plane_coords_a, __int16 *displaced_face_intersect_plane_coords_b, Vec3_short_ *IntersectPoint, BLVFace *pFace, unsigned int uModelID) 715 void Vis::ODM_CreateIntersectFacesVertexCoordList(int *a, int *b, __int16 *intersect_face_vertex_coords_list_a, __int16 *intersect_face_vertex_coords_list_b, Vec3_short_ *IntersectPoint, BLVFace *pFace, unsigned int uModelID)
720 { 716 {
721 if (pFace->uAttributes & FACE_XY_PLANE) 717 if (pFace->uAttributes & FACE_XY_PLANE)
722 { 718 {
723 *a1 = IntersectPoint->x; 719 *a = IntersectPoint->x;
724 *a2 = IntersectPoint->y; 720 *b = IntersectPoint->y;
725 721
726 for (int i = 0; i < pFace->uNumVertices; ++i) 722 for (int i = 0; i < pFace->uNumVertices; ++i)
727 { 723 {
728 displaced_face_intersect_plane_coords_a[2 * i] = pFace->pXInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].x; 724 intersect_face_vertex_coords_list_a[2 * i] = pFace->pXInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].x;
729 displaced_face_intersect_plane_coords_a[i * 2 + 1] = pFace->pXInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].x; 725 intersect_face_vertex_coords_list_a[i * 2 + 1] = pFace->pXInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].x;
730 726
731 displaced_face_intersect_plane_coords_b[2 * i] = pFace->pYInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].y; 727 intersect_face_vertex_coords_list_b[2 * i] = pFace->pYInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].y;
732 displaced_face_intersect_plane_coords_b[i * 2 + 1] = pFace->pYInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].y; 728 intersect_face_vertex_coords_list_b[i * 2 + 1] = pFace->pYInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].y;
733 } 729 }
734 } 730 }
735 else if (pFace->uAttributes & FACE_XZ_PLANE) 731 else if (pFace->uAttributes & FACE_XZ_PLANE)
736 { 732 {
737 *a1 = IntersectPoint->x; 733 *a = IntersectPoint->x;
738 *a2 = IntersectPoint->z; 734 *b = IntersectPoint->z;
739 735
740 for (int i = 0; i < pFace->uNumVertices; ++i) 736 for (int i = 0; i < pFace->uNumVertices; ++i)
741 { 737 {
742 displaced_face_intersect_plane_coords_a[2 * i] = pFace->pXInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].x; 738 intersect_face_vertex_coords_list_a[2 * i] = pFace->pXInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].x;
743 displaced_face_intersect_plane_coords_a[i * 2 + 1] = pFace->pXInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].x; 739 intersect_face_vertex_coords_list_a[i * 2 + 1] = pFace->pXInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].x;
744 740
745 displaced_face_intersect_plane_coords_b[2 * i] = pFace->pZInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].z; 741 intersect_face_vertex_coords_list_b[2 * i] = pFace->pZInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].z;
746 displaced_face_intersect_plane_coords_b[i * 2 + 1] = pFace->pZInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].z; 742 intersect_face_vertex_coords_list_b[i * 2 + 1] = pFace->pZInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].z;
747 } 743 }
748 } 744 }
749 else if (pFace->uAttributes & FACE_YZ_PLANE) 745 else if (pFace->uAttributes & FACE_YZ_PLANE)
750 { 746 {
751 *a1 = IntersectPoint->y; 747 *a = IntersectPoint->y;
752 *a2 = IntersectPoint->z; 748 *b = IntersectPoint->z;
753 749
754 for (int i = 0; i < pFace->uNumVertices; ++i) 750 for (int i = 0; i < pFace->uNumVertices; ++i)
755 { 751 {
756 displaced_face_intersect_plane_coords_a[2 * i] = pFace->pYInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].y; 752 intersect_face_vertex_coords_list_a[2 * i] = pFace->pYInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].y;
757 displaced_face_intersect_plane_coords_a[i * 2 + 1] = pFace->pYInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].y; 753 intersect_face_vertex_coords_list_a[i * 2 + 1] = pFace->pYInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].y;
758 754
759 displaced_face_intersect_plane_coords_b[2 * i] = pFace->pZInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].z; 755 intersect_face_vertex_coords_list_b[2 * i] = pFace->pZInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].z;
760 displaced_face_intersect_plane_coords_b[i * 2 + 1] = pFace->pZInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].z; 756 intersect_face_vertex_coords_list_b[i * 2 + 1] = pFace->pZInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].z;
761 } 757 }
762 } 758 }
763 else assert(false); 759 else assert(false);
764
765 return true;
766 } 760 }
767 761
768 //----- (0046A0A1) -------------------------------------------------------- 762 //----- (0046A0A1) --------------------------------------------------------
769 int UnprojectX(int x) 763 int UnprojectX(int x)
770 { 764 {