-
Notifications
You must be signed in to change notification settings - Fork 0
/
czbuffer.h
58 lines (46 loc) · 1.01 KB
/
czbuffer.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
#ifndef CZBUFFER_H
#define CZBUFFER_H
#include "cpuntofijo.h"
class CZBuffer
{
public:
CZBuffer () {zbuffer = 0;}
CZBuffer (int ancho, int alto)
{
width = ancho;
height = alto;
zbuffer = new CPuntoFijo[ancho * alto];
CalcularCentros();
}
~CZBuffer () {if (zbuffer) delete zbuffer;}
CPuntoFijo *zbuffer;
int width, height;
int centroX, centroY;
void CalcularCentros() {centroX = width / 2;centroY = height / 2;}
int CoorX(int x) {return (x + centroX);}
int CoorY(int y) {return (-y + centroY);}
CPuntoFijo *Z(int xm, int ym)
{
int x, y;
x = CoorX(xm);
y = CoorY(ym);
if ((x < 0) || (y < 0) || (x >= width) || (y >= height))
return 0;
return &(zbuffer[(width * y) + x]);
}
void CambiarTamano(int ancho, int alto)
{
if (zbuffer) delete zbuffer;
width = ancho;
height = alto;
zbuffer = new CPuntoFijo[width * height];
CalcularCentros();
Limpiar();
}
void Limpiar()
{
for (int i = 0; i < (width * height); i++)
zbuffer[i] = 10000000000000.0;
}
};
#endif