Sculpt:
[blender.git] / source / blender / editors / space_view3d / view3d_edit.c
index 8597f0b..fa69085 100644 (file)
@@ -275,7 +275,7 @@ static void calctrackballvec(rcti *rect, int mx, int my, float *vec)
 }
 
 
-static void viewops_data(bContext *C, wmOperator *op, wmEvent *event)
+static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event)
 {
        static float lastofs[3] = {0,0,0};
        View3D *v3d = CTX_wm_view3d(C);
@@ -314,6 +314,21 @@ static void viewops_data(bContext *C, wmOperator *op, wmEvent *event)
        if (rv3d->persmat[2][1] < 0.0f)
                vod->reverse= -1.0f;
 
+       rv3d->rflag |= RV3D_NAVIGATING;
+}
+
+static void viewops_data_free(bContext *C, wmOperator *op)
+{
+       Paint *p = paint_get_active(CTX_data_scene(C));
+       ViewOpsData *vod= op->customdata;
+
+       vod->rv3d->rflag &= ~RV3D_NAVIGATING;
+
+       if(p && (p->flags & PAINT_FAST_NAVIGATE))
+               ED_region_tag_redraw(vod->ar);
+
+       MEM_freeN(vod);
+       op->customdata= NULL;
 }
 
 /* ************************** viewrotate **********************************/
@@ -578,9 +593,7 @@ static int viewrotate_modal(bContext *C, wmOperator *op, wmEvent *event)
        }
        else if (event_code==VIEW_CONFIRM) {
                request_depth_update(CTX_wm_region_view3d(C));
-
-               MEM_freeN(vod);
-               op->customdata= NULL;
+               viewops_data_free(C, op);
 
                return OPERATOR_FINISHED;
        }
@@ -597,7 +610,7 @@ static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event)
                return OPERATOR_CANCELLED;
 
        /* makes op->customdata */
-       viewops_data(C, op, event);
+       viewops_data_create(C, op, event);
        vod= op->customdata;
 
        /* switch from camera view when: */
@@ -718,8 +731,7 @@ static int viewmove_modal(bContext *C, wmOperator *op, wmEvent *event)
        else if (event_code==VIEW_CONFIRM) {
                request_depth_update(CTX_wm_region_view3d(C));
 
-               MEM_freeN(vod);
-               op->customdata= NULL;
+               viewops_data_free(C, op);
 
                return OPERATOR_FINISHED;
        }
@@ -730,7 +742,7 @@ static int viewmove_modal(bContext *C, wmOperator *op, wmEvent *event)
 static int viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        /* makes op->customdata */
-       viewops_data(C, op, event);
+       viewops_data_create(C, op, event);
 
        /* add temp handler */
        WM_event_add_modal_handler(C, op);
@@ -911,9 +923,7 @@ static int viewzoom_modal(bContext *C, wmOperator *op, wmEvent *event)
        }
        else if (event_code==VIEW_CONFIRM) {
                request_depth_update(CTX_wm_region_view3d(C));
-
-               MEM_freeN(vod);
-               op->customdata= NULL;
+               viewops_data_free(C, op);
 
                return OPERATOR_FINISHED;
        }
@@ -974,7 +984,7 @@ static int viewzoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
        }
        else {
                /* makes op->customdata */
-               viewops_data(C, op, event);
+               viewops_data_create(C, op, event);
 
                /* add temp handler */
                WM_event_add_modal_handler(C, op);
@@ -1001,7 +1011,7 @@ void VIEW3D_OT_zoom(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_BLOCKING|OPTYPE_GRAB_POINTER;
 
-       RNA_def_int(ot->srna, "delta", 0, 0, INT_MAX, "Delta", "", 0, INT_MAX);
+       RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX);
        RNA_def_int(ot->srna, "mx", 0, 0, INT_MAX, "Zoom Position X", "", 0, INT_MAX);
        RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Zoom Position Y", "", 0, INT_MAX);
 }
@@ -1232,6 +1242,51 @@ void VIEW3D_OT_view_center(wmOperatorType *ot)
        ot->flag= 0;
 }
 
