diff --git a/.gitignore b/.gitignore index 226ada1..2b70b8a 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,11 @@ CTestTestfile.cmake _deps CMakeUserPresets.json +# Build / Compiled program + +build/Render +build/bin/* +Render +build/Render.exe +Render.exe + diff --git a/ROADMAP.md b/ROADMAP.md index c2f166a..b49e491 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -5,13 +5,17 @@ This roadmap breaks down the essential steps to build your CPU-based raytracer f --- ## Phase 1: Foundations & Core Engine -- [ ] Set up vector math utilities (`vec3`): add, subtract, dot, cross, normalize +- [x] Set up vector math utilities (`vec3`): add, subtract, dot, cross, normalize - [ ] Implement Ray class — origin, direction, basic functions - [ ] Basic Sphere object — position, radius, material properties - [ ] Ray-Sphere intersection logic — the core of your renderer - [ ] Camera setup — generate rays through the viewport - [ ] Scene structure — manage objects and lights +# Objectives: + - [ ] Render a single sphere with basic color + - [ ] Output to a simple PPM file format + --- ## Phase 2: Lighting & Shading Basics diff --git a/build/bin/test b/build/bin/test deleted file mode 100755 index e9a1248..0000000 Binary files a/build/bin/test and /dev/null differ diff --git a/include/vector/utils_vec.cpp b/include/vector/utils_vec.cpp new file mode 100644 index 0000000..79bfcfc --- /dev/null +++ b/include/vector/utils_vec.cpp @@ -0,0 +1,49 @@ +#include "utils_vec.hpp" + +vec3 vec3::operator+(const vec3 &other) const +{ + return vec3(x + other.x, y + other.y, z + other.z); +} + +vec3 vec3::operator-(const vec3 &other) const +{ + return vec3(x - other.x, y - other.y, z - other.z); +} + +vec3 vec3::operator*(float scalar) const +{ + return vec3(x * scalar, y * scalar, z * scalar); +} + +vec3 vec3::operator/(float scalar) const +{ + if (scalar == 0) + { + fprintf(stderr, "Error: Division by zero in vec3::operator/.\n"); + } + return vec3(x / scalar, y / scalar, z / scalar); +} + +vec3 vec3::dot(const vec3 &other) const +{ + return vec3(x * other.x, y * other.y, z * other.z); +} + +vec3 vec3::cross(const vec3 &other) const +{ + return vec3( + y * other.z - z * other.y, + z * other.x - x * other.z, + x * other.y - y * other.x); +} + +vec3 vec3::normalize() const +{ + float length = sqrt(x * x + y * y + z * z); + if (length == 0) + { + fprintf(stderr, "Error: Normalization of zero vector in vec3::normalize.\n"); + return vec3(0, 0, 0); // Return zero vector if normalization fails + } + return vec3(x / length, y / length, z / length); +} \ No newline at end of file diff --git a/include/vector/utils_vec.hpp b/include/vector/utils_vec.hpp new file mode 100644 index 0000000..ee56b19 --- /dev/null +++ b/include/vector/utils_vec.hpp @@ -0,0 +1,37 @@ +#ifndef UTILS_VEC_HPP +#define UTILS_VEC_HPP + +#include +#include +#include +#include +#include + +class vec3 +{ +private: + float x, y, z; + +public: + vec3() : x(0), y(0), z(0) {} + vec3(float x, float y, float z) : x(x), y(y), z(z) {} + + float getX() const { return x; } + float getY() const { return y; } + float getZ() const { return z; } + + void setX(float val) { this->x = val; } + void setY(float val) { this->y = val; } + void setZ(float val) { this->z = val; } + + vec3 operator+(const vec3 &other) const; + vec3 operator-(const vec3 &other) const; + vec3 operator*(float scalar) const; + vec3 operator/(float scalar) const; + + vec3 dot(const vec3 &other) const; + vec3 cross(const vec3 &other) const; + vec3 normalize() const; +}; + +#endif // !UTILS_VEC_HPP diff --git a/source/main.cpp b/source/main.cpp index df28b27..3874686 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,7 +1,29 @@ #include +// Include the vector utilities header file +#include "vector/utils_vec.hpp" + int main() { - std::cout << "Hello, World!" << std::endl; + vec3 *v1 = (vec3 *)malloc(sizeof(vec3) * 2); + + if (v1 == nullptr) + { + fprintf(stderr, "Error: Memory allocation failed for vec3 array.\n"); + return 1; // Exit with error code + } + + for (int i = 0; i < 2; i++) + { + v1[i].setX(i + 1.0f); + v1[i].setY(i + 2.0f); + v1[i].setZ(i + 3.0f); + } + + vec3 v2 = v1[0] + v1[1]; + + std::cout << "v2: (" << v2.getX() << ", " << v2.getY() << ", " << v2.getZ() << ")" << std::endl; + + free(v1); // Free the allocated memory return 0; } \ No newline at end of file