-
Notifications
You must be signed in to change notification settings - Fork 70
/
cylinder.go
48 lines (38 loc) · 1.05 KB
/
cylinder.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
// Copyright (c) 2019, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package physics
import (
"cogentcore.org/core/math32"
)
// Cylinder is a generalized cylinder body shape, with separate radii for top and bottom.
// A cone has a zero radius at one end.
type Cylinder struct {
BodyBase
// height of the cylinder
Height float32
// radius of the top -- set to 0 for a cone
TopRad float32
// radius of the bottom
BotRad float32
}
func (cy *Cylinder) SetBBox() {
h2 := cy.Height / 2
cy.BBox.SetBounds(math32.Vec3(-cy.BotRad, -h2, -cy.BotRad), math32.Vec3(cy.TopRad, h2, cy.TopRad))
cy.BBox.XForm(cy.Abs.Quat, cy.Abs.Pos)
}
func (cy *Cylinder) InitAbs(par *NodeBase) {
cy.InitAbsBase(par)
cy.SetBBox()
cy.BBox.VelNilProject()
}
func (cy *Cylinder) RelToAbs(par *NodeBase) {
cy.RelToAbsBase(par)
cy.SetBBox()
cy.BBox.VelProject(cy.Abs.LinVel, 1)
}
func (cy *Cylinder) Step(step float32) {
cy.StepBase(step)
cy.SetBBox()
cy.BBox.VelProject(cy.Abs.LinVel, step)
}