[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51047] trunk/blender/source/blender/ editors: refactor ED_view3d_project_short & ED_view3d_project_short_noclip,
Campbell Barton
ideasman42 at gmail.com
Thu Oct 4 18:46:15 CEST 2012
Revision: 51047
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51047
Author: campbellbarton
Date: 2012-10-04 16:46:15 +0000 (Thu, 04 Oct 2012)
Log Message:
-----------
refactor ED_view3d_project_short & ED_view3d_project_short_noclip,
This is apart of a code cleanup to make ED_view3d_project_short/ED_view3d_project_int/ED_view3d_project_float interchangeable. Currently they work very differently in a way thats quite confusing (and cause of bugs in blender that remain uncorrected) - fixes coming.
There are also cases where ED_view3d_project_short is used, then the values are converted from shorts into int's after because ED_view3d_project_int() behaves differently, will unify behavior of these functions after this commit.
- rather then clip/noclip versions, pass flags (for bound-box clip, window clip).
- rather then store the invalid clip-value, return success (or error value clip_near, clip_bb, clip_win, overflow).
- remove local copies of project functions from drawobject.c: view3d_project_short_clip, view3d_project_short_noclip, view3d_project_short_clip_persmat.
add functions:
- ED_view3d_project_short_global() global space projection
- ED_view3d_project_short_object() object space projection.
- ED_view3d_project_short_ex() take perspective matrix and local space option as args.
- ED_view3d_project_base() - special function to set the Object 'Base' screen coords (sx, sy), since this is a common enough operation.
Modified Paths:
--------------
trunk/blender/source/blender/editors/armature/editarmature_sketch.c
trunk/blender/source/blender/editors/include/ED_view3d.h
trunk/blender/source/blender/editors/physics/particle_edit.c
trunk/blender/source/blender/editors/space_view3d/drawobject.c
trunk/blender/source/blender/editors/space_view3d/view3d_select.c
trunk/blender/source/blender/editors/space_view3d/view3d_view.c
Modified: trunk/blender/source/blender/editors/armature/editarmature_sketch.c
===================================================================
--- trunk/blender/source/blender/editors/armature/editarmature_sketch.c 2012-10-04 15:14:15 UTC (rev 51046)
+++ trunk/blender/source/blender/editors/armature/editarmature_sketch.c 2012-10-04 16:46:15 UTC (rev 51047)
@@ -646,16 +646,17 @@
short pval[2];
int pdist;
- ED_view3d_project_short_noclip(ar, stk->points[i].p, pval);
+ if (ED_view3d_project_short_global(ar, stk->points[i].p, pval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
- pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]);
+ pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]);
- if (pdist < *dist) {
- *dist = pdist;
- pt = stk->points + i;
+ if (pdist < *dist) {
+ *dist = pdist;
+ pt = stk->points + i;
- if (index != NULL) {
- *index = i;
+ if (index != NULL) {
+ *index = i;
+ }
}
}
}
@@ -681,8 +682,25 @@
{
copy_v3_v3(vec, bone->head);
mul_m4_v3(ob->obmat, vec);
- ED_view3d_project_short_noclip(ar, vec, pval);
+ if (ED_view3d_project_short_noclip(ar, vec, pval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
+ pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]);
+
+ if (pdist < *dist)
+ {
+ *dist = pdist;
+ pt = &boneSnap;
+ copy_v3_v3(pt->p, vec);
+ pt->type = PT_EXACT;
+ }
+ }
+ }
+
+
+ copy_v3_v3(vec, bone->tail);
+ mul_m4_v3(ob->obmat, vec);
+ if (ED_view3d_project_short_noclip(ar, vec, pval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
+
pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]);
if (pdist < *dist)
@@ -693,21 +711,6 @@
pt->type = PT_EXACT;
}
}
-
-
- copy_v3_v3(vec, bone->tail);
- mul_m4_v3(ob->obmat, vec);
- ED_view3d_project_short_noclip(ar, vec, pval);
-
- pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]);
-
- if (pdist < *dist)
- {
- *dist = pdist;
- pt = &boneSnap;
- copy_v3_v3(pt->p, vec);
- pt->type = PT_EXACT;
- }
}
return pt;
@@ -936,10 +939,14 @@
initgrabz(ar->regiondata, fp[0], fp[1], fp[2]);
/* method taken from editview.c - mouse_cursor() */
- ED_view3d_project_short_noclip(ar, fp, cval);
- VECSUB2D(mval_f, cval, dd->mval);
- ED_view3d_win_to_delta(ar, mval_f, dvec);
- sub_v3_v3v3(vec, fp, dvec);
+ if (ED_view3d_project_short_global(ar, fp, cval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) {
+ VECSUB2D(mval_f, cval, dd->mval);
+ ED_view3d_win_to_delta(ar, mval_f, dvec);
+ sub_v3_v3v3(vec, fp, dvec);
+ }
+ else {
+ zero_v3(vec);
+ }
}
static int sk_getStrokeDrawPoint(bContext *C, SK_Point *pt, SK_Sketch *UNUSED(sketch), SK_Stroke *stk, SK_DrawData *dd)
@@ -1786,33 +1793,35 @@
short start_val[2], end_val[2];
short dist;
- ED_view3d_project_short_noclip(ar, gest->stk->points[0].p, start_val);
- ED_view3d_project_short_noclip(ar, sk_lastStrokePoint(gest->stk)->p, end_val);
+ if ((ED_view3d_project_short_global(ar, gest->stk->points[0].p, start_val, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS) &&
+ (ED_view3d_project_short_global(ar, sk_lastStrokePoint(gest->stk)->p, end_val, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_SUCCESS))
+ {
- dist = MAX2(ABS(start_val[0] - end_val[0]), ABS(start_val[1] - end_val[1]));
+ dist = MAX2(ABS(start_val[0] - end_val[0]), ABS(start_val[1] - end_val[1]));
- /* if gesture is a circle */
- if (dist <= 20) {
- SK_Intersection *isect;
+ /* if gesture is a circle */
+ if (dist <= 20) {
+ SK_Intersection *isect;
- /* check if it circled around an exact point */
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- /* only delete strokes that are crossed twice */
- if (isect->next && isect->next->stroke == isect->stroke) {
- int start_index, end_index;
- int i;
+ /* check if it circled around an exact point */
+ for (isect = gest->intersections.first; isect; isect = isect->next) {
+ /* only delete strokes that are crossed twice */
+ if (isect->next && isect->next->stroke == isect->stroke) {
+ int start_index, end_index;
+ int i;
- start_index = MIN2(isect->after, isect->next->after);
- end_index = MAX2(isect->before, isect->next->before);
+ start_index = MIN2(isect->after, isect->next->after);
+ end_index = MAX2(isect->before, isect->next->before);
- for (i = start_index; i <= end_index; i++) {
- if (isect->stroke->points[i].type == PT_EXACT) {
- return 1; /* at least one exact point found, stop detect here */
+ for (i = start_index; i <= end_index; i++) {
+ if (isect->stroke->points[i].type == PT_EXACT) {
+ return 1; /* at least one exact point found, stop detect here */
+ }
}
+
+ /* skip next */
+ isect = isect->next;
}
-
- /* skip next */
- isect = isect->next;
}
}
}
Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h 2012-10-04 15:14:15 UTC (rev 51046)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h 2012-10-04 16:46:15 UTC (rev 51047)
@@ -113,8 +113,31 @@
/* TODO, these functions work quite differently, we should make them behave in a uniform way
* otherwise we can't be sure bugs are not added when we need to move from short->float types for eg
* - Campbell */
-void ED_view3d_project_short(struct ARegion *ar, const float co[3], short r_co[2]);
-void ED_view3d_project_short_noclip(struct ARegion *ar, const float vec[3], short r_co[2]);
+
+
+/* return values for ED_view3d_project_...() */
+typedef enum {
+ V3D_PROJ_RET_SUCCESS = 0,
+ V3D_PROJ_RET_CLIP_NEAR = 1, /* can't avoid this when in perspective mode, (can't avoid) */
+ V3D_PROJ_RET_CLIP_BB = 2, /* bounding box clip - RV3D_CLIPPING */
+ V3D_PROJ_RET_CLIP_WIN = 3, /* outside window bounds */
+ V3D_PROJ_RET_OVERFLOW = 4 /* outside range (mainly for short), (can't avoid) */
+} eV3DProjStatus;
+
+/* some clipping tests are optional */
+typedef enum {
+ V3D_PROJ_TEST_NOP = 0,
+ V3D_PROJ_TEST_CLIP_BB = (1 << 0),
+ V3D_PROJ_TEST_CLIP_WIN = (1 << 1),
+} eV3DProjTest;
+
+
+eV3DProjStatus ED_view3d_project_short_ex(struct ARegion *ar, float perspmat[4][4], const int is_local,
+ const float co[3], short r_co[2], eV3DProjTest flag);
+eV3DProjStatus ED_view3d_project_short_global(struct ARegion *ar, const float co[3], short r_co[2], eV3DProjTest flag);
+eV3DProjStatus ED_view3d_project_short_object(struct ARegion *ar, const float co[3], short r_co[2], eV3DProjTest flag);
+void _ED_view3d_project_short(struct ARegion *ar, const float co[3], short r_co[2]); // V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN
+void _ED_view3d_project_short_noclip(struct ARegion *ar, const float vec[3], short r_co[2]); //
void ED_view3d_project_int(struct ARegion *ar, const float co[3], int r_co[2]);
void ED_view3d_project_int_noclip(struct ARegion *ar, const float co[3], int r_co[2]);
void ED_view3d_project_float(struct ARegion *ar, const float co[3], float r_co[2]);
@@ -122,6 +145,9 @@
void ED_view3d_project_float_v2_m4(const struct ARegion *a, const float co[3], float r_co[2], float mat[4][4]);
void ED_view3d_project_float_v3_m4(struct ARegion *a, const float co[3], float r_co[3], float mat[4][4]);
+/* Base's get their own function since its a common operation */
+eV3DProjStatus ED_view3d_project_base(struct ARegion *ar, struct Base *base);
+
void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, const float y, const float z);
int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, float *clipsta, float *clipend);
Modified: trunk/blender/source/blender/editors/physics/particle_edit.c
===================================================================
--- trunk/blender/source/blender/editors/physics/particle_edit.c 2012-10-04 15:14:15 UTC (rev 51046)
+++ trunk/blender/source/blender/editors/physics/particle_edit.c 2012-10-04 16:46:15 UTC (rev 51047)
@@ -408,11 +408,12 @@
/* nothing to do */
if ((v3d->drawtype<=OB_WIRE) || (v3d->flag & V3D_ZBUF_SELECT)==0)
return 1;
-
- ED_view3d_project_short(data->vc.ar, co, wco);
- if (wco[0] == IS_CLIPPED)
+ if (ED_view3d_project_short_global(data->vc.ar, co, wco,
+ V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN) != V3D_PROJ_RET_SUCCESS)
+ {
return 0;
+ }
gluProject(co[0], co[1], co[2], data->mats.modelview, data->mats.projection,
(GLint *)data->mats.viewport, &ux, &uy, &uz);
Modified: trunk/blender/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/drawobject.c 2012-10-04 15:14:15 UTC (rev 51046)
+++ trunk/blender/source/blender/editors/space_view3d/drawobject.c 2012-10-04 16:46:15 UTC (rev 51047)
@@ -239,107 +239,6 @@
return 1;
}
-/* ************* only use while object drawing **************
- * or after running ED_view3d_init_mats_rv3d
- * */
-static void view3d_project_short_clip(ARegion *ar, const float vec[3], short adr[2], int is_local)
-{
- RegionView3D *rv3d = ar->regiondata;
- float fx, fy, vec4[4];
-
- adr[0] = IS_CLIPPED;
-
- /* clipplanes in eye space */
- if (rv3d->rflag & RV3D_CLIPPING) {
- if (ED_view3d_clipping_test(rv3d, vec, is_local))
- return;
- }
-
- copy_v3_v3(vec4, vec);
- vec4[3] = 1.0;
-
- mul_m4_v4(rv3d->persmatob, vec4);
-
- /* clipplanes in window space */
- if (vec4[3] > (float)BL_NEAR_CLIP) { /* is the NEAR clipping cutoff for picking */
- fx = (ar->winx / 2) * (1 + vec4[0] / vec4[3]);
-
- if (fx > 0 && fx < ar->winx) {
-
- fy = (ar->winy / 2) * (1 + vec4[1] / vec4[3]);
-
- if (fy > 0.0f && fy < (float)ar->winy) {
- adr[0] = (short)floorf(fx);
- adr[1] = (short)floorf(fy);
- }
- }
- }
-}
-
-/* BMESH NOTE: this function is unused in bmesh only */
-
-/* only use while object drawing */
-static void UNUSED_FUNCTION(view3d_project_short_noclip) (ARegion * ar, const float vec[3], short adr[2])
-{
- RegionView3D *rv3d = ar->regiondata;
- float fx, fy, vec4[4];
-
- adr[0] = IS_CLIPPED;
-
- copy_v3_v3(vec4, vec);
- vec4[3] = 1.0;
-
- mul_m4_v4(rv3d->persmatob, vec4);
-
- if (vec4[3] > (float)BL_NEAR_CLIP) { /* is the NEAR clipping cutoff for picking */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list