Merging r59182 through r59257 from trunk into soc-2013-depsgraph_mt
[blender-staging.git] / source / blender / editors / sculpt_paint / sculpt.c
index 1ecd33b68772f839421bb374d29ac72d6bcc50f2..b16d5f6b4cda5f51899a8436ee1364da4c8b778f 100644 (file)
@@ -3719,7 +3719,8 @@ static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSessio
        Brush *brush = BKE_paint_brush(&sd->paint);
        ViewContext *vc = paint_stroke_view_context(op->customdata);
        Object *ob = CTX_data_active_object(C);
-       float rot[3][3], scale[3], loc[3];
+       float mat[3][3];
+       float viewDir[3] = {0.0f, 0.0f, 1.0f};
        int i;
        int mode;
 
@@ -3787,12 +3788,13 @@ static void sculpt_update_cache_invariants(bContext *C, Sculpt *sd, SculptSessio
        /* cache projection matrix */
        ED_view3d_ob_project_mat_get(cache->vc->rv3d, ob, cache->projection_mat);
 
-       mat4_to_loc_rot_size(loc, rot, scale, ob->obmat);
-       /* transposing an orthonormal matrix inverts */
-       transpose_m3(rot);
-       ED_view3d_global_to_vector(cache->vc->rv3d, cache->vc->rv3d->twmat[3], cache->true_view_normal);
-       /* This takes care of rotated mesh. Instead of rotating every normal, we inverse rotate view normal. */
-       mul_m3_v3(rot, cache->true_view_normal);
+       invert_m4_m4(ob->imat, ob->obmat);
+       copy_m3_m4(mat, cache->vc->rv3d->viewinv);
+       mul_m3_v3(mat, viewDir);
+       copy_m3_m4(mat, ob->imat);
+       mul_m3_v3(mat, viewDir);
+       normalize_v3_v3(cache->true_view_normal, viewDir);
+
        /* Initialize layer brush displacements and persistent coords */
        if (brush->sculpt_tool == SCULPT_TOOL_LAYER) {
                /* not supported yet for multires or dynamic topology */