diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-08-11 07:25:25 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-08-11 07:25:25 +0400 |
commit | 44aa221600448ac8649bfd58dbed9ee1356bc8af (patch) | |
tree | cde5d44d1c141bf105df8a18fc05e1b664921a27 /source/blender/blenkernel | |
parent | 5ad353b6c227e3f1b3330a91643ae24770e46b2d (diff) |
Utility functions for getting boundbox size/scale
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_object.h | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 22 |
2 files changed, 26 insertions, 6 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index c0da816ca59..1468d60ef9d 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -124,14 +124,18 @@ void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float /* possibly belong in own moduke? */ struct BoundBox *BKE_boundbox_alloc_unit(void); void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3]); -bool BKE_boundbox_ray_hit_check(struct BoundBox *bb, const float ray_start[3], const float ray_normal[3], - float *r_lambda); +bool BKE_boundbox_ray_hit_check( + const struct BoundBox *bb, + const float ray_start[3], const float ray_normal[3], + float *r_lambda); +void BKE_boundbox_calc_center_aabb(const struct BoundBox *bb, float r_cent[3]); +void BKE_boundbox_calc_size_aabb(const struct BoundBox *bb, float r_size[3]); struct BoundBox *BKE_object_boundbox_get(struct Object *ob); void BKE_object_dimensions_get(struct Object *ob, float vec[3]); void BKE_object_dimensions_set(struct Object *ob, const float value[3]); void BKE_object_empty_draw_type_set(struct Object *ob, const int value); -void BKE_object_boundbox_flag(struct Object *ob, int flag, int set); +void BKE_object_boundbox_flag(struct Object *ob, int flag, const bool set); void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden); bool BKE_object_minmax_dupli(struct Scene *scene, struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 98a197b9e02..6f1ffcdd5a9 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2469,6 +2469,20 @@ void BKE_boundbox_init_from_minmax(BoundBox *bb, const float min[3], const float bb->vec[1][2] = bb->vec[2][2] = bb->vec[5][2] = bb->vec[6][2] = max[2]; } +void BKE_boundbox_calc_center_aabb(const BoundBox *bb, float r_cent[3]) +{ + r_cent[0] = 0.5f * (bb->vec[0][0] + bb->vec[4][0]); + r_cent[1] = 0.5f * (bb->vec[0][1] + bb->vec[2][1]); + r_cent[2] = 0.5f * (bb->vec[0][2] + bb->vec[1][2]); +} + +void BKE_boundbox_calc_size_aabb(const BoundBox *bb, float r_size[3]) +{ + r_size[0] = 0.5f * fabsf(bb->vec[0][0] - bb->vec[4][0]); + r_size[1] = 0.5f * fabsf(bb->vec[0][1] - bb->vec[2][1]); + r_size[2] = 0.5f * fabsf(bb->vec[0][2] - bb->vec[1][2]); +} + BoundBox *BKE_object_boundbox_get(Object *ob) { BoundBox *bb = NULL; @@ -2486,7 +2500,7 @@ BoundBox *BKE_object_boundbox_get(Object *ob) } /* used to temporally disable/enable boundbox */ -void BKE_object_boundbox_flag(Object *ob, int flag, int set) +void BKE_object_boundbox_flag(Object *ob, int flag, const bool set) { BoundBox *bb = BKE_object_boundbox_get(ob); if (bb) { @@ -3129,8 +3143,10 @@ int BKE_object_obdata_texspace_get(Object *ob, short **r_texflag, float **r_loc, * Test a bounding box for ray intersection * assumes the ray is already local to the boundbox space */ -bool BKE_boundbox_ray_hit_check(struct BoundBox *bb, const float ray_start[3], const float ray_normal[3], - float *r_lambda) +bool BKE_boundbox_ray_hit_check( + const struct BoundBox *bb, + const float ray_start[3], const float ray_normal[3], + float *r_lambda) { const int triangle_indexes[12][3] = { {0, 1, 2}, {0, 2, 3}, |