-
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.
Implemented a hittable and sphere class.
- Loading branch information
Showing
9 changed files
with
124 additions
and
58 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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
!result.png | ||
|
||
# Ignore executables | ||
Image | ||
RayTracer | ||
|
||
# Ignore vscde folder | ||
.vscode |
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,25 @@ | ||
#ifndef RTWEEKEND_H | ||
#define RTWEEKEND_H | ||
|
||
#include <cmath> | ||
#include <limits> | ||
#include <memory> | ||
|
||
using std::make_shared; | ||
using std::shared_ptr; | ||
using std::sqrt; | ||
|
||
// Constants | ||
double const infinity = std::numeric_limits<double>::infinity(); | ||
double const pi = 3.1415926535897932385; | ||
|
||
// Utilities | ||
inline double DegreesToRadians(double degrees) | ||
{ | ||
return degrees * pi / 180.0; | ||
} | ||
|
||
#include "ray.h" | ||
#include "vec3.h" | ||
|
||
#endif |
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
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
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,45 @@ | ||
#ifndef HITTABLE_LIST_H | ||
#define HITTABLE_LIST_H | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "hittable.h" | ||
|
||
using std::make_shared; | ||
using std::shared_ptr; | ||
|
||
class HittableList : public Hittable | ||
{ | ||
public: | ||
std::vector<shared_ptr<Hittable>> objects; | ||
|
||
HittableList() {} | ||
HittableList(shared_ptr<Hittable> object) { Add(object); } | ||
|
||
void Clear() { objects.clear(); } | ||
|
||
void Add(shared_ptr<Hittable> object) { objects.push_back(object); } | ||
|
||
bool Hit(Ray const& r, double rayTMin, double rayTMax, HitRecord& rec) const override | ||
{ | ||
HitRecord tempRec; | ||
bool hitAnything = false; | ||
|
||
double closestSoFar = rayTMax; | ||
|
||
for (auto const& object : objects) | ||
{ | ||
if (object->Hit(r, rayTMin, closestSoFar, tempRec)) | ||
{ | ||
hitAnything = true; | ||
closestSoFar = tempRec.t; | ||
rec = tempRec; | ||
} | ||
} | ||
|
||
return hitAnything; | ||
} | ||
}; | ||
|
||
#endif |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.