#include "client/math/Plane.h"

Plane::Plane() : a(0), b(0), c(0), d(0) {
}

void Plane::set(const Vector& va, const Vector& vb, const Vector& vc) {
    Vector h1 = vb;
    h1.sub(va);
    Vector h2 = vc;
    h2.sub(va);
    h1.cross(h2);
    h1.normalize();

    a = h1.getX();
    b = h1.getY();
    c = h1.getZ();
    d = -h1.dot(va);
}

float Plane::getSignedDistance(float x, float y, float z) const {
    return x * a + y * b + z * c + d;
}

float Plane::getSignedDistance(const Vector& v) const {
    return getSignedDistance(v.getX(), v.getY(), v.getZ());
}