-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontact.ts
55 lines (51 loc) · 1.25 KB
/
contact.ts
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
50
51
52
53
54
55
import { Collider } from "./collider";
import { ContactInfo } from "./separating-axis";
import { Vector } from "./vector";
/**
* Represents contact between two rigid bodies
*
* Meant to be re-used over multiple frames
*/
export class Contact {
/**
* The unique id between 2 bodies
*/
public get id() {
return Contact.GetId(this.bodyA, this.bodyB);
}
/**
* Get the id of 2 bodies
* @param bodyA
* @param bodyB
* @returns
*/
public static GetId(bodyA: Collider, bodyB: Collider) {
if (bodyA.id < bodyB.id) {
return `${bodyA.id}+${bodyB.id}`;
} else {
return `${bodyB.id}+${bodyA.id}`;
}
}
constructor(
public bodyA: Collider,
public bodyB: Collider,
/**
* Normals point away from bodyA
*/
public normal: Vector,
/**
* Tangent to collision normal
*/
public tangent: Vector,
// TODO should this just be part of contact?
public info: ContactInfo,
/**
* World space contact points
*/
public points: Vector[] = [],
/**
* Local space contact points
*/
public locals: Vector[] = []
) {}
}