-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertex.go
24 lines (21 loc) · 1 KB
/
vertex.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
package csg
// Vertex represents a vertex of a polygon. Use your own vertex class instead of this
// one to provide additional features like texture coordinates and vertex
// colors. Custom vertex classes need to provide a `Pos` property and `Flip()`, and
// `Interpolate()` methods that behave analogous to the ones defined by `csg.Vertex`.
// This struct provides `Normal` so convenience functions like `csg.Sphere()` can
// return a smooth vertex normal, but `Normal` is not used anywhere else.
type Vertex struct{ Pos, Normal Vector }
// Flip inverts all orientation-specific data (e.g. vertex normal). Called when the
// orientation of a polygon is flipped.
func (v *Vertex) Flip() {
v.Normal = v.Normal.Negated()
}
// Interpolate creates a new vertex between this vertex and `other` by linearly
// interpolating all properties using a parameter of `t`.
func (v Vertex) Interpolate(other Vertex, t float64) Vertex {
return Vertex{
Pos: v.Pos.Lerp(other.Pos, t),
Normal: v.Normal.Lerp(other.Normal, t),
}
}