svn merge ^/trunk/blender -r43751:43819, need to look into changes made to editmesh_l...
[blender-staging.git] / source / blender / editors / space_view3d / view3d_view.c
index 67165560def66b8fef4b6c897a1da257d790acc6..c05f9de691b93bb53e29150d4c57557d140ae3e7 100644 (file)
@@ -68,6 +68,9 @@
 #include "BL_System.h"
 #endif
 
+#include "RNA_access.h"
+#include "RNA_define.h"
+
 #include "view3d_intern.h"     // own include
 
 /* use this call when executing an operator,
@@ -945,23 +948,29 @@ void project_short_noclip(ARegion *ar, const float vec[3], short adr[2])
        }
 }
 
-void project_float(ARegion *ar, const float vec[3], float adr[2])
+void apply_project_float(float persmat[4][4], int winx, int winy, const float vec[3], float adr[2])
 {
-       RegionView3D *rv3d= ar->regiondata;
        float vec4[4];
-       
+
        copy_v3_v3(vec4, vec);
        vec4[3]= 1.0;
        adr[0]= IS_CLIPPED;
-       
-       mul_m4_v4(rv3d->persmat, vec4);
-       
+
+       mul_m4_v4(persmat, vec4);
+
        if(vec4[3] > (float)BL_NEAR_CLIP) {
-               adr[0] = (float)(ar->winx/2.0f)+(ar->winx/2.0f)*vec4[0]/vec4[3];
-               adr[1] = (float)(ar->winy/2.0f)+(ar->winy/2.0f)*vec4[1]/vec4[3];
+               adr[0] = (float)(winx/2.0f)+(winx/2.0f)*vec4[0]/vec4[3];
+               adr[1] = (float)(winy/2.0f)+(winy/2.0f)*vec4[1]/vec4[3];
        }
 }
 
+void project_float(ARegion *ar, const float vec[3], float adr[2])
+{
+       RegionView3D *rv3d= ar->regiondata;
+
+       apply_project_float(rv3d->persmat, ar->winx, ar->winy, vec, adr);
+}
+
 void project_float_noclip(ARegion *ar, const float vec[3], float adr[2])
 {
        RegionView3D *rv3d= ar->regiondata;
@@ -1852,3 +1861,42 @@ float ED_view3d_pixel_size(struct RegionView3D *rv3d, const float co[3])
                                rv3d->persmat[2][3]*co[2])
                        ) * rv3d->pixsize;
 }
+
+/* view matrix properties utilities */
+
+void ED_view3d_operator_properties_viewmat(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+
+       prop = RNA_def_int(ot->srna, "region_width", 0, 0, INT_MAX, "Region Width", "", 0, INT_MAX);
+       RNA_def_property_flag(prop, PROP_HIDDEN);
+
+       prop = RNA_def_int(ot->srna, "region_height", 0, 0, INT_MAX, "Region height", "", 0, INT_MAX);
+       RNA_def_property_flag(prop, PROP_HIDDEN);
+
+       prop = RNA_def_float_matrix(ot->srna, "perspective_matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Perspective Matrix", 0.0f, 0.0f);
+       RNA_def_property_flag(prop, PROP_HIDDEN);
+}
+
+void ED_view3d_operator_properties_viewmat_set(bContext *C, wmOperator *op)
+{
+       ARegion *ar= CTX_wm_region(C);
+       RegionView3D *rv3d= ED_view3d_context_rv3d(C);
+
+       if(!RNA_struct_property_is_set(op->ptr, "region_width"))
+               RNA_int_set(op->ptr, "region_width", ar->winx);
+
+       if(!RNA_struct_property_is_set(op->ptr, "region_height"))
+               RNA_int_set(op->ptr, "region_height", ar->winy);
+
+       if(!RNA_struct_property_is_set(op->ptr, "perspective_matrix"))
+               RNA_float_set_array(op->ptr, "perspective_matrix", (float *)rv3d->persmat);
+}
+
+void ED_view3d_operator_properties_viewmat_get(wmOperator *op, int *winx, int *winy, float persmat[4][4])
+{
+       *winx = RNA_int_get(op->ptr, "region_width");
+       *winy = RNA_int_get(op->ptr, "region_height");
+
+       RNA_float_get_array(op->ptr, "perspective_matrix", (float *)persmat);
+}