This repository was archived by the owner on Jun 17, 2019. It is now read-only.
forked from avin1cius/Path-Tracer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene.cpp
More file actions
35 lines (28 loc) · 1.38 KB
/
scene.cpp
File metadata and controls
35 lines (28 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "scene.h"
Scene::Scene( void )
{}
Scene::~Scene( void )
{}
bool Scene::intersect( const Ray &ray,
IntersectionRecord &intersection_record ) const
{
bool intersection_result = false;
IntersectionRecord tmp_intersection_record;
std::size_t num_primitives = primitives_.size();
// Loops over the list of primitives, testing the intersection of each primitive against the given ray
for ( std::size_t primitive_id = 0; primitive_id < num_primitives; primitive_id++ )
if ( primitives_[primitive_id]->intersect( ray, tmp_intersection_record ) )
if ( ( tmp_intersection_record.t_ < intersection_record.t_ ) && ( tmp_intersection_record.t_ > 0.0 ) )
{
intersection_record = tmp_intersection_record;
intersection_result = true; // the ray intersects a primitive!
}
return intersection_result;
}
void Scene::load( void )
{
primitives_.push_back( Primitive::PrimitiveUniquePtr( new Sphere{ glm::vec3{ 0.0f, 0.0f, 0.0f }, 0.2f } ) );
primitives_.push_back( Primitive::PrimitiveUniquePtr( new Sphere{ glm::vec3{ -0.5f, 0.0f, -1.0f }, 0.2f } ) );
primitives_.push_back( Primitive::PrimitiveUniquePtr( new Sphere{ glm::vec3{ 0.0f,-0.5f, -2.0f }, 0.2f } ) );
primitives_.push_back( Primitive::PrimitiveUniquePtr( new Sphere{ glm::vec3{ 0.0f, 0.5f, -3.0f }, 0.2f } ) );
}