How to get center point of nodepath's bounding box

How do you get the center point of a nodepath’s bounding box?
I have seen this code in Python:

np.getBounds().getCenter()

But in C++ I can’t find the method get_center().
(I’m using version 1.7.0)

That call actually returns the center of the node’s bounding sphere, and it assumes that the node’s bounding volume is in fact a sphere in the first place (it often is, though it isn’t necessarily). It also assumes that the bounding volume is neither empty nor infinite. It relies on Python’s implicit downcasting to specific types.

The direct C++ equivalent is:

PT(BoundingSphere) bs = DCAST(BoundingSphere, np.get_bounds();
nassertv(bs != NULL);
LPoint3f center = bs->get_center();

A more reliable approach would be to use the method get_approx_center(), which is defined for BoundingBox and other shapes as well. You can also replace the DCAST macro with the as_blah() method, if you prefer that structure:

PT(GeometricBoundingVolume) gbv = np.get_bounds()->as_geometric_bounding_volume();
nassertv(gbv != NULL);
nassertv(!gbv->is_infinite() && !gbv->is_empty());
LPoint3f center = gbv->get_approx_center();

Both of these approaches return the center of the node’s computed bounding volume, which may or may not be near the actual center of geometry. If it’s really important for you to get the center of geometry, you have to use the more expensive calc_tight_bounds():

LPoint3f a, b;
if (np.calc_tight_bounds(a, b)) {
  LPoint3f center = (a + b) * 0.5;
} else {
  cerr << "No geometry.\n";
}

David