-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcamera_common.lua
More file actions
54 lines (36 loc) · 778 Bytes
/
camera_common.lua
File metadata and controls
54 lines (36 loc) · 778 Bytes
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
BBox_relative = {}
BBox_pix = {}
local inspect = require("inspect")
local function check_bbox(bbox)
if not bbox.w or not bbox.h then
return false
end
if bbox.w < 0.1 or bbox.w > 1. then
return false
end
if bbox.h < 0.1 or bbox.h > 1. then
return false
end
return true
end
local function calc_bbox_pix(
bbox,
screenW,
screenH,
cam_x,
cam_y)
if not check_bbox(bbox) then
error("bad camera bbox: " .. inspect(bbox))
end
local real_w, real_h = bbox.w * screenW, bbox.h * screenH
return {
x = cam_x + (screenW - real_w) / 2,
y = cam_y + (screenH - real_h) / 2,
w = real_w,
h = real_h,
}
end
return {
check_bbox = check_bbox,
calc_bbox_pix = calc_bbox_pix,
}