-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.cpp
61 lines (48 loc) · 1.66 KB
/
Map.cpp
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
#include "Map.h"
#include "Perlin.h"
#include <iostream>
float Map::windX = 0.0f, Map::windZ = 0.025f;
Map::Map(std::default_random_engine * generator) {
entities = new std::vector<Entity *>();
qobj = gluNewQuadric();
Entity * e;
width = 310.f;
height = 310.f;
e = new Floor(-2.f, 0.f, -150.f, width, height);
entities->push_back(e);
unsigned int seed = rand() % 256;
Perlin perlin(seed);
double px, py, n;
double pz = (float)(rand() % 1000) / 1000.f;
for (int x = -15; x < 15; x++) {
for (int z = 0; z < 30; z++) {
px = (double)(x*10.f) / ((double)width);
py = (double)(z*10.f) / ((double)height);
n = 13 * perlin.noise(px, py, pz);
n = n - floor(n);
if (n >= 0.55) {
float hi = (float)(10 * x) + 5.f;
float lo = (float)(10 * x) - 4.5f;
float genX = lo + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (hi - lo)));
hi = (float)(10 * z) + 5.f;
lo = (float)(10 * z) - 4.5f;
float genZ = lo + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / (hi - lo)));
e = new BambooStick(qobj, generator, genX, -0.3f, -genZ);
}
entities->push_back(e);
}
}
}
Map::~Map() {
}
void Map::updateWind() {
if (abs(Map::windX) < FLT_EPSILON)
Map::windX = 0.025f;
else
Map::windX = 0.f;
std::cout << "x: " << Map::windX << " z: " << Map::windZ << std::endl;
}
void Map::render() {
for (int i = 0; i < entities->size(); i++)
(*entities)[i]->render();
}