#ifndef OBJ_UTILS_HPP #define OBJ_UTILS_HPP #include "vector/vec_utils.hpp" class vertex3 { private: float x, y, z; float w; public: vertex3() : x(0), y(0), z(0), w(1) {} vertex3(float x, float y, float z, float w = 1.0f) : x(x), y(y), z(z), w(w) {} float getX() const { return x; } float getY() const { return y; } float getZ() const { return z; } float getW() const { return w; } void setX(float val) { this->x = val; } void setY(float val) { this->y = val; } void setZ(float val) { this->z = val; } void setW(float val) { this->w = val; } vertex3 operator+(const vertex3 &other) const; vertex3 operator-(const vertex3 &other) const; vertex3 operator*(float scalar) const; vertex3 operator/(float scalar) const; float dot(const vertex3 &other) const; vertex3 cross(const vertex3 &other) const; vertex3 normalize() const; }; class cube { private: vertex3 *vertices; vertex3 center; float size; public: cube() { vertices = (vertex3 *)malloc(8 * sizeof(vertex3)); if (!vertices) { fprintf(stderr, "Error: Memory allocation failed for cube vertices.\n"); return; } } ~cube() { if (vertices) { free(vertices); vertices = nullptr; } } void setVertex(int index, const vertex3 &v) { if (index < 0 || index >= 8) { fprintf(stderr, "Error: Index out of bounds in cube::setVertex.\n"); return; } vertices[index] = v; } vertex3 getVertex(int index) const { if (index < 0 || index >= 8) { fprintf(stderr, "Error: Index out of bounds in cube::getVertex.\n"); return vertex3(); } return vertices[index]; } vertex3 getCenter() const { return center; } float getSize() const { return size; } }; #endif // !OBJ_UTILS_HPP