diff options
author | Martin Poirier <theeth@yahoo.com> | 2008-06-09 21:50:21 +0400 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2008-06-09 21:50:21 +0400 |
commit | d5c80a3a1b05a184ab9dbf9e8b7be31f00c3461c (patch) | |
tree | 0e402c2100f226b5a38ef4ac9d13299c9397af21 | |
parent | ccc78eebdee6b019e485d94f8524daf0567d50a0 (diff) |
Revision 14929 partial merged from apricot
(partial because I'll merge all snap code in one fell swoop after the libs are done)
----------------------------------
object: ray - boundbox intersection test
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index a940ac62876..116a59fa97e 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -108,6 +108,7 @@ void object_boundbox_flag(struct Object *ob, int flag, int set); void minmax_object(struct Object *ob, float *min, float *max); void minmax_object_duplis(struct Object *ob, float *min, float *max); void solve_tracking (struct Object *ob, float targetmat[][4]); +int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3]); void object_handle_update(struct Object *ob); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 4f901ba7216..125243bc56f 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2380,3 +2380,31 @@ int give_obdata_texspace(Object *ob, int **texflag, float **loc, float **size, f } return 1; } + +/* + * Test a bounding box for ray intersection + * assumes the ray is already local to the boundbox space + */ +int ray_hit_boundbox(struct BoundBox *bb, float ray_start[3], float ray_normal[3]) +{ + static int triangle_indexes[12][3] = {{0, 1, 2}, {0, 2, 3}, + {3, 2, 6}, {3, 6, 7}, + {1, 2, 6}, {1, 6, 5}, + {5, 6, 7}, {4, 5, 7}, + {0, 3, 7}, {0, 4, 7}, + {0, 1, 5}, {0, 4, 5}}; + int result = 0; + int i; + + for (i = 0; i < 12 && result == 0; i++) + { + float lambda; + int v1, v2, v3; + v1 = triangle_indexes[i][0]; + v2 = triangle_indexes[i][1]; + v3 = triangle_indexes[i][2]; + result = RayIntersectsTriangle(ray_start, ray_normal, bb->vec[v1], bb->vec[v2], bb->vec[v3], &lambda, NULL); + } + + return result; +} |