mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Refactored bounding box to use 2 vectors, stubbed PhysicsManager.
This commit is contained in:
@@ -1,56 +1,42 @@
|
||||
class IMICFPS
|
||||
class BoundingBox
|
||||
attr_accessor :min_x, :min_y, :min_z, :max_x, :max_y, :max_z
|
||||
attr_accessor :min, :max
|
||||
|
||||
def initialize(min_x = 0.0, min_y = 0.0, min_z = 0.0, max_x = 0.0, max_y = 0.0, max_z = 0.0)
|
||||
@min_x = min_x
|
||||
@min_y = min_y
|
||||
@min_z = min_z
|
||||
|
||||
@max_x = max_x
|
||||
@max_y = max_y
|
||||
@max_z = max_z
|
||||
def initialize
|
||||
@min = Vector.new
|
||||
@max = Vector.new
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
min_x == other.min_x &&
|
||||
min_y == other.min_y &&
|
||||
min_z == other.min_z &&
|
||||
max_x == other.max_x &&
|
||||
max_y == other.max_y &&
|
||||
max_z == other.max_z
|
||||
@min == other.min &&
|
||||
@max == other.max
|
||||
end
|
||||
|
||||
# returns a new bounding box that includes both bounding boxes
|
||||
def union(other)
|
||||
temp = BoundingBox.new
|
||||
temp.min_x = [min_x, other.min_x].min
|
||||
temp.min_y = [min_y, other.min_y].min
|
||||
temp.min_z = [min_z, other.min_z].min
|
||||
temp.min.x = [@min.x, other.min.x].min
|
||||
temp.min.y = [@min.y, other.min.y].min
|
||||
temp.min.z = [@min.z, other.min.z].min
|
||||
|
||||
temp.max_x = [max_x, other.max_x].max
|
||||
temp.max_y = [max_y, other.max_y].max
|
||||
temp.max_z = [max_z, other.max_z].max
|
||||
temp.max.x = [@max.x, other.max.x].max
|
||||
temp.max.y = [@max.y, other.max.y].max
|
||||
temp.max.z = [@max.z, other.max.z].max
|
||||
|
||||
return temp
|
||||
end
|
||||
|
||||
# returns boolean
|
||||
def intersect(other)
|
||||
(min_x <= other.max_x && max_x >= other.min_x) &&
|
||||
(min_y <= other.max_y && max_y >= other.min_y) &&
|
||||
(min_z <= other.max_z && max_z >= other.min_z)
|
||||
(@min.x <= other.max.x && @max.x >= other.min.x) &&
|
||||
(@min.y <= other.max.y && @max.y >= other.min.y) &&
|
||||
(@min.z <= other.max.z && @max.z >= other.min.z)
|
||||
end
|
||||
|
||||
def difference(other)
|
||||
temp = BoundingBox.new
|
||||
temp.min_x = min_x - other.min_x
|
||||
temp.min_y = min_y - other.min_y
|
||||
temp.min_z = min_z - other.min_z
|
||||
|
||||
temp.max_x = max_x - other.max_x
|
||||
temp.max_y = max_y - other.max_y
|
||||
temp.max_z = max_z - other.max_z
|
||||
temp.min = @min - other.min
|
||||
temp.max = @max - other.max
|
||||
|
||||
return temp
|
||||
end
|
||||
@@ -60,39 +46,39 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def width
|
||||
@max_x - @min_x
|
||||
@max.x - @min.x
|
||||
end
|
||||
|
||||
def height
|
||||
@max_y - @min_y
|
||||
@max.y - @min.y
|
||||
end
|
||||
|
||||
def depth
|
||||
@max_z - @min_z
|
||||
@max.z - @min.z
|
||||
end
|
||||
|
||||
def normalize(entity)
|
||||
temp = BoundingBox.new
|
||||
temp.min_x = min_x.to_f * entity.scale
|
||||
temp.min_y = min_y.to_f * entity.scale
|
||||
temp.min_z = min_z.to_f * entity.scale
|
||||
temp.min.x = @min.x.to_f * entity.scale
|
||||
temp.min.y = @min.y.to_f * entity.scale
|
||||
temp.min.z = @min.z.to_f * entity.scale
|
||||
|
||||
temp.max_x = max_x.to_f * entity.scale
|
||||
temp.max_y = max_y.to_f * entity.scale
|
||||
temp.max_z = max_z.to_f * entity.scale
|
||||
temp.max.x = @max.x.to_f * entity.scale
|
||||
temp.max.y = @max.y.to_f * entity.scale
|
||||
temp.max.z = @max.z.to_f * entity.scale
|
||||
|
||||
return temp
|
||||
end
|
||||
|
||||
def normalize_with_offset(entity)
|
||||
temp = BoundingBox.new
|
||||
temp.min_x = min_x.to_f * entity.scale + entity.position.x
|
||||
temp.min_y = min_y.to_f * entity.scale + entity.position.y
|
||||
temp.min_z = min_z.to_f * entity.scale + entity.position.z
|
||||
temp.min.x = @min.x.to_f * entity.scale + entity.position.x
|
||||
temp.min.y = @min.y.to_f * entity.scale + entity.position.y
|
||||
temp.min.z = @min.z.to_f * entity.scale + entity.position.z
|
||||
|
||||
temp.max_x = max_x.to_f * entity.scale + entity.position.x
|
||||
temp.max_y = max_y.to_f * entity.scale + entity.position.y
|
||||
temp.max_z = max_z.to_f * entity.scale + entity.position.z
|
||||
temp.max.x = @max.x.to_f * entity.scale + entity.position.x
|
||||
temp.max.y = @max.y.to_f * entity.scale + entity.position.y
|
||||
temp.max.z = @max.z.to_f * entity.scale + entity.position.z
|
||||
|
||||
return temp
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user