Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2012-01-31 22:33:31 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2012-01-31 22:33:31 +0400
commitdb79c8b01e67e8707aa3810cb727997c9ea3c250 (patch)
tree9901a0588df91f92ed4a631a46d81cdcd89ec563 /source/blender/editors/space_view3d/view3d_view.c
parent23db21e2c17052ba756a68eb7450fedacc14c555 (diff)
Implemented general functions to store view context like viewport width/height
and projection matrix, so operators which depends on such things can easily save settings in operator properties in invoke and then reuse them in exec callback. This will fix: #24767: Knife tool last operations panel doesn't cause changes even though F6 pop-up does. #27129: Problem with knife cuts/midpoint type in quad view Usage is pretty simple: - From operator template declaration function call ED_view3d_operator_properties_viewmat() to register all needed properties in operator. - From invoke callback call ED_view3d_operator_properties_viewmat_set to store all needed settings in operator properties(). - To access this settings from exec callback, use function ED_view3d_operator_properties_viewmat_get(). Additional change: added function apply_project_float() which does the same as project_float() but accepts actual values for viewport width/height and projection matrix.
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_view.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c67
1 files changed, 59 insertions, 8 deletions
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index f57d8a5ec1b..05e8cb45611 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -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,
@@ -947,23 +950,30 @@ 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;
+ float vec4[4];
+
+ 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;
@@ -1854,3 +1864,44 @@ 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])
+{
+ float values[16];
+
+ *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);
+}