-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vertex.h
59 lines (48 loc) · 1.23 KB
/
Vertex.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
59
#ifndef _VERTEX_H_
#define _VERTEX_H_
#include <glm.hpp>
#include "Tools.h"
namespace EvoLisa {
using glm::vec3;
class Vertex {
public:
vec3 pos;
Vertex () {
pos.x = Tools::GenerateRandFloat (-1.0f, 1.0f);
pos.y = Tools::GenerateRandFloat (-1.0f, 1.0f);
pos.z = 0.0f;
}
Vertex (const Vertex *v) {
this->pos = v->pos;
}
~Vertex () {}
void Perturbation () {
float dx, dy;
if (Tools::GenerateRandFloat (0.0, 1.0) < Tools::VertPertrProb) {
dx = Tools::GenerateRandFloat (-0.02f, 0.02f);
pos.x += dx;
if (!Tools::InRange (pos.x, -1.0, 1.0))
pos.x = Tools::GenerateRandFloat (-1.0, 1.0);
}
if (Tools::GenerateRandFloat (0.0, 1.0) < Tools::VertPertrProb) {
dy = Tools::GenerateRandFloat (-0.02f, 0.02f);
pos.y += dy;
if (!Tools::InRange (pos.y, -1.0, 1.0))
pos.y = Tools::GenerateRandFloat (-1.0, 1.0);
}
}
void NewVertex () {
if (Tools::GenerateRandFloat (0.0, 1.0) < Tools::VertRandProb)
pos.x = Tools::GenerateRandFloat (-1.0, 1.0);
if (Tools::GenerateRandFloat (0.0, 1.0) < Tools::VertRandProb)
pos.y = Tools::GenerateRandFloat (-1.0, 1.0);
}
void Mutate (bool random) {
if (!random) {
Perturbation ();
}
else NewVertex ();
}
};
}
#endif;