-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (62 loc) · 2.51 KB
/
main.cpp
File metadata and controls
71 lines (62 loc) · 2.51 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
/**
* \author Marie DARRIGOL & Anthony LEONARD & Ophélie PELLOUX-PRAYER & Olivier SOLDANO
* \project Ray-Tracing
* \file main.h
* \brief main function and rendering loop.
*/
#include <Windows.h>
#include "RenderWindow.h"
#include "Camera.h"
#include "Sphere.h"
#include "Planar.h"
#include "collision.h"
#include "Ray.h"
#include <thread>
#include "Color.h"
#include "Octree.h"
#include <omp.h>
#include "Box.h"
/*
* Main rendering loop. It renders a scene on a window according to a
* specified camera.
*/
void renderingLoop(RenderWindow* window, Camera* cam, Scene & scene) {
Color tmp_color;
Octree octree = Octree(scene.getSceneObjects());
#pragma omp parallel for private(tmp_color)
for (int x = 0; x < 1024; x++) {
for (int y = 0; y < 768; y++) {
Ray currRay(cam->getRay(x, y));
tmp_color = currRay.phong_shading(scene, octree);
int r = (int)(tmp_color.getX() * 255);
int g = (int)(tmp_color.getY() * 255);
int b = (int)(tmp_color.getZ() * 255);
window->setPixel(x, y, r, g, b);
}
}
}
/*
* main functions. It starts a window, construct a scene and start the rendering. It also manage
* the main message loop.
*/
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow) {
RenderWindow mainWindow(hInstance, nCmdShow);
Camera cam( Vec3(0.0f, 0.0f, 0.0f), Vec3(0.0f, 0.0f, 1.0f), 1024, 768);
Scene scene = Scene();
scene.getLights()->push_back(new Light(Vec3(-10.0f, 0.0f, 0.0f), 1.0f, 1.0f, 1.0f));
scene.getSceneObjects()->push_back(new Sphere(Vec3(-0.23f, 0.5f, 5.0f), 1.08f, Material(1.05f)));
scene.getSceneObjects()->push_back(new Sphere(Vec3(1.0f, 2.0f, 8.f), 1.0f, Material(0.2f, 1.0f, 1.0f, 1000.0f, Color(255, 0, 0))));
scene.getSceneObjects()->push_back(new Sphere(Vec3(-2.0f, 1.5f, 7.0f), 1.0f, Material(0.2f, 1.0f, 1.0f, 1000.0f, Color(200, 50, 100))));
scene.getSceneObjects()->push_back(new Sphere(Vec3(-2.0f, -1.5f, 7.0f), 1.0f, Material(0.2f, 1.0f, 1.0f, 1000.0f, Color(0, 200, 200))));
Material mWall = Material(1.0f, 1.0f, 1.0f, 1.0f, Color(120, 40, 10), "Maps/wall_HD_1_bump.ppm");
scene.getSceneObjects()->push_back(new Planar(Vec3(2.0f, 1.0f, 10.0f), Vec3(6.0f, 0.0f, -3.0f), Vec3(0.0f, 6.0f, 0.0f), mWall));
scene.getSceneObjects()->push_back(new Planar(Vec3(-6.0f, 1.0f, 10.0f), Vec3(6.0f, 0.0f, 3.0f), Vec3(0.0f, 6.0f, 0.0f), mWall));
thread renderThread(renderingLoop, &mainWindow, &cam, scene);
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
renderThread.join();
return msg.wParam;
}