paysages3d/src/basics/Disk.cpp

44 lines
852 B
C++
Raw Normal View History

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