diff --git a/geometry.h b/geometry.h index 692f6a0..03a0c61 100644 --- a/geometry.h +++ b/geometry.h @@ -23,32 +23,30 @@ struct Triangle { struct Vector { Vector(float coordinates[3]) : c(coordinates) {} + Vector(float x, float y, float z) : c(new float[3]{x, y, z}) {} // Avoid having to write vector.c[index], instead allow vector[index] float operator[](int i) const { return c[i]; } float &operator[](int i) { return c[i]; } Vector operator+(const Vector &other) const { - return Vector(new float[3]{c[0] + other.c[0], c[1] + other.c[1], c[2] + other.c[2]}); + return Vector(c[0] + other.c[0], c[1] + other.c[1], c[2] + other.c[2]); } Vector operator-(const Vector &other) const { - return Vector(new float[3]{c[0] - other.c[0], c[1] - other.c[1], c[2] - other.c[2]}); + return Vector(c[0] - other.c[0], c[1] - other.c[1], c[2] - other.c[2]); } Vector operator*(float scalar) const { - return Vector(new float[3]{c[0] * scalar, c[1] * scalar, c[2] * scalar}); + return Vector(c[0] * scalar, c[1] * scalar, c[2] * scalar); } Vector cross(const Vector &other) { - // TODO - return other; + return Vector(c[2] * other[3] - c[3] - other[2], c[3] * other[1] - c[1] * other[3], + c[1] * other[2] - c[2] * other[1]); } - float dot(const Vector &other) { - // TODO - return 0.0; - } + float dot(const Vector &other) { return c[1] * other[1] + c[2] * other[2] + c[3] * other[3]; } float *c; };