mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Refactored GameObject to Entity, replaced @x,@y,@z with @position, added @velocity vector to Entity, bricked Player terrain interaction while authoring Axis Aligned Bounding Box Tree for CollisionManager to handle all collision interaction. Added PhysicsManager stub.
This commit is contained in:
49
lib/trees/aabb_tree.rb
Normal file
49
lib/trees/aabb_tree.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
class IMICFPS
|
||||
class AABBTree
|
||||
def initialize
|
||||
@objects = {}
|
||||
@root = nil
|
||||
end
|
||||
|
||||
def add(bounding_box, object)
|
||||
raise "BoundingBox can't be nil!" unless bounding_box
|
||||
raise "Object can't be nil!" unless object
|
||||
|
||||
if @root
|
||||
@root.insert_subtree(bounding_box, object)
|
||||
else
|
||||
@root = AABBNode.new(parent: nil, object: object, bounding_box: BoundingBox.new(0,0,0, 0,0,0))
|
||||
end
|
||||
end
|
||||
|
||||
def update(object)
|
||||
end
|
||||
|
||||
# Returns a list of all collided objects inside Bounding Box
|
||||
def search(bounding_box)
|
||||
items = []
|
||||
@root.search_subtree(bounding_box)
|
||||
end
|
||||
|
||||
def remove(object)
|
||||
end
|
||||
|
||||
class AABBNode
|
||||
def initialize(parent:, object:, bounding_box:)
|
||||
@parent = parent
|
||||
@object = object
|
||||
@bounding_box = bounding_box
|
||||
end
|
||||
|
||||
def insert_subtree(bounding_box, object)
|
||||
p "#{bounding_box} -> #{object.class}"
|
||||
end
|
||||
|
||||
def remove_subtree(node)
|
||||
end
|
||||
|
||||
def search_subtree(bounding_box)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user