forked from yvt/terravox
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathterrain.h
More file actions
58 lines (48 loc) · 1.28 KB
/
terrain.h
File metadata and controls
58 lines (48 loc) · 1.28 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
#ifndef TERRAIN_H
#define TERRAIN_H
#include <QSize>
#include <QVector>
#include <QPoint>
#include <QRect>
#include <cmath>
#include <array>
class Terrain final
{
public:
Terrain(const QSize &size);
~Terrain();
const QSize &size() const { return size_; }
float *landformData() { return landform_.data(); }
quint32 *colorData() { return color_.data(); }
float &landform(int x, int y)
{
Q_ASSERT(x >= 0);
Q_ASSERT(y >= 0);
Q_ASSERT(x < size_.width());
Q_ASSERT(y < size_.height());
return landform_[x + y * size_.width()];
}
quint32 &color(int x, int y)
{
Q_ASSERT(x >= 0);
Q_ASSERT(y >= 0);
Q_ASSERT(x < size_.width());
Q_ASSERT(y < size_.height());
return color_[x + y * size_.width()];
}
void copyFrom(Terrain *, QPoint destination, QRect src = QRect());
void quantize();
static inline float quantizeOne(float f)
{
return std::max(std::min(std::round(f), 63.f), 0.f);
}
static std::array<int, 3> expandColor(quint32 col)
{
return std::array<int, 3> {{int(col & 255), int((col >> 8) & 255), int((col >> 16) & 255)}};
}
private:
QSize size_;
QVector<float> landform_;
QVector<quint32> color_;
};
#endif // TERRAIN_H