SHOW:
|
|
- or go back to the newest paste.
1 | Events:Subscribe("ModuleLoad", function() | |
2 | ||
3 | boxes = { | |
4 | ['km07.submarine.eez/key014_02-a.lod'] = {Vector3(-66.16, -41.87, -265.63), Vector3(66.14, 69.94, 255.33)} | |
5 | } | |
6 | ||
7 | -- boxes = { | |
8 | -- ['km07.submarine.eez/key014_02-a.lod'] = {Vector3(-45, -42, -280), Vector3(45, 5, 260)} | |
9 | -- } | |
10 | ||
11 | ellipsoids = {} | |
12 | ||
13 | for model,box in pairs(boxes) do | |
14 | ||
15 | local a = (box[2].x - box[1].x) / 2 | |
16 | local b = (box[2].y - box[1].y) / 2 | |
17 | local c = (box[2].z - box[1].z) / 2 | |
18 | ||
19 | ellipsoids[model] = {a, b, c} | |
20 | ||
21 | end | |
22 | ||
23 | Events:Subscribe("Render", Draw) | |
24 | ||
25 | end) | |
26 | ||
27 | function Draw() | |
28 | ||
29 | for obj in Client:GetStaticObjects() do | |
30 | ||
31 | if IsValid(obj) and obj:GetModel() == "km07.submarine.eez/key014_02-a.lod" then | |
32 | ||
33 | -- DrawBoundingCorners(obj, Color.Yellow) | |
34 | -- DrawBoundingBoxRelative(obj, Color.Yellow) | |
35 | - | -- DrawBoundingEllipsoidRelative(obj, 20, color) |
35 | + | -- DrawBoundingEllipsoidRelative(obj, 20, Color.Cyan) |
36 | -- DrawBoundingBox(obj, Color.Yellow) | |
37 | ||
38 | end | |
39 | ||
40 | end | |
41 | ||
42 | end | |
43 | ||
44 | function DrawBoundingCorners(obj, color) | |
45 | ||
46 | local u, v = obj:GetBoundingBox() | |
47 | Render:DrawCircle(Render:WorldToScreen(u), 10, color) | |
48 | Render:DrawCircle(Render:WorldToScreen(v), 10, color) | |
49 | ||
50 | end | |
51 | ||
52 | function DrawBoundingBox(obj, color) | |
53 | ||
54 | local u, v = obj:GetBoundingBox() | |
55 | ||
56 | local corners = { | |
57 | Vector3(u.x, u.y, u.z), | |
58 | Vector3(u.x, u.y, v.z), | |
59 | Vector3(v.x, u.y, v.z), | |
60 | Vector3(v.x, u.y, u.z), | |
61 | Vector3(u.x, v.y, u.z), | |
62 | Vector3(u.x, v.y, v.z), | |
63 | Vector3(v.x, v.y, v.z), | |
64 | Vector3(v.x, v.y, u.z), | |
65 | } | |
66 | ||
67 | Render:DrawLine(corners[1], corners[2], color) | |
68 | Render:DrawLine(corners[2], corners[3], color) | |
69 | Render:DrawLine(corners[3], corners[4], color) | |
70 | Render:DrawLine(corners[4], corners[1], color) | |
71 | ||
72 | Render:DrawLine(corners[1], corners[5], color) | |
73 | Render:DrawLine(corners[2], corners[6], color) | |
74 | Render:DrawLine(corners[3], corners[7], color) | |
75 | Render:DrawLine(corners[4], corners[8], color) | |
76 | ||
77 | Render:DrawLine(corners[5], corners[6], color) | |
78 | Render:DrawLine(corners[6], corners[7], color) | |
79 | Render:DrawLine(corners[7], corners[8], color) | |
80 | Render:DrawLine(corners[8], corners[5], color) | |
81 | ||
82 | end | |
83 | ||
84 | function DrawBoundingBoxRelative(obj, color) | |
85 | ||
86 | local model = obj:GetModel() | |
87 | local position = obj:GetPosition() | |
88 | local angle = obj:GetAngle() | |
89 | ||
90 | local u = boxes[model][1] | |
91 | local v = boxes[model][2] | |
92 | ||
93 | local corners = { | |
94 | position + angle * Vector3(u.x, u.y, u.z), | |
95 | position + angle * Vector3(u.x, u.y, v.z), | |
96 | position + angle * Vector3(v.x, u.y, v.z), | |
97 | position + angle * Vector3(v.x, u.y, u.z), | |
98 | position + angle * Vector3(u.x, v.y, u.z), | |
99 | position + angle * Vector3(u.x, v.y, v.z), | |
100 | position + angle * Vector3(v.x, v.y, v.z), | |
101 | position + angle * Vector3(v.x, v.y, u.z), | |
102 | } | |
103 | ||
104 | Render:DrawLine(corners[1], corners[2], color) | |
105 | Render:DrawLine(corners[2], corners[3], color) | |
106 | Render:DrawLine(corners[3], corners[4], color) | |
107 | Render:DrawLine(corners[4], corners[1], color) | |
108 | ||
109 | Render:DrawLine(corners[1], corners[5], color) | |
110 | Render:DrawLine(corners[2], corners[6], color) | |
111 | Render:DrawLine(corners[3], corners[7], color) | |
112 | Render:DrawLine(corners[4], corners[8], color) | |
113 | ||
114 | Render:DrawLine(corners[5], corners[6], color) | |
115 | Render:DrawLine(corners[6], corners[7], color) | |
116 | Render:DrawLine(corners[7], corners[8], color) | |
117 | Render:DrawLine(corners[8], corners[5], color) | |
118 | ||
119 | end | |
120 | ||
121 | function DrawBoundingEllipsoidRelative(obj, resolution, color) | |
122 | ||
123 | local model = obj:GetModel() | |
124 | local position = obj:GetPosition() | |
125 | local angle = obj:GetAngle() | |
126 | ||
127 | local u = position + angle * boxes[model][1] | |
128 | local v = position + angle * boxes[model][2] | |
129 | local origin = math.lerp(u, v, 0.5) | |
130 | ||
131 | local a = ellipsoids[model][1] | |
132 | local b = ellipsoids[model][2] | |
133 | local c = ellipsoids[model][3] | |
134 | ||
135 | local ellipses = {{}, {}, {}} | |
136 | ||
137 | for theta = 0, (2 * math.pi), (2 * math.pi) / resolution do | |
138 | ||
139 | table.insert(ellipses[1], origin + angle * Vector3(a * math.cos(theta), b * math.sin(theta), 0)) | |
140 | table.insert(ellipses[2], origin + angle * Vector3(a * math.cos(theta), 0, c * math.sin(theta))) | |
141 | table.insert(ellipses[3], origin + angle * Vector3(0, b * math.sin(theta), c * math.cos(theta))) | |
142 | ||
143 | for i,u in ipairs(ellipses) do | |
144 | for j,v in ipairs(u) do | |
145 | if u[j+1] then Render:DrawLine(v, u[j+1], color) end | |
146 | end | |
147 | end | |
148 | ||
149 | end | |
150 | ||
151 | end | |
152 | ||
153 | function PositionIsInsideStaticObject(position, obj) | |
154 | ||
155 | local model = obj:GetModel() | |
156 | local position = vehicle:GetPosition() | |
157 | local angle = vehicle:GetAngle() | |
158 | ||
159 | local u = position + angle * boxes[model][1] | |
160 | local v = position + angle * boxes[model][2] | |
161 | local origin = math.lerp(u, v, 0.5) | |
162 | ||
163 | local coord = -angle * (position - origin) | |
164 | ||
165 | local x_term = (coord.x / ellipsoids[model][1])^2 | |
166 | local y_term = (coord.y / ellipsoids[model][2])^2 | |
167 | local z_term = (coord.z / ellipsoids[model][3])^2 | |
168 | ||
169 | if x_term + y_term + z_term > 1 then | |
170 | return false | |
171 | else | |
172 | return true | |
173 | end | |
174 | ||
175 | end |