Changeset 8668 in orxonox.OLD for branches/atmospheric_engine
- Timestamp:
- Jun 21, 2006, 1:56:41 PM (19 years ago)
- Location:
- branches/atmospheric_engine/src/lib/graphics/effects
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc
r8663 r8668 53 53 { 54 54 this->deactivate(); 55 56 delete shader; 55 57 } 56 58 … … 62 64 this->offsetZ = 0; 63 65 this->animationSpeed = 2; 64 65 noise3DTexSize = 64; 66 this->lightPos = Vector(0,0,0); 67 this->scale = 0.01f; 68 this->atmosphericRadius = 120; 69 this->planetRadius = 90; 70 this->divs = 100; 71 72 noise3DTexSize = 128; 66 73 noise3DTexName = 0; 67 74 … … 89 96 Shader::Uniform(shader, "SkyColor").set(0.0f, 0.0f, 0.8f); 90 97 Shader::Uniform(shader, "CloudColor").set(0.8f, 0.8f, 0.8f); 91 Shader::Uniform(shader, "LightPos").set(5.0f, 0.0f, 5.0f);92 Shader::Uniform(shader, "Scale").set(0.1f);93 98 94 99 offset = new Shader::Uniform(shader, "Offset"); … … 103 108 104 109 LoadParam(root, "speed", this, CloudEffect, setAnimationSpeed); 110 LoadParam(root, "lightPos", this, CloudEffect, setLightPosition); 111 LoadParam(root, "scale", this, CloudEffect, setCloudScale); 112 113 LoadParam(root, "planetRadius", this, CloudEffect, setPlanetRadius); 114 LoadParam(root, "atmosphericRadius", this, CloudEffect, setAtmosphericRadius); 115 LoadParam(root, "divisions", this, CloudEffect, setDivisions); 105 116 106 117 LOAD_PARAM_START_CYCLE(root, element); … … 115 126 { 116 127 PRINTF(0)( "Activating\n"); 128 129 // Can only be set after the loadParams call 130 this->shader->activateShader(); 131 Shader::Uniform(shader, "Scale").set(this->scale); 132 Shader::Uniform(shader, "LightPos").set(lightPos.x, lightPos.y, lightPos.z); 133 this->shader->deactivateShader(); 134 135 this->generateSkyPlane(this->divs, this->planetRadius, this->atmosphericRadius, 1, 1); 117 136 118 137 this->cloudActivate = true; … … 139 158 glBindTexture(GL_TEXTURE_3D, noise3DTexName); 140 159 141 glPushMatrix();160 //glPushMatrix(); 142 161 143 162 this->shader->activateShader(); … … 145 164 146 165 147 glColor3f(1.0, 1.0, 1.0);166 /*glColor3f(1.0, 1.0, 1.0); 148 167 glBegin(GL_QUADS); 149 168 … … 153 172 glTexCoord2f(1.0f, 0.0f); glVertex3f(10.0f, 0.0f, 0.0f); 154 173 174 glEnd();*/ 175 176 glPushMatrix(); 177 glTranslatef(0.0f,pRadius,0.0f); 178 //glRotatef(timeGetTime()/2000.0f,0.0f, 1.0f, 0.0f); 179 //glTranslatef(0.0f,0.0f,0.0f); 180 181 glBegin(GL_TRIANGLES); 182 183 for (int i=0; i < numIndices; i++) 184 { 185 glColor3f(1.0f, 1.0f, 1.0f); 186 187 glTexCoord2f(planeVertices[indices[i]].u, planeVertices[indices[i]].v); 188 glVertex3f(planeVertices[indices[i]].x, planeVertices[indices[i]].y, planeVertices[indices[i]].z); 189 } 190 155 191 glEnd(); 156 192 193 glPopMatrix(); 194 157 195 this->shader->deactivateShader(); 158 196 159 glPopMatrix();197 //glPopMatrix(); 160 198 glPopAttrib(); 161 199 … … 167 205 return; 168 206 this->offsetZ += 0.05 * dt * this->animationSpeed; 207 } 208 209 void CloudEffect::generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius, float hTile, float vTile) 210 { 211 // Make sure our vertex array is clear 212 if (planeVertices) 213 { 214 delete planeVertices; 215 planeVertices = NULL; 216 } 217 218 // Make sure our index array is clear 219 if (indices) 220 { 221 delete indices; 222 indices = NULL; 223 } 224 225 // Set the number of divisions into a valid range 226 int divs = divisions; 227 if (divisions < 1) 228 divs = 1; 229 230 if (divisions > 256) 231 divs = 256; 232 233 pRadius = planetRadius; 234 235 // Initialize the Vertex and indices arrays 236 numPlaneVertices = (divs + 1) * (divs + 1); // 1 division would give 4 verts 237 numIndices = divs * divs * 2 * 3; // 1 division would give 6 indices for 2 tris 238 239 planeVertices = new VERTEX[numPlaneVertices]; 240 memset(planeVertices, 0, sizeof(VERTEX)); 241 242 indices = new int[numIndices]; 243 memset(indices, 0, sizeof(int)*numIndices); 244 245 // Calculate some values we will need 246 float plane_size = 2.0f * (float)sqrt((SQR(atmosphereRadius)-SQR(planetRadius))); 247 float delta = plane_size/(float)divs; 248 float tex_delta = 2.0f/(float)divs; 249 250 // Variables we'll use during the dome's generation 251 float x_dist = 0.0f; 252 float z_dist = 0.0f; 253 float x_height = 0.0f; 254 float z_height = 0.0f; 255 float height = 0.0f; 256 257 VERTEX SV; // temporary vertex 258 259 for (int i=0;i <= divs;i++) 260 { 261 for (int j=0; j <= divs; j++) 262 { 263 x_dist = (-0.5f * plane_size) + ((float)j*delta); 264 z_dist = (-0.5f * plane_size) + ((float)i*delta); 265 266 x_height = (x_dist*x_dist) / atmosphereRadius; 267 z_height = (z_dist*z_dist) / atmosphereRadius; 268 height = x_height + z_height; 269 270 SV.x = x_dist; 271 SV.y = 0.0f - height; 272 SV.z = z_dist; 273 274 // Calculate the texture coordinates 275 SV.u = hTile*((float)j * tex_delta*0.5f); 276 SV.v = vTile*(1.0f - (float)i * tex_delta*0.5f); 277 278 planeVertices[i*(divs+1)+j] = SV; 279 } 280 } 281 282 // Calculate the indices 283 int index = 0; 284 for (int i=0; i < divs;i++) 285 { 286 for (int j=0; j < divs; j++) 287 { 288 int startvert = (i*(divs+1) + j); 289 290 // tri 1 291 indices[index++] = startvert; 292 indices[index++] = startvert+1; 293 indices[index++] = startvert+divs+1; 294 295 // tri 2 296 indices[index++] = startvert+1; 297 indices[index++] = startvert+divs+2; 298 indices[index++] = startvert+divs+1; 299 } 300 } 169 301 } 170 302 -
branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h
r8663 r8668 31 31 #define at3(rx,ry,rz) ( rx * q[0] + ry * q[1] + rz * q[2] ) 32 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 33 44 class CloudEffect : public WeatherEffect 34 45 { … … 45 56 46 57 inline void activateCloud() 47 { 48 this->activate(); 49 } 58 { this->activate(); } 59 50 60 inline void deactivateCloud() 51 { 52 this->deactivate(); 53 } 61 { this->deactivate(); } 62 54 63 inline void setCloudOption(const std::string& option) 55 64 { … … 57 66 this->cloudActivate = true; 58 67 } 68 59 69 inline void setAnimationSpeed(float speed) 60 { 61 this->animationSpeed = speed; 62 } 70 { this->animationSpeed = speed; } 71 72 inline void setLightPosition(float x, float y, float z) 73 { this->lightPos = Vector(x,y,z); } 63 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 64 87 virtual void draw() const; 65 88 virtual void tick(float dt); … … 72 95 void normalize3(double v[3]); 73 96 97 void generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius, 98 float hTile, float vTile); 74 99 private: 75 100 76 bool cloudActivate;77 float animationSpeed;101 bool cloudActivate; 102 float animationSpeed; 78 103 79 104 // Material cloudMaterial; 80 Shader* shader; 81 Shader::Uniform* offset; 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; 82 115 83 float offsetZ; 116 // NOISE STUFF 117 int noise3DTexSize; 118 GLuint noise3DTexName; 119 GLubyte *noise3DTexPtr; 84 120 85 int noise3DTexSize; 86 GLuint noise3DTexName; 87 GLubyte *noise3DTexPtr; 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]; 88 125 89 int p[MAXB + MAXB + 2]; 90 double g3[MAXB + MAXB + 2][3]; 91 double g2[MAXB + MAXB + 2][2]; 92 double g1[MAXB + MAXB + 2]; 126 int start; 127 int B; 128 int BM; 129 130 // SKYPLANE STUFF 131 VERTEX *planeVertices; 132 int numPlaneVertices; 93 133 94 int start; 95 int B; 96 int BM; 134 int *indices; 135 int numIndices; 136 137 float pRadius; 138 139 VERTEX *vertices; 140 int numVertices; 97 141 }; 98 142
Note: See TracChangeset
for help on using the changeset viewer.