+static int viewcenter_cursor_exec(bContext *C, wmOperator *op)
+{
+       View3D *v3d = CTX_wm_view3d(C);
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
+       Scene *scene= CTX_data_scene(C);
+       
+       if (rv3d) {
+               if (rv3d->persp==RV3D_CAMOB) {
+                       /* center the camera offset */
+                       rv3d->camdx= rv3d->camdy= 0.0;
+               }
+               else {
+                       /* non camera center */
+                       float *curs= give_cursor(scene, v3d);
+                       float new_ofs[3];
+                       
+                       new_ofs[0]= -curs[0];
+                       new_ofs[1]= -curs[1];
+                       new_ofs[2]= -curs[2];
+                       
+                       smooth_view(C, NULL, NULL, new_ofs, NULL, NULL, NULL);
+               }
+               
+               if (rv3d->viewlock & RV3D_BOXVIEW)
+                       view3d_boxview_copy(CTX_wm_area(C), CTX_wm_region(C));
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
+void VIEW3D_OT_view_center_cursor(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Center View to Cursor";
+       ot->description= "Centers the view so that the cursor is in the middle of the view.";
+       ot->idname= "VIEW3D_OT_view_center_cursor";
+       
+       /* api callbacks */
+       ot->exec= viewcenter_cursor_exec;
+       ot->poll= ED_operator_view3d_active;
+       
+       /* flags */
+       ot->flag= 0;
+}
+
 /* ********************* Set render border operator ****************** */
 
 static int render_border_exec(bContext *C, wmOperator *op)
@@ -1868,12 +1923,9 @@ void ED_view3d_local_clipping(RegionView3D *rv3d, float mat[][4])
 static int view3d_clipping_exec(bContext *C, wmOperator *op)
 {
        RegionView3D *rv3d= CTX_wm_region_view3d(C);
+       ViewContext vc;
+       bglMats mats;
        rcti rect;
-       double mvmatrix[16];
-       double projmatrix[16];
-       double xs, ys, p[3];
-       GLint viewport[4];
-       short val;
 
        rect.xmin= RNA_int_get(op->ptr, "xmin");
        rect.ymin= RNA_int_get(op->ptr, "ymin");
@@ -1886,36 +1938,9 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op)
        /* note; otherwise opengl won't work */
        view3d_operator_needs_opengl(C);
 
-       /* Get the matrices needed for gluUnProject */
-       glGetIntegerv(GL_VIEWPORT, viewport);
-       glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
-       glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
-
-       /* near zero floating point values can give issues with gluUnProject
-               in side view on some implementations */
-       if(fabs(mvmatrix[0]) < 1e-6) mvmatrix[0]= 0.0;
-       if(fabs(mvmatrix[5]) < 1e-6) mvmatrix[5]= 0.0;
-
-       /* Set up viewport so that gluUnProject will give correct values */
-       viewport[0] = 0;
-       viewport[1] = 0;
-
-       /* four clipping planes and bounding volume */
-       /* first do the bounding volume */
-       for(val=0; val<4; val++) {
-
-               xs= (val==0||val==3)?rect.xmin:rect.xmax;
-               ys= (val==0||val==1)?rect.ymin:rect.ymax;
-
-               gluUnProject(xs, ys, 0.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
-               VECCOPY(rv3d->clipbb->vec[val], p);
-
-               gluUnProject(xs, ys, 1.0, mvmatrix, projmatrix, viewport, &p[0], &p[1], &p[2]);
-               VECCOPY(rv3d->clipbb->vec[4+val], p);
-       }
-
-       /* then plane equations */
-       calc_clipping_plane(rv3d->clip, rv3d->clipbb);
+       view3d_set_viewcontext(C, &vc);
+       view3d_get_transformation(vc.ar, vc.rv3d, vc.obact, &mats);
+       view3d_calculate_clipping(rv3d->clipbb, rv3d->clip, &mats, &rect);
 
        return OPERATOR_FINISHED;
 }