-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSphere.hh
39 lines (35 loc) · 978 Bytes
/
Sphere.hh
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
#ifndef SPHERE_HH
#define SPHERE_HH
#include "Collidable.hh"
template<class F>
class Sphere:
public Collidable<F>
{
public:
Sphere(F springConstant, F dampeningConstant, F frictionMultiplier, F rollingResistance)
: Collidable<F>(springConstant, dampeningConstant, frictionMultiplier, rollingResistance)
{
}
protected:
bool
Collides(Collidable<F>* other, ZenMatrix<F, 3, 1>& location, ZenMatrix<F, 3, 1>& normal, F& overlap)
{
Sphere<F>* otherSphere = dynamic_cast<Sphere<F>*>(other);
if (otherSphere != NULL) {
ZenMatrix<F, 3, 1> r = other->mLocation - Object<F>::mLocation;
F distance = Length(r);
F overlapLocal = Object<F>::mRadius + other->mRadius - distance;
if (overlapLocal > 0) {
overlap = overlapLocal;
normal = Normalize(r);
location = (other->mLocation + Object<F>::mLocation) / 2;
return true;
} else {
return false;
}
} else {
throw std::exception();
}
}
};
#endif // SPHERE_HH