-
Notifications
You must be signed in to change notification settings - Fork 7
/
scene.h
78 lines (68 loc) · 4.06 KB
/
scene.h
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef _SCENE_H_
#define _SCENE_H_
#include "constant.h"
#include "sphere.h"
#include "intersection.h"
namespace edubpt {
// レンダリングするシーンデータ
const Sphere spheres[] = {
Sphere(7.5,Vec(50.0, 72.5, 81.6), Color(16,16,16), Color(), REFLECTION_TYPE_DIFFUSE), //照明
Sphere(1e5, Vec( 1e5+1, 40.8, 81.6), Color(), Color(0.75, 0.25, 0.25), REFLECTION_TYPE_DIFFUSE), // 左
Sphere(1e5, Vec(-1e5+99, 40.8, 81.6),Color(), Color(0.25, 0.25, 0.75), REFLECTION_TYPE_DIFFUSE), // 右
Sphere(1e5, Vec(50, 40.8, 1e5), Color(), Color(0.75, 0.75, 0.75), REFLECTION_TYPE_DIFFUSE), // 奥
Sphere(1e5, Vec(50, 40.8, -1e5+250), Color(), Color(), REFLECTION_TYPE_DIFFUSE), // 手前
Sphere(1e5, Vec(50, 1e5, 81.6), Color(), Color(0.75, 0.75, 0.75), REFLECTION_TYPE_DIFFUSE), // 床
Sphere(1e5, Vec(50, -1e5+81.6, 81.6),Color(), Color(0.75, 0.75, 0.75), REFLECTION_TYPE_DIFFUSE), // 天井
Sphere(20,Vec(50, 20, 50), Color(), Color(0.25, 0.75, 0.25), REFLECTION_TYPE_DIFFUSE), // 緑球
Sphere(16.5,Vec(19, 16.5, 25), Color(), Color(0.99, 0.99, 0.99), REFLECTION_TYPE_MIRROR), // 鏡
Sphere(16.5,Vec(77, 16.5, 78), Color(), Color(0.99, 0.99, 0.99), REFLECTION_TYPE_GLASS), //ガラス
};
/*
// 照明サイズ小
const Sphere spheres[] = {
Sphere(1.0, Vec(1.0, 1.0, 1.0), Color(64,64,64), Color(), REFLECTION_TYPE_DIFFUSE), //照明
Sphere(1e5, Vec( 1e5+1, 40.8, 81.6), Color(), Color(0.75, 0.25, 0.25), REFLECTION_TYPE_DIFFUSE), // 左
Sphere(1e5, Vec(-1e5+99, 40.8, 81.6),Color(), Color(0.25, 0.25, 0.75), REFLECTION_TYPE_DIFFUSE), // 右
Sphere(1e5, Vec(50, 40.8, 1e5), Color(), Color(0.75, 0.75, 0.75), REFLECTION_TYPE_DIFFUSE), // 奥
Sphere(1e5, Vec(50, 40.8, -1e5+250), Color(), Color(), REFLECTION_TYPE_DIFFUSE), // 手前
Sphere(1e5, Vec(50, 1e5, 81.6), Color(), Color(0.75, 0.75, 0.75), REFLECTION_TYPE_DIFFUSE), // 床
Sphere(1e5, Vec(50, -1e5+81.6, 81.6),Color(), Color(0.75, 0.75, 0.75), REFLECTION_TYPE_DIFFUSE), // 天井
Sphere(15,Vec(15, 15, 15), Color(), Color(0.25, 0.75, 0.25), REFLECTION_TYPE_DIFFUSE), // 緑球
Sphere(16.5,Vec(50, 16.5, 25), Color(), Color(0.99, 0.99, 0.99), REFLECTION_TYPE_MIRROR), // 鏡
Sphere(16.5,Vec(77, 16.5, 78), Color(), Color(0.99, 0.99, 0.99), REFLECTION_TYPE_GLASS), //ガラス
};*/
/*
// 照明サイズ小+ガラス球大
const Sphere spheres[] = {
Sphere(0.5,Vec(50.0, 78, 78), Color(256,256,256), Color(), REFLECTION_TYPE_DIFFUSE), //照明
Sphere(1e5, Vec( 1e5+1, 40.8, 81.6), Color(), Color(0.75, 0.25, 0.25), REFLECTION_TYPE_DIFFUSE), // 左
Sphere(1e5, Vec(-1e5+99, 40.8, 81.6),Color(), Color(0.25, 0.25, 0.75), REFLECTION_TYPE_DIFFUSE), // 右
Sphere(1e5, Vec(50, 40.8, 1e5), Color(), Color(0.75, 0.75, 0.75), REFLECTION_TYPE_DIFFUSE), // 奥
Sphere(1e5, Vec(50, 40.8, -1e5+250), Color(), Color(), REFLECTION_TYPE_DIFFUSE), // 手前
Sphere(1e5, Vec(50, 1e5, 81.6), Color(), Color(0.75, 0.75, 0.75), REFLECTION_TYPE_DIFFUSE), // 床
Sphere(1e5, Vec(50, -1e5+81.6, 81.6),Color(), Color(0.75, 0.75, 0.75), REFLECTION_TYPE_DIFFUSE), // 天井
Sphere(16,Vec(30, 16, 40), Color(), Color(0.25, 0.75, 0.25), REFLECTION_TYPE_DIFFUSE), // 緑球
Sphere(20,Vec(50, 50, 78), Color(), Color(0.99, 0.99, 0.99), REFLECTION_TYPE_GLASS), //ガラス
};
*/
const int LightID = 0;
// シーンとの交差判定関数
inline bool intersect_scene(const Ray &ray, Intersection *intersection) {
const double n = sizeof(spheres) / sizeof(Sphere);
// 初期化
intersection->hitpoint.distance = kINF;
intersection->object_id = -1;
// 線形探索
for (int i = 0; i < int(n); i ++) {
Hitpoint hitpoint;
if (spheres[i].intersect(ray, &hitpoint)) {
if (hitpoint.distance < intersection->hitpoint.distance) {
intersection->hitpoint = hitpoint;
intersection->object_id = i;
}
}
}
return (intersection->object_id != -1);
}
};
#endif