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:
authorCampbell Barton <ideasman42@gmail.com>2014-03-24 06:21:58 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-03-24 06:21:58 +0400
commit3214d4fd5aa803237637da2eee5d1b9e0006ae26 (patch)
treeb4b1faed52c55eea7da18b10eb216bfff90e3bf7 /source/blender/blenkernel
parent551d1a1ed56d7406f440c8e858ad64f177664c5b (diff)
Code Cleanup: PBVH, avoid sqrt and use bool for raycast functions
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_pbvh.h8
-rw-r--r--source/blender/blenkernel/intern/pbvh.c19
-rw-r--r--source/blender/blenkernel/intern/pbvh_bmesh.c32
3 files changed, 34 insertions, 25 deletions
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 3601ff1ce04..7517a931c76 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -94,12 +94,14 @@ void BKE_pbvh_raycast(PBVH *bvh, BKE_pbvh_HitOccludedCallback cb, void *data,
const float ray_start[3], const float ray_normal[3],
int original);
-int BKE_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], int use_origco,
+bool BKE_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], int use_origco,
const float ray_start[3], const float ray_normal[3],
float *dist);
-int BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, const float ray_start[3],
- const float ray_normal[3], float *detail, float *dist);
+bool BKE_pbvh_bmesh_node_raycast_detail(
+ PBVHNode *node,
+ const float ray_start[3], const float ray_normal[3],
+ float *detail, float *dist);
/* for orthographic cameras, project the far away ray segment points to the root node so
* we can have better precision. */
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 426a1e1646c..5a81bbf01a8 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1453,14 +1453,16 @@ static bool pbvh_faces_node_raycast(PBVH *bvh, const PBVHNode *node,
return hit;
}
-static int pbvh_grids_node_raycast(PBVH *bvh, PBVHNode *node,
- float (*origco)[3],
- const float ray_start[3],
- const float ray_normal[3], float *dist)
+static bool pbvh_grids_node_raycast(
+ PBVH *bvh, PBVHNode *node,
+ float (*origco)[3],
+ const float ray_start[3], const float ray_normal[3],
+ float *dist)
{
int totgrid = node->totprim;
int gridsize = bvh->gridkey.grid_size;
- int i, x, y, hit = 0;
+ int i, x, y;
+ bool hit = false;
for (i = 0; i < totgrid; ++i) {
CCGElem *grid = bvh->grids[node->prim_indices[i]];
@@ -1505,9 +1507,10 @@ static int pbvh_grids_node_raycast(PBVH *bvh, PBVHNode *node,
return hit;
}
-int BKE_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], int use_origco,
- const float ray_start[3], const float ray_normal[3],
- float *dist)
+bool BKE_pbvh_node_raycast(
+ PBVH *bvh, PBVHNode *node, float (*origco)[3], int use_origco,
+ const float ray_start[3], const float ray_normal[3],
+ float *dist)
{
bool hit = false;
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 4fedf76f376..0ea554cf89d 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1035,11 +1035,13 @@ int pbvh_bmesh_node_raycast(PBVHNode *node, const float ray_start[3],
return hit;
}
-int BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, const float ray_start[3],
- const float ray_normal[3], float *detail, float *dist)
+bool BKE_pbvh_bmesh_node_raycast_detail(
+ PBVHNode *node,
+ const float ray_start[3], const float ray_normal[3],
+ float *detail, float *dist)
{
GHashIterator gh_iter;
- int hit = 0;
+ bool hit = false;
BMFace *f_hit = NULL;
if (node->flag & PBVH_FullyHidden)
@@ -1051,17 +1053,19 @@ int BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, const float ray_start[3],
BLI_assert(f->len == 3);
if (f->len == 3 && !paint_is_bmesh_face_hidden(f)) {
BMVert *v_tri[3];
- int hit_local;
+ bool hit_local;
BM_face_as_array_vert_tri(f, v_tri);
- hit_local = ray_face_intersection(ray_start, ray_normal,
- v_tri[0]->co,
- v_tri[1]->co,
- v_tri[2]->co,
- NULL, dist);
+ hit_local = ray_face_intersection(
+ ray_start, ray_normal,
+ v_tri[0]->co,
+ v_tri[1]->co,
+ v_tri[2]->co,
+ NULL, dist);
+
if (hit_local) {
f_hit = f;
+ hit = true;
}
- hit |= hit_local;
}
}
@@ -1069,12 +1073,12 @@ int BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node, const float ray_start[3],
float len1, len2, len3;
BMVert *v_tri[3];
BM_face_as_array_vert_tri(f_hit, v_tri);
- len1 = len_v3v3(v_tri[0]->co, v_tri[1]->co);
- len2 = len_v3v3(v_tri[1]->co, v_tri[2]->co);
- len3 = len_v3v3(v_tri[2]->co, v_tri[0]->co);
+ len1 = len_squared_v3v3(v_tri[0]->co, v_tri[1]->co);
+ len2 = len_squared_v3v3(v_tri[1]->co, v_tri[2]->co);
+ len3 = len_squared_v3v3(v_tri[2]->co, v_tri[0]->co);
/* detail returned will be set to the maximum allowed size, so take max here */
- *detail = max_fff(len1, len2, len3);
+ *detail = sqrtf(max_fff(len1, len2, len3));
}
return hit;