-
Notifications
You must be signed in to change notification settings - Fork 1
/
buffer.hpp
64 lines (51 loc) · 1.24 KB
/
buffer.hpp
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
#ifndef BUFFER_H
#define BUFFER_H
#include "main.hpp"
#include <cstring>
class Buffer
{
public:
Buffer();
~Buffer();
float z_buff(int i, int j);
float f_buff(int i, int j);
void update(int i, int j, unsigned char new_f, float new_z);
void svimg(const char *f_name);
private:
unsigned char FB[HEIGHT][WIDTH];
float ZB[HEIGHT][WIDTH];
};
Buffer::Buffer() {
for (int j = 0; j < HEIGHT; ++j) {
for (int i = 0; i < WIDTH; ++i) {
this->FB[j][i] = 0x8F;
this->ZB[j][i] = -1000.0;
}
}
}
Buffer::~Buffer() { }
float Buffer::z_buff(int i, int j) {
return this->ZB[j][i];
}
float Buffer::f_buff(int i, int j) {
return this->FB[j][i];
}
void Buffer::update(int i, int j, unsigned char new_f, float new_z) {
this->FB[j][i] = new_f;
this->ZB[j][i] = new_z;
}
void Buffer::svimg(const char *f_name) {
FILE *f = fopen(f_name, "wb");
fprintf(f, "P5\n%i %i 255\n", WIDTH, HEIGHT);
for (int jj = 0; jj < HEIGHT; jj++)
for (int ii = 0; ii < WIDTH; ii++)
fputc(this->FB[jj][ii], f);
fclose(f);
char cmd[100] = {0};
strcat(cmd, "convert ");
strcat(cmd, f_name);
strcat(cmd, " ");
strcat(cmd, f_name);
system(cmd);
}
#endif