Class: BulldogPhysics::Grid
- Inherits:
-
Object
- Object
- BulldogPhysics::Grid
- Defined in:
- lib/RigidBodies/rigid_collisions.rb
Instance Attribute Summary collapse
-
#active_sets ⇒ Object
Returns the value of attribute active_sets.
-
#inverse_cell_size ⇒ Object
Returns the value of attribute inverse_cell_size.
-
#locations ⇒ Object
Returns the value of attribute locations.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#x_extent ⇒ Object
Returns the value of attribute x_extent.
-
#z_extent ⇒ Object
Returns the value of attribute z_extent.
Instance Method Summary collapse
- #add(object) ⇒ Object
- #get_location_index(object_centre) ⇒ Object
-
#initialize ⇒ Grid
constructor
A new instance of Grid.
- #remove(object) ⇒ Object
Constructor Details
#initialize ⇒ Grid
Returns a new instance of Grid.
156 157 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 156 def initialize end |
Instance Attribute Details
#active_sets ⇒ Object
Returns the value of attribute active_sets.
154 155 156 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 154 def active_sets @active_sets end |
#inverse_cell_size ⇒ Object
Returns the value of attribute inverse_cell_size.
154 155 156 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 154 def inverse_cell_size @inverse_cell_size end |
#locations ⇒ Object
Returns the value of attribute locations.
154 155 156 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 154 def locations @locations end |
#origin ⇒ Object
Returns the value of attribute origin.
154 155 156 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 154 def origin @origin end |
#x_extent ⇒ Object
Returns the value of attribute x_extent.
154 155 156 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 154 def x_extent @x_extent end |
#z_extent ⇒ Object
Returns the value of attribute z_extent.
154 155 156 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 154 def z_extent @z_extent end |
Instance Method Details
#add(object) ⇒ Object
164 165 166 167 168 169 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 164 def add(object) location = get_location_index(object.center) set = @locations[location] @active_sets.insert(set) if(set.size() == 1) set.add(object) end |
#get_location_index(object_centre) ⇒ Object
159 160 161 162 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 159 def get_location_index(object_centre) square = object_centre.componentProduct(inverseCellSize) square.x + @x_extent * square.z end |
#remove(object) ⇒ Object
171 172 173 174 175 176 |
# File 'lib/RigidBodies/rigid_collisions.rb', line 171 def remove(object) location = get_location_index(object.center) set = @locations[location] @active_sets.erase(set) if set.size == 2 set.remove(object) end |