Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenlib/BLI_math_vector.h6
-rw-r--r--source/blender/blenlib/BLI_rect.h3
-rw-r--r--source/blender/blenlib/intern/math_vector.c6
-rw-r--r--source/blender/blenlib/intern/rct.c20
-rw-r--r--source/blender/editors/gpencil/drawgpencil.c47
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c48
-rw-r--r--source/blender/editors/include/ED_gpencil.h2
-rw-r--r--source/blender/editors/include/ED_view3d.h3
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c23
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_intern.h1
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c2
12 files changed, 123 insertions, 40 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 15135e08225..c6902d01059 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -151,9 +151,9 @@ void bisect_v3_v3v3v3(float r[3], float a[3], float b[3], float c[3]);
/*********************************** Other ***********************************/
-void print_v2(char *str, float a[2]);
-void print_v3(char *str, float a[3]);
-void print_v4(char *str, float a[4]);
+void print_v2(const char *str, const float a[2]);
+void print_v3(const char *str, const float a[3]);
+void print_v4(const char *str, const float a[4]);
MINLINE void normal_short_to_float_v3(float r[3], const short n[3]);
MINLINE void normal_float_to_short_v3(short r[3], const float n[3]);
diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h
index 0b886c17309..13b12fc4e1e 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -60,7 +60,10 @@ int BLI_isect_rctf(struct rctf *src1, struct rctf *src2, struct rctf *dest);
int BLI_isect_rcti(struct rcti *src1, struct rcti *src2, struct rcti *dest);
void BLI_union_rctf(struct rctf *rcta, struct rctf *rctb);
void BLI_union_rcti(struct rcti *rcti1, struct rcti *rcti2);
+void BLI_copy_rcti_rctf(struct rcti *tar, const struct rctf *src);
+void print_rctf(const char *str, struct rctf *rect);
+void print_rcti(const char *str, struct rcti *rect);
#ifdef __cplusplus
}
diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index b1cea9ab3c4..6d908ddb1cd 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -298,17 +298,17 @@ void ortho_basis_v3v3_v3(float *v1, float *v2, float *v)
/*********************************** Other ***********************************/
-void print_v2(char *str, float v[2])
+void print_v2(const char *str, const float v[2])
{
printf("%s: %.3f %.3f\n", str, v[0], v[1]);
}
-void print_v3(char *str, float v[3])
+void print_v3(const char *str, const float v[3])
{
printf("%s: %.3f %.3f %.3f\n", str, v[0], v[1], v[2]);
}
-void print_v4(char *str, float v[4])
+void print_v4(const char *str, const float v[4])
{
printf("%s: %.3f %.3f %.3f %.3f\n", str, v[0], v[1], v[2], v[3]);
}
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index 5466acdba9f..aa424c1c2bb 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -36,6 +36,8 @@
*/
#include "DNA_vec_types.h"
+#include <stdio.h>
+#include <math.h>
int BLI_rcti_is_empty(rcti * rect)
{
@@ -222,3 +224,21 @@ int BLI_isect_rcti(rcti *src1, rcti *src2, rcti *dest)
return 0;
}
}
+
+void BLI_copy_rcti_rctf(rcti *tar, const rctf *src)
+{
+ tar->xmin= floor(src->xmin + 0.5);
+ tar->xmax= floor((src->xmax - src->xmin) + 0.5);
+ tar->ymin= floor(src->ymin + 0.5);
+ tar->ymax= floor((src->ymax - src->ymin) + 0.5);
+}
+
+void print_rctf(const char *str, rctf *rect)
+{
+ printf("%s: xmin %.3f, xmax %.3f, ymin %.3f, ymax %.3f\n", str, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
+}
+
+void print_rcti(const char *str, rcti *rect)
+{
+ printf("%s: xmin %d, xmax %d, ymin %d, ymax %d\n", str, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
+}
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 284dac7a0ae..4867c5233bb 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -42,6 +42,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
+#include "DNA_view3d_types.h"
#include "BKE_context.h"
#include "BKE_global.h"
@@ -56,6 +57,7 @@
#include "ED_gpencil.h"
#include "ED_sequencer.h"
+#include "ED_view3d.h"
#include "gpencil_intern.h"
@@ -164,8 +166,8 @@ static void gp_draw_stroke_point (bGPDspoint *points, short thickness, short sfl
co[1]= (points->y * winy) + offsy;
}
else {
- co[0]= (points->x / 100 * winx);
- co[1]= (points->y / 100 * winy);
+ co[0]= (points->x / 100 * winx) + offsx;
+ co[1]= (points->y / 100 * winy) + offsy;
}
/* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, simple dot looks ok
@@ -265,8 +267,8 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
glVertex2f(x, y);
}
else {
- const float x= (pt->x / 100 * winx);
- const float y= (pt->y / 100 * winy);
+ const float x= (pt->x / 100 * winx) + offsx;
+ const float y= (pt->y / 100 * winy) + offsy;
glVertex2f(x, y);
}
@@ -305,10 +307,10 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
s1[1]= (pt2->y * winy) + offsy;
}
else {
- s0[0]= (pt1->x / 100 * winx);
- s0[1]= (pt1->y / 100 * winy);
- s1[0]= (pt2->x / 100 * winx);
- s1[1]= (pt2->y / 100 * winy);
+ s0[0]= (pt1->x / 100 * winx) + offsx;
+ s0[1]= (pt1->y / 100 * winy) + offsy;
+ s1[0]= (pt2->x / 100 * winx) + offsx;
+ s1[1]= (pt2->y / 100 * winy) + offsy;
}
/* calculate gradient and normal - 'angle'=(ny/nx) */
@@ -453,8 +455,8 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
glVertex2f(x, y);
}
else {
- const float x= (float)(pt->x / 100 * winx);
- const float y= (float)(pt->y / 100 * winy);
+ const float x= (float)(pt->x / 100 * winx) + offsx;
+ const float y= (float)(pt->y / 100 * winy) + offsy;
glVertex2f(x, y);
}
@@ -732,25 +734,44 @@ void draw_gpencil_view2d (bContext *C, short onlyv2d)
/* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly
* Note: this gets called twice - first time with only3d=1 to draw 3d-strokes, second time with only3d=0 for screen-aligned strokes
*/
-void draw_gpencil_view3d_ext (Scene *scene, ARegion *ar, short only3d)
+
+void draw_gpencil_view3d_ext (Scene *scene, View3D *v3d, ARegion *ar, short only3d)
{
bGPdata *gpd;
int dflag = 0;
+ rcti rect;
+ RegionView3D *rv3d= ar->regiondata;
/* check that we have grease-pencil stuff to draw */
gpd= gpencil_data_get_active_v3d(scene); // XXX
if(gpd == NULL) return;
+ /* when rendering to the offscreen buffer we dont want to
+ * deal with the camera border, otherwise map the coords to the camera border. */
+ if(rv3d->persp == RV3D_CAMOB && !(G.f & G_RENDER_OGL)) {
+ rctf rectf;
+ view3d_calc_camera_border(scene, ar, rv3d, v3d, &rectf);
+ BLI_copy_rcti_rctf(&rect, &rectf);
+ }
+ else {
+ rect.xmin= 0;
+ rect.ymin= 0;
+ rect.xmax= ar->winx;
+ rect.ymax= ar->winy;
+ }
+
/* draw it! */
if (only3d) dflag |= (GP_DRAWDATA_ONLY3D|GP_DRAWDATA_NOSTATUS);
- gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag);
+
+ gp_draw_data(gpd, rect.xmin, rect.ymin, rect.xmax, rect.ymax, CFRA, dflag);
}
void draw_gpencil_view3d (bContext *C, short only3d)
{
ARegion *ar= CTX_wm_region(C);
+ View3D *v3d= CTX_wm_view3d(C);
Scene *scene= CTX_data_scene(C);
- draw_gpencil_view3d_ext(scene, ar, only3d);
+ draw_gpencil_view3d_ext(scene, v3d, ar, only3d);
}
/* ************************************************** */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index cfa7af99d2a..083a90efb25 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -68,6 +68,9 @@ typedef struct tGPsdata {
ScrArea *sa; /* area where painting originated */
ARegion *ar; /* region where painting originated */
View2D *v2d; /* needed for GP_STROKE_2DSPACE */
+ rctf *subrect; /* for using the camera rect within the 3d view */
+ rctf subrect_data;
+
#if 0 // XXX review this 2d image stuff...
ImBuf *ibuf; /* needed for GP_STROKE_2DIMAGE */
@@ -271,8 +274,14 @@ static void gp_stroke_convertcoords (tGPsdata *p, short mval[], float out[], flo
/* 2d - relative to screen (viewport area) */
else {
- out[0] = (float)(mval[0]) / (float)(p->ar->winx) * 100;
- out[1] = (float)(mval[1]) / (float)(p->ar->winy) * 100;
+ if(p->subrect == NULL) { /* normal 3D view */
+ out[0] = (float)(mval[0]) / (float)(p->ar->winx) * 100;
+ out[1] = (float)(mval[1]) / (float)(p->ar->winy) * 100;
+ }
+ else { /* camera view, use subrect */
+ out[0]= ((mval[0] - p->subrect->xmin) / ((p->subrect->xmax - p->subrect->xmin))) * 100;
+ out[1]= ((mval[1] - p->subrect->ymin) / ((p->subrect->ymax - p->subrect->ymin))) * 100;
+ }
}
}
@@ -704,8 +713,14 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, int mval[], int mvalo[], sho
}
#endif
else {
- x0= (int)(gps->points->x / 100 * p->ar->winx);
- y0= (int)(gps->points->y / 100 * p->ar->winy);
+ if(p->subrect == NULL) { /* normal 3D view */
+ x0= (int)(gps->points->x / 100 * p->ar->winx);
+ y0= (int)(gps->points->y / 100 * p->ar->winy);
+ }
+ else { /* camera view, use subrect */
+ x0= (int)((gps->points->x / 100) * (p->subrect->xmax - p->subrect->xmin)) + p->subrect->xmin;
+ y0= (int)((gps->points->y / 100) * (p->subrect->ymax - p->subrect->ymin)) + p->subrect->ymin;
+ }
}
/* do boundbox check first */
@@ -761,10 +776,18 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, int mval[], int mvalo[], sho
}
#endif
else {
- x0= (int)(pt1->x / 100 * p->ar->winx);
- y0= (int)(pt1->y / 100 * p->ar->winy);
- x1= (int)(pt2->x / 100 * p->ar->winx);
- y1= (int)(pt2->y / 100 * p->ar->winy);
+ if(p->subrect == NULL) { /* normal 3D view */
+ x0= (int)(pt1->x / 100 * p->ar->winx);
+ y0= (int)(pt1->y / 100 * p->ar->winy);
+ x1= (int)(pt2->x / 100 * p->ar->winx);
+ y1= (int)(pt2->y / 100 * p->ar->winy);
+ }
+ else { /* camera view, use subrect */
+ x0= (int)((pt1->x / 100) * (p->subrect->xmax - p->subrect->xmin)) + p->subrect->xmin;
+ y0= (int)((pt1->y / 100) * (p->subrect->ymax - p->subrect->ymin)) + p->subrect->ymin;
+ x1= (int)((pt2->x / 100) * (p->subrect->xmax - p->subrect->xmin)) + p->subrect->xmin;
+ y1= (int)((pt2->y / 100) * (p->subrect->ymax - p->subrect->ymin)) + p->subrect->ymin;
+ }
}
/* check that point segment of the boundbox of the eraser stroke */
@@ -849,7 +872,8 @@ static tGPsdata *gp_session_initpaint (bContext *C)
/* supported views first */
case SPACE_VIEW3D:
{
- //View3D *v3d= curarea->spacedata.first;
+ View3D *v3d= curarea->spacedata.first;
+ RegionView3D *rv3d= ar->regiondata;
/* set current area
* - must verify that region data is 3D-view (and not something else)
@@ -864,6 +888,12 @@ static tGPsdata *gp_session_initpaint (bContext *C)
return p;
}
+ /* for camera view set the subrect */
+ if(rv3d->persp == RV3D_CAMOB) {
+ view3d_calc_camera_border(p->scene, p->ar, NULL, v3d, &p->subrect_data);
+ p->subrect= &p->subrect_data;
+ }
+
#if 0 // XXX will this sort of antiquated stuff be restored?
/* check that gpencil data is allowed to be drawn */
if ((v3d->flag2 & V3D_DISPGP)==0) {
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 0003cea8147..6c5a0cc3bf3 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -72,7 +72,7 @@ void ED_operatortypes_gpencil(void);
void draw_gpencil_2dimage(struct bContext *C, struct ImBuf *ibuf);
void draw_gpencil_view2d(struct bContext *C, short onlyv2d);
void draw_gpencil_view3d(struct bContext *C, short only3d);
-void draw_gpencil_view3d_ext(struct Scene *scene, struct ARegion *ar, short only3d);
+void draw_gpencil_view3d_ext(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, short only3d);
void gpencil_panel_standard(const struct bContext *C, struct Panel *pa);
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index ced2536b411..5d33816bf02 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -101,10 +101,11 @@ void viewline(struct ARegion *ar, struct View3D *v3d, float mval[2], float ray_s
void viewray(struct ARegion *ar, struct View3D *v3d, float mval[2], float ray_start[3], float ray_normal[3]);
int get_view3d_cliprange(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend);
-int get_view3d_viewplane(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize);
+int get_view3d_viewplane(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend, float *pixsize);
int get_view3d_ortho(struct View3D *v3d, struct RegionView3D *rv3d);
void view3d_get_object_project_mat(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]);
void view3d_project_float(struct ARegion *a, float *vec, float *adr, float mat[4][4]);
+void view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct RegionView3D *rv3d, struct View3D *v3d, struct rctf *viewborder_r);
/* drawobject.c itterators */
void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 048a0d95617..e48aef2a12c 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -862,7 +862,7 @@ static void view3d_get_viewborder_size(Scene *scene, ARegion *ar, float size_r[2
}
}
-void calc_viewborder(Scene *scene, ARegion *ar, RegionView3D *rv3d, View3D *v3d, rctf *viewborder_r)
+void view3d_calc_camera_border(Scene *scene, ARegion *ar, RegionView3D *rv3d, View3D *v3d, rctf *viewborder_r)
{
float zoomfac, size[2];
float dx= 0.0f, dy= 0.0f;
@@ -988,7 +988,7 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
if(v3d->camera->type==OB_CAMERA)
ca = v3d->camera->data;
- calc_viewborder(scene, ar, rv3d, v3d, &viewborder);
+ view3d_calc_camera_border(scene, ar, rv3d, v3d, &viewborder);
/* the offsets */
x1= viewborder.xmin;
y1= viewborder.ymin;
@@ -1325,7 +1325,7 @@ static void draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d)
if(rv3d->persp==RV3D_CAMOB) {
rctf vb;
- calc_viewborder(scene, ar, rv3d, v3d, &vb);
+ view3d_calc_camera_border(scene, ar, rv3d, v3d, &vb);
x1= vb.xmin;
y1= vb.ymin;
@@ -1672,7 +1672,7 @@ void draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d)
v3d->zbuf= TRUE;
glEnable(GL_DEPTH_TEST);
- draw_gpencil_view3d_ext(scene, ar, 1);
+ draw_gpencil_view3d_ext(scene, v3d, ar, 1);
v3d->zbuf= zbuf;
@@ -1976,14 +1976,22 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
Base *base;
float backcol[3];
int bwinx, bwiny;
+ rcti brect;
glPushMatrix();
/* set temporary new size */
bwinx= ar->winx;
bwiny= ar->winy;
+ brect= ar->winrct;
+
ar->winx= winx;
- ar->winy= winy;
+ ar->winy= winy;
+ ar->winrct.xmin= 0;
+ ar->winrct.ymin= 0;
+ ar->winrct.xmax= winx;
+ ar->winrct.ymax= winy;
+
/* set flags */
G.f |= G_RENDER_OGL;
@@ -2052,12 +2060,12 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
}
/* draw grease-pencil stuff */
- draw_gpencil_view3d_ext(scene, ar, 1);
+ draw_gpencil_view3d_ext(scene, v3d, ar, 1);
ED_region_pixelspace(ar);
/* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */
- draw_gpencil_view3d_ext(scene, ar, 0);
+ draw_gpencil_view3d_ext(scene, v3d, ar, 0);
/* freeing the images again here could be done after the operator runs, leaving for now */
GPU_free_images_anim();
@@ -2065,6 +2073,7 @@ void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx,
/* restore size */
ar->winx= bwinx;
ar->winy= bwiny;
+ ar->winrct = brect;
glPopMatrix();
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index d1c5429c1a8..132f43ff327 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -1604,7 +1604,7 @@ static int render_border_exec(bContext *C, wmOperator *op)
rect.ymax= RNA_int_get(op->ptr, "ymax");
/* calculate range */
- calc_viewborder(scene, ar, rv3d, v3d, &vb);
+ view3d_calc_camera_border(scene, ar, rv3d, v3d, &vb);
scene->r.border.xmin= ((float)rect.xmin-vb.xmin)/(vb.xmax-vb.xmin);
scene->r.border.ymin= ((float)rect.ymin-vb.ymin)/(vb.ymax-vb.ymin);
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 173d8256269..d51a45f92ad 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -126,7 +126,6 @@ void draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d);
void view3d_clr_clipping(void);
void view3d_set_clipping(RegionView3D *rv3d);
void add_view3d_after(View3D *v3d, Base *base, int type, int flag);
-void calc_viewborder(Scene *scene, struct ARegion *ar, struct RegionView3D *rv3d, View3D *v3d, rctf *viewborder_r);
void circf(float x, float y, float rad);
void circ(float x, float y, float rad);
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 334b72ee1ed..45d099cbb4d 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -1784,7 +1784,7 @@ static int game_engine_exec(bContext *C, wmOperator *op)
if(rv3d->persp==RV3D_CAMOB && startscene->gm.framing.type == SCE_GAMEFRAMING_BARS && startscene->gm.stereoflag != STEREO_DOME) { /* Letterbox */
rctf cam_framef;
- calc_viewborder(startscene, ar, rv3d, CTX_wm_view3d(C), &cam_framef);
+ view3d_calc_camera_border(startscene, ar, rv3d, CTX_wm_view3d(C), &cam_framef);
cam_frame.xmin = cam_framef.xmin + ar->winrct.xmin;
cam_frame.xmax = cam_framef.xmax + ar->winrct.xmin;
cam_frame.ymin = cam_framef.ymin + ar->winrct.ymin;