-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewer.go
72 lines (57 loc) · 1.22 KB
/
viewer.go
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
70
71
72
package main
import (
"rapidengine/child"
"rapidengine/geometry"
"rapidengine/material"
)
var V Viewer
type Viewer struct {
aabbs map[*child.Child2D]*AABB
hbs map[*AABB]*Hitbox
Mat *material.BasicMaterial
}
func InitializeHitboxViewer() {
V = Viewer{
aabbs: make(map[*child.Child2D]*AABB),
hbs: make(map[*AABB]*Hitbox),
Mat: Engine.MaterialControl.NewBasicMaterial(),
}
}
func (v *Viewer) AddBox(hb *Hitbox) {
v.AddAABBHitbox(&hb.LAABB, hb)
v.AddAABBHitbox(&hb.RAABB, hb)
v.AddAABBHitbox(&hb.DAABB, hb)
v.AddAABBHitbox(&hb.UAABB, hb)
}
func (v *Viewer) AddAABBHitbox(a *AABB, h *Hitbox) {
c := Engine.ChildControl.NewChild2D()
c.AttachMaterial(v.Mat)
c.AttachMesh(geometry.NewRectangle())
c.ScaleX = a.Width
c.ScaleY = a.Height
v.aabbs[c] = a
v.hbs[a] = h
}
func (v *Viewer) AddAABB(a *AABB) {
c := Engine.ChildControl.NewChild2D()
c.AttachMaterial(v.Mat)
c.AttachMesh(geometry.NewRectangle())
c.ScaleX = a.Width
c.ScaleY = a.Height
v.aabbs[c] = a
}
func (v *Viewer) Update() {
for c, ab := range v.aabbs {
c.X = ab.X
c.Y = ab.Y
if h, ok := v.hbs[ab]; ok {
c.X += h.X
c.Y += h.Y
}
}
}
func (v *Viewer) Render() {
for c, _ := range v.aabbs {
Engine.Renderer.RenderChild(c)
}
}