forked from cleroy8/PositionBasedDynamics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanecollider.cpp
More file actions
36 lines (26 loc) · 867 Bytes
/
Copy pathplanecollider.cpp
File metadata and controls
36 lines (26 loc) · 867 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
#include "planecollider.h"
#include "vec2.h"
PlaneCollider::PlaneCollider(const Vec2 pc_, const Vec2 nc_)
: Collider(), pc(pc_), nc((1.0/nc_.length())*nc_) {
}
PlaneCollider::PlaneCollider(const Vec2 pc_, const Vec2 nc_, const int role_)
: Collider(role_), pc(pc_), nc((1.0/nc_.length())*nc_) {}
const std::optional<StaticConstraint> PlaneCollider::checkContact(Particle& collider) {
const Vec2 expPos = collider.getExpPos();
const Vec2 diff = expPos - getPoint();
const float ri = collider.getRad();
if(diff.dotProduct(getNormal()) - ri < 0.0) {
StaticConstraint sc;
sc.pc = getPoint();
sc.nc = getNormal();
sc.part_ptr = &collider;
return sc;
}
return {};
}
const Vec2 PlaneCollider::getPoint() const {
return pc;
}
const Vec2 PlaneCollider::getNormal() const {
return nc;
}