paysages3d/src/basics/Disk.cpp

35 lines
837 B
C++
Raw Normal View History

2015-10-15 18:21:32 +00:00
#include "Disk.h"
#include "PackStream.h"
Disk::Disk() {
2015-10-15 18:21:32 +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;
}
int Disk::checkRayIntersection(const InfiniteRay &ray, Vector3 *intersection) const {
2015-10-15 18:21:32 +00:00
int result = InfinitePlane::checkRayIntersection(ray, intersection);
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;
} else {
2015-10-15 18:21:32 +00:00
return result;
}
}
void Disk::save(PackStream *stream) const {
2015-10-15 18:21:32 +00:00
InfinitePlane::save(stream);
stream->write(&radius);
stream->write(&radius2);
}
void Disk::load(PackStream *stream) {
2015-10-15 18:21:32 +00:00
InfinitePlane::load(stream);
stream->read(&radius);
stream->read(&radius2);
}