void Geometry::update_bounding_volume() const { const mat4& model_m = SceneObject::get_local_to_world(); //TODO: we should use OBB in here... //at the moment we use bounding spheres only //Note that the (non-uniform) scale operation would invalidate //the bounding sphere as well, at the moment const Sphere& sphere = _mesh->bounding_volume().sphere(); vec4 center = vec4(sphere.center(), 1); vec4 ctr_m = model_m * center; //Note: this works only with uniform scale operations! //Transform a point on sphere to get the new radius vec4 p = center; p.z += sphere.radius(); vec4 p_m = model_m * p; vec4 diff = (p_m - ctr_m); float new_radius = glm::length(diff); Sphere s_m(new_radius, vec3(ctr_m)); _bounding_volume = BoundingVolume(s_m); }
void rPrimitiveSphere::RecalculateBoundingVolume(){ rSphere s(0, m_radius, 0, m_radius); rSphereBoundingVolume* boundingVolume = (rSphereBoundingVolume*)BoundingVolume(); boundingVolume->SetSphere(s); }
BoundingVolume BoundingVolume::sphere(Size radius) { return BoundingVolume(radius); }
BoundingVolume BoundingVolume::capsule(Size radius, Size height) { return BoundingVolume(radius, height); }
BoundingVolume BoundingVolume::box(const Dimension &dimensions) { return BoundingVolume(dimensions); }