-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from milmana/dev
Dev
- Loading branch information
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
all: | ||
g++ main.cc | ||
./a.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 << "]"; | ||
} |