1 | /** |
---|
2 | * @file cloud_effect.h |
---|
3 | */ |
---|
4 | |
---|
5 | #ifndef _CLOUD_EFFECT |
---|
6 | #define _CLOUD_EFFECT |
---|
7 | |
---|
8 | #include "weather_effect.h" |
---|
9 | |
---|
10 | #include "sound_buffer.h" |
---|
11 | #include "sound_source.h" |
---|
12 | |
---|
13 | #include "world_entity.h" |
---|
14 | #include "material.h" |
---|
15 | #include "shader.h" |
---|
16 | |
---|
17 | #define MAXB 0x100 |
---|
18 | #define N 0x1000 |
---|
19 | #define NP 12 /* 2^N */ |
---|
20 | #define NM 0xfff |
---|
21 | |
---|
22 | #define s_curve(t) ( t * t * (3. - 2. * t) ) |
---|
23 | #define lerp(t, a, b) ( a + t * (b - a) ) |
---|
24 | #define setup(i,b0,b1,r0,r1)\ |
---|
25 | t = vec[i] + N;\ |
---|
26 | b0 = ((int)t) & BM;\ |
---|
27 | b1 = (b0+1) & BM;\ |
---|
28 | r0 = t - (int)t;\ |
---|
29 | r1 = r0 - 1.; |
---|
30 | #define at2(rx,ry) ( rx * q[0] + ry * q[1] ) |
---|
31 | #define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] ) |
---|
32 | |
---|
33 | |
---|
34 | #define DTOR (PI/180.0f) |
---|
35 | #define SQR(x) (x*x) |
---|
36 | |
---|
37 | typedef struct { |
---|
38 | float x,y,z; |
---|
39 | unsigned int color; |
---|
40 | float u, v; |
---|
41 | } VERTEX; |
---|
42 | |
---|
43 | |
---|
44 | class CloudEffect : public WeatherEffect |
---|
45 | { |
---|
46 | public: |
---|
47 | CloudEffect(const TiXmlElement* root = NULL); |
---|
48 | virtual ~CloudEffect(); |
---|
49 | |
---|
50 | virtual void loadParams(const TiXmlElement* root); |
---|
51 | |
---|
52 | virtual void init(); |
---|
53 | |
---|
54 | virtual void activate(); |
---|
55 | virtual void deactivate(); |
---|
56 | |
---|
57 | inline void activateCloud() |
---|
58 | { this->activate(); } |
---|
59 | |
---|
60 | inline void deactivateCloud() |
---|
61 | { this->deactivate(); } |
---|
62 | |
---|
63 | inline void setCloudOption(const std::string& option) |
---|
64 | { |
---|
65 | if (option == "activate") |
---|
66 | this->cloudActivate = true; |
---|
67 | } |
---|
68 | |
---|
69 | inline void setAnimationSpeed(float speed) |
---|
70 | { this->animationSpeed = speed; } |
---|
71 | |
---|
72 | inline void setLightPosition(float x, float y, float z) |
---|
73 | { this->lightPos = Vector(x,y,z); } |
---|
74 | |
---|
75 | inline void setCloudScale(float scale) |
---|
76 | { this->scale = scale; } |
---|
77 | |
---|
78 | inline void setPlanetRadius(float planetRadius) |
---|
79 | { this->planetRadius = planetRadius; } |
---|
80 | |
---|
81 | inline void setAtmosphericRadius(float atmosphericRadius) |
---|
82 | { this->atmosphericRadius = atmosphericRadius; } |
---|
83 | |
---|
84 | inline void setDivisions(int divs) |
---|
85 | { this->divs = divs; } |
---|
86 | |
---|
87 | virtual void draw() const; |
---|
88 | virtual void tick(float dt); |
---|
89 | |
---|
90 | void make3DNoiseTexture(); |
---|
91 | void initNoise(); |
---|
92 | void SetNoiseFrequency(int frequency); |
---|
93 | double noise3(double vec[3]); |
---|
94 | void normalize2(double v[2]); |
---|
95 | void normalize3(double v[3]); |
---|
96 | |
---|
97 | void generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius, |
---|
98 | float hTile, float vTile); |
---|
99 | private: |
---|
100 | |
---|
101 | bool cloudActivate; |
---|
102 | float animationSpeed; |
---|
103 | |
---|
104 | // Material cloudMaterial; |
---|
105 | |
---|
106 | // SHADER STUFF |
---|
107 | Shader* shader; |
---|
108 | Shader::Uniform* offset; |
---|
109 | float offsetZ; |
---|
110 | Vector lightPos; |
---|
111 | float scale; |
---|
112 | float planetRadius; |
---|
113 | float atmosphericRadius; |
---|
114 | int divs; |
---|
115 | |
---|
116 | // NOISE STUFF |
---|
117 | int noise3DTexSize; |
---|
118 | GLuint noise3DTexName; |
---|
119 | GLubyte *noise3DTexPtr; |
---|
120 | |
---|
121 | int p[MAXB + MAXB + 2]; |
---|
122 | double g3[MAXB + MAXB + 2][3]; |
---|
123 | double g2[MAXB + MAXB + 2][2]; |
---|
124 | double g1[MAXB + MAXB + 2]; |
---|
125 | |
---|
126 | int start; |
---|
127 | int B; |
---|
128 | int BM; |
---|
129 | |
---|
130 | // SKYPLANE STUFF |
---|
131 | VERTEX *planeVertices; |
---|
132 | int numPlaneVertices; |
---|
133 | |
---|
134 | int *indices; |
---|
135 | int numIndices; |
---|
136 | |
---|
137 | float pRadius; |
---|
138 | |
---|
139 | VERTEX *vertices; |
---|
140 | int numVertices; |
---|
141 | }; |
---|
142 | |
---|
143 | #endif /* _CLOUD_EFFECT */ |
---|