From f9ff47464d9fd30d5def3852dd7fd8e71c0e25d3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 18 Apr 2007 22:53:20 +0000 Subject: [PATCH] remove warnings from last commit. smooth view now works for change between cameras, smooth view now blends the lens angle too. --- source/blender/include/BSE_drawview.h | 5 +- source/blender/python/api2_2x/bpy.c | 1 + source/blender/python/api2_2x/bpy_data.c | 2 - source/blender/src/editview.c | 2 +- source/blender/src/space.c | 4 +- source/blender/src/toets.c | 144 ++++++++++++--------- source/blender/src/view.c | 157 ++++++++++++++++++----- 7 files changed, 215 insertions(+), 100 deletions(-) diff --git a/source/blender/include/BSE_drawview.h b/source/blender/include/BSE_drawview.h index 1283ba4fdca..9c577746da9 100644 --- a/source/blender/include/BSE_drawview.h +++ b/source/blender/include/BSE_drawview.h @@ -79,7 +79,10 @@ int play_anim(int mode); void make_axis_color(char *col, char *col2, char axis); /* SMOOTHVIEW */ -void smooth_view(struct View3D *v3d, float *ofs, float *quat, float *dist); +void smooth_view(struct View3D *v3d, float *ofs, float *quat, float *dist, float *lens); +void smooth_view_to_camera(struct View3D *v3d); +void view_settings_from_ob(struct Object *ob, float *ofs, float *quat, float *dist, float *lens); +void object_view_settings(struct Object *ob, float *lens, float *clipsta, float *clipend); #endif /* BSE_DRAWVIEW_H */ diff --git a/source/blender/python/api2_2x/bpy.c b/source/blender/python/api2_2x/bpy.c index 31dd261b610..cee862c0e23 100644 --- a/source/blender/python/api2_2x/bpy.c +++ b/source/blender/python/api2_2x/bpy.c @@ -41,6 +41,7 @@ #include "DNA_scene_types.h" #include "Types.h" +#include "Library.h" #include "bpy.h" #include "bpy_data.h" diff --git a/source/blender/python/api2_2x/bpy_data.c b/source/blender/python/api2_2x/bpy_data.c index ce7b41700c9..61951069ae7 100644 --- a/source/blender/python/api2_2x/bpy_data.c +++ b/source/blender/python/api2_2x/bpy_data.c @@ -793,8 +793,6 @@ PyTypeObject LibBlockSeq_Type = { /*-----------------------------BPy module Init())-----------------------------*/ -static char M_BPy_Init_doc[] = "The bpy module"; - PyObject * Data_Init( void ) { PyObject *module; diff --git a/source/blender/src/editview.c b/source/blender/src/editview.c index 29e08dce7b1..3511e460a2d 100644 --- a/source/blender/src/editview.c +++ b/source/blender/src/editview.c @@ -2094,7 +2094,7 @@ void view3d_border_zoom(void) /* zoom in as required, or as far as we can go */ new_dist = ((new_dist*scale) >= 0.001*G.vd->grid)? new_dist*scale:0.001*G.vd->grid; - smooth_view(G.vd, new_ofs, NULL, &new_dist); + smooth_view(G.vd, new_ofs, NULL, &new_dist, NULL); } } diff --git a/source/blender/src/space.c b/source/blender/src/space.c index 335c636b987..aa69548ee4c 100644 --- a/source/blender/src/space.c +++ b/source/blender/src/space.c @@ -1338,7 +1338,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) new_ofs[0]= -curs[0]; new_ofs[1]= -curs[1]; new_ofs[2]= -curs[2]; - smooth_view(G.vd, new_ofs, NULL, NULL); + smooth_view(G.vd, new_ofs, NULL, NULL, NULL); } } doredraw= 1; @@ -1743,7 +1743,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt) new_ofs[0]= -curs[0]; new_ofs[1]= -curs[1]; new_ofs[2]= -curs[2]; - smooth_view(G.vd, new_ofs, NULL, NULL); + smooth_view(G.vd, new_ofs, NULL, NULL, NULL); } scrarea_queue_winredraw(curarea); } diff --git a/source/blender/src/toets.c b/source/blender/src/toets.c index 63c4d764d74..7530b82a63e 100644 --- a/source/blender/src/toets.c +++ b/source/blender/src/toets.c @@ -120,6 +120,35 @@ static int is_an_active_object(void *ob) { return 0; } +/* run when pressing 1,3 or 7 */ +static void axis_set_view(float q1, float q2, float q3, float q4, short view, int perspo) +{ + float new_quat[4]; + new_quat[0]= q1; new_quat[1]= q2; + new_quat[2]= q3; new_quat[3]= q4; + G.vd->view=0; + + if (G.vd->persp==2 && G.vd->camera) { + /* Is this switching from a camera view ? */ + float orig_ofs[3]; + float orig_lens= G.vd->lens; + VECCOPY(orig_ofs, G.vd->ofs); + view_settings_from_ob(G.vd->camera, G.vd->ofs, G.vd->viewquat, &G.vd->dist, &G.vd->lens); + + if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; + else if(G.vd->persp>=2) G.vd->persp= perspo; + + smooth_view(G.vd, orig_ofs, new_quat, NULL, &orig_lens); + } else { + + if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; + else if(G.vd->persp>=2) G.vd->persp= perspo; + + smooth_view(G.vd, NULL, new_quat, NULL, NULL); + } + G.vd->view= view; +} + void persptoetsen(unsigned short event) { static Object *oldcamera=0; @@ -127,7 +156,12 @@ void persptoetsen(unsigned short event) static int perspo=1; int preview3d_event= 1; - float new_quat[4], new_dist; + float new_dist, orig_ofs[3]; + + /* Use this to test if we started out with a camera */ + Object *act_cam_orig=NULL; + if (G.vd->persp == 2) + act_cam_orig = G.vd->camera; if(event==PADENTER) { if (G.qual == LR_SHIFTKEY) { @@ -137,7 +171,7 @@ void persptoetsen(unsigned short event) G.vd->camzoom= 0; } else { new_dist = 10.0; - smooth_view(G.vd, NULL, NULL, &new_dist); + smooth_view(G.vd, NULL, NULL, &new_dist, NULL); } } } @@ -152,38 +186,13 @@ void persptoetsen(unsigned short event) /* G.vd->persp= 3; */ } else if(event==PAD7) { - new_quat[0]=0.0; - new_quat[1]=-1.0; - new_quat[2]=0.0; - new_quat[3]=0.0; - G.vd->view= 0; - smooth_view(G.vd, NULL, new_quat, NULL); - G.vd->view= 7; - - if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; - else if(G.vd->persp>=2) G.vd->persp= perspo; + axis_set_view(0.0, -1.0, 0.0, 0.0, 7, perspo); } else if(event==PAD1) { - new_quat[0]=0.0; - new_quat[1]=0.0; - new_quat[2]=(float)-cos(M_PI/4.0); - new_quat[3]=(float)-cos(M_PI/4.0); - G.vd->view=0; - smooth_view(G.vd, NULL, new_quat, NULL); - G.vd->view=1; - if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; - else if(G.vd->persp>=2) G.vd->persp= perspo; + axis_set_view(0.0, 0.0, (float)-cos(M_PI/4.0), (float)-cos(M_PI/4.0), 1, perspo); } else if(event==PAD3) { - new_quat[0]= 0.5; - new_quat[1]=-0.5; - new_quat[2]= 0.5; - new_quat[3]= 0.5; - G.vd->view=0; - smooth_view(G.vd, NULL, new_quat, NULL); - G.vd->view=3; - if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; - else if(G.vd->persp>=2) G.vd->persp= perspo; + axis_set_view(0.5, -0.5, 0.5, 0.5, 3, perspo); } else if(event==PADMINUS) { /* this min and max is also in viewmove() */ @@ -221,37 +230,13 @@ void persptoetsen(unsigned short event) if(event==PAD7) { - new_quat[0]=1.0; - new_quat[1]=0.0; - new_quat[2]=0.0; - new_quat[3]=0.0; - G.vd->view=0; - smooth_view(G.vd, NULL, new_quat, NULL); - G.vd->view=7; - if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; - else if(G.vd->persp>=2) G.vd->persp= perspo; + axis_set_view(1.0, 0.0, 0.0, 0.0, 7, perspo); } else if(event==PAD1) { - new_quat[0]= (float)cos(M_PI/4.0); - new_quat[1]= (float)-sin(M_PI/4.0); - new_quat[2]= 0.0; - new_quat[3]= 0.0; - G.vd->view=0; - smooth_view(G.vd, NULL, new_quat, NULL); - G.vd->view=1; - if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; - else if(G.vd->persp>=2) G.vd->persp= perspo; + axis_set_view((float)cos(M_PI/4.0), (float)-sin(M_PI/4.0), 0.0, 0.0, 1, perspo); } else if(event==PAD3) { - new_quat[0]= 0.5; - new_quat[1]= -0.5; - new_quat[2]= -0.5; - new_quat[3]= -0.5; - G.vd->view=0; - smooth_view(G.vd, NULL, new_quat, NULL); - G.vd->view=3; - if (U.uiflag & USER_AUTOPERSP) G.vd->persp= 0; - else if(G.vd->persp>=2) G.vd->persp= perspo; + axis_set_view(0.5, -0.5, -0.5, -0.5, 3, perspo); } else if(event==PADMINUS) { /* this min and max is also in viewmove() */ @@ -269,15 +254,34 @@ void persptoetsen(unsigned short event) if(G.vd->persp!=1) preview3d_event= 0; } else if(event==PAD5) { - if(G.vd->persp==1) G.vd->persp=0; - else G.vd->persp=1; + if (U.smooth_viewtx) { + if(G.vd->persp==1) { G.vd->persp=0; + } else if (act_cam_orig) { + /* were from a camera view */ + float orig_dist= G.vd->dist; + float orig_lens= G.vd->lens; + VECCOPY(orig_ofs, G.vd->ofs); + + G.vd->persp=1; + G.vd->dist= 0.0; + + view_settings_from_ob(act_cam_orig, G.vd->ofs, NULL, NULL, &G.vd->lens); + + smooth_view(G.vd, orig_ofs, NULL, &orig_dist, &orig_lens); + + } else { + G.vd->persp=1; + } + } else { + if(G.vd->persp==1) G.vd->persp=0; + else G.vd->persp=1; + } } else if(event==PAD0) { if(G.qual==LR_ALTKEY) { if(oldcamera && is_an_active_object(oldcamera)) { G.vd->camera= oldcamera; } - handle_view3d_lock(); } else if(BASACT) { @@ -301,16 +305,31 @@ void persptoetsen(unsigned short event) handle_view3d_lock(); } - if(G.vd->camera) { + if(G.vd->camera && (G.vd->camera != act_cam_orig)) { G.vd->persp= 2; G.vd->view= 0; + if(((G.qual & LR_CTRLKEY) && (G.qual & LR_ALTKEY)) || (G.qual & LR_SHIFTKEY)) { void setcameratoview3d(void); // view.c setcameratoview3d(); DAG_object_flush_update(G.scene, G.scene->camera, OB_RECALC_OB); BIF_undo_push("View to Camera position"); allqueue(REDRAWVIEW3D, 0); - } + + } else if (U.smooth_viewtx) { + /* move 3d view to camera view */ + float orig_lens = G.vd->lens; + VECCOPY(orig_ofs, G.vd->ofs); + + if (act_cam_orig) + view_settings_from_ob(act_cam_orig, G.vd->ofs, G.vd->viewquat, &G.vd->dist, &G.vd->lens); + + smooth_view_to_camera(G.vd); + VECCOPY(G.vd->ofs, orig_ofs); + G.vd->lens = orig_lens; + } + + } } else if(event==PAD9) { @@ -332,7 +351,6 @@ void persptoetsen(unsigned short event) G.vd->view= 0; } if(event==PAD2 || event==PAD8) { - /* horizontal axis */ VECCOPY(q1+1, G.vd->viewinv[0]); diff --git a/source/blender/src/view.c b/source/blender/src/view.c index 3e052dde07c..a6e689d23fc 100644 --- a/source/blender/src/view.c +++ b/source/blender/src/view.c @@ -800,6 +800,31 @@ void viewmove(int mode) } +/* Gets the lens and clipping values from a camera of lamp type object */ +void object_view_settings(Object *ob, float *lens, float *clipsta, float *clipend) +{ + if (!ob) return; + + if(ob->type==OB_LAMP ) { + Lamp *la = ob->data; + if (lens) { + float x1, fac; + fac= cos( M_PI*la->spotsize/360.0); + x1= saacos(fac); + *lens= 16.0*fac/sin(x1); + } + if (clipsta) *clipsta= la->clipsta; + if (clipend) *clipend= la->clipend; + } + else if(ob->type==OB_CAMERA) { + Camera *cam= ob->data; + if (lens) *lens= cam->lens; + if (clipsta) *clipsta= cam->clipsta; + if (clipend) *clipend= cam->clipend; + } +} + + int get_view3d_viewplane(int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend) { Camera *cam=NULL; @@ -812,30 +837,8 @@ int get_view3d_viewplane(int winxi, int winyi, rctf *viewplane, float *clipsta, *clipsta= G.vd->near; *clipend= G.vd->far; - if(G.vd->persp==2) { - *clipsta= G.vd->near; - *clipend= G.vd->far; - if(G.vd->camera) { - if(G.vd->camera->type==OB_LAMP ) { - Lamp *la; - - la= G.vd->camera->data; - fac= cos( M_PI*la->spotsize/360.0); - - x1= saacos(fac); - lens= 16.0*fac/sin(x1); - - *clipsta= la->clipsta; - *clipend= la->clipend; - } - else if(G.vd->camera->type==OB_CAMERA) { - cam= G.vd->camera->data; - lens= cam->lens; - *clipsta= cam->clipsta; - *clipend= cam->clipend; - } - } - } + if(G.vd->persp==2) + object_view_settings(G.vd->camera, &lens, clipsta, clipend); if(G.vd->persp==0) { if(winx>winy) x1= -G.vd->dist; @@ -956,7 +959,7 @@ void obmat_to_viewmat(Object *ob, short smooth) if (smooth) { float new_quat[4]; Mat3ToQuat(tmat, new_quat); - smooth_view(G.vd, NULL, new_quat, NULL); + smooth_view(G.vd, NULL, new_quat, NULL, NULL); } else { Mat3ToQuat(tmat, G.vd->viewquat); } @@ -1380,7 +1383,7 @@ void centerview() /* like a localview without local! */ G.vd->cursor[1]= -new_ofs[1]; G.vd->cursor[2]= -new_ofs[2]; - smooth_view(G.vd, new_ofs, NULL, &new_dist); + smooth_view(G.vd, new_ofs, NULL, &new_dist, NULL); scrarea_queue_winredraw(curarea); BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT); @@ -1496,7 +1499,7 @@ void view3d_home(int center) if(G.vd->persp==2) G.vd->persp= 1; - smooth_view(G.vd, new_ofs, NULL, &new_dist); + smooth_view(G.vd, new_ofs, NULL, &new_dist, NULL); scrarea_queue_winredraw(curarea); } @@ -1525,13 +1528,13 @@ void view3d_align_axis_to_vector(View3D *v3d, int axisidx, float vec[3]) v3d->view= 0; if (v3d->persp>=2) v3d->persp= 0; /* switch out of camera mode */ - smooth_view(v3d, NULL, new_quat, NULL); + smooth_view(v3d, NULL, new_quat, NULL, NULL); } /* SMOOTHVIEW */ -void smooth_view(View3D *v3d, float *ofs, float *quat, float *dist) +void smooth_view(View3D *v3d, float *ofs, float *quat, float *dist, float *lens) { /* View Animation enabled */ if (U.smooth_viewtx) { @@ -1539,6 +1542,7 @@ void smooth_view(View3D *v3d, float *ofs, float *quat, float *dist) char changed = 0; float step = 0.0, step_inv; float orig_dist; + float orig_lens; float orig_quat[4]; float orig_ofs[3]; @@ -1551,6 +1555,11 @@ void smooth_view(View3D *v3d, float *ofs, float *quat, float *dist) changed = 1; } + if (lens) { + if ((*lens) != v3d->lens) + changed = 1; + } + if (!changed && ofs) { if ((ofs[0]!=v3d->ofs[0]) || (ofs[1]!=v3d->ofs[1]) || @@ -1574,6 +1583,7 @@ void smooth_view(View3D *v3d, float *ofs, float *quat, float *dist) VECCOPY(orig_ofs, v3d->ofs); QUATCOPY(orig_quat, v3d->viewquat); orig_dist = v3d->dist; + orig_lens = v3d->lens; time_allowed= (float)U.smooth_viewtx / 1000.0; time_current = time_start = PIL_check_seconds_timer(); @@ -1606,12 +1616,15 @@ void smooth_view(View3D *v3d, float *ofs, float *quat, float *dist) for (i=0; i<3; i++) v3d->ofs[i] = ofs[i]*step + orig_ofs[i]*step_inv; + if (quat) QuatInterpol(v3d->viewquat, orig_quat, quat, step); - if (dist) { + if (dist) v3d->dist = ((*dist)*step) + (orig_dist*step_inv); - } + + if (lens) + v3d->lens = ((*lens)*step) + (orig_lens*step_inv); /*redraw the view*/ scrarea_do_windraw(curarea); @@ -1630,6 +1643,88 @@ void smooth_view(View3D *v3d, float *ofs, float *quat, float *dist) QUATCOPY(v3d->viewquat, quat); if (dist) v3d->dist = *dist; + if (lens) + v3d->lens = *lens; } + + +/* Gets the view trasnformation from a camera + * currently dosnt take camzoom into account + * + * The dist is not modified for this function, if NULL its assimed zero + * */ +void view_settings_from_ob(Object *ob, float *ofs, float *quat, float *dist, float *lens) +{ + float bmat[4][4]; + float imat[4][4]; + float tmat[3][3]; + + if (!ob) return; + + /* Offset */ + if (ofs) { + where_is_object(ob); + VECCOPY(ofs, ob->obmat[3]); + VecMulf(ofs, -1.0f); /*flip the vector*/ + } + + /* Quat */ + if (quat) { + Mat4CpyMat4(bmat, ob->obmat); + Mat4Ortho(bmat); + Mat4Invert(imat, bmat); + Mat3CpyMat4(tmat, imat); + Mat3ToQuat(tmat, quat); + } + + if (dist) { + float vec[3]; + Mat3CpyMat4(tmat, ob->obmat); + + vec[0]= vec[1] = 0.0; + vec[2]= -(*dist); + Mat3MulVecfl(tmat, vec); + VecSubf(ofs, ofs, vec); + } + + /* Lens */ + if (lens) + object_view_settings(ob, lens, NULL, NULL); +} + +/* For use with smooth view + * + * the current view is unchanged, blend between the current view and the + * camera view + * */ +void smooth_view_to_camera(View3D *v3d) +{ + if (!U.smooth_viewtx || !v3d->camera || G.vd->persp != 2) { + return; + } else { + Object *ob = v3d->camera; + + float orig_ofs[3]; + float orig_dist=v3d->dist; + float orig_lens=v3d->lens; + float new_dist=0.0; + float new_lens=35.0; + float new_quat[4]; + float new_ofs[3]; + + VECCOPY(orig_ofs, v3d->ofs); + + view_settings_from_ob(ob, new_ofs, new_quat, NULL, &new_lens); + + G.vd->persp=1; + smooth_view(v3d, new_ofs, new_quat, &new_dist, &new_lens); + VECCOPY(v3d->ofs, orig_ofs); + v3d->lens= orig_lens; + v3d->dist = orig_dist; /* restore the dist */ + + v3d->camera = ob; + v3d->persp=2; + } +}