-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.h
74 lines (57 loc) · 1.84 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
#ifndef SCENE_HEADER
#define SCENE_HEADER
#include <string>
#include <vector>
#include "util.h"
#include "camera.h"
#include "surface.h"
#include "shader.h"
#include "lightSource.h"
class Scene
{
public:
Scene(); // by default uses a parallel orthographic camera
Scene(std::unique_ptr<Camera> camera);
void setCamera(std::unique_ptr<Camera>);
void setSurface(std::shared_ptr<Surface>);
void addLightSource(std::unique_ptr<LightSource> lightSource);
virtual void render() = 0;
virtual std::string computePixelArray() const = 0;
void exportToFile(std::string filename) const;
protected:
std::shared_ptr<Surface> surface;
std::unique_ptr<Camera> camera;
std::vector<std::unique_ptr<LightSource>> lightSources;
};
class GrayscaleScene : public Scene
{
public:
static uint8_t colorToGrayscale(Util::Color color);
GrayscaleScene();
GrayscaleScene(std::unique_ptr<Camera> camera);
void initializeBitmap();
void setCamera(std::unique_ptr<Camera> camera);
void setBackgroundColor(uint8_t backgroundColor);
void render(); // updates the bitmap. note bitmap(0,0) is at the bottom left of the frame
std::string computePixelArray() const;
private:
std::vector<std::vector<uint8_t>> bitmap;
uint8_t backgroundColor = 0;
uint8_t computeValueAtPixelIndex(int pixelIndexX, int pixelIndexY) const;
};
class RGBScene : public Scene
{
public:
RGBScene();
RGBScene(std::unique_ptr<Camera> camera);
void initializeBitmap();
void setCamera(std::unique_ptr<Camera> camera);
void setBackgroundColor(Util::Color backgroundColor);
void render();
std::string computePixelArray() const;
private:
std::vector<std::vector<Util::Color>> bitmap;
Util::Color backgroundColor = { 0, 0, 0 };
Util::Color computeValueAtPixelIndex(int pixelIndexX, int pixelIndexY) const;
};
#endif