2015-10-15 18:21:32 +00:00
|
|
|
#include "InfinitePlane.h"
|
|
|
|
|
|
|
|
#include "PackStream.h"
|
|
|
|
#include "InfiniteRay.h"
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
InfinitePlane::InfinitePlane() {
|
2015-10-15 18:21:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
InfinitePlane::InfinitePlane(const Vector3 &point, const Vector3 &normal) : point(point), normal(normal) {
|
2015-10-15 18:21:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +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);
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
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;
|
2015-11-09 21:30:46 +00:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void InfinitePlane::save(PackStream *stream) const {
|
2015-10-15 18:21:32 +00:00
|
|
|
point.save(stream);
|
|
|
|
normal.save(stream);
|
|
|
|
}
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
void InfinitePlane::load(PackStream *stream) {
|
2015-10-15 18:21:32 +00:00
|
|
|
point.load(stream);
|
|
|
|
normal.load(stream);
|
|
|
|
}
|