-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbox_segs_sweep1_indexed.go
More file actions
34 lines (31 loc) · 1.05 KB
/
box_segs_sweep1_indexed.go
File metadata and controls
34 lines (31 loc) · 1.05 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
package coll
import (
"github.com/setanarut/v"
)
// BoxSegmentsSweep1Indexed returns the index of the colliding segment, or -1 if no collision was detected.
//
// Performs a sweep test of an box against a slice of segments.
//
// To determine the earliest point of impact along a movement vector,
// It iterates through the provided segments and finds the collision that occurs at the minimum time value.
// If h is not nil and a collision is detected, it will be populated with:
// - Normal: Collision surface normal for the box
// - Data: Normalized time of impact (0.0 to 1.0) along the movement path
func BoxSegmentsSweep1Indexed(s []*Segment, a *AABB, deltaA v.Vec, h *Hit) (index int) {
colliderIndex := -1
var resHitTime float64
var tmpHitInfo Hit
for i, line := range s {
if BoxSegmentSweep1(line, a, deltaA, &tmpHitInfo) {
if colliderIndex == -1 || tmpHitInfo.Data < resHitTime {
colliderIndex = i
resHitTime = tmpHitInfo.Data
// hitInfo nil değilse güncelle
if h != nil {
*h = tmpHitInfo
}
}
}
}
return colliderIndex
}