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

Function BuildMirroredRoomList

Descent3/render.cpp:2761–2866  ·  view source on GitHub ↗

Goes through and builds a list of rooms that can be seen from a mirror

Source from the content-addressed store, hash-verified

2759}
2760// Goes through and builds a list of rooms that can be seen from a mirror
2761void BuildMirroredRoomList() {
2762 room *rp = &Rooms[Mirror_room];
2763 clip_wnd wnd;
2764 Num_mirrored_rooms = 0;
2765 memset(Mirrored_room_checked, 0, MAX_ROOMS);
2766 Mirrored_room_checked[Mirror_room] = 1;
2767 Mirrored_room_list[Num_mirrored_rooms++] = Mirror_room;
2768
2769 // Initial clip window is whole screen
2770 wnd.left = wnd.top = 0.0;
2771 wnd.right = Render_width;
2772 wnd.bot = Render_height;
2773 g3Point portal_points[MAX_VERTS_PER_FACE], temp_points[MAX_VERTS_PER_FACE * 2];
2774 g3Point *pointlist[MAX_VERTS_PER_FACE * 2], **pl = pointlist;
2775 room *mirror_rp = &Rooms[Mirror_room];
2776 vector *mirror_vec = &mirror_rp->verts[mirror_rp->faces[mirror_rp->mirror_face].face_verts[0]];
2777 face *mirror_fp = &mirror_rp->faces[mirror_rp->mirror_face];
2778 vector *mirror_norm = &mirror_fp->normal;
2779 // This is how far the mirror face is from the normalized plane
2780 float mirror_dist =
2781 -(mirror_vec->x * mirror_norm->x + mirror_vec->y * mirror_norm->y + mirror_vec->z * mirror_norm->z);
2782 int total_points = 0;
2783 for (int t = 0; t < rp->num_mirror_faces; t++) {
2784 face *fp = &rp->faces[rp->mirror_faces_list[t]];
2785 int i;
2786 ASSERT(total_points + fp->num_verts <= MAX_VERTS_PER_FACE * 2);
2787 g3Codes cc;
2788 cc.cc_and = 0xff;
2789 cc.cc_or = 0;
2790 int nv = fp->num_verts;
2791 int clipped = 0;
2792
2793 for (i = 0; i < fp->num_verts; i++) {
2794 vector temp_vec;
2795 vector *vec = &rp->verts[fp->face_verts[i]];
2796 float dist_from_mirror =
2797 vec->x * mirror_norm->x + vec->y * mirror_norm->y + vec->z * mirror_norm->z + mirror_dist;
2798 // dest_vecs contains the point on the other side of the mirror (ie the reflected point)
2799 temp_vec = *vec - (*mirror_norm * (dist_from_mirror * 2));
2800 g3_RotatePoint(&portal_points[i], &temp_vec);
2801 cc.cc_and &= portal_points[i].p3_codes;
2802 cc.cc_or |= portal_points[i].p3_codes;
2803 pointlist[i] = &portal_points[i];
2804 }
2805
2806 // Clipped away
2807 if (cc.cc_and)
2808 continue;
2809 if (cc.cc_or) {
2810 // Must clip
2811 pl = g3_ClipPolygon(pl, &nv, &cc);
2812
2813 if (cc.cc_and) {
2814 g3_FreeTempPoints(pl, nv);
2815 continue;
2816 } else {
2817 for (i = 0; i < nv; i++) {
2818 temp_points[i + total_points] = *pl[i];

Callers 1

RenderMirrorRoomsFunction · 0.85

Calls 5

g3_RotatePointFunction · 0.85
g3_ClipPolygonFunction · 0.85
g3_FreeTempPointsFunction · 0.85
g3_ProjectPointFunction · 0.85
BuildMirroredRoomListSubFunction · 0.85

Tested by

no test coverage detected