Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8730 in orxonox.OLD for branches/atmospheric_engine/src/lib/graphics


Ignore:
Timestamp:
Jun 22, 2006, 4:19:27 PM (18 years ago)
Author:
hdavid
Message:

branches/atmospheric_engine: created skydome.[h,cc]

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

    r8713 r8730  
    5454  this->deactivate();
    5555 
     56  if (glIsTexture(noise3DTexName))
     57    glDeleteTextures(1, &noise3DTexName);
     58 
    5659  delete shader;
    5760}
     
    8790               0, GL_RGBA, GL_UNSIGNED_BYTE, noise3DTexPtr);
    8891 
     92  skydome = new Skydome();
     93  skydome->setTexture(noise3DTexName);
     94 
    8995  shader = new Shader(ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.vert",
    9096                      ResourceManager::getInstance()->getDataDir() + "/shaders/cloud.frag");
     
    99105
    100106  this->shader->deactivateShader();
     107 
     108  skydome->setShader(shader);
    101109}
    102110
     
    130138  this->shader->deactivateShader();
    131139 
    132   this->generateSkyPlane(this->divs, this->planetRadius, this->atmosphericRadius, 1, 1);
     140  skydome->generateSkyPlane(this->divs, this->planetRadius, this->atmosphericRadius, 1, 1);
    133141
    134142  this->cloudActivate = true;
     
    144152void CloudEffect::draw() const
    145153{
    146   if (!this->cloudActivate)
    147     return;
    148 
    149   glPushAttrib(GL_ENABLE_BIT);
    150 
    151   glDisable(GL_LIGHTING);
    152   glDisable(GL_BLEND);
    153 
    154   glEnable(GL_TEXTURE_3D);
    155   glBindTexture(GL_TEXTURE_3D, noise3DTexName);
    156 
    157   this->shader->activateShader();
    158   offset->set(0.0f, 0.0f, offsetZ);
    159 
    160 
    161   /*glColor3f(1.0, 1.0, 1.0);
    162   glBegin(GL_QUADS);
    163 
    164   glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, 0.0f,  0.0f);
    165   glTexCoord2f(0.0f, 1.0f); glVertex3f( 0.0f, 10.0f,  0.0f);
    166   glTexCoord2f(0.0f, 0.0f); glVertex3f( 10.0f, 10.0f,  0.0f);
    167   glTexCoord2f(1.0f, 0.0f); glVertex3f(10.0f, 0.0f,  0.0f);
    168 
    169   glEnd();*/
    170 
    171   glPushMatrix();
    172   glTranslatef(0.0f,pRadius,0.0f);
    173   //glRotatef(timeGetTime()/2000.0f,0.0f, 1.0f, 0.0f);
    174 
    175   glBegin(GL_TRIANGLES);
    176 
    177   for (int i=0; i < numIndices; i++)
    178   {
    179     glColor3f(1.0f, 1.0f, 1.0f);
    180 
    181     glTexCoord2f(planeVertices[indices[i]].u, planeVertices[indices[i]].v);
    182     glVertex3f(planeVertices[indices[i]].x, planeVertices[indices[i]].y, planeVertices[indices[i]].z);
    183   }
    184 
    185   glEnd();
    186 
    187   glPopMatrix();
    188 
    189   this->shader->deactivateShader();
    190 
    191   glPopAttrib();
    192 
    193154}
    194155
     
    196157{
    197158  if (this->cloudActivate)
     159  {
    198160    this->offsetZ += 0.05 * dt * this->animationSpeed;
    199 }
    200 
    201 void CloudEffect::generateSkyPlane(int divisions, float planetRadius, float atmosphereRadius, float hTile, float vTile)
    202 {
    203   // Make sure our vertex array is clear
    204   if (planeVertices)
    205   {
    206     delete planeVertices;
    207     planeVertices = NULL;
    208   }
    209 
    210   // Make sure our index array is clear
    211   if (indices)
    212   {
    213     delete indices;
    214     indices = NULL;
    215   }
    216 
    217   // Set the number of divisions into a valid range
    218   int divs = divisions;
    219   if (divisions < 1)
    220     divs = 1;
    221 
    222   if (divisions > 256)
    223     divs = 256;
    224 
    225   pRadius = planetRadius;
    226 
    227   // Initialize the Vertex and indices arrays
    228   numPlaneVertices = (divs + 1) * (divs + 1);   // 1 division would give 4 verts
    229   numIndices  = divs * divs * 2 * 3;       // 1 division would give 6 indices for 2 tris
    230 
    231   planeVertices = new VERTEX[numPlaneVertices];
    232   memset(planeVertices, 0, sizeof(VERTEX));
    233 
    234   indices = new int[numIndices];
    235   memset(indices, 0, sizeof(int)*numIndices);
    236 
    237   // Calculate some values we will need
    238   float plane_size = 2.0f * (float)sqrt((SQR(atmosphereRadius)-SQR(planetRadius)));
    239   float delta = plane_size/(float)divs;
    240   float tex_delta = 2.0f/(float)divs;
    241  
    242   // Variables we'll use during the dome's generation
    243   float x_dist   = 0.0f;
    244   float z_dist   = 0.0f;
    245   float x_height = 0.0f;
    246   float z_height = 0.0f;
    247   float height = 0.0f;
    248 
    249   VERTEX SV; // temporary vertex
    250 
    251   for (int i=0;i <= divs;i++)
    252   {
    253     for (int j=0; j <= divs; j++)
    254     {
    255       x_dist = (-0.5f * plane_size) + ((float)j*delta);
    256       z_dist = (-0.5f * plane_size) + ((float)i*delta);
    257 
    258       x_height = (x_dist*x_dist) / atmosphereRadius;
    259       z_height = (z_dist*z_dist) / atmosphereRadius;
    260       height = x_height + z_height;
    261 
    262       SV.x = x_dist;
    263       SV.y = 0.0f - height;
    264       SV.z = z_dist;
    265 
    266       // Calculate the texture coordinates
    267       SV.u = hTile*((float)j * tex_delta*0.5f);
    268       SV.v = vTile*(1.0f - (float)i * tex_delta*0.5f);
    269 
    270       planeVertices[i*(divs+1)+j] = SV;
    271     }
    272   }
    273 
    274   // Calculate the indices
    275   int index = 0;
    276   for (int i=0; i < divs;i++)
    277   {
    278     for (int j=0; j < divs; j++)
    279     {
    280       int startvert = (i*(divs+1) + j);
    281 
    282         // tri 1
    283       indices[index++] = startvert;
    284       indices[index++] = startvert+1;
    285       indices[index++] = startvert+divs+1;
    286 
    287       // tri 2
    288       indices[index++] = startvert+1;
    289       indices[index++] = startvert+divs+2;
    290       indices[index++] = startvert+divs+1;
    291     }
    292   } 
    293 }
     161   
     162    this->shader->activateShader();
     163    offset->set(0.0f, 0.0f, offsetZ);
     164    this->shader->deactivateShader();
     165  }
     166}
     167
    294168
    295169void CloudEffect::make3DNoiseTexture()
  • branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h

    r8713 r8730  
    1111#include "sound_source.h"
    1212
    13 #include "world_entity.h"
     13#include "skydome.h"
    1414#include "material.h"
    1515#include "shader.h"
     
    3030#define at2(rx,ry) ( rx * q[0] + ry * q[1] )
    3131#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;
    4232
    4333
     
    10090
    10191  // Material                 cloudMaterial;
     92  Skydome*         skydome;
    10293 
    10394  // SHADER STUFF
     
    123114  int              B;
    124115  int              BM;
    125  
    126   // SKYPLANE STUFF
    127   VERTEX *planeVertices;
    128   int numPlaneVertices;
    129 
    130   int *indices;
    131   int numIndices;
    132 
    133   float pRadius;
    134  
    135   VERTEX *vertices;
    136   int numVertices;
    137116};
    138117
Note: See TracChangeset for help on using the changeset viewer.