Exemple #1
0
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);
}
vcl::tools::shared_ptr<vcl::matrix<SCALARTYPE, F> >
matrix_init_scalar(vcl::vcl_size_t n, vcl::vcl_size_t m, SCALARTYPE value, const vcl::context& ctx)
{
    ublas::scalar_matrix<SCALARTYPE> s_m(n, m, value);
    ublas::matrix<SCALARTYPE> cpu_m(s_m);
    vcl::matrix<SCALARTYPE, F>* mat = new vcl::matrix<SCALARTYPE, F>(n, m, ctx);
    vcl::copy(cpu_m, (*mat));
    return vcl::tools::shared_ptr<vcl::matrix<SCALARTYPE, F> >(mat);
}