@@ -726,12 +726,45 @@ compute_planar_bounds(const LPoint2 ¢er, PN_stdfloat point_dist, PN_stdfloat
726726 }
727727 }
728728 }
729-
730- PT (BoundingHexahedron) bounds = new BoundingHexahedron
731- (LPoint3 (min_x, min_y, min_z), LPoint3 (max_x, min_y, min_z),
732- LPoint3 (min_x, min_y, max_z), LPoint3 (max_x, min_y, max_z),
733- LPoint3 (min_x, max_y, min_z), LPoint3 (max_x, max_y, min_z),
734- LPoint3 (min_x, max_y, max_z), LPoint3 (max_x, max_y, max_z));
729+
730+ PT (BoundingHexahedron) bounds;
731+
732+ // We create a BoundingHexahedron with the points in a particular
733+ // well-defined order, based on the current coordinate system.
734+ CoordinateSystem cs = get_default_coordinate_system ();
735+ switch (cs) {
736+ case CS_yup_right:
737+ bounds = new BoundingHexahedron
738+ (LPoint3 (min_x, min_y, min_z), LPoint3 (max_x, min_y, min_z),
739+ LPoint3 (min_x, max_y, min_z), LPoint3 (max_x, max_y, min_z),
740+ LPoint3 (min_x, min_y, max_z), LPoint3 (max_x, min_y, max_z),
741+ LPoint3 (min_x, max_y, max_z), LPoint3 (max_x, max_y, max_z));
742+ break ;
743+
744+ case CS_zup_right:
745+ bounds = new BoundingHexahedron
746+ (LPoint3 (min_x, min_y, min_z), LPoint3 (max_x, min_y, min_z),
747+ LPoint3 (min_x, min_y, max_z), LPoint3 (max_x, min_y, max_z),
748+ LPoint3 (min_x, max_y, min_z), LPoint3 (max_x, max_y, min_z),
749+ LPoint3 (min_x, max_y, max_z), LPoint3 (max_x, max_y, max_z));
750+ break ;
751+
752+ case CS_yup_left:
753+ bounds = new BoundingHexahedron
754+ (LPoint3 (max_x, min_y, max_z), LPoint3 (min_x, min_y, max_z),
755+ LPoint3 (max_x, max_y, max_z), LPoint3 (min_x, max_y, max_z),
756+ LPoint3 (max_x, min_y, min_z), LPoint3 (min_x, min_y, min_z),
757+ LPoint3 (max_x, max_y, min_z), LPoint3 (min_x, max_y, min_z));
758+ break ;
759+
760+ case CS_zup_left:
761+ bounds = new BoundingHexahedron
762+ (LPoint3 (max_x, max_y, min_z), LPoint3 (min_x, max_y, min_z),
763+ LPoint3 (max_x, max_y, max_z), LPoint3 (min_x, max_y, max_z),
764+ LPoint3 (max_x, min_y, min_z), LPoint3 (min_x, min_y, min_z),
765+ LPoint3 (max_x, min_y, max_z), LPoint3 (min_x, min_y, max_z));
766+ break ;
767+ }
735768
736769 // Rotate the bounding volume back into the original space of the
737770 // screen.
@@ -885,6 +918,12 @@ make_vis_mesh_geom(GeomNode *gnode, bool inverted) const {
885918 return ;
886919 }
887920
921+ bool reverse_normals = inverted;
922+ bool reverse_faces = inverted;
923+ if (!is_right_handed (get_default_coordinate_system ())) {
924+ reverse_faces = !reverse_faces;
925+ }
926+
888927 // This is the max number of vertex indices we might add to the
889928 // GeomTriangles. (We might actually add fewer than this due to
890929 // omitting the occasional missing data point.)
@@ -1025,7 +1064,7 @@ make_vis_mesh_geom(GeomNode *gnode, bool inverted) const {
10251064 }
10261065 n.normalize ();
10271066 nassertv (!n.is_nan ());
1028- if (inverted ) {
1067+ if (reverse_normals ) {
10291068 n = -n;
10301069 }
10311070 normal.add_data3 (n);
@@ -1062,7 +1101,7 @@ make_vis_mesh_geom(GeomNode *gnode, bool inverted) const {
10621101 int vi2 = ((xi0 + 1 ) + (yi0 + 1 ) * x_size);
10631102 int vi3 = ((xi0 + 1 ) + (yi0) * x_size);
10641103
1065- if (inverted ) {
1104+ if (reverse_faces ) {
10661105 tris->add_vertices (vi2, vi0, vi1);
10671106 tris->close_primitive ();
10681107
0 commit comments