-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbbox.go
More file actions
46 lines (41 loc) · 1.11 KB
/
bbox.go
File metadata and controls
46 lines (41 loc) · 1.11 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
package bedsim
import (
"github.com/df-mc/dragonfly/server/block/cube"
"github.com/go-gl/mathgl/mgl64"
)
// BoundingBox returns the entity bounding box translated to the current position.
func (s *MovementState) BoundingBox(useSlideOffset bool) cube.BBox {
scale := s.Size[2]
width := (s.Size[0] * 0.5) * scale
height := s.Size[1] * scale
yOffset := 0.0
if useSlideOffset {
yOffset = s.SlideOffset.Y()
}
return cube.Box(
s.Pos[0]-width,
s.Pos[1]+yOffset,
s.Pos[2]-width,
s.Pos[0]+width,
s.Pos[1]+height+yOffset,
s.Pos[2]+width,
).GrowVec3(mgl64.Vec3{-1e-4, 0, -1e-4})
}
// ClientBoundingBox returns the bounding box translated to the client's position.
func (s *MovementState) ClientBoundingBox(useSlideOffset bool) cube.BBox {
scale := s.Size[2]
width := (s.Size[0] * 0.5) * scale
height := s.Size[1] * scale
yOffset := 0.0
if useSlideOffset {
yOffset = s.SlideOffset.Y()
}
return cube.Box(
s.Client.Pos[0]-width,
s.Client.Pos[1]+yOffset,
s.Client.Pos[2]-width,
s.Client.Pos[0]+width,
s.Client.Pos[1]+height+yOffset,
s.Client.Pos[2]+width,
).GrowVec3(mgl64.Vec3{-1e-4, 0, -1e-4})
}