Connects two rooms in a pleasing way
| 2462 | |
| 2463 | // Connects two rooms in a pleasing way |
| 2464 | void BuildSmoothBridge(room *rp0, int facenum0, room *rp1, int facenum1) { |
| 2465 | room *rp; |
| 2466 | int nv0, nv1, nverts, nfaces; |
| 2467 | int i; |
| 2468 | vector tverts[MAX_VERTS_PER_FACE]; |
| 2469 | |
| 2470 | // Get values from current faces |
| 2471 | face *fp0 = &rp0->faces[facenum0]; |
| 2472 | face *fp1 = &rp1->faces[facenum1]; |
| 2473 | nv0 = fp0->num_verts; |
| 2474 | nv1 = fp1->num_verts; |
| 2475 | |
| 2476 | // Check for portal already here |
| 2477 | if (fp0->portal_num != -1) { |
| 2478 | OutrageMessageBox("Cannot build bridge: There is already a connection at %d:%d.", ROOMNUM(rp0), facenum0); |
| 2479 | return; |
| 2480 | } |
| 2481 | if (fp1->portal_num != -1) { |
| 2482 | OutrageMessageBox("Cannot build bridge: There is already a connection at %d:%d.", ROOMNUM(rp1), facenum1); |
| 2483 | return; |
| 2484 | } |
| 2485 | |
| 2486 | // Get values for new room |
| 2487 | nverts = nv0 + nv1; |
| 2488 | nfaces = nverts + 2; |
| 2489 | |
| 2490 | // Get a pointer to our room |
| 2491 | rp = CreateNewRoom(nverts, nfaces); |
| 2492 | if (rp == NULL) { |
| 2493 | OutrageMessageBox("Cannot build bridge: No free rooms."); |
| 2494 | return; |
| 2495 | } |
| 2496 | |
| 2497 | // Set the vertices for the room |
| 2498 | for (i = 0; i < nv0; i++) |
| 2499 | rp->verts[i] = rp0->verts[fp0->face_verts[i]]; |
| 2500 | for (i = 0; i < nv1; i++) |
| 2501 | rp->verts[nv0 + i] = rp1->verts[fp1->face_verts[nv1 - 1 - i]]; |
| 2502 | |
| 2503 | // Create the connecting faces |
| 2504 | |
| 2505 | // Compute normalized vector from attach face to base face |
| 2506 | vector c0, c1, delta_vec; |
| 2507 | #ifndef NEWEDITOR |
| 2508 | ComputeCenterPointOnFace(&c0, rp0, facenum0); |
| 2509 | ComputeCenterPointOnFace(&c1, rp1, facenum1); |
| 2510 | #else |
| 2511 | ComputeFaceBoundingCircle(&c0, rp0, facenum0); |
| 2512 | ComputeFaceBoundingCircle(&c1, rp1, facenum1); |
| 2513 | #endif |
| 2514 | vm_GetNormalizedDir(&delta_vec, &c1, &c0); |
| 2515 | |
| 2516 | // Compute the cosine of the angle between our vector and the normal of the base face |
| 2517 | float cos = delta_vec * fp1->normal; |
| 2518 | |
| 2519 | // Get a pointer to a vertex on face1 |
| 2520 | vector *vp = &rp->verts[nv0]; |
| 2521 |
no test coverage detected