Circle Collider

engine/collider.h
namespace ng {

class CircleCollider; // Add: forward declare CircleCollider.

class Collider : public Node {
 public:
  // -----
 
  // --- Add: Specialization for CircleCollider. ---
  /// @brief Checks for collision with a CircleCollider.
  /// @param other A constant reference to the other CircleCollider.
  /// @return True if a collision occurs, false otherwise.
  [[nodiscard]] virtual bool Collides(const CircleCollider& other) const = 0;
  // --- End ---

  // -----
};

}  // namespace ng

Circle - Circle

Two circles collide if the distance between their centers is less than the sum of their radii: Collision occurs if distance < r1​+r2​.

The distance between two points requires a square root operation (relatively computationally heavy), but we can avoid it by comparing the squared distance to the squared sum of the radii: Collision occurs if distance^2 < (r1​+r2​)^2.

Last updated