Commit b5fe4cf9 authored by Libor Moravčík's avatar Libor Moravčík
Browse files

Improved interface for CollisionSystem and part of the code moved to...

Improved interface for CollisionSystem and part of the code moved to RigidBodySimulator to make the collision system working standalone
parent 21e14f10
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -47,20 +47,15 @@ struct CollisionSystem final : com::System
	~CollisionSystem() override = default;

	// Methods
	bool detect_collisions(
	    com::Folder *world, bool clear_cache = false,
	    BroadDetector::Algorithm broad_detector = BroadDetector::Algorithm::AABB_TREE,
	    NarrowDetector::Algorithm narrow_detector = NarrowDetector::Algorithm::GJK,
	    dyn::bodies_pair_to_manifold_t *bodies_pair_to_manifold = nullptr, dyn::contact_manifolds_t *manifolds = nullptr);
	bool detect_collisions(com::Folder *world, std::function<void(CollisionInfo const &info)> processCollisionInfo = nullptr);

	PotentialCollisions broadphase_collisions(com::Folder *world) const;

	bool raycast(com::Folder *world, geometry::Ray const &ray, RayCastResult &result,
		     NarrowDetector::Algorithm algorithm = NarrowDetector::Algorithm::VCLIP,
		     std::unordered_set<std::size_t> layers = {});
		     
	bool raycast(const geometry::Ray &ray, ConvexHullCollider *collider, RayCastResult &result,
		     NarrowDetector::Algorithm algorithm =NarrowDetector::Algorithm::VCLIP) const;
		     NarrowDetector::Algorithm alg = NarrowDetector::Algorithm::GJK) const;

	bool distance_query(com::Folder *world, Collider *collider_a, Collider *collider_b,
			    geometry::ClosestPoints &result);
@@ -77,6 +72,14 @@ struct CollisionSystem final : com::System
		m_use_dedicated_collision_algorithms = use_dedicated;
	}

	void clear_cache(com::Folder *world);
	
	inline void set_broadphase_algorithm(BroadDetector::Algorithm alg) { m_broad_alg = alg; }
	inline void set_narrowphase_algorithm(NarrowDetector::Algorithm alg) { m_narrow_alg = alg; }

	inline BroadDetector *broad_detector(com::Folder *world) const { return m_broad_detectors[(int) m_worlds.at(world).first]; }
	inline NarrowDetector *narrow_detector(com::Folder *world) const { return m_narrow_detectors[(int) m_worlds.at(world).second]; }
	
      protected:
	void on_erase(ContextItem *subject) override;

@@ -84,8 +87,7 @@ struct CollisionSystem final : com::System
	void release() override;

      private:
	void register_world(com::Folder *world, BroadDetector::Algorithm broad_phase_type,
			    NarrowDetector::Algorithm narrow_phase_type);
	void register_world(com::Folder *world);
	void unregister_world(com::Folder *world);
	void on_world_erase(com::Folder *world);

@@ -100,6 +102,8 @@ struct CollisionSystem final : com::System
	com::Folder *m_narrow_detectors_folder = nullptr;
	BroadDetector *m_broad_detectors[3];
	NarrowDetector *m_narrow_detectors[3];
	BroadDetector::Algorithm m_broad_alg = BroadDetector::Algorithm::AABB_TREE;
	NarrowDetector::Algorithm m_narrow_alg = NarrowDetector::Algorithm::GJK;
	bool m_use_dedicated_collision_algorithms = true;
};
} // namespace phx::coll
+2 −2
Original line number Diff line number Diff line
@@ -32,9 +32,9 @@ struct RayCastResult
		add(collider, points);
	}

	explicit operator bool() const
	bool empty() const
	{
		return !m_hits.empty();
		return m_hits.empty();
	}
	const std::multiset<Hit> &hits() const
	{
+1 −1
Original line number Diff line number Diff line
@@ -623,7 +623,7 @@ bool AABBTree::raycast(com::Folder *world, geometry::Ray const & ray, RayCastRes
			  result.add(collider, aabb_raycast);
		  });

	return bool(result);
	return result.empty() == false;
}

void AABBTree::register_world(com::Folder *world)
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ bool BroadBrute::raycast(com::Folder *world, geometry::Ray const &ray, RayCastRe
			result.add({collider, r});
		}
	}
	return bool(result);
	return result.empty() == false;
}

} // namespace phx::coll
+1 −1
Original line number Diff line number Diff line
@@ -394,7 +394,7 @@ bool SweepAndPrune::raycast(com::Folder *world, geometry::Ray const &ray, RayCas
		current = current->next[axis];
	}

	return bool(result);
	return result.empty() == false;
}

void SweepAndPrune::register_world(com::Folder *world)
Loading