svn merge -r41779:41847 ^/trunk/blender
[blender.git] / source / blender / editors / space_view3d / view3d_view.c
index ca03ee5..1b4b26a 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "BKE_anim.h"
 #include "BKE_action.h"
+#include "BKE_camera.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_object.h"
@@ -406,9 +407,8 @@ static int view3d_setcameratoview_poll(bContext *C)
        return 0;
 }
 
-void VIEW3D_OT_setcameratoview(wmOperatorType *ot)
+void VIEW3D_OT_camera_to_view(wmOperatorType *ot)
 {
-       
        /* identifiers */
        ot->name= "Align Camera To View";
        ot->description= "Set camera view to active view";
@@ -422,6 +422,55 @@ void VIEW3D_OT_setcameratoview(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* unlike VIEW3D_OT_view_selected this is for framing a render and not
+ * meant to take into account vertex/bone selection for eg. */
+static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       Scene *scene= CTX_data_scene(C);
+       View3D *v3d = CTX_wm_view3d(C);
+       Object *camera_ob= v3d->camera;
+
+       float r_co[3]; /* the new location to apply */
+
+       /* this function does all the important stuff */
+       if (camera_view_frame_fit_to_scene(scene, v3d, camera_ob, r_co)) {
+
+               ObjectTfmProtectedChannels obtfm;
+               float obmat_new[4][4];
+
+               copy_m4_m4(obmat_new, camera_ob->obmat);
+               copy_v3_v3(obmat_new[3], r_co);
+
+               /* only touch location */
+               object_tfm_protected_backup(camera_ob, &obtfm);
+               object_apply_mat4(camera_ob, obmat_new, TRUE, TRUE);
+               object_tfm_protected_restore(camera_ob, &obtfm, OB_LOCK_SCALE | OB_LOCK_ROT4D);
+
+               /* notifiers */
+               DAG_id_tag_update(&camera_ob->id, OB_RECALC_OB);
+               WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, camera_ob);
+               return OPERATOR_FINISHED;
+       }
+       else {
+               return OPERATOR_CANCELLED;
+       }
+}
+
+void VIEW3D_OT_camera_to_view_selected(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Camera Fit Frame to Selected";
+       ot->description= "Move the camera so selected objects are framed";
+       ot->idname= "VIEW3D_OT_camera_to_view_selected";
+
+       /* api callbacks */
+       ot->exec= view3d_camera_to_view_selected_exec;
+       // ot->poll= view3d_setcameratoview_poll;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 
 static int view3d_setobjectascamera_exec(bContext *C, wmOperator *UNUSED(op))
 {
@@ -461,7 +510,7 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
        ot->idname= "VIEW3D_OT_object_as_camera";
        
        /* api callbacks */
-       ot->exec= view3d_setobjectascamera_exec;        
+       ot->exec= view3d_setobjectascamera_exec;
        ot->poll= ED_operator_rv3d_unlock_poll;
        
        /* flags */