Add setters to BoundingBox and BoundingSphere

This commit is contained in:
tobspr 2015-08-08 20:24:23 +02:00 committed by rdb
parent bff070430e
commit 8a8cc94cbb
4 changed files with 44 additions and 2 deletions

View File

@ -114,3 +114,17 @@ get_plane(int n) const {
get_point(plane_def[n][1]),
get_point(plane_def[n][2]));
}
////////////////////////////////////////////////////////////////////
// Function: BoundingBox::set_min_max
// Access: Published
// Description: Sets the min and max point of the rectangular solid.
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL void BoundingBox::
set_min_max(const LPoint3 &min, const LPoint3 &max) {
nassertv(!min.is_nan() && !max.is_nan());
nassertv(_min[0] <= _max[0] && _min[1] <= _max[1] && _min[2] <= _max[2]);
_min = min;
_max = max;
_flags = 0;
}

View File

@ -46,6 +46,7 @@ public:
virtual void output(ostream &out) const;
PUBLISHED:
INLINE_MATHUTIL int get_num_points() const;
INLINE_MATHUTIL LPoint3 get_point(int n) const;
@ -54,6 +55,8 @@ PUBLISHED:
INLINE_MATHUTIL LPlane get_plane(int n) const;
MAKE_SEQ(get_planes, get_num_planes, get_plane);
INLINE_MATHUTIL void set_min_max(const LPoint3 &min, const LPoint3 &max);
public:
// Inline accessors for speed.
INLINE_MATHUTIL const LPoint3 &get_minq() const;

View File

@ -19,7 +19,7 @@
// Description: Constructs an empty sphere.
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL BoundingSphere::
BoundingSphere() {
BoundingSphere() : _center(0) {
}
////////////////////////////////////////////////////////////////////
@ -44,7 +44,6 @@ BoundingSphere(const LPoint3 &center, PN_stdfloat radius) :
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL LPoint3 BoundingSphere::
get_center() const {
nassertr(!is_empty(), LPoint3::zero());
nassertr(!is_infinite(), LPoint3::zero());
return _center;
}
@ -61,3 +60,25 @@ get_radius() const {
return _radius;
}
////////////////////////////////////////////////////////////////////
// Function: BoundingSphere::set_center
// Access: Published
// Description: Sets the center point of the sphere.
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL void BoundingSphere::
set_center(const LPoint3 &center) {
nassertv(!center.is_nan());
_center = center;
}
////////////////////////////////////////////////////////////////////
// Function: BoundingSphere::set_radius
// Access: Published
// Description: Sets the radius of the sphere.
////////////////////////////////////////////////////////////////////
INLINE_MATHUTIL void BoundingSphere::
set_radius(PN_stdfloat radius) {
nassertv(!cnan(radius));
_radius = radius;
_flags = 0;
}

View File

@ -47,6 +47,10 @@ PUBLISHED:
INLINE_MATHUTIL LPoint3 get_center() const;
INLINE_MATHUTIL PN_stdfloat get_radius() const;
INLINE_MATHUTIL void set_center(const LPoint3 &center);
INLINE_MATHUTIL void set_radius(PN_stdfloat radius);
public:
virtual const BoundingSphere *as_bounding_sphere() const;