-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBoundingVolume.lua
More file actions
69 lines (58 loc) · 1.79 KB
/
BoundingVolume.lua
File metadata and controls
69 lines (58 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
fysiks.BoundingVolume = {
object = nil,
id = 0,
rotation = nil,
position = nil,
type = "abstract",
removed = false,
aabb = nil
}
fysiks.BoundingVolume.__index = fysiks.BoundingVolume
fysiks.nextVolumeID = 0
function fysiks.getVolumeID()
fysiks.nextVolumeID = fysiks.nextVolumeID + 1
return fysiks.nextVolumeID
end
function fysiks.BoundingVolume:new(obj)
local bV = setmetatable({}, self)
bV.object = obj
if obj then
bV.id = fysiks.getVolumeID()
end
bV.rotation = Matrix:rotation({x = 0, y = 0, z = 0})
bV.position = {x = 0, y = 0, z = 0}
bV.removed = false
return bV
end
function fysiks.BoundingVolume:getAABB()
return self.aabb
end
function fysiks.BoundingVolume:calculateAABB()
local xMax = self:getFurthestPointInDirection({x = 1, y = 0, z = 0}).x
local xMin = self:getFurthestPointInDirection({x = -1, y = 0, z = 0}).x
local yMax = self:getFurthestPointInDirection({x = 0, y = 1, z = 0}).y
local yMin = self:getFurthestPointInDirection({x = 0, y = -1, z = 0}).y
local zMax = self:getFurthestPointInDirection({x = 0, y = 0, z = 1}).z
local zMin = self:getFurthestPointInDirection({x = 0, y = 0, z = -1}).z
self.aabb = fysiks.AABB:new({x = xMax, y = yMax, z = zMax}, {x = xMin, y = yMin, z = zMin}, self)
end
function fysiks.BoundingVolume:getFurthestPointInDirection(dir)
return {x = 0, y = 0, z = 0}
end
function fysiks.BoundingVolume:setRotation(rot)
self.rotation = rot
end
function fysiks.BoundingVolume:setPosition(pos)
self.position = pos
self:calculateAABB()
end
function fysiks.BoundingVolume:intersectRay(pos, dir, dir_inv, dist)
local t = self.aabb:intersectRay(pos, dir_inv, dist)
if t and t < dist then
return self:intersectRayImpl(pos, dir, dir_inv, dist)
end
return nil
end
function fysiks.BoundingVolume:intersectRayImpl(pos, dir, dir_inv, dist)
return nil
end