Use simpler method to check the planes view aligned
authorCampbell Barton <ideasman42@gmail.com>
Tue, 2 Feb 2016 01:03:32 +0000 (12:03 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 2 Feb 2016 01:40:07 +0000 (12:40 +1100)
source/blender/editors/transform/transform_constraints.c

index 17adff9b60960fb4c9eb7ba73cf93ca4209ec7f2..beeba7cf10f228d21115094f70f7cae106748810 100644 (file)
@@ -280,9 +280,7 @@ static void axisProjection(TransInfo *t, const float axis[3], const float in[3],
  */
 static bool isPlaneProjectionViewAligned(TransInfo *t)
 {
-       RegionView3D *rv3d = t->ar->regiondata;
        const float eps = 0.001f;
-
        const float *constraint_vector[2];
        int n = 0;
        for (int i = 0; i < 3; i++) {
@@ -295,28 +293,15 @@ static bool isPlaneProjectionViewAligned(TransInfo *t)
        }
        BLI_assert(n == 2);
 
-       float points[2][3];
-       add_v3_v3v3(points[0], constraint_vector[0], t->center_global);
-       add_v3_v3v3(points[1], constraint_vector[1], t->center_global);
-
-       float coords[3][2];
-       projectFloatView(t, points[0],        coords[0]);
-       projectFloatView(t, t->center_global, coords[1]);
-       projectFloatView(t, points[1],        coords[2]);
-
-       float dir[2][2];
-
-       sub_v2_v2v2(dir[0], coords[0], coords[1]);
-       sub_v2_v2v2(dir[1], coords[2], coords[1]);
+       float view_to_plane[3], plane_normal[3];
 
-       /* remove pixel scaling */
-       float scale = mul_project_m4_v3_zfac((float(*)[4])rv3d->persmat, t->center_global) * rv3d->pixsize;
-       mul_v2_fl(dir[0], scale);
-       mul_v2_fl(dir[1], scale);
+       getViewVector(t, t->center_global, view_to_plane);
 
-       float area = fabsf(cross_v2v2(dir[0], dir[1]));
+       cross_v3_v3v3(plane_normal, constraint_vector[0], constraint_vector[1]);
+       normalize_v3(plane_normal);
 
-       return (area < eps);
+       float factor = dot_v3v3(plane_normal, view_to_plane);
+       return fabsf(factor) < eps;
 }
 
 static void planeProjection(TransInfo *t, const float in[3], float out[3])