Class: RGame::Engine::CircleCollider
- Inherits:
-
Object
- Object
- RGame::Engine::CircleCollider
- Defined in:
- lib/rgame/engine/circle_collider.rb
Overview
A circular collision shape, the sibling of CollisionBox for entities that rotate (rocks, ship): a circle is rotation-invariant, so a spinning rock needs no per-frame box recompute. The collider owns only the radius; the entity owns its centre position. Pure logic; no graphics.
Instance Attribute Summary collapse
-
#radius ⇒ Object
readonly
Returns the value of attribute radius.
Class Method Summary collapse
-
.overlap?(x1, y1, r1, x2, y2, r2) ⇒ Boolean
Squared-distance overlap test (no sqrt): true when two circles touch.
Instance Method Summary collapse
-
#aabb(cx, cy) ⇒ Object
Bounding AABB [x, y, w, h] for a circle centred at (cx, cy) — what the spatial hash buckets on.
-
#initialize(radius:) ⇒ CircleCollider
constructor
A new instance of CircleCollider.
Constructor Details
#initialize(radius:) ⇒ CircleCollider
Returns a new instance of CircleCollider.
20 21 22 |
# File 'lib/rgame/engine/circle_collider.rb', line 20 def initialize(radius:) @radius = radius end |
Instance Attribute Details
#radius ⇒ Object (readonly)
Returns the value of attribute radius.
10 11 12 |
# File 'lib/rgame/engine/circle_collider.rb', line 10 def radius @radius end |
Class Method Details
.overlap?(x1, y1, r1, x2, y2, r2) ⇒ Boolean
Squared-distance overlap test (no sqrt): true when two circles touch.
13 14 15 16 17 18 |
# File 'lib/rgame/engine/circle_collider.rb', line 13 def self.overlap?(x1, y1, r1, x2, y2, r2) dx = x2 - x1 dy = y2 - y1 sum = r1 + r2 (dx * dx) + (dy * dy) <= sum * sum end |
Instance Method Details
#aabb(cx, cy) ⇒ Object
Bounding AABB [x, y, w, h] for a circle centred at (cx, cy) — what the spatial hash buckets on.
26 27 28 29 |
# File 'lib/rgame/engine/circle_collider.rb', line 26 def aabb(cx, cy) d = @radius * 2 [cx - @radius, cy - @radius, d, d] end |