-
Notifications
You must be signed in to change notification settings - Fork 2
/
capsule.go
49 lines (39 loc) · 1.11 KB
/
capsule.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
// Copyright (c) 2019, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package eve
import (
"cogentcore.org/core/math32"
)
// Capsule is a generalized cylinder body shape, with hemispheres at each end,
// with separate radii for top and bottom.
type Capsule struct {
BodyBase
// height of the cylinder portion of the capsule
Height float32
// radius of the top hemisphere
TopRad float32
// radius of the bottom hemisphere
BotRad float32
}
func (cp *Capsule) SetBBox() {
th := cp.Height + cp.TopRad + cp.BotRad
h2 := th / 2
cp.BBox.SetBounds(math32.Vec3(-cp.BotRad, -h2, -cp.BotRad), math32.Vec3(cp.TopRad, h2, cp.TopRad))
cp.BBox.XForm(cp.Abs.Quat, cp.Abs.Pos)
}
func (cp *Capsule) InitAbs(par *NodeBase) {
cp.InitAbsBase(par)
cp.SetBBox()
cp.BBox.VelNilProject()
}
func (cp *Capsule) RelToAbs(par *NodeBase) {
cp.RelToAbsBase(par)
cp.SetBBox()
cp.BBox.VelProject(cp.Abs.LinVel, 1)
}
func (cp *Capsule) StepPhys(step float32) {
cp.StepPhysBase(step)
cp.SetBBox()
cp.BBox.VelProject(cp.Abs.LinVel, step)
}