bool VisualActor::intersectRay(const Math::Ray &ray, const Math::Vector3d position, float direction) { Math::Matrix4 inverseModelMatrix = getModelMatrix(position, direction); inverseModelMatrix.inverse(); // Build an object local ray from the world ray Math::Ray localRay = ray; localRay.transform(inverseModelMatrix); return _model->intersectRay(localRay); }
bool Planet::get_color(ColorRGBA& resulting_color, const Vector2& screen, Math::Ray ray, gfloat& distance)const { if(sphere.radius<=0.f) return false; ray.transform(sphere.inv_transformation); if(!sphere.intersects_local(ray, distance)) return false; Vector3 p = ray.origin + ray.dir*distance; p.normalize(); p *= sphere.radius; Vector3 normal = p; normal *= 1.f/sphere.radius; if(Manager::get_settings().get_dbg_normal()) { resulting_color.set_direction(normal); }else { Vector2 uv; vec_to_uv(uv, normal); if(Manager::get_settings().get_dbg_uv()) { resulting_color.set(uv.x, uv.y, 0.f, 1.f); }else { shader(resulting_color, screen, uv, normal, ray); } } return true; }