Plane.cpp 565 B

1234567891011121314151617181920212223242526
  1. #include "client/math/Plane.h"
  2. Plane::Plane() : a(0), b(0), c(0), d(0) {
  3. }
  4. void Plane::set(const Vector& va, const Vector& vb, const Vector& vc) {
  5. Vector h1 = vb;
  6. h1.sub(va);
  7. Vector h2 = vc;
  8. h2.sub(va);
  9. h1.cross(h2);
  10. h1.normalize();
  11. a = h1.getX();
  12. b = h1.getY();
  13. c = h1.getZ();
  14. d = -h1.dot(va);
  15. }
  16. float Plane::getSignedDistance(float x, float y, float z) const {
  17. return x * a + y * b + z * c + d;
  18. }
  19. float Plane::getSignedDistance(const Vector& v) const {
  20. return getSignedDistance(v.getX(), v.getY(), v.getZ());
  21. }