-
Notifications
You must be signed in to change notification settings - Fork 0
/
water.cpp
103 lines (85 loc) · 3.3 KB
/
water.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "water.hpp"
#include <GLFW/glfw3.h>
unsigned char Water::_frame = 0;
Water::Water(unsigned char visibility):
Cube(visibility)
{
}
void Water::inc()
{
static double time = glfwGetTime();
if (glfwGetTime() - time > 1.0f/30.0f)
{
_frame = (_frame + 1) % 64;
time = glfwGetTime();
}
}
void Water::display()
{
if (_visibility & FRONT)
{
//face avant
_renderer->setNormal(_normals);
_renderer->addVertexUV(_points, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 3, 1.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 6, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 6, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 9, 0.0f, (15 + 16*_frame) / 1024.0f);
}
if (_visibility & RIGHT)
{
//face droite
_renderer->setNormal(_normals + 3);
_renderer->addVertexUV(_points + 9, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 6, 1.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 18, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 9, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 18, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 21, 0.0f, (15 + 16*_frame) / 1024.0f);
}
if (_visibility & BACK)
{
//face arriere
_renderer->setNormal(_normals + 6);
_renderer->addVertexUV(_points + 21, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 18, 1.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 15, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 21, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 15, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 12, 0.0f, (15 + 16*_frame) / 1024.0f);
}
if (_visibility & LEFT)
{
//face gauche
_renderer->setNormal(_normals + 9);
_renderer->addVertexUV(_points + 12, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 15, 1.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 3, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 12, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 3, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points, 0.0f, (15 + 16*_frame) / 1024.0f);
}
if (_visibility & TOP)
{
//face haute
_renderer->setNormal(_normals + 12);
_renderer->addVertexUV(_points, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 9, 1.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 21, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 21, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 12, 0.0f, (15 + 16*_frame) / 1024.0f);
}
if (_visibility & BOT)
{
//face basse
_renderer->setNormal(_normals + 15);
_renderer->addVertexUV(_points + 3, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 15, 1.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 18, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 3, 0.0f, (16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 18, 1.0f, (15 + 16*_frame) / 1024.0f);
_renderer->addVertexUV(_points + 6, 0.0f, (15 + 16*_frame) / 1024.0f);
}
}