Collision stuff

This commit is contained in:
2019-02-25 11:33:18 -06:00
parent d5a5ced955
commit 97818c8a33
8 changed files with 32 additions and 9 deletions

View File

@@ -66,7 +66,7 @@ class IMICFPS
other_child.parent = @parent
return other_child
else
leaf.disown_child(leaf)
leaf.parent.disown_child(leaf)
return self
end
end

View File

@@ -18,6 +18,10 @@ class IMICFPS
leaf = AABBNode.new(parent: nil, object: object, bounding_box: bounding_box.dup)
@objects[object] = leaf
insert_leaf(leaf)
end
def insert_leaf(leaf)
if @root
@root = @root.insert_subtree(leaf)
else
@@ -26,8 +30,10 @@ class IMICFPS
end
def update(object, bounding_box)
remove(object)
insert(object, bounding_box)
leaf = remove(object)
leaf.bounding_box = bounding_box
@objects[object] = leaf
insert_leaf(leaf)
end
# Returns a list of all collided objects inside Bounding Box
@@ -44,6 +50,9 @@ class IMICFPS
def remove(object)
leaf = @objects.delete(object)
@root = @root.remove_subtree(leaf) if leaf
@root.parent = nil
return leaf
end
end
end