Commit: 143dbfb33e2a7ef1dad43fde9af427f47bca5f34
Author: Campbell Barton
Date:   Wed Mar 25 19:46:07 2015 +1100
Branches: blender-v2.74-release
https://developer.blender.org/rB143dbfb33e2a7ef1dad43fde9af427f47bca5f34

Fix T44118: Rotated background image disappears

Image clipping didn't take rotation into account.

===================================================================

M       source/blender/blenlib/BLI_rect.h
M       source/blender/blenlib/intern/rct.c
M       source/blender/editors/space_view3d/view3d_draw.c

===================================================================

diff --git a/source/blender/blenlib/BLI_rect.h 
b/source/blender/blenlib/BLI_rect.h
index a132ac4..e0a0b34 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -89,6 +89,8 @@ void BLI_rctf_union(struct rctf *rctf1, const struct rctf 
*rctf2);
 void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src);
 void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src);
 
+void BLI_rctf_rotate_expand(rctf *dst, const rctf *src, const float angle);
+
 void print_rctf(const char *str, const struct rctf *rect);
 void print_rcti(const char *str, const struct rcti *rect);
 
diff --git a/source/blender/blenlib/intern/rct.c 
b/source/blender/blenlib/intern/rct.c
index 61e5783..d7ca749 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -571,3 +571,44 @@ void print_rcti(const char *str, const rcti *rect)
        printf("%s: xmin %d, xmax %d, ymin %d, ymax %d (%dx%d)\n", str,
               rect->xmin, rect->xmax, rect->ymin, rect->ymax, 
BLI_rcti_size_x(rect), BLI_rcti_size_y(rect));
 }
+
+
+/* -------------------------------------------------------------------- */
+/* Comprehensive math (float only) */
+
+/** \name Rect math functions
+ * \{ */
+
+#define ROTATE_SINCOS(r_vec, mat2, vec) { \
+       (r_vec)[0] = (mat2)[1] * (vec)[0] + (+(mat2)[0]) * (vec)[1]; \
+       (r_vec)[1] = (mat2)[0] * (vec)[0] + (-(mat2)[1]) * (vec)[1]; \
+} ((void)0)
+
+/**
+ * Expand the rectangle to fit a rotated \a src.
+ */
+void BLI_rctf_rotate_expand(rctf *dst, const rctf *src, const float angle)
+{
+       const float mat2[2] = {sinf(angle), cosf(angle)};
+       const float cent[2] = {BLI_rctf_cent_x(src), BLI_rctf_cent_y(src)};
+       float corner[2], corner_rot[2], corder_max[2];
+
+       ARRAY_SET_ITEMS(corner, src->xmin - cent[0], src->ymax - cent[1]);
+       ROTATE_SINCOS(corner_rot, mat2, corner);
+       corder_max[0] = fabsf(corner_rot[0]);
+       corder_max[1] = fabsf(corner_rot[1]);
+
+       ARRAY_SET_ITEMS(corner, src->xmax - cent[0], src->ymax - cent[1]);
+       ROTATE_SINCOS(corner_rot, mat2, corner);
+       corder_max[0] = MAX2(corder_max[0], fabsf(corner_rot[0]));
+       corder_max[1] = MAX2(corder_max[1], fabsf(corner_rot[1]));
+
+       dst->xmin = cent[0] - corder_max[0];
+       dst->xmax = cent[0] + corder_max[0];
+       dst->ymin = cent[1] - corder_max[1];
+       dst->ymax = cent[1] + corder_max[1];
+}
+
+#undef ROTATE_SINCOS
+
+/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_draw.c 
b/source/blender/editors/space_view3d/view3d_draw.c
index f871d36..585db1e 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1620,6 +1620,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, 
View3D *v3d,
 
                        ImBuf *ibuf = NULL, *freeibuf, *releaseibuf;
                        void *lock;
+                       rctf clip_rect;
 
                        Image *ima = NULL;
                        MovieClip *clip = NULL;
@@ -1782,8 +1783,12 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, 
View3D *v3d,
                        }
 
                        /* complete clip? */
+                       BLI_rctf_init(&clip_rect, x1, x2, y1, y2);
+                       if (bgpic->rotation) {
+                               BLI_rctf_rotate_expand(&clip_rect, &clip_rect, 
bgpic->rotation);
+                       }
 
-                       if (x2 < 0 || y2 < 0 || x1 > ar->winx || y1 > ar->winy) 
{
+                       if (clip_rect.xmax < 0 || clip_rect.ymax < 0 || 
clip_rect.xmin > ar->winx || clip_rect.ymin > ar->winy) {
                                if (freeibuf)
                                        IMB_freeImBuf(freeibuf);
                                if (releaseibuf)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to