From fe03bc2a02a0c9e5ecd554f72839ae0a407a8e86 Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Wed, 4 Feb 2015 15:05:22 +0100 Subject: Support rotation and flipping for background images, patch by Andre D. (T34583) with minor changes. Thanks for the patch! --- source/blender/editors/space_view3d/view3d_draw.c | 33 +++++++++++++++++------ source/blender/editors/space_view3d/view3d_edit.c | 5 ++-- source/blender/makesdna/DNA_view3d_types.h | 11 +++++--- source/blender/makesrna/intern/rna_space.c | 17 +++++++++++- 4 files changed, 52 insertions(+), 14 deletions(-) (limited to 'source/blender') diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 1a57e63d586..49cb24f7c2c 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1615,7 +1615,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, { float image_aspect[2]; float fac, asp, zoomx, zoomy; - float x1, y1, x2, y2; + float x1, y1, x2, y2, centx, centy; ImBuf *ibuf = NULL, *freeibuf, *releaseibuf; void *lock; @@ -1721,6 +1721,9 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, y2 += yof_scale; } + centx = (x1 + x2) / 2.0f; + centy = (y1 + y2) / 2.0f; + /* aspect correction */ if (bgpic->flag & V3D_BGPIC_CAMERA_ASPECT) { /* apply aspect from clip */ @@ -1738,16 +1741,14 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, if ((asp_src > asp_dst) == ((bgpic->flag & V3D_BGPIC_CAMERA_CROP) != 0)) { /* fit X */ const float div = asp_src / asp_dst; - const float cent = (x1 + x2) / 2.0f; - x1 = ((x1 - cent) * div) + cent; - x2 = ((x2 - cent) * div) + cent; + x1 = ((x1 - centx) * div) + centx; + x2 = ((x2 - centx) * div) + centx; } else { /* fit Y */ const float div = asp_dst / asp_src; - const float cent = (y1 + y2) / 2.0f; - y1 = ((y1 - cent) * div) + cent; - y2 = ((y2 - cent) * div) + cent; + y1 = ((y1 - centy) * div) + centy; + y2 = ((y2 - centy) * div) + centy; } } } @@ -1774,6 +1775,9 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, y1 = sco[1] + asp * fac * (bgpic->yof - bgpic->size); x2 = sco[0] + fac * (bgpic->xof + bgpic->size); y2 = sco[1] + asp * fac * (bgpic->yof + bgpic->size); + + centx = (x1 + x2) / 2.0f; + centy = (y1 + y2) / 2.0f; } /* complete clip? */ @@ -1824,6 +1828,19 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, glPushMatrix(); ED_region_pixelspace(ar); + glTranslatef(centx, centy, 0.0); + if(rv3d->persp != RV3D_CAMOB) { + glRotatef(RAD2DEGF(-bgpic->rotation), 0.0f, 0.0f, 1.0f); + } + + if(bgpic->flag & V3D_BGPIC_FLIP_V) { + zoomy *= -1.0f; + y1 = y2; + } + if(bgpic->flag & V3D_BGPIC_FLIP_H) { + zoomx *= -1.0f; + x1 = x2; + } glPixelZoom(zoomx, zoomy); glColor4f(1.0f, 1.0f, 1.0f, 1.0f - bgpic->blend); @@ -1831,7 +1848,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d, * glaDrawPixelsSafe in some cases, which will end up in missing * alpha transparency for the background image (sergey) */ - glaDrawPixelsTex(x1, y1, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect); + glaDrawPixelsTex(x1 - centx, y1 - centy, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect); glPixelZoom(1.0, 1.0); glPixelTransferf(GL_ALPHA_SCALE, 1.0f); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 7a1cd88ba49..e6f61fb4aca 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -5004,8 +5004,9 @@ BGpic *ED_view3D_background_image_new(View3D *v3d) { BGpic *bgpic = MEM_callocN(sizeof(BGpic), "Background Image"); - bgpic->size = 5.0; - bgpic->blend = 0.5; + bgpic->rotation = 0.0f; + bgpic->size = 5.0f; + bgpic->blend = 0.5f; bgpic->iuser.fie_ima = 2; bgpic->iuser.ok = 1; bgpic->view = 0; /* 0 for all */ diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 069ea7a8b97..0c290ab8435 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -74,10 +74,11 @@ typedef struct BGpic { struct ImageUser iuser; struct MovieClip *clip; struct MovieClipUser cuser; - float xof, yof, size, blend; + float xof, yof, size, blend, rotation; short view; short flag; - short source, pad; + short source; + char pad[6]; } BGpic; /* ********************************* */ @@ -340,7 +341,11 @@ enum { /* Camera framing options */ V3D_BGPIC_CAMERA_ASPECT = (1 << 5), /* don't stretch to fit the camera view */ - V3D_BGPIC_CAMERA_CROP = (1 << 6) /* crop out the image */ + V3D_BGPIC_CAMERA_CROP = (1 << 6), /* crop out the image */ + + /* Axis flip options */ + V3D_BGPIC_FLIP_H = (1 << 7), + V3D_BGPIC_FLIP_V = (1 << 8) }; #define V3D_BGPIC_EXPANDED (V3D_BGPIC_EXPANDED | V3D_BGPIC_CAMERACLIP) diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index ff9df16ae94..7eaf7376a4b 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -1700,7 +1700,22 @@ static void rna_def_background_image(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Size", "Scaling factor for the background image"); RNA_def_property_range(prop, 0.0, FLT_MAX); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); - + + prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_EULER); + RNA_def_property_float_sdna(prop, NULL, "rotation"); + RNA_def_property_ui_text(prop, "Rotation", "Rotation for the background image"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + + prop = RNA_def_property(srna, "flip_h", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FLIP_H); + RNA_def_property_ui_text(prop, "Flip Horizontally", "Flip the background image horizontally"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + + prop = RNA_def_property(srna, "flip_v", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FLIP_V); + RNA_def_property_ui_text(prop, "Flip Vertically", "Flip the background image vertically"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + prop = RNA_def_property(srna, "opacity", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "blend"); RNA_def_property_float_funcs(prop, "rna_BackgroundImage_opacity_get", "rna_BackgroundImage_opacity_set", NULL); -- cgit v1.2.3