[#17388] snap view to main views while rotating from Roelf De Kock (kiemdoder)
authorCampbell Barton <ideasman42@gmail.com>
Mon, 22 Sep 2008 10:00:31 +0000 (10:00 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 22 Sep 2008 10:00:31 +0000 (10:00 +0000)
hold down ctrl when rotating the viewport

source/blender/src/view.c

index 4c56e5ce64ecad61e4279e3ada3b8c687b6503c8..d6bc9cea311b96e502bb346dd131aedd3a32ed5a 100644 (file)
@@ -94,6 +94,9 @@
 #define TRACKBALLSIZE  (1.1)
 #define BL_NEAR_CLIP 0.001
 
+#define COS45 0.70710678118654746
+#define SIN45 COS45
+
 
 /* local prototypes ----------*/
 void setcameratoview3d(void); /* windows.c & toets.c */
@@ -1104,6 +1107,87 @@ void viewmove(int mode)
                                                VecAddf(G.vd->ofs, G.vd->ofs, obofs);
                                        }
                                }
+                               
+                               /* check for view snap */
+                               if (G.qual==LR_CTRLKEY){
+                                       int i;
+                                       float viewmat[3][3];
+
+                                       static const float thres = 0.93; //cos(20 deg);
+                                       
+                                       static float snapquats[39][6] = {
+                                               /*{q0, q1, q3, q4, view, oposite_direction}*/
+                                               {COS45, -SIN45, 0.0, 0.0, 1, 0},  //front
+                                               {0.0, 0.0, -SIN45, -SIN45, 1, 1}, //back
+                                               {1.0, 0.0, 0.0, 0.0, 7, 0},       //top
+                                               {0.0, -1.0, 0.0, 0.0, 7, 1},      //bottom
+                                               {0.5, -0.5, -0.5, -0.5, 3, 0},    //left
+                                               {0.5, -0.5, 0.5, 0.5, 3, 1},      //right
+                                               
+                                               /* some more 45 deg snaps */
+                                               {0.65328145027160645, -0.65328145027160645, 0.27059805393218994, 0.27059805393218994, 0, 0},
+                                               {0.92387950420379639, 0.0, 0.0, 0.38268342614173889, 0, 0},
+                                               {0.0, -0.92387950420379639, 0.38268342614173889, 0.0, 0, 0},
+                                               {0.35355335474014282, -0.85355335474014282, 0.35355338454246521, 0.14644660055637360, 0, 0},
+                                               {0.85355335474014282, -0.35355335474014282, 0.14644660055637360, 0.35355338454246521, 0, 0},
+                                               {0.49999994039535522, -0.49999994039535522, 0.49999997019767761, 0.49999997019767761, 0, 0},
+                                               {0.27059802412986755, -0.65328145027160645, 0.65328145027160645, 0.27059802412986755, 0, 0},
+                                               {0.65328145027160645, -0.27059802412986755, 0.27059802412986755, 0.65328145027160645, 0, 0},
+                                               {0.27059799432754517, -0.27059799432754517, 0.65328139066696167, 0.65328139066696167, 0, 0},
+                                               {0.38268336653709412, 0.0, 0.0, 0.92387944459915161, 0, 0},
+                                               {0.0, -0.38268336653709412, 0.92387944459915161, 0.0, 0, 0},
+                                               {0.14644658565521240, -0.35355335474014282, 0.85355335474014282, 0.35355335474014282, 0, 0},
+                                               {0.35355335474014282, -0.14644658565521240, 0.35355335474014282, 0.85355335474014282, 0, 0},
+                                               {0.0, 0.0, 0.92387944459915161, 0.38268336653709412, 0, 0},
+                                               {-0.0, 0.0, 0.38268336653709412, 0.92387944459915161, 0, 0},
+                                               {-0.27059802412986755, 0.27059802412986755, 0.65328133106231689, 0.65328133106231689, 0, 0},
+                                               {-0.38268339633941650, 0.0, 0.0, 0.92387938499450684, 0, 0},
+                                               {0.0, 0.38268339633941650, 0.92387938499450684, 0.0, 0, 0},
+                                               {-0.14644658565521240, 0.35355338454246521, 0.85355329513549805, 0.35355332493782043, 0, 0},
+                                               {-0.35355338454246521, 0.14644658565521240, 0.35355332493782043, 0.85355329513549805, 0, 0},
+                                               {-0.49999991059303284, 0.49999991059303284, 0.49999985098838806, 0.49999985098838806, 0, 0},
+                                               {-0.27059799432754517, 0.65328145027160645, 0.65328139066696167, 0.27059799432754517, 0, 0},
+                                               {-0.65328145027160645, 0.27059799432754517, 0.27059799432754517, 0.65328139066696167, 0, 0},
+                                               {-0.65328133106231689, 0.65328133106231689, 0.27059793472290039, 0.27059793472290039, 0, 0},
+                                               {-0.92387932538986206, 0.0, 0.0, 0.38268333673477173, 0, 0},
+                                               {0.0, 0.92387932538986206, 0.38268333673477173, 0.0, 0, 0},
+                                               {-0.35355329513549805, 0.85355329513549805, 0.35355329513549805, 0.14644657075405121, 0, 0},
+                                               {-0.85355329513549805, 0.35355329513549805, 0.14644657075405121, 0.35355329513549805, 0, 0},
+                                               {-0.38268330693244934, 0.92387938499450684, 0.0, 0.0, 0, 0},
+                                               {-0.92387938499450684, 0.38268330693244934, 0.0, 0.0, 0, 0},
+                                               {-COS45, 0.0, 0.0, SIN45, 0, 0},
+                                               {COS45, 0.0, 0.0, SIN45, 0, 0},
+                                               {0.0, 0.0, 0.0, 1.0, 0, 0}
+                                       };
+
+                                       QuatToMat3(G.vd->viewquat, viewmat);
+
+                                       for (i = 0 ; i < 39; i++){
+                                               float snapmat[3][3];
+                                               float view = (int)snapquats[i][4];
+                                               float oposite_dir = (int)snapquats[i][5];
+                                               
+                                               QuatToMat3(snapquats[i], snapmat);
+                                               
+                                               if ((Inpf(snapmat[0], viewmat[0]) > thres) &&
+                                                       (Inpf(snapmat[1], viewmat[1]) > thres) &&
+                                                       (Inpf(snapmat[2], viewmat[2]) > thres)){
+                                                       
+                                                       QUATCOPY(G.vd->viewquat, snapquats[i]);
+                                                       
+                                                       G.vd->view = view;
+                                                       if (view){
+                                                               if (oposite_dir){
+                                                                       G.vd->flag2 |= V3D_OPP_DIRECTION_NAME;
+                                                               }else{
+                                                                       G.vd->flag2 &= ~V3D_OPP_DIRECTION_NAME;
+                                                               }
+                                                       }
+                                                       
+                                                       break;
+                                               }
+                                       }
+                               }
                        }
                        else if(mode==1) {      /* translate */
                                if(G.vd->persp==V3D_CAMOB) {