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 | class CloudEffect : public WeatherEffect |
---|
34 | { |
---|
35 | public: |
---|
36 | CloudEffect(const TiXmlElement* root = NULL); |
---|
37 | virtual ~CloudEffect(); |
---|
38 | |
---|
39 | virtual void loadParams(const TiXmlElement* root); |
---|
40 | |
---|
41 | virtual void init(); |
---|
42 | |
---|
43 | virtual void activate(); |
---|
44 | virtual void deactivate(); |
---|
45 | |
---|
46 | inline void activateCloud() |
---|
47 | { |
---|
48 | this->activate(); |
---|
49 | } |
---|
50 | inline void deactivateCloud() |
---|
51 | { |
---|
52 | this->deactivate(); |
---|
53 | } |
---|
54 | |
---|
55 | virtual void draw() const; |
---|
56 | virtual void tick(float dt); |
---|
57 | |
---|
58 | void make3DNoiseTexture(); |
---|
59 | void initNoise(); |
---|
60 | void SetNoiseFrequency(int frequency); |
---|
61 | double noise3(double vec[3]); |
---|
62 | void normalize2(double v[2]); |
---|
63 | void normalize3(double v[3]); |
---|
64 | |
---|
65 | /*inline void setCloudOption(const std::string& option) { |
---|
66 | if (option == "activate") |
---|
67 | this->cloudActivate = true; |
---|
68 | }*/ |
---|
69 | |
---|
70 | |
---|
71 | private: |
---|
72 | //void initialize(char* fileName); |
---|
73 | |
---|
74 | //bool cloudActivate; |
---|
75 | |
---|
76 | // Material cloudMaterial; |
---|
77 | Shader* shader; |
---|
78 | Shader::Uniform* offset; |
---|
79 | |
---|
80 | float coor; |
---|
81 | |
---|
82 | int noise3DTexSize; |
---|
83 | GLuint noise3DTexName; |
---|
84 | GLubyte *noise3DTexPtr; |
---|
85 | |
---|
86 | int p[MAXB + MAXB + 2]; |
---|
87 | double g3[MAXB + MAXB + 2][3]; |
---|
88 | double g2[MAXB + MAXB + 2][2]; |
---|
89 | double g1[MAXB + MAXB + 2]; |
---|
90 | |
---|
91 | int start; |
---|
92 | int B; |
---|
93 | int BM; |
---|
94 | }; |
---|
95 | |
---|
96 | #endif /* _CLOUD_EFFECT */ |
---|