diff options
author | Arystanbek Dyussenov <arystan.d@gmail.com> | 2010-09-04 22:49:07 +0400 |
---|---|---|
committer | Arystanbek Dyussenov <arystan.d@gmail.com> | 2010-09-04 22:49:07 +0400 |
commit | 90b464d3728d9ed8ec26fdf59058d236b99dbcd9 (patch) | |
tree | e88cab4fb1358e962b19f658064ca8c9f8d29f5b /source/blender/editors/space_view3d/view3d_view.c | |
parent | 08d02dd04d836976b25793bb1d4c6a86b3f924c7 (diff) | |
parent | b0b787ef38f9947b3176642556f5282eb3518f69 (diff) |
COLLADA branch: merge from trunk -r 28015:31610.soc-2009-chingachgook
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_view.c')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 307 |
1 files changed, 138 insertions, 169 deletions
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 543af197370..45d099cbb4d 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -35,6 +35,7 @@ #include "DNA_camera_types.h" #include "DNA_lamp_types.h" #include "DNA_scene_types.h" +#include "DNA_object_types.h" #include "MEM_guardedalloc.h" @@ -51,8 +52,6 @@ #include "BKE_main.h" #include "BKE_report.h" #include "BKE_scene.h" -#include "BKE_screen.h" -#include "BKE_utildefines.h" #include "BKE_depsgraph.h" /* for fly mode updating */ @@ -138,37 +137,32 @@ static void object_lens_clip_settings(Object *ob, float *lens, float *clipsta, f * * The dist is not modified for this function, if NULL its assimed zero * */ -static 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]; - +void view3d_settings_from_ob(Object *ob, float *ofs, float *quat, float *dist, float *lens) +{ if (!ob) return; - + /* Offset */ if (ofs) negate_v3_v3(ofs, ob->obmat[3]); /* Quat */ if (quat) { - copy_m4_m4(bmat, ob->obmat); - normalize_m4(bmat); - invert_m4_m4(imat, bmat); - copy_m3_m4(tmat, imat); - mat3_to_quat( quat,tmat); + float imat[4][4]; + invert_m4_m4(imat, ob->obmat); + mat4_to_quat(quat, imat); } - + if (dist) { - float vec[3]; - copy_m3_m4(tmat, ob->obmat); - - vec[0]= vec[1] = 0.0; - vec[2]= -(*dist); - mul_m3_v3(tmat, vec); - sub_v3_v3v3(ofs, ofs, vec); + float vec[3] = {0.0f, 0.0f, -(*dist)}; + float tquat[4]; + + mat4_to_quat(tquat, ob->obmat); + + mul_qt_v3(tquat, vec); + + sub_v3_v3(ofs, vec); } - + /* Lens */ if (lens) object_lens_clip_settings(ob, lens, NULL, NULL); @@ -199,20 +193,20 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo /* initialize sms */ memset(&sms,0,sizeof(struct SmoothViewStore)); - VECCOPY(sms.new_ofs, rv3d->ofs); - QUATCOPY(sms.new_quat, rv3d->viewquat); + copy_v3_v3(sms.new_ofs, rv3d->ofs); + copy_qt_qt(sms.new_quat, rv3d->viewquat); sms.new_dist= rv3d->dist; sms.new_lens= v3d->lens; sms.to_camera= 0; /* store the options we want to end with */ - if(ofs) VECCOPY(sms.new_ofs, ofs); - if(quat) QUATCOPY(sms.new_quat, quat); + if(ofs) copy_v3_v3(sms.new_ofs, ofs); + if(quat) copy_qt_qt(sms.new_quat, quat); if(dist) sms.new_dist= *dist; if(lens) sms.new_lens= *lens; if (camera) { - view_settings_from_ob(camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens); + view3d_settings_from_ob(camera, sms.new_ofs, sms.new_quat, &sms.new_dist, &sms.new_lens); sms.to_camera= 1; /* restore view3d values in end */ } @@ -224,46 +218,24 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo if (sms.new_lens != v3d->lens) changed = 1; - if ((sms.new_ofs[0]!=rv3d->ofs[0]) || - (sms.new_ofs[1]!=rv3d->ofs[1]) || - (sms.new_ofs[2]!=rv3d->ofs[2]) ) + if (!equals_v3v3(sms.new_ofs, rv3d->ofs)) changed = 1; - - if ((sms.new_quat[0]!=rv3d->viewquat[0]) || - (sms.new_quat[1]!=rv3d->viewquat[1]) || - (sms.new_quat[2]!=rv3d->viewquat[2]) || - (sms.new_quat[3]!=rv3d->viewquat[3]) ) + + if (!equals_v4v4(sms.new_quat, rv3d->viewquat)) changed = 1; /* The new view is different from the old one * so animate the view */ if (changed) { - - sms.time_allowed= (double)U.smooth_viewtx / 1000.0; - - /* if this is view rotation only - * we can decrease the time allowed by - * the angle between quats - * this means small rotations wont lag */ - if (quat && !ofs && !dist) { - float vec1[3], vec2[3]; - - VECCOPY(vec1, sms.new_quat); - VECCOPY(vec2, sms.orig_quat); - normalize_v3(vec1); - normalize_v3(vec2); - /* scale the time allowed by the rotation */ - sms.time_allowed *= angle_normalized_v3v3(vec1, vec2)/(M_PI/2); - } - + /* original values */ if (oldcamera) { sms.orig_dist= rv3d->dist; // below function does weird stuff with it... - view_settings_from_ob(oldcamera, sms.orig_ofs, sms.orig_quat, &sms.orig_dist, &sms.orig_lens); + view3d_settings_from_ob(oldcamera, sms.orig_ofs, sms.orig_quat, &sms.orig_dist, &sms.orig_lens); } else { - VECCOPY(sms.orig_ofs, rv3d->ofs); - QUATCOPY(sms.orig_quat, rv3d->viewquat); + copy_v3_v3(sms.orig_ofs, rv3d->ofs); + copy_qt_qt(sms.orig_quat, rv3d->viewquat); sms.orig_dist= rv3d->dist; sms.orig_lens= v3d->lens; } @@ -274,6 +246,26 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo rv3d->view= 0; } + sms.time_allowed= (double)U.smooth_viewtx / 1000.0; + + /* if this is view rotation only + * we can decrease the time allowed by + * the angle between quats + * this means small rotations wont lag */ + if (quat && !ofs && !dist) { + float vec1[3]={0,0,1}, vec2[3]= {0,0,1}; + float q1[4], q2[4]; + + invert_qt_qt(q1, sms.new_quat); + invert_qt_qt(q2, sms.orig_quat); + + mul_qt_v3(q1, vec1); + mul_qt_v3(q2, vec2); + + /* scale the time allowed by the rotation */ + sms.time_allowed *= angle_v3v3(vec1, vec2) / M_PI; /* 180deg == 1.0 */ + } + /* ensure it shows correct */ if(sms.to_camera) rv3d->persp= RV3D_PERSP; @@ -294,8 +286,8 @@ void smooth_view(bContext *C, Object *oldcamera, Object *camera, float *ofs, flo /* if we get here nothing happens */ if(sms.to_camera==0) { - VECCOPY(rv3d->ofs, sms.new_ofs); - QUATCOPY(rv3d->viewquat, sms.new_quat); + copy_v3_v3(rv3d->ofs, sms.new_ofs); + copy_qt_qt(rv3d->viewquat, sms.new_quat); rv3d->dist = sms.new_dist; v3d->lens = sms.new_lens; } @@ -314,7 +306,10 @@ static int view3d_smoothview_invoke(bContext *C, wmOperator *op, wmEvent *event) if(rv3d->smooth_timer==NULL || rv3d->smooth_timer!=event->customdata) return OPERATOR_PASS_THROUGH; - step = (rv3d->smooth_timer->duration)/sms->time_allowed; + if(sms->time_allowed != 0.0f) + step = (rv3d->smooth_timer->duration)/sms->time_allowed; + else + step = 1.0f; /* end timer */ if(step >= 1.0f) { @@ -322,14 +317,14 @@ static int view3d_smoothview_invoke(bContext *C, wmOperator *op, wmEvent *event) /* if we went to camera, store the original */ if(sms->to_camera) { rv3d->persp= RV3D_CAMOB; - VECCOPY(rv3d->ofs, sms->orig_ofs); - QUATCOPY(rv3d->viewquat, sms->orig_quat); + copy_v3_v3(rv3d->ofs, sms->orig_ofs); + copy_qt_qt(rv3d->viewquat, sms->orig_quat); rv3d->dist = sms->orig_dist; v3d->lens = sms->orig_lens; } else { - VECCOPY(rv3d->ofs, sms->new_ofs); - QUATCOPY(rv3d->viewquat, sms->new_quat); + copy_v3_v3(rv3d->ofs, sms->new_ofs); + copy_qt_qt(rv3d->viewquat, sms->new_quat); rv3d->dist = sms->new_dist; v3d->lens = sms->new_lens; } @@ -363,7 +358,7 @@ static int view3d_smoothview_invoke(bContext *C, wmOperator *op, wmEvent *event) v3d->lens = sms->new_lens*step + sms->orig_lens*step_inv; } - ED_region_tag_redraw(CTX_wm_region(C)); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, v3d); return OPERATOR_FINISHED; } @@ -463,7 +458,7 @@ static int view3d_setobjectascamera_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void VIEW3D_OT_setobjectascamera(wmOperatorType *ot) +void VIEW3D_OT_object_as_camera(wmOperatorType *ot) { /* identifiers */ @@ -536,7 +531,7 @@ void viewline(ARegion *ar, View3D *v3d, float mval[2], float ray_start[3], float mul_v3_fl(vec, 1.0f / vec[3]); copy_v3_v3(ray_start, rv3d->viewinv[3]); - sub_v3_v3v3(vec, vec, ray_start); + sub_v3_v3(vec, ray_start); normalize_v3(vec); VECADDFAC(ray_start, rv3d->viewinv[3], vec, v3d->near); @@ -576,9 +571,9 @@ void viewvector(RegionView3D *rv3d, float coord[3], float vec[3]) { float p1[4], p2[4]; - VECCOPY(p1, coord); + copy_v3_v3(p1, coord); p1[3] = 1.0f; - VECCOPY(p2, p1); + copy_v3_v3(p2, p1); p2[3] = 1.0f; mul_m4_v4(rv3d->viewmat, p2); @@ -589,16 +584,18 @@ void viewvector(RegionView3D *rv3d, float coord[3], float vec[3]) sub_v3_v3v3(vec, p1, p2); } else { - VECCOPY(vec, rv3d->viewinv[2]); + copy_v3_v3(vec, rv3d->viewinv[2]); } normalize_v3(vec); } -void initgrabz(RegionView3D *rv3d, float x, float y, float z) +int initgrabz(RegionView3D *rv3d, float x, float y, float z) { - if(rv3d==NULL) return; + int flip= FALSE; + if(rv3d==NULL) return flip; rv3d->zfac= rv3d->persmat[0][3]*x+ rv3d->persmat[1][3]*y+ rv3d->persmat[2][3]*z+ rv3d->persmat[3][3]; - + if (rv3d->zfac < 0.0f) + flip= TRUE; /* if x,y,z is exactly the viewport offset, zfac is 0 and we don't want that * (accounting for near zero values) * */ @@ -611,6 +608,8 @@ void initgrabz(RegionView3D *rv3d, float x, float y, float z) // -- Aligorith, 2009Aug31 //if (rv3d->zfac < 0.0f) rv3d->zfac = 1.0f; if (rv3d->zfac < 0.0f) rv3d->zfac= -rv3d->zfac; + + return flip; } /* always call initgrabz */ @@ -691,7 +690,7 @@ void view3d_project_float(ARegion *ar, float *vec, float *adr, float mat[4][4]) float vec4[4]; adr[0]= IS_CLIPPED; - VECCOPY(vec4, vec); + copy_v3_v3(vec4, vec); vec4[3]= 1.0; mul_m4_v4(mat, vec4); @@ -718,7 +717,7 @@ int boundbox_clip(RegionView3D *rv3d, float obmat[][4], BoundBox *bb) mul_m4_m4m4(mat, obmat, rv3d->persmat); for(a=0; a<8; a++) { - VECCOPY(vec, bb->vec[a]); + copy_v3_v3(vec, bb->vec[a]); vec[3]= 1.0; mul_m4_v4(mat, vec); max= vec[3]; @@ -751,7 +750,7 @@ void project_short(ARegion *ar, float *vec, short *adr) /* clips */ return; } - VECCOPY(vec4, vec); + copy_v3_v3(vec4, vec); vec4[3]= 1.0; mul_m4_v4(rv3d->persmat, vec4); @@ -776,7 +775,7 @@ void project_int(ARegion *ar, float *vec, int *adr) float fx, fy, vec4[4]; adr[0]= (int)2140000000.0f; - VECCOPY(vec4, vec); + copy_v3_v3(vec4, vec); vec4[3]= 1.0; mul_m4_v4(rv3d->persmat, vec4); @@ -800,7 +799,7 @@ void project_int_noclip(ARegion *ar, float *vec, int *adr) RegionView3D *rv3d= ar->regiondata; float fx, fy, vec4[4]; - VECCOPY(vec4, vec); + copy_v3_v3(vec4, vec); vec4[3]= 1.0; mul_m4_v4(rv3d->persmat, vec4); @@ -825,7 +824,7 @@ void project_short_noclip(ARegion *ar, float *vec, short *adr) float fx, fy, vec4[4]; adr[0]= IS_CLIPPED; - VECCOPY(vec4, vec); + copy_v3_v3(vec4, vec); vec4[3]= 1.0; mul_m4_v4(rv3d->persmat, vec4); @@ -851,7 +850,7 @@ void project_float(ARegion *ar, float *vec, float *adr) float vec4[4]; adr[0]= IS_CLIPPED; - VECCOPY(vec4, vec); + copy_v3_v3(vec4, vec); vec4[3]= 1.0; mul_m4_v4(rv3d->persmat, vec4); @@ -867,7 +866,7 @@ void project_float_noclip(ARegion *ar, float *vec, float *adr) RegionView3D *rv3d= ar->regiondata; float vec4[4]; - VECCOPY(vec4, vec); + copy_v3_v3(vec4, vec); vec4[3]= 1.0; mul_m4_v4(rv3d->persmat, vec4); @@ -1114,7 +1113,7 @@ static void obmat_to_viewmat(View3D *v3d, RegionView3D *rv3d, Object *ob, short float orig_ofs[3]; float orig_dist= rv3d->dist; float orig_lens= v3d->lens; - VECCOPY(orig_ofs, rv3d->ofs); + copy_v3_v3(orig_ofs, rv3d->ofs); /* Switch from camera view */ mat3_to_quat( new_quat,tmat); @@ -1122,7 +1121,7 @@ static void obmat_to_viewmat(View3D *v3d, RegionView3D *rv3d, Object *ob, short rv3d->persp=RV3D_PERSP; rv3d->dist= 0.0; - view_settings_from_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens); + view3d_settings_from_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens); smooth_view(NULL, NULL, NULL, orig_ofs, new_quat, &orig_dist, &orig_lens); // XXX rv3d->persp=RV3D_CAMOB; /* just to be polite, not needed */ @@ -1210,11 +1209,11 @@ void setviewmatrixview3d(Scene *scene, View3D *v3d, RegionView3D *rv3d) Object *ob= v3d->ob_centre; float vec[3]; - VECCOPY(vec, ob->obmat[3]); + copy_v3_v3(vec, ob->obmat[3]); if(ob->type==OB_ARMATURE && v3d->ob_centre_bone[0]) { bPoseChannel *pchan= get_pose_channel(ob->pose, v3d->ob_centre_bone); if(pchan) { - VECCOPY(vec, pchan->pose_mat[3]); + copy_v3_v3(vec, pchan->pose_mat[3]); mul_m4_v3(ob->obmat, vec); } } @@ -1351,7 +1350,7 @@ short view3d_opengl_select(ViewContext *vc, unsigned int *buffer, unsigned int b /* ********************** local view operator ******************** */ -static unsigned int free_localbit(void) +static unsigned int free_localbit(Main *bmain) { unsigned int lay; ScrArea *sa; @@ -1361,7 +1360,7 @@ static unsigned int free_localbit(void) /* sometimes we loose a localview: when an area is closed */ /* check all areas: which localviews are in use? */ - for(sc= G.main->screen.first; sc; sc= sc->id.next) { + for(sc= bmain->screen.first; sc; sc= sc->id.next) { for(sa= sc->areabase.first; sa; sa= sa->next) { SpaceLink *sl= sa->spacedata.first; for(; sl; sl= sl->next) { @@ -1385,61 +1384,7 @@ static unsigned int free_localbit(void) return 0; } -static void copy_view3d_lock_space(View3D *v3d, Scene *scene) -{ - int bit; - - if(v3d->scenelock && v3d->localvd==NULL) { - v3d->lay= scene->lay; - v3d->camera= scene->camera; - - if(v3d->camera==NULL) { - ARegion *ar; - - for(ar=v3d->regionbase.first; ar; ar= ar->next) { - if(ar->regiontype == RGN_TYPE_WINDOW) { - RegionView3D *rv3d= ar->regiondata; - if(rv3d->persp==RV3D_CAMOB) - rv3d->persp= RV3D_PERSP; - } - } - } - - if((v3d->lay & v3d->layact) == 0) { - for(bit= 0; bit<32; bit++) { - if(v3d->lay & (1<<bit)) { - v3d->layact= 1<<bit; - break; - } - } - } - } -} - -void ED_view3d_scene_layers_copy(struct View3D *v3d, struct Scene *scene) -{ - copy_view3d_lock_space(v3d, scene); -} - -void ED_view3d_scene_layers_update(Main *bmain, Scene *scene) -{ - bScreen *sc; - ScrArea *sa; - SpaceLink *sl; - - /* from scene copy to the other views */ - for(sc=bmain->screen.first; sc; sc=sc->id.next) { - if(sc->scene!=scene) - continue; - - for(sa=sc->areabase.first; sa; sa=sa->next) - for(sl=sa->spacedata.first; sl; sl=sl->next) - if(sl->spacetype==SPACE_VIEW3D) - copy_view3d_lock_space((View3D*)sl, scene); - } -} - -int ED_view3d_scene_layer_set(int lay, const int *values) +int ED_view3d_scene_layer_set(int lay, const int *values, int *active) { int i, tot= 0; @@ -1452,14 +1397,32 @@ int ED_view3d_scene_layer_set(int lay, const int *values) return lay; for(i=0; i<20; i++) { - if(values[i]) lay |= (1<<i); + + if (active) { + /* if this value has just been switched on, make that layer active */ + if (values[i] && (lay & (1<<i))==0) { + *active = (1<<i); + } + } + + if (values[i]) lay |= (1<<i); else lay &= ~(1<<i); } + /* ensure always an active layer */ + if (active && (lay & *active)==0) { + for(i=0; i<20; i++) { + if(lay & (1<<i)) { + *active= 1<<i; + break; + } + } + } + return lay; } -static void initlocalview(Scene *scene, ScrArea *sa) +static void initlocalview(Main *bmain, Scene *scene, ScrArea *sa) { View3D *v3d= sa->spacedata.first; Base *base; @@ -1471,7 +1434,7 @@ static void initlocalview(Scene *scene, ScrArea *sa) INIT_MINMAX(min, max); - locallay= free_localbit(); + locallay= free_localbit(bmain); if(locallay==0) { printf("Sorry, no more than 8 localviews\n"); // XXX error @@ -1584,8 +1547,8 @@ static void restore_localviewdata(ScrArea *sa, int free) if(rv3d->localvd) { rv3d->dist= rv3d->localvd->dist; - VECCOPY(rv3d->ofs, rv3d->localvd->ofs); - QUATCOPY(rv3d->viewquat, rv3d->localvd->viewquat); + copy_v3_v3(rv3d->ofs, rv3d->localvd->ofs); + copy_qt_qt(rv3d->viewquat, rv3d->localvd->viewquat); rv3d->view= rv3d->localvd->view; rv3d->persp= rv3d->localvd->persp; rv3d->camzoom= rv3d->localvd->camzoom; @@ -1635,7 +1598,7 @@ static int localview_exec(bContext *C, wmOperator *unused) if(v3d->localvd) endlocalview(CTX_data_scene(C), CTX_wm_area(C)); else - initlocalview(CTX_data_scene(C), CTX_wm_area(C)); + initlocalview(CTX_data_main(C), CTX_data_scene(C), CTX_wm_area(C)); ED_area_tag_redraw(CTX_wm_area(C)); @@ -1773,7 +1736,8 @@ int ED_view3d_context_activate(bContext *C) ARegion *ar; RegionView3D *rv3d; - if(sa->spacetype != SPACE_VIEW3D) + /* sa can be NULL when called from python */ + if(sa==NULL || sa->spacetype != SPACE_VIEW3D) for(sa=sc->areabase.first; sa; sa= sa->next) if(sa->spacetype==SPACE_VIEW3D) break; @@ -1820,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, 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; @@ -1847,8 +1811,8 @@ static int game_engine_exec(bContext *C, wmOperator *op) RestoreState(C); //XXX restore_all_scene_cfra(scene_cfra_store); - set_scene_bg(startscene); - //XXX scene_update_for_newframe(G.scene, G.scene->lay); + set_scene_bg(CTX_data_main(C), startscene); + //XXX scene_update_for_newframe(bmain, scene, scene->lay); ED_area_tag_redraw(CTX_wm_area(C)); @@ -2045,7 +2009,7 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even fly->axis= 2; fly->pan_view= FALSE; fly->xlock= FALSE; - fly->zlock= TRUE; + fly->zlock= FALSE; fly->xlock_momentum=0.0f; fly->zlock_momentum=0.0f; fly->grid= 1.0f; @@ -2097,13 +2061,13 @@ static int initFlyInfo (bContext *C, FlyInfo *fly, wmOperator *op, wmEvent *even /* perspective or ortho */ if (fly->rv3d->persp==RV3D_ORTHO) fly->rv3d->persp= RV3D_PERSP; /*if ortho projection, make perspective */ - QUATCOPY(fly->rot_backup, fly->rv3d->viewquat); - VECCOPY(fly->ofs_backup, fly->rv3d->ofs); - fly->rv3d->dist= 0.0; + copy_qt_qt(fly->rot_backup, fly->rv3d->viewquat); + copy_v3_v3(fly->ofs_backup, fly->rv3d->ofs); + fly->rv3d->dist= 0.0f; upvec[2]= fly->dist_backup; /*x and y are 0*/ mul_m3_v3(mat, upvec); - sub_v3_v3v3(fly->rv3d->ofs, fly->rv3d->ofs, upvec); + sub_v3_v3(fly->rv3d->ofs, upvec); /*Done with correcting for the dist*/ } @@ -2141,8 +2105,8 @@ static int flyEnd(bContext *C, FlyInfo *fly) DAG_id_flush_update(&ob_back->id, OB_RECALC_OB); } else { /* Non Camera we need to reset the view back to the original location bacause the user canceled*/ - QUATCOPY(rv3d->viewquat, fly->rot_backup); - VECCOPY(rv3d->ofs, fly->ofs_backup); + copy_qt_qt(rv3d->viewquat, fly->rot_backup); + copy_v3_v3(rv3d->ofs, fly->ofs_backup); rv3d->persp= fly->persp_backup; } } @@ -2174,7 +2138,7 @@ static int flyEnd(bContext *C, FlyInfo *fly) upvec[2]= fly->dist_backup; /*x and y are 0*/ copy_m3_m4(mat, rv3d->viewinv); mul_m3_v3(mat, upvec); - add_v3_v3v3(rv3d->ofs, rv3d->ofs, upvec); + add_v3_v3(rv3d->ofs, upvec); /*Done with correcting for the dist */ } @@ -2262,7 +2226,7 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) /* impliment WASD keys */ case FLY_MODAL_DIR_FORWARD: if (fly->speed < 0.0f) fly->speed= -fly->speed; /* flip speed rather then stopping, game like motion */ - else fly->speed += fly->grid; /* increse like mousewheel if were alredy moving in that difection*/ + else fly->speed += fly->grid; /* increse like mousewheel if were already moving in that difection*/ fly->axis= 2; break; case FLY_MODAL_DIR_BACKWARD: @@ -2317,6 +2281,11 @@ static void flyEvent(FlyInfo *fly, wmEvent *event) static int flyApply(bContext *C, FlyInfo *fly) { + +#define FLY_ROTATE_FAC 2.5f /* more is faster */ +#define FLY_ZUP_CORRECT_FAC 0.1f /* ammount to correct per step */ +#define FLY_ZUP_CORRECT_ACCEL 0.05f /* increase upright momentum each step */ + /* fly mode - Shift+F a fly loop where the user can move move the view as if they are flying @@ -2432,7 +2401,7 @@ static int flyApply(bContext *C, FlyInfo *fly) upvec[1]=0; upvec[2]=0; mul_m3_v3(mat, upvec); - axis_angle_to_quat( tmp_quat, upvec, (float)moffset[1]*-time_redraw*20); /* Rotate about the relative up vec */ + axis_angle_to_quat( tmp_quat, upvec, (float)moffset[1] * time_redraw * -FLY_ROTATE_FAC); /* Rotate about the relative up vec */ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); if (fly->xlock) fly->xlock = 2; /*check for rotation*/ @@ -2464,7 +2433,7 @@ static int flyApply(bContext *C, FlyInfo *fly) mul_m3_v3(mat, upvec); } - axis_angle_to_quat( tmp_quat, upvec, (float)moffset[0]*time_redraw*20); /* Rotate about the relative up vec */ + axis_angle_to_quat( tmp_quat, upvec, (float)moffset[0] * time_redraw * FLY_ROTATE_FAC); /* Rotate about the relative up vec */ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); if (fly->xlock) fly->xlock = 2;/*check for rotation*/ @@ -2485,10 +2454,10 @@ static int flyApply(bContext *C, FlyInfo *fly) upvec[2]=1; mul_m3_v3(mat, upvec); - axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->zlock_momentum*0.1); /* Rotate about the relative up vec */ + axis_angle_to_quat( tmp_quat, upvec, roll*time_redraw_clamped*fly->zlock_momentum * FLY_ZUP_CORRECT_FAC); /* Rotate about the relative up vec */ mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat); - fly->zlock_momentum += 0.05f; + fly->zlock_momentum += FLY_ZUP_CORRECT_ACCEL; } else { fly->zlock=1; /* dont check until the view rotates again */ fly->zlock_momentum= 0.0f; @@ -2544,7 +2513,7 @@ static int flyApply(bContext *C, FlyInfo *fly) if (lock_ob->protectflag & OB_LOCK_LOCZ) dvec[2] = 0.0; } - add_v3_v3v3(rv3d->ofs, rv3d->ofs, dvec); + add_v3_v3(rv3d->ofs, dvec); /* todo, dynamic keys */ #if 0 @@ -2625,7 +2594,7 @@ static int flyApply(bContext *C, FlyInfo *fly) /*were not redrawing but we need to update the time else the view will jump */ fly->time_lastdraw= PIL_check_seconds_timer(); /* end drawing */ - VECCOPY(fly->dvec_prev, dvec); + copy_v3_v3(fly->dvec_prev, dvec); } /* moved to flyEnd() */ @@ -2738,10 +2707,10 @@ void view3d_align_axis_to_vector(View3D *v3d, RegionView3D *rv3d, int axisidx, f float orig_dist= rv3d->dist; float orig_lens= v3d->lens; - VECCOPY(orig_ofs, rv3d->ofs); + copy_v3_v3(orig_ofs, rv3d->ofs); rv3d->persp= RV3D_PERSP; rv3d->dist= 0.0; - view_settings_from_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens); + view3d_settings_from_ob(v3d->camera, rv3d->ofs, NULL, NULL, &v3d->lens); smooth_view(NULL, NULL, NULL, orig_ofs, new_quat, &orig_dist, &orig_lens); // XXX } else { if (rv3d->persp==RV3D_CAMOB) rv3d->persp= RV3D_PERSP; /* switch out of camera mode */ |