paysages3d/src/basics/InfinitePlane.cpp

38 lines
907 B
C++
Raw Normal View History

2015-10-15 18:21:32 +00:00
#include "InfinitePlane.h"
#include "PackStream.h"
#include "InfiniteRay.h"
InfinitePlane::InfinitePlane() {
2015-10-15 18:21:32 +00:00
}
InfinitePlane::InfinitePlane(const Vector3 &point, const Vector3 &normal) : point(point), normal(normal) {
2015-10-15 18:21:32 +00:00
}
int InfinitePlane::checkRayIntersection(const InfiniteRay &ray, Vector3 *intersection) const {
2015-10-15 18:21:32 +00:00
Vector3 p1 = ray.getDirection();
double d = normal.dotProduct(p1);
if (fabs(d) < 1e-8) {
if (normal.dotProduct(ray.getPointAtCursor(1.0).sub(point)) == 0) {
2015-10-15 18:21:32 +00:00
return -1;
} else {
2015-10-15 18:21:32 +00:00
return 0;
}
}
double u = point.sub(ray.getOrigin()).dotProduct(normal) / d;
*intersection = ray.getPointAtCursor(u);
return 1;
}
void InfinitePlane::save(PackStream *stream) const {
2015-10-15 18:21:32 +00:00
point.save(stream);
normal.save(stream);
}
void InfinitePlane::load(PackStream *stream) {
2015-10-15 18:21:32 +00:00
point.load(stream);
normal.load(stream);
}