#include "object.h"
using namespace std;
+using namespace Msp;
namespace R2C2 {
return get_type().get_shape();
}
-bool Object::collide_ray(const Ray &ray) const
+bool Object::collide_ray(const Ray &ray, float *d) const
{
const Shape *s = get_shape();
if(!s)
Transform reverse_trans = Transform::rotation(rotation, Vector(0, 0, -1))*
Transform::translation(-position);
- return s->check_intersection(reverse_trans.transform(ray));
+ if(d)
+ {
+ vector<Geometry::SurfacePoint<float, 3> > points = s->get_intersections(reverse_trans.transform(ray));
+ if(points.empty())
+ return false;
+ *d = points.front().distance;
+ return true;
+ }
+ else
+ return s->check_intersection(reverse_trans.transform(ray));
}
BoundingBox Object::get_bounding_box() const