MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / BuildMirroredRoomListSub

Function BuildMirroredRoomListSub

Descent3/render.cpp:2634–2759  ·  view source on GitHub ↗

Recursive function that mirrored rooms use

Source from the content-addressed store, hash-verified

2632}
2633// Recursive function that mirrored rooms use
2634void BuildMirroredRoomListSub(int start_room_num, clip_wnd *wnd) {
2635 room *rp = &Rooms[start_room_num];
2636 g3Point portal_points[MAX_VERTS_PER_FACE];
2637 int i, t;
2638 if (!Mirrored_room_checked[start_room_num]) {
2639 Mirrored_room_list[Num_mirrored_rooms++] = start_room_num;
2640 }
2641 Mirrored_room_checked[start_room_num] = 1;
2642
2643 // If this room is a closed (non-seethrough) door, don't check any of its portals,
2644 //...UNLESS this is the first room we're looking at (meaning the viewer is in this room)
2645 if ((rp->flags & RF_DOOR) && (DoorwayGetPosition(rp) == 0.0) &&
2646 !(Doors[rp->doorway_data->doornum].flags & DF_SEETHROUGH))
2647 return;
2648 room *mirror_rp = &Rooms[Mirror_room];
2649 vector *mirror_vec = &mirror_rp->verts[mirror_rp->faces[mirror_rp->mirror_face].face_verts[0]];
2650 face *mirror_fp = &mirror_rp->faces[mirror_rp->mirror_face];
2651 vector *mirror_norm = &mirror_fp->normal;
2652 // This is how far the mirror face is from the normalized plane
2653 float mirror_dist =
2654 -(mirror_vec->x * mirror_norm->x + mirror_vec->y * mirror_norm->y + mirror_vec->z * mirror_norm->z);
2655 // Check all the portals for this room
2656 for (t = 0; t < rp->num_portals; t++) {
2657 portal *pp = &rp->portals[t];
2658 int croom = pp->croom;
2659 ASSERT(croom >= 0);
2660 // If we are an external room portalizing into another external room, then skip!
2661 if ((rp->flags & RF_EXTERNAL) && (Rooms[croom].flags & RF_EXTERNAL))
2662 continue;
2663 // Check if we can see through this portal, and if not, skip it
2664 if (!RenderPastPortal(rp, pp))
2665 continue;
2666 // If this portal has been visited, skip it
2667 if (Mirrored_room_checked[croom])
2668 continue;
2669 // Deal with external portals differently
2670 int external_door_hack = 0;
2671 if (rp->flags & RF_EXTERNAL && Rooms[croom].flags & RF_DOOR)
2672 external_door_hack = 1;
2673 // Get pointer to this portal's face
2674 face *fp = &rp->faces[pp->portal_face];
2675 // See if portal is facing toward us
2676 if (!external_door_hack) {
2677 vector temp_vec;
2678 vector *vec = &rp->verts[fp->face_verts[0]];
2679 float dist_from_mirror =
2680 vec->x * mirror_norm->x + vec->y * mirror_norm->y + vec->z * mirror_norm->z + mirror_dist;
2681 // dest_vecs contains the point on the other side of the mirror (ie the reflected point)
2682 temp_vec = *vec - (*mirror_norm * (dist_from_mirror * 2));
2683 vector incident_norm;
2684 ReflectRay(&incident_norm, &fp->normal, &mirror_fp->normal);
2685
2686 vector tvec = Viewer_eye - temp_vec;
2687 if ((tvec * incident_norm) <= 0)
2688 continue; // not facing
2689 }
2690
2691 g3Codes cc;

Callers 1

BuildMirroredRoomListFunction · 0.85

Calls 7

RenderPastPortalFunction · 0.85
ReflectRayFunction · 0.85
g3_RotatePointFunction · 0.85
g3_ClipPolygonFunction · 0.85
g3_ProjectPointFunction · 0.85
clip2dFunction · 0.85
g3_FreeTempPointsFunction · 0.85

Tested by

no test coverage detected