comparison stru10.cpp @ 1435:94e4c3ef9b8e

Слияние
author Ritor1
date Fri, 05 Jul 2013 21:16:12 +0600
parents 2ddb0af0f437
children a109bb203e28
comparison
equal deleted inserted replaced
1434:03d6ea33a8c9 1435:94e4c3ef9b8e
182 y_max = v46[i].y; 182 y_max = v46[i].y;
183 y_max_idx = v46[i].c; 183 y_max_idx = v46[i].c;
184 } 184 }
185 } 185 }
186 186
187
188
189 auto p1 = &pIndoor->pVertices[pFace->pVertexIDs[x_min_idx]];
190 RenderVertexSoft v1; // [sp+30Ch] [bp-54h]@24 187 RenderVertexSoft v1; // [sp+30Ch] [bp-54h]@24
191 v1.vWorldPosition.x = (float)p1->x; 188 v1.vWorldPosition.x = (float)pIndoor->pVertices[pFace->pVertexIDs[x_min_idx]].x;
192 v1.vWorldPosition.y = (float)p1->y; 189 v1.vWorldPosition.y = (float)pIndoor->pVertices[pFace->pVertexIDs[x_min_idx]].y;
193 v1.vWorldPosition.z = (float)p1->z; 190 v1.vWorldPosition.z = (float)pIndoor->pVertices[pFace->pVertexIDs[x_min_idx]].z;
194 memcpy(pOutVertices + 0, &v1, sizeof(RenderVertexSoft)); 191 memcpy(&pOutVertices[0], &v1, sizeof(RenderVertexSoft));
195 192
196 auto p2 = &pIndoor->pVertices[pFace->pVertexIDs[y_min_idx]];
197 RenderVertexSoft v2; // [sp+30Ch] [bp-54h]@24 193 RenderVertexSoft v2; // [sp+30Ch] [bp-54h]@24
198 v2.vWorldPosition.x = (float)p2->x; 194 v2.vWorldPosition.x = (float)pIndoor->pVertices[pFace->pVertexIDs[y_min_idx]].x;
199 v2.vWorldPosition.y = (float)p2->y; 195 v2.vWorldPosition.y = (float)pIndoor->pVertices[pFace->pVertexIDs[y_min_idx]].y;
200 v2.vWorldPosition.z = (float)p2->z; 196 v2.vWorldPosition.z = (float)pIndoor->pVertices[pFace->pVertexIDs[y_min_idx]].z;
201 memcpy(pOutVertices + 1, &v2, sizeof(RenderVertexSoft)); 197 memcpy(&pOutVertices[1], &v2, sizeof(RenderVertexSoft));
202 198
203 auto p3 = &pIndoor->pVertices[pFace->pVertexIDs[x_max_idx]];
204 RenderVertexSoft v3; // [sp+30Ch] [bp-54h]@24 199 RenderVertexSoft v3; // [sp+30Ch] [bp-54h]@24
205 v3.vWorldPosition.x = (float)p3->x; 200 v3.vWorldPosition.x = (float)pIndoor->pVertices[pFace->pVertexIDs[x_max_idx]].x;
206 v3.vWorldPosition.y = (float)p3->y; 201 v3.vWorldPosition.y = (float)pIndoor->pVertices[pFace->pVertexIDs[x_max_idx]].y;
207 v3.vWorldPosition.z = (float)p3->z; 202 v3.vWorldPosition.z = (float)pIndoor->pVertices[pFace->pVertexIDs[x_max_idx]].z;
208 memcpy(pOutVertices + 2, &v3, sizeof(RenderVertexSoft)); 203 memcpy(&pOutVertices[2], &v3, sizeof(RenderVertexSoft));
209 204
210 auto p4 = &pIndoor->pVertices[pFace->pVertexIDs[y_max_idx]];
211 RenderVertexSoft v4; // [sp+30Ch] [bp-54h]@24 205 RenderVertexSoft v4; // [sp+30Ch] [bp-54h]@24
212 v4.vWorldPosition.x = (double)p4->x; 206 v4.vWorldPosition.x = (double)pIndoor->pVertices[pFace->pVertexIDs[y_max_idx]].x;
213 v4.vWorldPosition.y = (double)p4->y; 207 v4.vWorldPosition.y = (double)pIndoor->pVertices[pFace->pVertexIDs[y_max_idx]].y;
214 v4.vWorldPosition.z = (double)p4->z; 208 v4.vWorldPosition.z = (double)pIndoor->pVertices[pFace->pVertexIDs[y_max_idx]].z;
215 memcpy(pOutVertices + 3, &v4, sizeof(RenderVertexSoft)); 209 memcpy(&pOutVertices[3], &v4, sizeof(RenderVertexSoft));
216 } 210 }
217 211
218 212
219 //----- (0049C9E3) -------------------------------------------------------- 213 //----- (0049C9E3) --------------------------------------------------------
220 bool stru10::CalcFaceBounding(BLVFace *pFace, RenderVertexSoft *pFaceLimits, unsigned int uNumVertices, RenderVertexSoft *pOutBounding) 214 bool stru10::CalcFaceBounding(BLVFace *pFace, RenderVertexSoft *pFaceLimits, unsigned int uNumVertices, RenderVertexSoft *pOutBounding)
257 float var_28; 251 float var_28;
258 float var_24; 252 float var_24;
259 switch (pFace->uPolygonType) 253 switch (pFace->uPolygonType)
260 { 254 {
261 case POLYGON_VerticalWall: 255 case POLYGON_VerticalWall:
262 a1.x = -pFace->pFacePlane.vNormal.y; 256 a1.x = -pFace->pFacePlane.vNormal.y;//
263 a1.y = pFace->pFacePlane.vNormal.x; 257 a1.y = pFace->pFacePlane.vNormal.x;
264 a1.z = 0.0f; 258 a1.z = 0.0f;
265 a1.Normalize(); 259 a1.Normalize();
266 260
267 var_28 = 0; 261 var_28 = 0;
298 a3 = face_center_x - pFaceLimits[0].vWorldPosition.x; 292 a3 = face_center_x - pFaceLimits[0].vWorldPosition.x;
299 var_8 = face_center_y - pFaceLimits[1].vWorldPosition.y; 293 var_8 = face_center_y - pFaceLimits[1].vWorldPosition.y;
300 } 294 }
301 if (pFace->uAttributes & 0x0200) 295 if (pFace->uAttributes & 0x0200)
302 { 296 {
303 face_center_x = (pFaceLimits[0].vWorldPosition.x + pFaceLimits[2].vWorldPosition.x) / 2; 297 face_center_x = (pFaceLimits[0].vWorldPosition.x + pFaceLimits[2].vWorldPosition.x) / 2;//
304 face_center_y = (pFaceLimits[0].vWorldPosition.y + pFaceLimits[2].vWorldPosition.y) / 2; 298 face_center_y = (pFaceLimits[0].vWorldPosition.y + pFaceLimits[2].vWorldPosition.y) / 2;
305 face_center_z = (pFaceLimits[1].vWorldPosition.z + pFaceLimits[3].vWorldPosition.z) / 2; 299 face_center_z = (pFaceLimits[1].vWorldPosition.z + pFaceLimits[3].vWorldPosition.z) / 2;
306 300
307 a3 = face_center_x - pFaceLimits[0].vWorldPosition.x; 301 a3 = face_center_x - pFaceLimits[0].vWorldPosition.x;//
308 var_8 = face_center_z - pFaceLimits[1].vWorldPosition.z; 302 var_8 = face_center_z - pFaceLimits[1].vWorldPosition.z;//
309 303
310 if (pFace->uPolygonType == POLYGON_VerticalWall) 304 if (pFace->uPolygonType == POLYGON_VerticalWall)
311 a3 /= a1.x; 305 a3 /= a1.x;
312 } 306 }
313 if (pFace->uAttributes & 0x0400) 307 if (pFace->uAttributes & 0x0400)
678 float _dp = (v25.vWorldPosition.x - pBLVRenderParams->vPartyPos.x) * a1.x + 672 float _dp = (v25.vWorldPosition.x - pBLVRenderParams->vPartyPos.x) * a1.x +
679 (v25.vWorldPosition.y - pBLVRenderParams->vPartyPos.y) * a1.y + 673 (v25.vWorldPosition.y - pBLVRenderParams->vPartyPos.y) * a1.y +
680 (v25.vWorldPosition.z - pBLVRenderParams->vPartyPos.z) * a1.z; 674 (v25.vWorldPosition.z - pBLVRenderParams->vPartyPos.z) * a1.z;
681 if (fabs(_dp) < 1e-6f) 675 if (fabs(_dp) < 1e-6f)
682 { 676 {
683 memcpy(&v25, pOutBounding + 1, sizeof(RenderVertexSoft)); 677 memcpy(&v25, &pOutBounding[1], sizeof(RenderVertexSoft));
684 memcpy(pOutBounding + 1, pOutBounding + 3, sizeof(RenderVertexSoft)); 678 memcpy(&pOutBounding[1], &pOutBounding[3], sizeof(RenderVertexSoft));
685 memcpy(pOutBounding + 3, &v25, sizeof(RenderVertexSoft)); 679 memcpy(&pOutBounding[3], &v25, sizeof(RenderVertexSoft));
686 } 680 }
687 681
688 //if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS) 682 //if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
689 //{ 683 //{
690 RenderVertexSoft v26; // [sp+40h] [bp-60h]@20 684 RenderVertexSoft v26; // [sp+40h] [bp-60h]@20
692 { 686 {
693 v26.vWorldPosition.x = pParty->vPosition.x; 687 v26.vWorldPosition.x = pParty->vPosition.x;
694 v26.vWorldPosition.y = pParty->vPosition.y; 688 v26.vWorldPosition.y = pParty->vPosition.y;
695 v26.vWorldPosition.z = pParty->vPosition.z + pParty->sEyelevel; // frustum 689 v26.vWorldPosition.z = pParty->vPosition.z + pParty->sEyelevel; // frustum
696 690
697 pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFF0000u, pOutBounding, 0xFF0000u, 0, 0); 691 pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFF0000u, &pOutBounding[0], 0xFF0000u, 0, 0);
698 pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFF00u, pOutBounding + 1, 0xFF00u, 0, 0); 692 pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFF00u, &pOutBounding[1], 0xFF00u, 0, 0);
699 pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFFu, pOutBounding + 2, 0xFFu, 0, 0); 693 pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFFu, &pOutBounding[2], 0xFFu, 0, 0);
700 pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFFFFFFu, pOutBounding + 3, 0xFFFFFFu, 0, 0); 694 pGame->pIndoorCameraD3D->do_draw_debug_line_sw(&v26, 0xFFFFFFu, &pOutBounding[3], 0xFFFFFFu, 0, 0);
701 bDoNotDrawPortalFrustum = true; 695 bDoNotDrawPortalFrustum = true;
702 } 696 }
703 pGame->pIndoorCameraD3D->debug_outline_sw(pOutBounding, uNumVertices, 0x1EFF1Eu, 0.00019999999); // bounding 697 pGame->pIndoorCameraD3D->debug_outline_sw(pOutBounding, uNumVertices, 0x1EFF1Eu, 0.00019999999); // bounding
704 //} 698 //}
705 699
765 return false; 759 return false;
766 } 760 }
767 // 4D864C: using guessed type char byte_4D864C; 761 // 4D864C: using guessed type char byte_4D864C;
768 762
769 //----- (0049C681) -------------------------------------------------------- 763 //----- (0049C681) --------------------------------------------------------
770 bool stru10::CalcPortalShape(BLVFace *pFace, IndoorCameraD3D_Vec4 *a3, RenderVertexSoft *pOutBounding) 764 bool stru10::CalcPortalShape(BLVFace *pFace, IndoorCameraD3D_Vec4 *pPortalDataFrustum, RenderVertexSoft *pOutBounding)
771 { 765 {
772 RenderVertexSoft pLimits[4]; // [sp+Ch] [bp-C0h]@1 766 RenderVertexSoft pLimits[4]; // [sp+Ch] [bp-C0h]@1
773 767
774 CalcPolygonLimits(pFace, pLimits); 768 CalcPolygonLimits(pFace, pLimits);//
775 //if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS) 769 //if ( byte_4D864C && pGame->uFlags & GAME_FLAGS_1_DRAW_BLV_DEBUGS)
776 // pGame->pIndoorCameraD3D->debug_outline_sw(pLimits, 4, 0xFF1E1E, 0.000099999997); 770 // pGame->pIndoorCameraD3D->debug_outline_sw(pLimits, 4, 0xFF1E1E, 0.000099999997);
777 if (CalcFaceBounding(pFace, pLimits, 4, pOutBounding)) 771 if (CalcFaceBounding(pFace, pLimits, 4, pOutBounding))
778 return _49C720(pOutBounding, a3) != 0; 772 return _49C720(pOutBounding, pPortalDataFrustum) != 0;
779 return false; 773 return false;
780 } 774 }
775
781 // 4D864C: using guessed type char byte_4D864C; 776 // 4D864C: using guessed type char byte_4D864C;
782 777
783 //----- (0049C720) -------------------------------------------------------- 778 //----- (0049C720) --------------------------------------------------------
784 char stru10::_49C720(RenderVertexSoft *pFaceBounding, IndoorCameraD3D_Vec4 *a4) 779 char stru10::_49C720(RenderVertexSoft *pFaceBounding, IndoorCameraD3D_Vec4 *pPortalDataFrustum)
785 { 780 {
786 Vec3_float_ a3; // [sp+4h] [bp-34h]@1 781 Vec3_float_ pRayStart; // [sp+4h] [bp-34h]@1
787 a3.x = (double)pBLVRenderParams->vPartyPos.x; 782 pRayStart.x = (double)pBLVRenderParams->vPartyPos.x;
788 a3.y = (double)pBLVRenderParams->vPartyPos.y; 783 pRayStart.y = (double)pBLVRenderParams->vPartyPos.y;
789 a3.z = (double)pBLVRenderParams->vPartyPos.z; 784 pRayStart.z = (double)pBLVRenderParams->vPartyPos.z;
790 785
791 if (FindFaceNormal(pFaceBounding, pFaceBounding + 1, &a3, a4) && 786 if (FindFaceNormal(&pFaceBounding[0], &pFaceBounding[1], &pRayStart, &pPortalDataFrustum[0]) &&
792 FindFaceNormal(pFaceBounding + 1, pFaceBounding + 2, &a3, a4 + 1) && 787 FindFaceNormal(&pFaceBounding[1], &pFaceBounding[2], &pRayStart, &pPortalDataFrustum[1]) &&
793 FindFaceNormal(pFaceBounding + 2, pFaceBounding + 3, &a3, a4 + 2) && 788 FindFaceNormal(&pFaceBounding[2], &pFaceBounding[3], &pRayStart, &pPortalDataFrustum[2]) &&
794 FindFaceNormal(pFaceBounding + 3, pFaceBounding, &a3, a4 + 3)) 789 FindFaceNormal(&pFaceBounding[3], &pFaceBounding[0], &pRayStart, &pPortalDataFrustum[3]))
795 return true; 790 return true;
796 return false; 791 return false;
797 } 792 }
798 793
799 //----- (0049C7C5) -------------------------------------------------------- 794 //----- (0049C7C5) --------------------------------------------------------
800 bool stru10::FindFaceNormal(RenderVertexSoft *a1, RenderVertexSoft *a2, Vec3_float_ *a3, IndoorCameraD3D_Vec4 *a4) 795 bool stru10::FindFaceNormal(RenderVertexSoft *pFaceBounding1, RenderVertexSoft *pFaceBounding2, Vec3_float_ *pRayStart, IndoorCameraD3D_Vec4 *pPortalDataFrustum)
801 { 796 {
802 Vec3_float_ v1; // [sp+4h] [bp-48h]@1 797 Vec3_float_ ray_dir; // [sp+4h] [bp-48h]@1
803 Vec3_float_ v2; // [sp+10h] [bp-3Ch]@1 798 Vec3_float_ pRay2; // [sp+10h] [bp-3Ch]@1
804 799
805 v1.x = a1->vWorldPosition.x - a3->x; 800 ray_dir.x = pFaceBounding1->vWorldPosition.x - pRayStart->x;//get ray for cmera to bounding1
806 v1.y = a1->vWorldPosition.y - a3->y; 801 ray_dir.y = pFaceBounding1->vWorldPosition.y - pRayStart->y;
807 v1.z = a1->vWorldPosition.z - a3->z; 802 ray_dir.z = pFaceBounding1->vWorldPosition.z - pRayStart->z;
808 Vec3_float_::Cross(&v1, &v2, a2->vWorldPosition.x - a1->vWorldPosition.x, 803 Vec3_float_::Cross(&ray_dir, &pRay2, pFaceBounding2->vWorldPosition.x - pFaceBounding1->vWorldPosition.x,
809 a2->vWorldPosition.y - a1->vWorldPosition.y, 804 pFaceBounding2->vWorldPosition.y - pFaceBounding1->vWorldPosition.y,
810 a2->vWorldPosition.z - a1->vWorldPosition.z); 805 pFaceBounding2->vWorldPosition.z - pFaceBounding1->vWorldPosition.z);
811 806
812 float sqr_mag = v2.x * v2.x + v2.y * v2.y + v2.z * v2.z; 807 float sqr_mag = pRay2.x * pRay2.x + pRay2.y * pRay2.y + pRay2.z * pRay2.z;
813 if (fabsf(sqr_mag) > 1e-6f) 808 if (fabsf(sqr_mag) > 1e-6f)
814 { 809 {
815 float inv_mag = 1.0f / sqrtf(sqr_mag); 810 float inv_mag = 1.0f / sqrtf(sqr_mag);
816 v2.x *= inv_mag; 811 pRay2.x *= inv_mag;
817 v2.y *= inv_mag; 812 pRay2.y *= inv_mag;
818 v2.z *= inv_mag; 813 pRay2.z *= inv_mag;
819 //v2.Normalize(); 814 pRay2.Normalize();
820 815
821 a4->x = v2.x; 816 pPortalDataFrustum->x = pRay2.x;
822 a4->y = v2.y; 817 pPortalDataFrustum->y = pRay2.y;
823 a4->z = v2.z; 818 pPortalDataFrustum->z = pRay2.z;
824 a4->dot = a3->z * v2.z + a3->y * v2.y + a3->x * v2.x; 819 pPortalDataFrustum->dot = pRayStart->z * pRay2.z + pRayStart->y * pRay2.y + pRayStart->x * pRay2.x;
825 return true; 820 return true;
826 } 821 }
827 return false; 822 return false;
828 } 823 }
829 824