2015-10-15 18:21:32 +00:00
|
|
|
#include "Disk.h"
|
|
|
|
|
|
|
|
#include "PackStream.h"
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
Disk::Disk() {
|
2015-10-15 18:21:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
Disk::Disk(const Vector3 &point, const Vector3 &normal, double radius) : InfinitePlane(point, normal), radius(radius) {
|
2015-10-15 18:21:32 +00:00
|
|
|
radius2 = radius * radius;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
int Disk::checkRayIntersection(const InfiniteRay &ray, Vector3 *intersection) const {
|
2015-10-15 18:21:32 +00:00
|
|
|
int result = InfinitePlane::checkRayIntersection(ray, intersection);
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
if (result == 1) {
|
2015-10-15 18:21:32 +00:00
|
|
|
Vector3 v = intersection->sub(getPoint());
|
|
|
|
double d2 = v.dotProduct(v);
|
|
|
|
return (d2 <= radius2) ? 1 : 0;
|
2015-11-09 21:30:46 +00:00
|
|
|
} else {
|
2015-10-15 18:21:32 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void Disk::save(PackStream *stream) const {
|
2015-10-15 18:21:32 +00:00
|
|
|
InfinitePlane::save(stream);
|
|
|
|
stream->write(&radius);
|
|
|
|
stream->write(&radius2);
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void Disk::load(PackStream *stream) {
|
2015-10-15 18:21:32 +00:00
|
|
|
InfinitePlane::load(stream);
|
|
|
|
stream->read(&radius);
|
|
|
|
stream->read(&radius2);
|
|
|
|
}
|