voxel material::intersect_ray(kdtree* tree, glm::vec3& pos, glm::vec3& dir, glm::vec3& inv_dir) { if (!tree) return voxel(); if (tree->box_.intersect(pos, inv_dir)) { if (tree->right_ == tree->left_) { // TODO at the moment we only have bounding boxes kdtree_leaf* leaf = static_cast<kdtree_leaf*>(tree); return ::intersect_ray(*this, pos, dir, leaf->indices_); } else { voxel v0 = intersect_ray(tree->left_, pos, dir, inv_dir); voxel v1 = intersect_ray(tree->right_, pos, dir, inv_dir); return v0.dist < v1.dist ? v0 : v1; } } else return voxel(); }
voxel material::intersect_ray(glm::vec3& pos, glm::vec3& dir) { glm::vec3 inv_dir; inv_dir.x = fabsf(dir.x) < 0.001f ? FLT_MAX : 1.f / dir.x; inv_dir.y = fabsf(dir.y) < 0.001f ? FLT_MAX : 1.f / dir.y; inv_dir.z = fabsf(dir.z) < 0.001f ? FLT_MAX : 1.f / dir.z; return intersect_ray(tree_, pos, dir, inv_dir); }
bool triangle3<T>::get_intersection_with_line_fast(const vec3<T>& linePoint, const vec3<T>& lineVect, vec3<T>& outIntersection) const { T t,u,v; bool ret = intersect_ray(linePoint,lineVect,false,t,u,v); if (ret) { // calculate intersection point outIntersection = linePoint + t*lineVect; } return ret; }
void Triangle::intersect_packet(const Packet& packet, IsectInfo *infos, bool *intersected) const { if (intersect_frustum(packet.frustum)) { // TODO simd for (int i = 0; i < rays_per_packet; i++) { intersected[i] = intersected[i] || intersect_ray(packet.rays[i], infos[i]); } } }
Variant PhysicsDirectSpaceState::_intersect_ray(const Vector3& p_from, const Vector3& p_to,const Vector<RID>& p_exclude,uint32_t p_user_mask) { RayResult inters; Set<RID> exclude; for(int i=0;i<p_exclude.size();i++) exclude.insert(p_exclude[i]); bool res = intersect_ray(p_from,p_to,inters,exclude,p_user_mask); if (!res) return Variant(); Dictionary d; d["position"]=inters.position; d["normal"]=inters.normal; d["collider_id"]=inters.collider_id; d["collider"]=inters.collider; d["shape"]=inters.shape; d["rid"]=inters.rid; return d; }
Dictionary Physics2DDirectSpaceState::_intersect_ray(const Vector2& p_from, const Vector2& p_to,const Vector<RID>& p_exclude,uint32_t p_layers,uint32_t p_object_type_mask) { RayResult inters; Set<RID> exclude; for(int i=0;i<p_exclude.size();i++) exclude.insert(p_exclude[i]); bool res = intersect_ray(p_from,p_to,inters,exclude,p_layers,p_object_type_mask); if (!res) return Dictionary(true); Dictionary d(true); d["position"]=inters.position; d["normal"]=inters.normal; d["collider_id"]=inters.collider_id; d["collider"]=inters.collider; d["shape"]=inters.shape; d["rid"]=inters.rid; d["metadata"]=inters.metadata; return d; }