Renders a mirror flipped about the mirrored plane
| 2868 | g3Point mirror_save_points[MAX_VERTS_PER_ROOM]; |
| 2869 | // Renders a mirror flipped about the mirrored plane |
| 2870 | void RenderMirroredRoom(room *rp) { |
| 2871 | int i; |
| 2872 | #if (defined(RELEASE) && defined(KATMAI)) |
| 2873 | vector4 kat_vecs[MAX_VERTS_PER_ROOM]; |
| 2874 | #endif |
| 2875 | uint16_t save_flags[MAX_FACES_PER_ROOM]; |
| 2876 | bool restore_index = true; |
| 2877 | int save_index = Global_buffer_index; |
| 2878 | |
| 2879 | // Save old rotated points |
| 2880 | if (rp->wpb_index == -1) { |
| 2881 | restore_index = false; |
| 2882 | rp->wpb_index = Global_buffer_index; |
| 2883 | } else { |
| 2884 | for (i = 0; i < rp->num_verts; i++) |
| 2885 | mirror_save_points[i] = World_point_buffer[rp->wpb_index + i]; |
| 2886 | } |
| 2887 | |
| 2888 | // Find facing faces for this mirror |
| 2889 | face *fp = &rp->faces[0]; |
| 2890 | for (i = 0; i < rp->num_faces; i++, fp++) { |
| 2891 | save_flags[i] = fp->flags; |
| 2892 | fp->flags &= ~FF_NOT_FACING; |
| 2893 | fp->flags |= FF_VISIBLE; |
| 2894 | } |
| 2895 | room *mirror_rp = &Rooms[Mirror_room]; |
| 2896 | vector *mirror_vec = &mirror_rp->verts[mirror_rp->faces[mirror_rp->mirror_face].face_verts[0]]; |
| 2897 | face *mirror_fp = &mirror_rp->faces[mirror_rp->mirror_face]; |
| 2898 | vector *norm = &mirror_fp->normal; |
| 2899 | // This is how far the mirror face is from the normalized plane |
| 2900 | float mirror_dist = -(mirror_vec->x * norm->x + mirror_vec->y * norm->y + mirror_vec->z * norm->z); |
| 2901 | |
| 2902 | for (i = 0; i < rp->num_verts; i++) { |
| 2903 | vector *vec = &rp->verts[i]; |
| 2904 | float dist_from_mirror = vec->x * norm->x + vec->y * norm->y + vec->z * norm->z + mirror_dist; |
| 2905 | // dest_vecs contains the point on the other side of the mirror (ie the reflected point) |
| 2906 | mirror_dest_vecs[i] = *vec - (*norm * (dist_from_mirror * 2)); |
| 2907 | #if (defined(RELEASE) && defined(KATMAI)) |
| 2908 | if (Katmai) { |
| 2909 | kat_vecs[i].x = mirror_dest_vecs[i].x; |
| 2910 | kat_vecs[i].y = mirror_dest_vecs[i].y; |
| 2911 | kat_vecs[i].z = mirror_dest_vecs[i].z; |
| 2912 | } |
| 2913 | #endif |
| 2914 | } |
| 2915 | // Rotate our mirror points |
| 2916 | vector revnorm = -*norm; |
| 2917 | g3_SetCustomClipPlane(1, mirror_vec, &revnorm); |
| 2918 | |
| 2919 | // Katmai enhanced rotate only in a release build, because not |
| 2920 | // everyone has the intel compiler! |
| 2921 | #if (defined(RELEASE) && defined(KATMAI)) |
| 2922 | if (Katmai) |
| 2923 | RotateRoomPoints(rp, kat_vecs); |
| 2924 | else |
| 2925 | #endif |
| 2926 | RotateRoomPoints(rp, mirror_dest_vecs); |
| 2927 |
no test coverage detected