-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoll.go
More file actions
35 lines (30 loc) · 766 Bytes
/
coll.go
File metadata and controls
35 lines (30 loc) · 766 Bytes
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
// 2D Collision functions
package coll
import (
"github.com/setanarut/v"
)
const (
Epsilon float64 = 1e-8
Padding float64 = 0.005
)
// Hit holds the information about a collision or contact event.
type Hit struct {
// The normal vector of the hit.
Normal v.Vec
// 1. The time (0.0 to 1.0) along the movement path for moving objects.
//
// 2. Penetration depth for overlap tests
Data float64
}
// Resets the zero values.
func (h *Hit) Reset() {
*h = Hit{} // Reinitializes all fields of the struct to their zero values (nil, 0, false, etc.).
}
// SegmentNormal returns surface normal of the segment.
func SegmentNormal(pointA, pointB v.Vec) (normal v.Vec) {
d := pointB.Sub(pointA)
if d.IsZero() {
return
}
return v.Vec{X: d.Y, Y: -d.X}.Unit()
}