Skip to content

Commit

Permalink
Merge pull request #1 from milmana/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
milmana authored Aug 5, 2024
2 parents f316340 + 1f8fdd3 commit 2bcd8c1
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
all:
g++ main.cc
./a.out
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# raytrace
ray tracing and other graphical stuff

# textbook
[Ray Tracing in One Weekend](https://raytracing.github.io/)
23 changes: 23 additions & 0 deletions main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <vector>
#include <tuple>

#include "raytrace.hh"

int main(int argc, char **argv) {

auto vec = vec3<double>{1., 2., 3.};
std::cout << vec << std::endl;

auto orig = vec3<double>{15., 16., 17.};
auto dir = vec3<double>{21., 22., 23.};
ray3 ray{orig, dir};
std::cout << ray << std::endl;
std::cout << vec * .001 << std::endl;
std::cout << .2 * vec << std::endl;

std::cout << ray(100) << std::endl;

return 0;

}
71 changes: 71 additions & 0 deletions raytrace.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <iostream>
#include <vector>

template <typename T>
struct vec3 {

std::vector<T> val;

vec3() { val = {0., 0., 0.}; }
vec3(T x, T y, T z) { val = {x,y,z}; }

};

template <typename T>
vec3<T> operator*(const vec3<T>& lhs, const vec3<T> &rhs) {
return {lhs.val[0] * rhs.val[0], lhs.val[1] * rhs.val[1], lhs.val[2] * rhs.val[2]};
}

template <typename T>
vec3<T> operator*(const vec3<T>& lhs, const T& rhs) {
return {lhs.val[0] * rhs, lhs.val[1] * rhs, lhs.val[2] * rhs};
}

template <typename T>
vec3<T> operator*(const T& lhs, const vec3<T>& rhs) {
return {lhs * rhs.val[0], lhs * rhs.val[1], lhs * rhs.val[2]};
}

template <typename T>
vec3<T> operator+(const vec3<T>& lhs, const vec3<T>& rhs) {
return {lhs.val[0] + rhs.val[0], lhs.val[1] + rhs.val[1], lhs.val[2] + rhs.val[2]};
}

template <typename T>
vec3<T> operator+(const vec3<T>& lhs, const T& rhs) {
return {lhs.val[0] + rhs, lhs.val[1] + rhs, lhs.val[2] + rhs};
}

template <typename T>
vec3<T> operator+(const T& lhs, const vec3<T>& rhs) {
return {lhs + rhs.val[0], lhs + rhs.val[1], lhs + rhs.val[2]};
}

template<typename T>
std::ostream &operator<<(std::ostream &os, const vec3<T> &v)
{
return os << "(" << v.val[0] << "," << v.val[1] << "," << v.val[2] << ")";
}

template <typename T>
struct ray3 {

// p = a + tb
// a := origin
// b := direction

vec3<T> a, b;

ray3 (vec3<T> orig, vec3<T> dir) {
a = orig;
b = dir;
}

vec3<T> operator()(const T t) { return a + t*b; }
};

template<typename T>
std::ostream &operator<<(std::ostream &os, const ray3<T> &v)
{
return os << "[" << v.a << "; " << v.b << "]";
}

0 comments on commit 2bcd8c1

Please sign in to comment.