Fix #27897: mesh with negative scale disappears while sculpting, clipping
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 8 Jul 2011 15:58:00 +0000 (15:58 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 8 Jul 2011 15:58:00 +0000 (15:58 +0000)
planes were wrong in that case.

source/blender/editors/space_view3d/view3d_view.c

index aadb355f743553f66d066ed1c0f1b136f7e6da09..eeaf87757cecfd2aa4801562eb33da7db62ae624 100644 (file)
@@ -468,8 +468,9 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
 
 void ED_view3d_calc_clipping(BoundBox *bb, float planes[4][4], bglMats *mats, rcti *rect)
 {
+       float modelview[4][4];
        double xs, ys, p[3];
-       short val;
+       int val, flip_sign, a;
 
        /* near zero floating point values can give issues with gluUnProject
                in side view on some implementations */
@@ -493,11 +494,21 @@ void ED_view3d_calc_clipping(BoundBox *bb, float planes[4][4], bglMats *mats, rc
                VECCOPY(bb->vec[4+val], p);
        }
 
+       /* verify if we have negative scale. doing the transform before cross
+          product flips the sign of the vector compared to doing cross product
+          before transform then, so we correct for that. */
+       for(a=0; a<16; a++)
+               ((float*)modelview)[a] = mats->modelview[a];
+       flip_sign = is_negative_m4(modelview);
+
        /* then plane equations */
        for(val=0; val<4; val++) {
 
                normal_tri_v3(planes[val], bb->vec[val], bb->vec[val==3?0:val+1], bb->vec[val+4]);
 
+               if(flip_sign)
+                       negate_v3(planes[val]);
+
                planes[val][3]= - planes[val][0]*bb->vec[val][0]
                        - planes[val][1]*bb->vec[val][1]
                        - planes[val][2]*bb->vec[val][2];