-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
148 lines (121 loc) · 5.41 KB
/
Copy pathmain.cpp
File metadata and controls
148 lines (121 loc) · 5.41 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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <iostream>
#include <fstream>
#include "utils/vector3.h"
#include "utils/image.h"
#include "scene/sphere.h"
#include "scene/scene.h"
#include "scene/plane.h"
#include "scene/point_light.h"
#include "cmath"
#include "scene/triangle.h"
#include "scene/blob.h"
#include "scene/bezier.h"
#include "scene/grass_blade.h"
#include "scene/grass.h"
int main() {
bool test = true;
test = false;
if (test)
{
auto v = raytracer::Vector3(45, 68, -32);
std::cout << v;
auto img = raytracer::Image(200, 300);
img.fill_black();
for (int i = 50; i < 100; i++)
{
for (int j = 50; j < 100; j++)
{
img.m_pix_array[i * img.m_width + j] = raytracer::Color(255, 0, 0);
}
}
std::ofstream f;
f.open("../out.ppm");
f << img.to_PPM();
f.close();
auto sph = raytracer::Sphere(0.10, raytracer::Point3(-10, 0, 0));
auto p = sph.find_intersection(raytracer::Ray3(raytracer::Point3(0, 0, 0),
raytracer::Vector3(2, 0, 0)));
std::cout << '\n' << p;
}
else
{
using namespace raytracer;
auto scene = Scene();
// B L O B
// auto blob = Blob(1);
// blob.potential_points.emplace_back(1.75, 0.25, -0.25);
// blob.potential_points.emplace_back(1.75, 0.25, 0.25);
// blob.potential_points.emplace_back(0.75, 0, 0.25);
// blob.potential_points.emplace_back(0.75, 0, -0.25);
//
// auto triangles = blob.marchingCubes();
// std::cout << triangles.size();
// for (auto tri : triangles)
// {
// scene.objects.push_back(tri);
// }
// Bezier
auto p0 = Point3(0.75, -0.1, 0);
auto p1 = Point3(0.75, 0.25, 0.02);
//
// auto bezier = Bezier(p0, p1, Point3(0.75, 0.0833, 0),
// Point3(0.75, 0.0833 * 2, 0.0));
auto grassb = GrassBlade(p0, 0.35, 0.1, 0.35 / 16, Vector3(1, 0, 0));
auto grass = Grass(Point3(0.75, -0.099, -0.5),
Point3(1.5, -0.099, 0.75),
2);
// auto triangles = grass.generate();
auto trtri = grassb.generate_triangles();
for (int i = -4; i < 6; i++)
{
for (int j = -10; j < 10; j++)
{
int r = rand();
auto grassg = GrassBlade(p0 + Point3(i * (0.055 + (r % 400 / 40000.0)), 0, j * (0.04 + (r % 400 / 40000.0))), 0.051 + (r % 400 / 40000.0), -0.01 + (r % 400 / 40000.0), 0.10 / 16,
Vector3(1, 0, (r % 600) / 600.0));
auto trtr = grassg.generate_triangles();
scene.add_to_objects(std::vector<Object*>(trtr.begin(),trtr.end()));
}
}
// scene.add_to_objects(std::vector<Object*>(triangles.begin(),triangles.end()));
// scene.add_to_objects(std::vector<Object*>(trtri.begin(),trtri.end()));
std::cout << "nb_triangles = " << scene.objects.size();
scene.objects.push_back(new Sphere(0.01, Point3(1.5, 0, -0.25)));
scene.objects.push_back(new Sphere(0.01, Point3(1.5, 0, 0.25)));
scene.objects.push_back(new Sphere(0.01, Point3(1.5, 0.5, -0.25)));
scene.objects.push_back(new Sphere(0.01, Point3(1.5, 0.5, 0.25)));
scene.objects.push_back(new Sphere(0.01, Point3(2, 0, -0.25)));
scene.objects.push_back(new Sphere(0.01, Point3(2, 0, 0.25)));
scene.objects.push_back(new Sphere(0.01, Point3(2, 0.5, -0.25)));
scene.objects.push_back(new Sphere(0.01, Point3(2, 0.5, 0.25)));
scene.camera = Camera();
// scene.objects.emplace_back(new Sphere(0.1, Point3(1, 0, 0),
// Color(0, 0, 255)));
// scene.objects.emplace_back(new Sphere(0.1, Point3(1, 0, -0.3), Color(255, 0, 0)));
// scene.objects.emplace_back(new Sphere(0.1, Point3(1, 0, 0.3), Color(0, 255, 100)));
// scene.objects.emplace_back(new Triangle(Point3(1, -0.1, -0.1), Point3(1.2, 0.1, 0), Point3(1, -0.1, 0.1)));
scene.objects.emplace_back(new Plane(Vector3(0, 1, 0), Point3(0, -0.10, 0)));
// scene.objects.emplace_back(new Plane(Vector3(1, 0, 0), Point3(7, 0, 0)));
// scene.lights.emplace_back(new PointLight(0.5, Point3(0, 3, -2)));
scene.lights.emplace_back(new PointLight(0.5, Point3(0, 1, -1)));
// scene.lights.emplace_back(new PointLight(1, Point3(1, 1, 1)));
scene.lights.emplace_back(new PointLight(0.2, Point3(0, 1, 2)));
// scene.lights.emplace_back(new PointLight(0.5, Point3(1, 0, 0.15)));
int nb_cols = 1280;
int nb_rows = 720;
auto im = scene.generate_image(nb_cols, nb_rows);
// std::cout << "up= " << scene.camera.up << "\n up.norm() = " << scene.camera.up.norm();
// std::cout << "\nImg_height = " <<img_height << "\nImg_width = " << img_width;
// std::cout << "\ny_a = " << y_a_scaled << "\nx_a = " << x_a_scaled;
// std::cout << "\np = " << p << "\n p.norm() = " << p.norm();
//
// std::cout << "\ntopleft = " << top_left;
// std::cout << "\nbottomright = " << top_left - (x_a_scaled * nb_cols).to_point()
// - (y_a_scaled * nb_rows).to_point();
std::ofstream f;
f.open("../out.ppm");
f << im.to_PPM();
f.close();
}
return 0;
}