Class: BulldogPhysics::Grid

Inherits:
Object
  • Object
show all
Defined in:
lib/RigidBodies/rigid_collisions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGrid

Returns a new instance of Grid.



156
157
# File 'lib/RigidBodies/rigid_collisions.rb', line 156

def initialize
end

Instance Attribute Details

#active_setsObject

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_sizeObject

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

#locationsObject

Returns the value of attribute locations.



154
155
156
# File 'lib/RigidBodies/rigid_collisions.rb', line 154

def locations
  @locations
end

#originObject

Returns the value of attribute origin.



154
155
156
# File 'lib/RigidBodies/rigid_collisions.rb', line 154

def origin
  @origin
end

#x_extentObject

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_extentObject

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