-
Notifications
You must be signed in to change notification settings - Fork 0
/
Engine.hpp
197 lines (181 loc) · 5.76 KB
/
Engine.hpp
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#ifndef __ENGINE_H_INCLUDED__
#define __ENGINE_H_INCLUDED__
#include <string>
#include <functional> // aby fungoval bind
#include <random> // Generatory
#include <thread> // Multithreading
#include <vector> // Dynamicke containery
#include <exception>
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
//#include <d3d11.h>
#include "SWU/Okno.hpp"
#include "SWU/Konzole.hpp"
#include "Kontroler3d.hpp"
#include "CustomVertex.hpp"
#include "JednoduchyVertex.hpp"
#include "TreeType.hpp"
#include "Helper.hpp"
#include "Tree.hpp"
#include "Tree3.hpp"
#include "Usecka.hpp"
#include "Svetlo.hpp"
#include "globals.hpp"
namespace se
{
class EngineVyjimka: public std::exception
{
public:
EngineVyjimka(const char* say) : zpravicka {say} {}
virtual const char* what() const throw()
{
return zpravicka;
}
private:
const char* zpravicka;
} ;
class Engine;
using UkazatelNaFunkciEnginu = void (se::Engine::*)(float);
using MapaFunkciEnginu = std::map<std::string, UkazatelNaFunkciEnginu>;
class Engine
{
public:
std::string prikaz; // pouzivam k precteni zpravy (WM_QUIT, etc.)
Engine(sw::Okno*);
~Engine();
void releaseD3d();
void priprav();
void prectiVstupAUpravKameru() {
prectiVstupAUpravKameru(arg);
}
void prectiVstupAUpravKameru(float&);
void render3d();
void dejKonzoli(const sk::Konzole& x){
iKonzole = x;
iKontroler3d.dejKonzoli(x);
}
private:
sw::Okno* iOkno;
sktrl::Kontroler3d iKontroler3d;
sk::Konzole iKonzole; // abych mohl konzoli pouzivat vsude, to nejde
LPDIRECT3D9 g_pD3D; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 pd3dZarizeni; // Our rendering device, lp= neco pointer, je to jenom typedef typedef struct IDirect3DDevice9 *LPDIRECT3DDEVICE9;
bool bbClearColor = true;
bool bwireframe = false;
bool bosvetlovat = true;
bool bcull = true;
bool bflatShading = false;
float fFOV;
D3DXMATRIX maticeProjekce;
MapaFunkciEnginu mapaFci;
std::vector<t::Tree> stromy;
std::vector<t3::Tree3> stromy3D;
std::vector<se::Usecka> usecky;
std::vector<se::Svetlo> svetla;
float fDalka; //0
void pripravView();
void pripravGeometrii();
float arg;
UkazatelNaFunkciEnginu najdiFunkci(const std::string&);
void zavolejFunkci(se::UkazatelNaFunkciEnginu, float arg);
void selfTest(float arg){
if(arg <= 0.) arg = 1; // chybi argument
for(int k = 0; k < (int)arg; ++k)
for(auto i = mapaFci.begin(); i!=mapaFci.end(); ++i)
{
if(i->first == "testy")
continue;
iKonzole.nastavBarvuPisma(sk::fmodra);
std::cout << "Volam: "<< i->first << std::endl;
zavolejFunkci(i->second, arg);
}
nastavRychlost(50000.);
iKonzole.nastavBarvuPisma(sk::ftmavezelena);
std::cout << "All passed" << std::endl;
iOkno->nastavDoPopredi();
}
void reset(float){
iKonzole.nastavBarvuPisma(sk::Barva::fzluta);
pripravView();
pripravGeometrii();
nastavRychlost(50000.);
fFOV = PI/3.6;
dejCitlivost(3);
}
void generujJedenStrom(float);
void dejFov(float fov){
fFOV = PI/fov;
}
void pridejStrom(float);
void regenerujStromy(float);
void odeberStromy(float);
void odeberStrom(float);
void nastavRychlost(float rychlost){
iKontroler3d.nastavRychlost(rychlost);
}
void dejCitlivost(float citlivost){
iKontroler3d.nastavCitlivost(citlivost);
}
void setRenderElement(float elem){
for (auto i = stromy.begin(); i!=stromy.end(); ++i)
{
if(elem==0.)
i->nastavVykreslovaciElement(t::Element::bod);
if(elem==1. && ( (i->vemDruhStromu()).element == t::Element::bod || (i->vemDruhStromu()).element == t::Element::testValec) )
i->nastavVykreslovaciElement(t::Element::usecka);
if(elem==2. && (i->vemDruhStromu()).element == t::Element::usecka)
i->nastavVykreslovaciElement(t::Element::testValec);
}
for (auto i = stromy3D.begin(); i!=stromy3D.end(); ++i)
{
if(elem==0.)
i->nastavVykreslovaciElement(t::Element::bod);
if(elem==1. && ( (i->vemDruhStromu()).element == t::Element::bod || (i->vemDruhStromu()).element == t::Element::testValec) )
i->nastavVykreslovaciElement(t::Element::usecka);
if(elem==2.)
i->nastavVykreslovaciElement(t::Element::testValec);
}
}
void switchClearColor(float){
bbClearColor = !bbClearColor;
}
void switchCulling(float){
bcull = !bcull;
if(bcull)
pd3dZarizeni->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
else
pd3dZarizeni->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
}
void switchWireframe(float){
bwireframe = !bwireframe;
if (bwireframe)
pd3dZarizeni->SetRenderState( D3DRS_FILLMODE , D3DFILL_WIREFRAME );
else
pd3dZarizeni->SetRenderState( D3DRS_FILLMODE , D3DFILL_SOLID );
}
void switchOsvetlovat(float){
bosvetlovat = !bosvetlovat;
}
void switchShading(float){
bflatShading = !bflatShading;
if(bflatShading)
pd3dZarizeni->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_FLAT );
else
pd3dZarizeni->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
}
void nerotuj(float){
for (auto& iTree : stromy)
iTree.nastavRotaci(0.);
for (auto& iTree : stromy3D)
iTree.nastavRotaci(0.);
}
void zhasniSvitilnu(float){
(--svetla.end())->zhasni();
}
void rozzniSvitilnu(float){
(--svetla.end())->rozsvit();
}
};
}
#endif // __ENGINE_H_INCLUDED__