Fix T44118: Rotated background image disappears
Image clipping didn't take rotation into account.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -1624,6 +1624,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;
|
||||
@@ -1786,8 +1787,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)
|
||||
|
||||
Reference in New Issue
Block a user