-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrame.cpp
More file actions
77 lines (69 loc) · 1.93 KB
/
Copy pathFrame.cpp
File metadata and controls
77 lines (69 loc) · 1.93 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
#include "Frame.h"
// Empty constructor
Frame::Frame()
{
// Inialize to a default resolution of 1280x720
width = 1280;
height = 720;
// Push back black pixels till the frame is generated
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
pixelData.push_back(glm::vec3(0,0,0));
}
}
}
// Constructor that takes resoluiton as parameter
Frame::Frame(int _width, int _height)
{
// Take resoluiton parameters and set respective values
width = _width;
height = _height;
// Push back black pixels till the frame is generated
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
pixelData.push_back(glm::vec3(0, 0, 0));
}
}
}
// Wipes the frame of all data, reseting all pixels to black
void Frame::purge()
{
// Loop through all pixels and reset to black
for (int i = 0; i < pixelData.size(); i++)
{
pixelData.at(i) = glm::vec3(0, 0, 0);
}
}
// Writes data to the frame given 2 interger coordinate values and vec3 colour value
void Frame::writeData(int _x, int _y, glm::vec3 _colour)
{
// Cast x and y coordinates to 1 dimentional array location
int index = _x + (_y * width);
// Set pixel data at coordinate to _colour parameter
pixelData.at(index) = _colour;
}
// Writes data to the frame given a ivec2 coordinate value and vec3 colour value
void Frame::writeData(glm::ivec2 _coord, glm::vec3 _colour)
{
// Cast x and y coordinates to 1 dimentional array location
int index = _coord.x + (_coord.y * width);
// Set pixel data at coordinate to _colour parameter
pixelData.at(index) = _colour;
}
// Reads data from the frame given x and y coordinate values and returns a vec3 colour value
glm::vec3 Frame::readData(int _x, int _y)
{
// Cast x and y coordinates to 1 dimentional array location
int index = _x + (_y * width);
// Return pixle data at coordinate
return pixelData.at(index);
}
// Return the resolution of the frame
glm::ivec2 Frame::getResolution()
{
return glm::ivec2(width, height);
}