-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscene.hpp
More file actions
55 lines (41 loc) · 1022 Bytes
/
scene.hpp
File metadata and controls
55 lines (41 loc) · 1022 Bytes
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#ifndef _SCENE_HPP_
#define _SCENE_HPP_
#include<cuda.h>
#include<helper_cuda.h>
#include<helper_math.h>
#include"sphere.hpp"
#include"ray.hpp"
#include"intersection.hpp"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class scene : public sphere
{
public:
__device__ scene() {}
__device__ scene( sphere **obj, const int n ) : m_n( n ) { m_object = obj; }
__device__ bool intersect( const ray &r, intersection &isect ) const
{
float mint = 1e10f;
bool hit = false;
int id = 0;
for( int i = 0; i < m_n; ++i ) {
float t = m_object[ i ]->intersect( r );
if( t < mint && t > 0.f ) {
mint = t;
hit = true;
id = i;
}
}
if( hit ) {
isect.m_p = r.o() + mint * r.d();
isect.m_n = normalize( isect.m_p - m_object[ id ]->center() );
isect.m_c = m_object[ id ]->color();
}
return hit;
}
__device__ int size() const { return m_n; }
private:
sphere **m_object;
int m_n;
};
#endif