forked from cleroy8/PositionBasedDynamics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspherecollider.cpp
More file actions
31 lines (24 loc) · 815 Bytes
/
Copy pathspherecollider.cpp
File metadata and controls
31 lines (24 loc) · 815 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
#include "spherecollider.h"
SphereCollider::SphereCollider(const Vec2 pc_, const float rc_)
: Collider(), pc(pc_), rc(rc_) {
}
SphereCollider::SphereCollider(const Vec2 pc_, const float rc_, const int role_)
: Collider(role_), pc(pc_), rc(rc_) {}
const std::optional<StaticConstraint> SphereCollider::checkContact(Particle& collider) {
Vec2 diff = collider.getExpPos()-this->getPoint();
float sdf = diff.length() - this->getRadius();
if (sdf<collider.getRad()){
StaticConstraint sc;
sc.nc = (1.0/diff.length())*diff;
sc.pc = collider.getExpPos() - sdf * sc.nc;
sc.part_ptr = &collider;
return sc;
}
return {};
}
const Vec2 SphereCollider::getPoint() const {
return pc;
}
const float SphereCollider::getRadius() const {
return rc;
}