Fix #27897: mesh with negative scale disappears while sculpting, clipping

planes were wrong in that case.
This commit is contained in:
2011-07-08 15:58:00 +00:00
parent a5906de7c4
commit a6bb0f93ad

View 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];