Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8255 in orxonox.OLD


Ignore:
Timestamp:
Jun 8, 2006, 3:44:12 PM (18 years ago)
Author:
bensch
Message:

merged the atmos back with command: https://svn.orxonox.net/orxonox/branches/atmospheric_engine

Location:
trunk/src
Files:
21 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/effects/cloud_effect.cc

    r7810 r8255  
    1111### File Specific:
    1212        main-programmer: hdavid, amaechler
     13
     14        INSPIRED BY http://www.codesampler.com/usersrc/usersrc_6.htm#oglu_sky_dome_shader
    1315*/
    1416
     
    1719#include "util/loading/load_param.h"
    1820#include "util/loading/factory.h"
     21#include "util/loading/resource_manager.h"
    1922
    2023#include "glincl.h"
    21 //#include "graphics_engine.h"
     24#include "material.h"
    2225#include <math.h>
     26#include "state.h"
     27#include "p_node.h"
     28#include "shader.h"
     29#include "shell_command.h"
    2330
    2431#include "parser/tinyxml/tinyxml.h"
    2532
     33#include "sglmodel.h"
     34
    2635using namespace std;
     36
     37SHELL_COMMAND(activate, CloudEffect, activateCloud);
     38SHELL_COMMAND(deactivate, CloudEffect, deactivateCloud);
    2739
    2840CREATE_FACTORY(CloudEffect, CL_CLOUD_EFFECT);
     
    3749                this->loadParams(root);
    3850
    39         this->activate();
     51        if(cloudActivate)
     52                this->activate();
    4053}
    4154
     
    4356{
    4457        this->deactivate();
    45 }
     58
     59        delete this->cloudMaterial;
     60
     61        cloudModel.Delete();
     62        Shader::unload(this->cloudShader);
     63
     64}
     65
     66
     67bool CloudEffect::init()
     68{
     69        PRINTF(1)("Initializing CloudEffect\n");
     70
     71        // Default values
     72        this->cloudActivate = false;
     73        this->cloudTint[4] = ( 0.9f, 0.7f, 0.7f, 1.0f );
     74        this->cloudScroll = 1.0f;
     75        this->time = 0.0f;
     76        //g_cloud_texture = 0;
     77
     78        this->cloudTexture = "pictures/sky/cloud1.jpg";
     79
     80        cloudModel.Load("sky.sgl");
     81        cloudModel.Unitize();
     82
     83        // Get the bounding box of the sky dome
     84        float bbox[3] = {0};
     85        cloudModel.GetDimensions(bbox[0], bbox[1], bbox[2]);
     86       
     87        // Load Shaders
     88        this->cloudShader = new Shader( ResourceManager::getInstance()->getDataDir() + "/shaders/sky.vert", ResourceManager::getInstance()->getDataDir() +"/shaders/sky.frag");
     89
     90        // Tell the shader the bounding box of the sky dome
     91        this->cloudShader->bindShader("bbox", bbox, 4);
     92
     93        // Initialze Cloud Material
     94        this->cloudMaterial = new Material("Sky");
     95        this->cloudMaterial->setIllum(3);
     96        this->cloudMaterial->setAmbient(1.0, 1.0, 1.0);
     97        this->cloudMaterial->setDiffuseMap(this->cloudTexture);
     98
     99}
     100
    46101
    47102void CloudEffect::loadParams(const TiXmlElement* root)
     
    49104        WeatherEffect::loadParams(root);
    50105
    51         LoadParam(root, "animSpeed", this, CloudEffect, setCloudAnimation);
    52 
    53 }
    54 
    55 
    56 bool CloudEffect::init()
    57 {
    58         // default values
    59         this->cloudAnimTimeStep = 0;
    60 
    61         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    62         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    63         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    64         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    65 
    66         // Generate noise map a
    67         CloudEffect::genNoiseMap(cloudMap32_a);
    68        
    69         if (this->cloudAnimTimeStep > 0) {
    70                 // Generate noise map b
    71                 CloudEffect::genNoiseMap(cloudMap32_b);
     106        // LoadParam(root, "speed", this, CloudEffect, setCloudAnimation);
     107        // LoadParam(root, "texture", this, CloudEffect, setCloudTexture);
     108
     109        LOAD_PARAM_START_CYCLE(root, element);
     110        {
     111                LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption);
    72112        }
    73 }
     113        LOAD_PARAM_END_CYCLE(element);
     114}
     115
    74116
    75117bool CloudEffect::activate()
    76118{
    77         PRINTF(0)( "Activating CloudEffect\n");
    78         if (this->cloudAnimTimeStep == 0) {
    79                 for (int i = 0; i < 32*32; i++)
    80                         cloudMap32_c[i] = cloudMap32_a[i];
    81 
    82                 CloudEffect::overlapOctaves();
    83                 CloudEffect::expFilter();
    84                 CloudEffect::genCloudTexture();
    85         }
     119        PRINTF(0)( "Activating CloudEffect with Material %s\n", this->cloudTexture.c_str());
     120
     121        this->cloudActivate = true;
     122       
    86123}
    87124
     
    89126{
    90127        PRINTF(0)("Deactivating CloudEffect\n");
    91 }
    92 
    93 void CloudEffect::genCloudTexture() {
    94         for(int i=0; i<256; i++)
    95                 for(int j=0; j<256; j++)
    96                 {
    97                         float color = cloudMap256[i*256+j];
    98                         cloudTexture[i][j][0] = (char) color;
    99                         cloudTexture[i][j][1] = (char) color;
    100                         cloudTexture[i][j][2] = (char) color;
    101                 }
    102 
    103         glGenTextures(2, &texID[0]);
    104         glBindTexture(GL_TEXTURE_2D, texID[0]);
    105         gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, cloudTexture);
    106 }
    107 
    108 void CloudEffect::calcAnimMap(float timer) {
    109 
    110         for (int x=0; x<32*32; x++)
    111                 cloudMap32_c[x] = (cloudMap32_a[x] * ((this->cloudAnimTimeStep - timer) / this->cloudAnimTimeStep)) + (cloudMap32_b[x] * (timer / this->cloudAnimTimeStep));
    112 
     128
     129        this->cloudActivate = false;
    113130}
    114131
    115132void CloudEffect::draw() const
    116133{
    117         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    118 
     134        if (!this->cloudActivate)
     135                return;
     136               
     137        //      glMatrixMode(GL_MODELVIEW);
     138        //      glPushMatrix();
     139        //
     140        //      // Move sphere along with the camera
     141        //      Vector r = State::getCameraNode()->getAbsCoor();
     142        //      glTranslatef(r.x, r.y, r.z);
     143        //
     144        //      // Sky movement
     145        //      glRotatef(mover, 0, 0, 1);
     146        //
     147        //      cloudMaterial->select();
     148        //      gluSphere(this->sphereObj, this->sphereRadius, 20, 20);
     149        //      glPopMatrix();
     150
     151        // ******
     152
     153        glMatrixMode(GL_MODELVIEW);
    119154        glPushMatrix();
    120         glEnable(GL_TEXTURE_2D);
    121 
    122         glBindTexture(GL_TEXTURE_2D, texID[0]);
    123 
    124         // FIXME : Bind this to the sky - how do I do this?
    125         glBegin(GL_QUADS);
    126                 glTexCoord2f(0.0f, 0.0f); glVertex3f(20, 20,  60);      // Bottom Left Of The Texture and Quad
    127                 glTexCoord2f(1.0f, 0.0f); glVertex3f(60, 20,  60);      // Bottom Right Of The Texture and Quad
    128                 glTexCoord2f(1.0f, 1.0f); glVertex3f(60, 60,  60);      // Top Right Of The Texture and Quad
    129                 glTexCoord2f(0.0f, 1.0f); glVertex3f(20, 60,  60);      // Top Left Of The Texture and Quad
    130         glEnd();
     155
     156        // glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     157        // glShadeModel(GL_SMOOTH);
     158        // glEnable(GL_DEPTH_TEST);
     159        // glEnable(GL_CULL_FACE);
     160        // glCullFace(GL_BACK);
     161        // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     162       
     163        // glLineWidth(3.0f);
     164
     165        static float time = 0.0f;
     166        // static vector3f eye = {0.0f, 0.0f, 0.0f}, look = {0.0f, 0.0f, 1.0f}, up = {0.0f, 1.0f, 0.0f};
     167
     168        // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     169        // glLoadIdentity();
     170        // gluLookAt(eye[x], eye[y], eye[z], look[x], look[y], look[z], up[x], up[y], up[z]);
     171
     172        // Turn off the depth buffer when rendering the background
     173        // glDisable(GL_DEPTH_TEST);
     174
     175        this->cloudShader->activateShader();
     176
     177        /* Select the shader program and update parameters. */
     178        /* The "time" parameter controls the cloud scrolling. */
     179        this->cloudShader->bindShader("time", &time, 1);
     180        /* The "horizon" parameter controls the sky tinting. */
     181        this->cloudShader->bindShader("horizon", cloudTint, 4);
     182
     183        glActiveTexture(GL_TEXTURE0 + 0);
     184        glActiveTexture(GL_TEXTURE0 + 1);
     185
     186        // Load the cloud texture
     187        //glBindTexture(GL_TEXTURE_2D, g_cloud_texture);
     188        this->cloudMaterial->select();
     189
     190        // Render the sky dome
     191        cloudModel.Render();
     192
     193        // Unselect the shader
     194        Shader::deactivateShader();
     195
     196        /* Turn on the depth buffer when rendering the foreground. */
     197        // glEnable(GL_DEPTH_TEST);
     198
     199        /* Render the forground, for example, a teapot or bunny. */
     200        //    glEnable(GL_LIGHTING);
     201        //    glColor3f(0.0f, 1.0f, 0.0f);
     202        //    glBegin(GL_QUADS);
     203        //    glNormal3f( 0.0f,  1.0f,  0.0f);
     204        //    glVertex3f( 20.0f, -1.0f,  20.0f);
     205        //    glVertex3f( 20.0f, -1.0f, -20.0f);
     206        //    glVertex3f(-20.0f, -1.0f, -20.0f);
     207        //    glVertex3f(-20.0f, -1.0f,  20.0f);
     208        //    glEnd();
     209        //    glDisable(GL_LIGHTING);
    131210
    132211        glPopMatrix();
     212       
    133213}
    134214
    135215void CloudEffect::tick (float dt)
    136216{
    137         if (this->cloudAnimTimeStep > 0) {
    138                 if (timer >= this->cloudAnimTimeStep) {
    139                         timer -= this->cloudAnimTimeStep;
    140                         for (int i = 0; i < 32*32; i++)
    141                                 cloudMap32_a[i] = cloudMap32_b[i];
    142                         CloudEffect::genNoiseMap(cloudMap32_b);
    143                 }
    144 
    145                 //map32anim = (map32a * (10 - timer)) + (map32b * timer);
    146                 CloudEffect::calcAnimMap(timer);
    147 
    148                 CloudEffect::overlapOctaves();
    149                 CloudEffect::expFilter();
    150                 CloudEffect::genCloudTexture();
    151 
    152                 timer += dt;
    153         }
    154 }
    155 
    156 /*
    157         Random noise generator
    158 */
    159 float CloudEffect::noise(int x, int y, int random)
    160 {
    161                 int n = x + y * 57 + random * 131;
    162                 n = (n<<13) ^ n;
    163                 return (1.0f - ( (n * (n * n * 15731 + 789221) +
    164                                                 1376312589)&0x7fffffff)* 0.000000000931322574615478515625f);
    165 }
    166 
    167 /*
    168         Set noise for the 32*32 noise map:
    169 */
    170 void CloudEffect::genNoiseMap(float  *map)
    171 {
    172         float temp[34][34];
    173 
    174         int random = rand() % 5000;
    175 
    176         for (int y = 1; y < 33; y++)
    177                 for (int x = 1; x < 33; x++)
    178                         temp[x][y] = 128.0f + CloudEffect::noise(x,  y,  random) * 128.0f;
    179 
    180         // Seamless cloud
    181         for (int x=1; x<33; x++)
    182         {
    183                 temp[0][x] = temp[32][x];
    184                 temp[33][x] = temp[1][x];
    185                 temp[x][0] = temp[x][32];
    186                 temp[x][33] = temp[x][1];
    187         }
    188         temp[0][0] = temp[32][32];
    189         temp[33][33] = temp[1][1];
    190         temp[0][33] = temp[32][1];
    191         temp[33][0] = temp[1][32];
    192 
    193         // We mirror the side and corner elements so our final cloud will be seamless without any ugly borders showing.
    194         for (int y=1; y<33; y++)
    195                 for (int x=1; x<33; x++)
    196                 {
    197                         float center = temp[x][y]/4.0f;
    198                         float sides = (temp[x+1][y] + temp[x-1][y] + temp[x][y+1] + temp[x][y-1])/8.0f;
    199                         float corners = (temp[x+1][y+1] + temp[x+1][y-1] + temp[x-1][y+1] + temp[x-1][y-1])/16.0f;
    200 
    201                         map[((x-1)*32) + (y-1)] = center + sides + corners;
    202                 }
    203 }
    204 
    205 /*
    206         Interpolation - average the value of each pixel value with that of its neighbors' values.
    207 */
    208 float CloudEffect::interpolate(float x, float y, float  *map)
    209 {
    210         int Xint = (int)x;
    211         int Yint = (int)y;
    212 
    213         float Xfrac = x - Xint;
    214         float Yfrac = y - Yint;
    215 
    216         int X0 = Xint % 32;
    217         int Y0 = Yint % 32;
    218         int X1 = (Xint + 1) % 32;
    219         int Y1 = (Yint + 1) % 32;
    220 
    221         float bot = map[X0*32 + Y0] + Xfrac * (map[X1*32 + Y0] - map[X0*32 + Y0]);
    222         float top = map[X0*32 + Y1] + Xfrac * (map[X1*32 +  Y1] - map[X0*32 + Y1]);
    223 
    224         return (bot + Yfrac * (top - bot));
    225 }
    226 
    227 
    228 /*
    229         Octaves are overlapped together to give cloud more turbulence. We will use four octaves for our cloud.
    230 */
    231 void CloudEffect::overlapOctaves()
    232 {
    233         for (int x=0; x<256*256; x++)
    234         {
    235                 cloudMap256[x] = 0;
    236         }
    237 
    238         for (int octave=0; octave<4; octave++)
    239                 for (int x=0; x<256; x++)
    240                         for (int y=0; y<256; y++)
    241                         {
    242                                 float scale = 1 / pow(2.0f, (float) 3-octave);
    243                                 float noise = CloudEffect::interpolate(x*scale, y*scale , cloudMap32_c);
    244 
    245                                 //The octaves are added together with the proper weight factors.
    246                                 //You could replace pow(2, i) with 1<<i for faster computation
    247                                 cloudMap256[(y*256) + x] += noise / pow(2.0f, (float) octave);
    248                         }
    249 }
    250 
    251 
    252 /*
    253         Filter the noise with exponential function
    254 */
    255 void CloudEffect::expFilter()
    256 {
    257         float cover = 20.0f;
    258         float sharpness = 0.95f;
    259 
    260         for (int x=0; x<256*256; x++)
    261         {
    262                 float c = cloudMap256[x] - (255.0f-cover);
    263                 if (c<0)     c = 0;
    264                 cloudMap256[x] = 255.0f - ((float)(pow(sharpness, c))*255.0f);
    265         }
    266 }
    267 
    268 
     217        if (!this->cloudActivate)
     218                return;
     219
     220        // Update the timer for scrolling the clouds
     221        time = time + ((1.0f / 2000.0f) * cloudScroll);
     222}
     223
  • trunk/src/lib/graphics/effects/cloud_effect.h

    r7810 r8255  
    66#define _CLOUD_EFFECT
    77
    8 #include "vector.h"
    9 #include "vector2D.h"
    10 
    118#include "weather_effect.h"
    129
    1310#include "sound_buffer.h"
    1411#include "sound_source.h"
     12
     13#include "world_entity.h"
     14#include "glincl.h"
     15
     16#include "sglmodel.h"
     17
     18class Shader;
     19class Material;
     20class Vector;
    1521
    1622class CloudEffect : public WeatherEffect
     
    2733                virtual bool deactivate();
    2834
     35                inline void activateCloud() { this->activate(); }
     36                inline void deactivateCloud() { this->deactivate(); }
     37               
    2938                virtual void draw() const;
    3039                virtual void tick(float dt);
    3140
    32                 inline void setCloudAnimation(float timestep) { this->cloudAnimTimeStep = timestep; }
     41                inline void setCloudOption(const std::string& option) {
     42                        if (option == "activate") this->cloudActivate = true;
     43                }
     44
    3345
    3446        private:
    35                 // Basic noise maps 32x32
    36                 float                                                                                                           cloudMap32_a[32 * 32];
    37                 float                                                                                                           cloudMap32_b[32 * 32];
    38                 float                                                                                                           cloudMap32_c[32 * 32];
     47                void initialize(char* fileName);
    3948
    40                 // The cloud map 256x256
    41                 float                                                                                                           cloudMap256[256 * 256];
     49                bool                            cloudActivate;
    4250
    43                 // Temporary array to hold texture RGB values
    44                 char                                                                                                                    cloudTexture[256][256][3];
     51                Material*                       cloudMaterial;          // A Material for the Sphere.
    4552
    46                 GLuint                                                                                                          texID[2];
    47                 float                                                                                                           timer;
     53                std::string                     cloudTexture;
    4854
    49                 bool                                                                                                                    cloudAnimTimeStep;
     55                Sglmodel_sgl                    cloudModel;
     56                Shader*                         cloudShader;
    5057
    51                 float                                                                                                           noise(int x, int y, int random);
    52                 float                                                                                                           interpolate(float x, float y, float  *map);
    53                 void                                                                                                            overlapOctaves();
    54                 void                                                                                                            expFilter();
     58                GLfloat                         cloudTint[4];
     59                GLfloat                         cloudScroll;
    5560
    56                 void                                                                                                            genNoiseMap(float  *map);
    57                 void                                                                                                            genCloudTexture();
    58                 void                                                                                                            calcAnimMap(float timer);
     61                float                           time;
    5962
    6063};
  • trunk/src/lib/graphics/effects/fog_effect.cc

    r7810 r8255  
    2020#include "glincl.h"
    2121
    22 /*#include "shell_command.h"
    23 SHELL_COMMAND(activateFog, FogEffect, FogEffect::activate)
    24         ->setAlias("aFog");
    25 SHELL_COMMAND(deactivateFog, FogEffect, FogEffect::deactivate)
    26         ->setAlias("dFog");*/
     22#include "shell_command.h"
     23
     24SHELL_COMMAND(activate, FogEffect, activateFog);
     25SHELL_COMMAND(deactivate, FogEffect, deactivateFog);
     26SHELL_COMMAND(startfogging, FogEffect, startFogging);
    2727
    2828using namespace std;
     
    3939                this->loadParams(root);
    4040
    41         this->activate();
     41        if (this->fogActivate)
     42                this->activate();
    4243}
    4344
     
    5758        LoadParam(root, "range", this, FogEffect, setFogRange);
    5859        LoadParam(root, "color", this, FogEffect, setFogColor);
     60
     61        LOAD_PARAM_START_CYCLE(root, element);
     62        {
     63                LoadParam_CYCLE(element, "option", this, FogEffect, setFogOption);
     64        }
     65        LOAD_PARAM_END_CYCLE(element);
    5966}
    6067
     
    6269{
    6370        //default values
     71        this->fogActivate = false;
     72        this->fogFadeDuration = 0;
     73        this->localTimer = 0;
     74       
    6475        this->fogMode = GL_EXP2;
    6576        this->fogDensity = 0.001;
    6677        this->fogStart = 0;
    6778        this->fogEnd = 5000;
    68   this->colorVector = Vector(0.7, 0.7, 0.7);
     79        this->colorVector = Vector(0.7, 0.7, 0.7);
     80
    6981}
    70 
    7182
    7283
     
    7586        PRINTF(0)( "Enabling FogEffect, mode: %i, density: %f, start: %f, end: %f, color %f, %f, %f\n", this->fogMode, this->fogDensity, this->fogStart, this->fogEnd, this->colorVector.x, this->colorVector.y, this->colorVector.z);
    7687
     88        this->fogActivate = true;
     89       
     90        GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
     91        glFogi(GL_FOG_MODE, this->fogMode);
     92        glFogfv(GL_FOG_COLOR, fogColor);
     93        glFogf(GL_FOG_DENSITY, this->fogDensity);
     94        glHint(GL_FOG_HINT, GL_DONT_CARE);
     95        glFogf(GL_FOG_START, this->fogStart);
     96        glFogf(GL_FOG_END, this->fogEnd);
     97       
    7798        glEnable(GL_FOG);
    78         {
    79                 GLfloat fogColor[4] = { colorVector.x, colorVector.y, colorVector.z, 1.0};
    80 
    81                 glFogi(GL_FOG_MODE, this->fogMode);
    82                 glFogfv(GL_FOG_COLOR, fogColor);
    83                 glFogf(GL_FOG_DENSITY, this->fogDensity);
    84                 glHint(GL_FOG_HINT, GL_DONT_CARE);
    85                 glFogf(GL_FOG_START, this->fogStart);
    86                 glFogf(GL_FOG_END, this->fogEnd);
    87         }
    88         glClearColor(0.5, 0.5, 0.5, 1.0);
     99        // glClearColor(0.5, 0.5, 0.5, 1.0);
    89100}
    90101
     
    93104{
    94105        PRINTF(0)("Deactivating FogEffect\n");
     106
     107        this->fogActivate = false;
     108       
    95109        glDisable(GL_FOG);
     110}
     111
     112void FogEffect::draw() const {
     113
     114        if (this->fogFadeDuration != 0 && this->localTimer < this->fogFadeDuration)
     115                glFogf(GL_FOG_DENSITY, this->fogFadeDensity);
     116        //else
     117        //      glFogf(GL_FOG_DENSITY, this->fogDensity);
     118
     119}
     120void FogEffect::tick(float dt)
     121{
     122        if (!this->fogActivate)
     123                return;
     124               
     125
     126        if (this->fogFadeDuration != 0 && this->localTimer < this->fogFadeDuration) {
     127                this->localTimer += dt;
     128                float progress = this->localTimer / this->fogFadeDuration;
     129                this->fogFadeDensity = progress * this->fogDensity;
     130        }
     131}
     132
     133void FogEffect::startFogging() {
     134
     135        if (this->fogActivate)
     136                this->deactivate();
     137
     138        this->fogFadeDuration = 10;
     139        this->localTimer = 0;
     140        this->activate();
     141
    96142}
    97143
  • trunk/src/lib/graphics/effects/fog_effect.h

    r7810 r8255  
    2323                virtual bool deactivate();
    2424
     25                void activateFog() { this->activate(); }
     26                void deactivateFog() { this->deactivate(); }
     27
     28                virtual void draw() const;
     29                virtual void tick(float dt);
     30
    2531                inline void setFogMode(const std::string& mode) { this->fogMode = this->stringToFogMode(mode); }
    2632                inline void setFogDensity(float density) { this->fogDensity = density; }
    2733                inline void setFogRange(float start, float end) { this->fogStart = start; this->fogEnd = end; }
    2834                inline void setFogColor(float r, float g, float b) { this->colorVector = Vector(r, g, b); }
     35                inline void setFogOption(const std::string& option) { if (option == "activate") this->fogActivate = true; }
     36
     37                void startFogging();
    2938
    3039        private:
    3140                GLint stringToFogMode(const std::string& mode);
    3241
    33         private:
    34                 GLint                   fogMode;
    35                 GLfloat                 fogDensity;
    36                 GLfloat                 fogStart;
    37                 GLfloat                 fogEnd;
    38                 Vector                  colorVector;
     42                bool                            fogActivate;
     43                GLfloat                         fogFadeDuration;
     44                float                           localTimer;
     45               
     46                GLint                           fogMode;
     47                GLfloat                         fogDensity;
     48                GLfloat                         fogFadeDensity;
     49
     50                GLfloat                         fogStart;
     51                GLfloat                         fogEnd;
     52                Vector                          colorVector;
    3953};
    4054
  • trunk/src/lib/graphics/effects/lightening_effect.cc

    r7810 r8255  
    1818#include "util/loading/load_param.h"
    1919#include "util/loading/factory.h"
    20 #include "render2D/image_plane.h"
     20#include "effects/billboard.h"
    2121
    2222#include "glincl.h"
    2323#include "parser/tinyxml/tinyxml.h"
    2424
     25#include "shell_command.h"
     26#include "light.h"
     27
     28SHELL_COMMAND(activate, LighteningEffect, activateLightening);
     29SHELL_COMMAND(deactivate, LighteningEffect, deactivateLightening);
     30
    2531using namespace std;
    2632
     
    3036{
    3137        this->setClassID(CL_LIGHTENING_EFFECT, "LighteningEffect");
    32  
    33  
    34   lightening = new ImagePlane(NULL);
    35   lightening->setTexture("maps/lightning_bolt.png");
    36   lightening->setSize(50, 50);
    37   lightening->setAbsCoor2D(10,10);
    38   lightening->setVisibility(true);
    39  
    4038 
    4139        this->init();
     
    4442                this->loadParams(root);
    4543
    46         this->activate();
     44  if(this->lighteningActivate)
     45         this->activate();
    4746}
    4847
     
    5049{
    5150        this->deactivate();
    52   delete lightening;
    5351}
    5452
     
    5654{
    5755        WeatherEffect::loadParams(root);
     56 
     57  LoadParam(root, "coord", this, LighteningEffect, coord);
     58  LoadParam(root, "option", this, LighteningEffect, setLighteningOption);
     59  LoadParam(root, "frequency", this, LighteningEffect, setFlashFrequency);
     60  LoadParam(root, "const-time", this, LighteningEffect, setFlashConstTime);
     61  LoadParam(root, "rising-time", this, LighteningEffect, setFlashRisingTime);
     62  LoadParam(root, "size", this, LighteningEffect, setFlashSize);
     63  LoadParam(root, "seed", this, LighteningEffect, setFlashSeed);
    5864}
    5965
     
    6167bool LighteningEffect::init()
    6268{
    63         //Default values
     69  lighteningActivate = false;
     70 
     71  this->time = 0.0;
     72  this->flashFrequency = 1.4f;
     73  this->flashConstTime = 0.5f;
     74  this->flashRisingTime = 0.1f;
     75
     76  this->width = 400.0f;
     77  this->height = 100.0f;
     78  this->seedWidth = 50;
     79  this->seedHeight = 50;
     80  this->bNewCoordinate = false;
     81
     82  this->seedX = 500.f;
     83  this->seedZ = 1000.0f;
     84  this->seedTime = 4.0f;
     85
     86  this->billboard[0] = new Billboard(NULL);
     87  this->billboard[0]->setTexture("maps/lightning_bolt1.png");
     88  this->billboard[0]->setSize(this->width, this->height);
     89  this->billboard[0]->setAbsCoor(3000,850,0);
     90  this->billboard[0]->setVisibiliy(false);
     91
     92  this->billboard[1] = new Billboard(NULL);
     93  this->billboard[1]->setTexture("maps/lightning_bolt2.png");
     94  this->billboard[1]->setSize(this->width, this->height);
     95  this->billboard[1]->setAbsCoor(3000,850,0);
     96  this->billboard[1]->setVisibiliy(false);
     97
     98  this->billboard[2] = new Billboard(NULL);
     99  this->billboard[2]->setTexture("maps/lightning_bolt3.png");
     100  this->billboard[2]->setSize(this->width, this->height);
     101  this->billboard[2]->setAbsCoor(3000,850,0);
     102  this->billboard[2]->setVisibiliy(false);
     103
     104  this->billboard[3] = new Billboard(NULL);
     105  this->billboard[3]->setTexture("maps/lightning_bolt4.png");
     106  this->billboard[3]->setSize(this->width, this->height);
     107  this->billboard[3]->setAbsCoor(0.0f, 50.0f, 0.0f);
     108  this->billboard[3]->setVisibiliy(false);
     109/*
     110  this->soundSource = NULL;
     111  this->thunderBuffer = NULL;
     112
     113  this->soundSource.setSourceNode(this);
     114
     115  //load sound
     116  if (this->thunderBuffer != NULL)
     117    ResourceManager::getInstance()->unload(this->thunderBuffer);
     118  this->thunderBuffer = (OrxSound::SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);*/
     119}
     120
     121void LighteningEffect::coord(float x, float y, float z)
     122{
     123  this->billboard[0]->setAbsCoor(x, y, z);
     124  this->billboard[1]->setAbsCoor(x, y, z);
     125  this->billboard[2]->setAbsCoor(x, y, z);
     126  this->billboard[3]->setAbsCoor(x, y, z);
     127  this->mainPosX = x;
     128  this->mainPosY = y;
     129  this->mainPosZ = z;
     130}
     131
     132
     133void LighteningEffect::setFlashSize(float width, float height, float seedWidth, float seedHeight)
     134{
     135  this->width = width;
     136  this->height = height;
     137  this->seedWidth = seedWidth;
     138  this->seedHeight = seedHeight;
     139  this->billboard[0]->setSize(this->width, this->height);
     140  this->billboard[1]->setSize(this->width, this->height);
     141  this->billboard[2]->setSize(this->width, this->height);
     142  this->billboard[3]->setSize(this->width, this->height);
    64143}
    65144
     
    68147{
    69148        PRINTF(0)( "Activating LighteningEffect\n" );
    70 
     149  this->time = 0;
     150  lighteningActivate = true;
    71151}
    72152
     
    75155{
    76156        PRINTF(0)("Deactivating LighteningEffect\n");
     157  this->billboard[0]->setVisibiliy(false);
     158  this->billboard[1]->setVisibiliy(false);
     159  this->billboard[2]->setVisibiliy(false);
     160  this->billboard[3]->setVisibiliy(false);
     161  lighteningActivate = false;
    77162}
    78163
    79164void LighteningEffect::tick (float dt)
    80165{
    81 
    82 }
     166  if(!lighteningActivate)
     167    return;
     168 
     169  this->time += dt;
     170
     171  /*if( flashLight != NULL)
     172  {
     173    if((int)(100*time)%2)
     174      this->flashLight->setDiffuseColor(0,0,0);
     175    else
     176      this->flashLight->setDiffuseColor(100,100,100);
     177   
     178    //PRINTF(0)("100*time: %f %i\n", 100*time, (int)(100*time));
     179}*/
     180 
     181  if( this->time > this->flashFrequency)
     182  {
     183    this->billboard[0]->setVisibiliy(true);
     184    this->time = 0.0f;
     185   
     186    this->flashLight = new Light();
     187    this->flashLight->setAbsCoor(this->billboard[0]->getAbsCoor().x, this->billboard[0]->getAbsCoor().y, this->billboard[0]->getAbsCoor().z);
     188    this->flashLight->setDiffuseColor(100,100,100);
     189   
     190    //this->soundSource.play(this->thunderBuffer);
     191  }
     192  else if( this->billboard[3]->isVisible() && this->time > this->flashConstTime)
     193  {
     194    this->billboard[3]->setVisibiliy(false);
     195    this->time = 0.0f;
     196    this->bNewCoordinate = true;
     197   
     198    if(flashLight != NULL)
     199    {
     200      delete this->flashLight;
     201      flashLight = NULL;
     202    }
     203  }
     204
     205  if( this->billboard[2]->isVisible() && this->time > this->flashRisingTime)
     206  {
     207    this->billboard[2]->setVisibiliy(false);
     208    this->billboard[3]->setVisibiliy(true);
     209    this->flashLight->setDiffuseColor(100,100,100);
     210  }
     211  else if( this->billboard[1]->isVisible() && this->time > this->flashRisingTime*2/3 )
     212  {
     213    this->billboard[1]->setVisibiliy(false);
     214    this->billboard[2]->setVisibiliy(true);
     215    this->flashLight->setDiffuseColor(0,0,0);
     216  }
     217  else if( this->billboard[0]->isVisible() && this->time > this->flashRisingTime*1/3 )
     218  {
     219    this->billboard[0]->setVisibiliy(false);
     220    this->billboard[1]->setVisibiliy(true);
     221    this->flashLight->setDiffuseColor(100,100,100);
     222  }
     223
     224  if( this->bNewCoordinate)
     225  {
     226    float posX = this->mainPosX - this->seedX * (float)rand()/(float)RAND_MAX;
     227    float posZ = this->mainPosZ + this->seedZ * (float)rand()/(float)RAND_MAX;
     228    this->billboard[0]->setAbsCoor(posX, this->mainPosY, posZ);
     229    this->billboard[1]->setAbsCoor(posX, this->mainPosY, posZ);
     230    this->billboard[2]->setAbsCoor(posX, this->mainPosY, posZ);
     231    this->billboard[3]->setAbsCoor(posX, this->mainPosY, posZ);
     232    this->bNewCoordinate = false;
     233  }
     234}
     235
     236void LighteningEffect::draw() const
     237{
     238}
  • trunk/src/lib/graphics/effects/lightening_effect.h

    r7810 r8255  
    1515
    1616
    17 class ImagePlane;
     17class Billboard;
     18class Light;
    1819
    1920class LighteningEffect : public WeatherEffect
     
    3031                virtual bool deactivate();
    3132
    32                 virtual void tick(float dt);
     33    virtual void draw() const;
     34    virtual void tick(float dt);
     35   
     36    void coord(float x, float y, float z);
     37    void setFlashSize(float width, float height, float seedWidth, float seedHeight);
     38   
     39    inline void setLighteningOption(const std::string& option) { if (option == "activate") this->lighteningActivate = true;}
     40    inline void setFlashFrequency(float flashFrequency) { this->flashFrequency = flashFrequency; }
     41    inline void setFlashConstTime(float flashConstTime) { this->flashConstTime = flashConstTime; }
     42    inline void setFlashRisingTime(float flashRisingTime) { if(flashRisingTime > this->flashConstTime)
     43                                                                                        this->flashRisingTime = this->flashConstTime/2;
     44                                                                                      else
     45                                                                                        this->flashRisingTime = flashRisingTime; }
     46    inline void setFlashSeed(float seedX, float seedZ, float seedTime) { this->seedX = seedX;
     47                                                                                                         this->seedZ = seedZ;
     48                                                                                                         this->seedTime = seedTime; }
    3349
     50    void activateLightening() { this->activate(); }
     51    void deactivateLightening() { this->deactivate(); }
     52   
    3453        private:
    35     ImagePlane* lightening;
     54    Billboard* billboard[4];
     55    bool lighteningActivate;
     56
     57    float flashFrequency;
     58    float flashConstTime;
     59    float flashRisingTime;
     60
     61    float time;
     62
     63    bool  bNewCoordinate;
     64    float width;
     65    float height;
     66    float seedWidth;
     67    float seedHeight;
     68
     69    float seedX;
     70    float seedZ;
     71    float seedTime;
     72   
     73    float mainPosX;
     74    float mainPosY;
     75    float mainPosZ;
     76
     77    Light* flashLight;
     78   
     79    //OrxSound::SoundSource    soundSource;
     80    //OrxSound::SoundBuffer*   thunderBuffer;
    3681
    3782};
  • trunk/src/lib/graphics/effects/rain_effect.cc

    r7810 r8255  
    11/*
    2    orxonox - the future of 3D-vertical-scrollers
    3 
    4    Copyright (C) 2004 orx
    5 
    6    This program is free software; you can redistribute it and/or modify
    7    it under the terms of the GNU General Public License as published by
    8    the Free Software Foundation; either version 2, or (at your option)
    9    any later version.
     2orxonox - the future of 3D-vertical-scrollers
     3
     4Copyright (C) 2004 orx
     5
     6This program is free software; you can redistribute it and/or modify
     7it under the terms of the GNU General Public License as published by
     8the Free Software Foundation; either version 2, or (at your option)
     9any later version.
    1010
    1111### File Specific:
    12    main-programmer: hdavid, amaechler
     12main-programmer: hdavid, amaechler
    1313*/
    1414
     
    2525#include "plane_emitter.h"
    2626#include "shell_command.h"
     27#include "light.h"
    2728
    2829#include "parser/tinyxml/tinyxml.h"
     
    3132SHELL_COMMAND(deactivate, RainEffect, deactivateRain);
    3233
     34SHELL_COMMAND(startRaining, RainEffect, startRaining);
     35
    3336using namespace std;
    3437
    3538CREATE_FACTORY(RainEffect, CL_RAIN_EFFECT);
     39
     40// TODO: Dim Light with Rain, Finish preCaching, check out if multiple rain emitters work,  Think about what happens with building poss. to hang movewithcam off, benchmark, possible to activate lightening, turn off visibility when in a building, variable emitter size depending on playable, also rain velocity
    3641
    3742RainEffect::RainEffect(const TiXmlElement* root)
     
    5055
    5156        //load wind sound
    52         if (this->rainWindForce > 0) {
     57        if (this->rainWindForce != 0) {
    5358                if (this->windBuffer != NULL)
    5459                        ResourceManager::getInstance()->unload(this->windBuffer);
     
    5661        }
    5762
    58         this->activate();
     63        if(rainActivate)
     64                this->activate();
    5965}
    6066
     
    8086        LoadParam(root, "life", this, RainEffect, setRainLife);
    8187        LoadParam(root, "wind", this, RainEffect, setRainWind);
    82         LoadParam(root, "option", this, RainEffect, setRainOption);
     88        LoadParam(root, "startraining", this, RainEffect, setRainStart);
     89
     90        LOAD_PARAM_START_CYCLE(root, element);
     91        {
     92                LoadParam_CYCLE(element, "option", this, RainEffect, setRainOption);
     93        }
     94        LOAD_PARAM_END_CYCLE(element);
     95
    8396}
    8497
     
    87100{
    88101        //Default values
     102        this->rainActivate = false;
     103        this->rainMove = false;
    89104        this->rainCoord = Vector(500, 500, 500);
    90105        this->rainSize = Vector2D(1000, 1000);
     
    94109        this->rainMaxParticles = this->rainRate * this->rainLife;
    95110        this->rainWindForce  = 0;
     111        this->rainStartDuration = 0;
     112        this->localTimer = 0;
     113        this->soundRainVolume = 0.8f;
    96114
    97115        this->emitter = new PlaneEmitter(this->rainSize);
     116
     117        lightMan = LightManager::getInstance();
     118        this->rainAmbient = lightMan->getAmbientColor();
    98119}
    99120
     
    104125{
    105126        PRINTF(0)( "Activating RainEffect, coord: %f, %f, %f, size: %f, %f, rate: %f, velocity: %f, moveRain: %s\n", this->rainCoord.x, this->rainCoord.y, this->rainCoord.z, this->rainSize.x, this-> rainSize.y, this->rainRate, this->rainVelocity, this->rainMove ? "true" : "false" );
     127
     128        this->rainActivate = true;
    106129
    107130        if (unlikely(RainEffect::rainParticles == NULL))
     
    114137                RainEffect::rainParticles->setRadius(0.2, 0.02);
    115138                RainEffect::rainParticles->setRadius(1, 0.01);
    116                 RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2); // grey blue 1
    117                 RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2); // grey blue 2
    118                 RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2); // light grey
     139                RainEffect::rainParticles->setColor(0, 0.3, 0.3, 0.5, 0.2);     // grey blue 1
     140                RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2);   // grey blue 2
     141                RainEffect::rainParticles->setColor(1, 0.7, 0.7, 0.7, 0.2);     // light grey
    119142        }
    120143
     
    128151        this->emitter->setSpread(this->rainWindForce / 50, 0.2);
    129152       
    130         this->soundSource.loop(this->rainBuffer);
    131         if (this->rainWindForce > 0)
    132                 this->soundSource.loop(this->windBuffer);
     153        this->soundSource.loop(this->rainBuffer, this->soundRainVolume);
     154        if (this->rainWindForce != 0) this->soundSource.loop(this->windBuffer, 0.1f * this->rainWindForce);
     155
     156        lightMan->setAmbientColor(.1,.1,.1);
    133157}
    134158
     
    137161{
    138162        PRINTF(0)("Deactivating RainEffect\n");
     163       
     164        this->rainActivate = false;
    139165        this->emitter->setSystem(NULL);
    140166
     167        // Stop Sound
    141168        this->soundSource.stop();
    142 }
    143 
    144 void RainEffect::activateRain()
    145 {
    146         this->activate();
    147 }
    148 
    149 void RainEffect::deactivateRain()
    150 {
    151         this->deactivate();
    152 }
    153 
     169
     170        // Restore Light Ambient
     171        lightMan->setAmbientColor(this->rainAmbient, this->rainAmbient, this->rainAmbient);
     172}
    154173
    155174void RainEffect::tick (float dt)
    156175{
     176        if (!this->rainActivate)
     177                return;
     178               
    157179        if (this->rainMove) {
    158180                this->rainCoord = State::getCameraNode()->getAbsCoor();
    159181                this->emitter->setRelCoor(this->rainCoord.x , this->rainCoord.y+800, this->rainCoord.z);
    160182        }
    161 }
     183
     184        if (this->rainStartDuration != 0 && this->localTimer < this->rainStartDuration) {
     185                this->localTimer += dt;
     186                float progress = this->localTimer / this->rainStartDuration;
     187
     188                // Dim Light
     189                lightMan->setAmbientColor(1.1 - progress, 1.1 - progress, 1.1 - progress);
     190
     191                // use alpha in color to fade in
     192                RainEffect::rainParticles->setColor(0,   0.3, 0.3, 0.5, 0.2 * progress); // grey blue 1
     193                RainEffect::rainParticles->setColor(0.5, 0.4, 0.4, 0.5, 0.2 * progress); // grey blue 2
     194                RainEffect::rainParticles->setColor(1,   0.7, 0.7, 0.7, 0.2 * progress); // light grey
     195
     196                // increase radius for more "heavy" rain
     197                RainEffect::rainParticles->setRadius(0, 0.03 * progress);
     198                RainEffect::rainParticles->setRadius(0.2, 0.02 * progress);
     199                RainEffect::rainParticles->setRadius(1, 0.01 * progress);
     200
     201                // increase sound volume
     202                // this->soundSource.fadein(this->rainBuffer, 10);
     203        }
     204       
     205}
     206
     207void RainEffect::startRaining() {
     208
     209        if (this->rainActivate)
     210                this->deactivate();
     211
     212        this->rainStartDuration = 10;
     213        this->localTimer = 0;
     214        this->activate();
     215
     216}
  • trunk/src/lib/graphics/effects/rain_effect.h

    r7810 r8255  
    1414class SparkParticles;
    1515class PlainEmitter;
     16class LightManager;
    1617
    1718#include "weather_effect.h"
     
    3435                virtual bool deactivate();
    3536
    36                 void activateRain();
    37                 void deactivateRain();
     37                virtual void tick(float dt);
    3838
    39                 virtual void tick(float dt);
     39                inline void activateRain() { this->activate(); }
     40                inline void deactivateRain() { this->deactivate(); }
     41                void startRaining();
    4042
    4143                inline void setRainCoord(float x, float y, float z) { this->rainCoord = Vector(x, y, z); }
     
    4547                inline void setRainLife(float life) { this->rainLife = life; }
    4648                inline void setRainWind(int force) { this->rainWindForce = force; }
    47                 inline void setRainOption(const std::string& option) { if (option == "moverain") this->rainMove = true; }
     49                inline void setRainStart(float duration) { this->rainStartDuration = duration; }
     50
     51                inline void setRainOption(const std::string& option) {
     52                        if (option == "moverain") this->rainMove = true;
     53                        if (option == "activate") this->rainActivate = true;
     54                }
    4855
    4956
    5057        private:
    51                 static SparkParticles*                                          rainParticles;
    52                 ParticleEmitter*                                                                        emitter;
     58                static SparkParticles*                  rainParticles;
     59                ParticleEmitter*                        emitter;
    5360
    54                 Vector                                                                                                          rainCoord;
    55                 Vector2D                                                                                                        rainSize;
    56                 GLfloat                                                                                                         rainRate;
    57                 GLfloat                                                                                                         rainVelocity;
    58                 GLfloat                                                                                                         rainLife;
    59                 GLfloat                                                                                                         rainMaxParticles;
    60                 int                                                                                                                             rainWindForce;
    61                 bool                                                                                                                    rainMove;
     61                float                                   localTimer;
     62
     63                Vector                                  rainCoord;
     64                Vector2D                                rainSize;
     65                GLfloat                                 rainRate;
     66                GLfloat                                 rainVelocity;
     67                GLfloat                                 rainLife;
     68                GLfloat                                 rainMaxParticles;
     69                int                                     rainWindForce;
     70                GLfloat                                 rainStartDuration;
     71                bool                                    rainMove;
     72                bool                                    rainActivate;
    6273
    6374                OrxSound::SoundSource                   soundSource;
    6475                OrxSound::SoundBuffer*                  rainBuffer;
    6576                OrxSound::SoundBuffer*                  windBuffer;
     77
     78                float                                   soundRainVolume;
     79
     80                LightManager*                           lightMan;
     81                GLfloat                                 rainAmbient;
     82
    6683};
    6784
    68 
    6985#endif  /* _RAIN_EFFECT */
  • trunk/src/lib/graphics/effects/snow_effect.cc

    r7810 r8255  
    5353        }
    5454
    55         this->activate();
     55        if(snowActivate)
     56                this->activate();
    5657}
    5758
     
    7576        LoadParam(root, "emissionRate", this, SnowEffect, emissionRate);
    7677        LoadParam(root, "emissionVelocity", this, SnowEffect, emissionVelocity);
    77   LoadParam(root, "wind", this, SnowEffect, wind);
     78        LoadParam(root, "wind", this, SnowEffect, wind);
    7879        LoadParam(root, "size", this, SnowEffect, size);
    7980        LoadParam(root, "coord", this, SnowEffect, coord);
     81 
     82        LOAD_PARAM_START_CYCLE(root, element);
     83        {
     84                LoadParam_CYCLE(element, "option", this, SnowEffect, setSnowOption);
     85        }
     86        LOAD_PARAM_END_CYCLE(element);
    8087}
    8188
     
    8592
    8693        // Default values
     94        this->snowActivate = false;
     95        this->snowMove = false;
    8796        this->particles = 12000;
    8897        this->texture = "maps/snow_flake_01_32x32.png";
     
    100109        this->alpha = 0.5;
    101110        this->snowSize = Vector2D(2500, 2500);
    102   this->snowCoord = Vector(100,450,400);
     111        this->snowCoord = Vector(100,450,400);
    103112        this->snowWindForce = 1;
    104 
    105         this->activated = false;
    106113}
    107114
     
    109116{
    110117        PRINTF(0)("Activating SnowEffect\n");
    111         activated = true;
     118
     119        this->snowActivate = true;
    112120
    113121        SnowEffect::snowParticles = new SpriteParticles(particles);
     
    131139        this->emitter->setSize(snowSize);
    132140
    133   //SnowEffect::snowParticles->precache(8);
     141        // SnowEffect::snowParticles->precache(8);
    134142
    135143        if (this->snowWindForce > 1)
     
    141149{
    142150        PRINTF(0)("Deactivating SnowEffect\n");
    143         activated = false;
    144 
     151
     152        this->snowActivate = false;
    145153        this->emitter->setSystem(NULL);
    146154
     
    150158}
    151159
    152 void SnowEffect::activateSnow()
    153 {
     160void SnowEffect::draw() const
     161{
     162        if (!this->snowActivate)
     163                return;
     164}
     165
     166void SnowEffect::tick(float dt)
     167{
     168        if (!this->snowActivate)
     169                return;
     170
     171        /*
     172        float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len();
     173       
     174        if(activated)
     175        {
     176        if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y)
     177                        this->deactivate();
     178        else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y)
     179        this->alpha = 0.15;
     180        else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y)
     181        this->alpha = 0.25;
     182        else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y)
     183        this->alpha = 0.4;
     184       
     185        SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
     186        SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
     187        SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
     188        }
     189        else
     190        {
     191        if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y )
    154192        this->activate();
    155 }
    156 
    157 void SnowEffect::deactivateSnow()
    158 {
    159         this->deactivate();
    160 }
    161 
    162 void SnowEffect::draw() const
    163 {
    164 }
    165 
    166 void SnowEffect::tick(float dt)
    167 {
    168   float distance = (State::getCameraNode()->getAbsCoor() - Vector(snowCoord.x, State::getCameraNode()->getAbsCoor().y, snowCoord.z)).len();
    169  
    170   if(activated)
    171   {
    172     if(distance > 0.3*snowSize.x || distance > 0.3*snowSize.y)
    173                   this->deactivate();
    174     else if(distance > 0.25*snowSize.x || distance > 0.25*snowSize.y)
    175       this->alpha = 0.15;
    176     else if(distance > 0.2*snowSize.x || distance > 0.2*snowSize.y)
    177       this->alpha = 0.25;
    178     else if(distance > 0.1*snowSize.x || distance > 0.1*snowSize.y)
    179       this->alpha = 0.4;
    180 
    181     SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
    182     SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
    183     SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
    184   }
    185   else
    186   {
    187   if(distance < 0.3*snowSize.x || distance < 0.3*snowSize.y )
    188     this->activate();
    189   if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y )
    190     this->alpha = 0.25;
    191   else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y )
    192     this->alpha = 0.4;
    193   else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y )
    194     this->alpha = 0.5;
    195 
    196     SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
    197     SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
    198     SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
    199   }
    200 }
    201 
     193        if( distance < 0.25*snowSize.x || distance < 0.25*snowSize.y )
     194        this->alpha = 0.25;
     195        else if( distance < 0.2*snowSize.x || distance < 0.2*snowSize.y )
     196        this->alpha = 0.4;
     197        else if( distance < 0.1*snowSize.x || distance < 0.1*snowSize.y )
     198        this->alpha = 0.5;
     199       
     200        SnowEffect::snowParticles->setColor(0,1, 1, 1, alpha);
     201        SnowEffect::snowParticles->setColor(.5, .6, .6, .6, alpha/2);
     202        SnowEffect::snowParticles->setColor(1, .0, .0, .0, .0);
     203        }*/
     204
     205        if (this->snowMove) {
     206                this->snowCoord = State::getCameraNode()->getAbsCoor();
     207                this->emitter->setRelCoor(this->snowCoord.x , this->snowCoord.y+300, this->snowCoord.z);
     208        }
     209}
  • trunk/src/lib/graphics/effects/snow_effect.h

    r7810 r8255  
    3333                virtual bool deactivate();
    3434
     35                inline void activateSnow() { this->activate(); }
     36                inline void deactivateSnow() { this->deactivate(); }
     37               
    3538                virtual void draw() const;
    3639                virtual void tick(float dt);
    3740
    38                 void activateSnow();
    39                 void deactivateSnow();
    4041
    4142                inline void numParticles(int n) { this->particles = n; }
     
    4849                inline void size(float sizeX, float sizeY) { this->snowSize = Vector2D(sizeX, sizeY); }
    4950                inline void coord(float x, float y, float z) { this->snowCoord = Vector(x, y, z); }
    50     inline void wind(int force) { this->snowWindForce = force; }
     51                inline void wind(int force) { this->snowWindForce = force; }
     52
     53                inline void setSnowOption(const std::string& option) {
     54                        /*if (option == "fade") this->snowFade = true;*/
     55                        if (option == "movesnow") this->snowMove = true;
     56                        if (option == "activate") this->snowActivate = true;
     57                }
    5158
    5259
    5360        private:
    54                 int                                                                                                                             particles;
    55                 std::string                                                                                             texture;
    56                 float                                                                                                                   life, randomLife;
    57                 float                                                                                                                           snowRadius, randomRadius;
    58                 float                                                                                                                           snowMass, randomMass;
    59                 float                                                                                                                   rate;
    60                 float                                                                                                                   velocity, randomVelocity;
    61                 float                                                                                                                   angle, randomAngle;
    62                 float                                                                                                                   alpha;
    63                 Vector                                                                                                                  snowCoord;
    64                 Vector2D                                                                                                                snowSize;
    65                 int                                                                                                                                     snowWindForce;
     61                int                             particles;
     62                std::string                     texture;
     63                float                           life, randomLife;
     64                float                           snowRadius, randomRadius;
     65                float                           snowMass, randomMass;
     66                float                           rate;
     67                float                           velocity, randomVelocity;
     68                float                           angle, randomAngle;
     69                float                           alpha;
     70                Vector                          snowCoord;
     71                Vector2D                        snowSize;
     72                int                             snowWindForce;
    6673
    67                 bool                                                                                                                            activated;
     74                bool                            snowMove;
     75                bool                            snowActivate;
    6876
    69                 PlaneEmitter*                                                                                           emitter;
     77                PlaneEmitter*                   emitter;
    7078
    71                 static SpriteParticles*                                                 snowParticles;
    72                 OrxSound::SoundSource              soundSource;
    73                 OrxSound::SoundBuffer*             windBuffer;
     79                static SpriteParticles*         snowParticles;
     80                OrxSound::SoundSource           soundSource;
     81                OrxSound::SoundBuffer*          windBuffer;
    7482
    7583};
  • trunk/src/lib/graphics/effects/weather_effect.cc

    r7810 r8255  
    1515*/
    1616
     17// TODO: descriptions to loadparams, movealong unified, start activation
    1718
    1819#include "weather_effect.h"
  • trunk/src/lib/graphics/light.h

    r6512 r8255  
    11/*!
    2  * @file light.h
    3   *  Handles Lights.
     2* @file light.h
     3*  Handles Lights.
    44
    5     A Light is one of the more important things in a 3D-environment,
    6     without it one sees nothing :)
    7     It is here for diffuse-, specular- and Bump-Mappings.
     5A Light is one of the more important things in a 3D-environment,
     6without it one sees nothing :)
     7It is here for diffuse-, specular- and Bump-Mappings.
    88*/
    99
     
    2525class Light : public PNode
    2626{
    27  public:
    28   Light(const TiXmlElement* root = NULL);
    29   virtual ~Light();
    30 
    31   virtual void loadParams(const TiXmlElement* root);
    32 
    33   void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
    34   void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
    35   void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
    36   void setSpotDirection(const Vector& direction);
    37   void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); };
    38   void setSpotCutoff(GLfloat cutoff);
    39 
    40   /** @returns the lightNumber*/
    41   int getLightNumber() const {return this->lightNumber;}
    42 
    43   virtual void draw() const;
    44 
    45   void debug() const;
    46 
    47   // attributes
    48  private:
    49   int              lightNumber;               //!< The number of this Light.
    50   GLfloat          diffuseColor[4];           //!< The Diffuse Color this Light emmits.
    51   GLfloat          specularColor[4];          //!< The specular Color of this Light.
    52   float            constantAttenuation;       //!< The Factor of the the Constant Attenuation.
    53   float            linearAttenuation;         //!< The Factor of the the Linear Attenuation.
    54   float            quadraticAttenuation;      //!< The Factor of the the Quadratic Attenuation.
    55   GLfloat          spotDirection[4];          //!< The direction of the Spot Light.
    56   GLfloat          spotCutoff;                //!< The cutoff Angle of the Light Source
     27        public:
     28                Light(const TiXmlElement* root = NULL);
     29                virtual ~Light();
     30               
     31                virtual void loadParams(const TiXmlElement* root);
     32               
     33                void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
     34                void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
     35                void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
     36                void setSpotDirection(const Vector& direction);
     37                void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); };
     38                void setSpotCutoff(GLfloat cutoff);
     39               
     40                /** @returns the lightNumber*/
     41                int getLightNumber() const {return this->lightNumber;}
     42               
     43                virtual void draw() const;
     44               
     45                void debug() const;
     46       
     47        // attributes
     48        private:
     49                int              lightNumber;               //!< The number of this Light.
     50                GLfloat          diffuseColor[4];           //!< The Diffuse Color this Light emmits.
     51                GLfloat          specularColor[4];          //!< The specular Color of this Light.
     52                float            constantAttenuation;       //!< The Factor of the the Constant Attenuation.
     53                float            linearAttenuation;         //!< The Factor of the the Linear Attenuation.
     54                float            quadraticAttenuation;      //!< The Factor of the the Quadratic Attenuation.
     55                GLfloat          spotDirection[4];          //!< The direction of the Spot Light.
     56                GLfloat          spotCutoff;                //!< The cutoff Angle of the Light Source
    5757};
    58 
    59 
    60 
     58       
     59       
     60       
    6161//! A class that handles Lights
    6262/**
    63    A Light is a source that emits light rays (photons)
     63A Light is a source that emits light rays (photons)
    6464
    65    <b>Usage:</b>\n
    66    First you have to get the Light Manager up and running by using LightManager::getInstance().
    67    This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n
    68    Then you will create a new light using:
    69    \li new Light();
     65<b>Usage:</b>\n
     66First you have to get the Light Manager up and running by using LightManager::getInstance().
     67This automatically initiates the GL_LIGHTING, and sets some default stuff about the light.\n
     68Then you will create a new light using:
     69\li new Light();
    7070
    71    if you want to operate on this Light just apply the following functions onto it.
    72        (You can also optain the Light-pointer with LightManager::getInstance()->getLight(lightNumber))
     71if you want to operate on this Light just apply the following functions onto it.
     72(You can also optain the Light-pointer with LightManager::getInstance()->getLight(lightNumber))
    7373
    74    now you can operate on the light as follows:
    75    \li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
    76    \li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
    77    \li void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
    78    \li void setSpotDirection(Vector direction);
    79    \li void setSpotCutoff(GLfloat cutoff);
    80    \li all PNode stuff also works
     74now you can operate on the light as follows:
     75\li void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b);
     76\li void setSpecularColor(GLfloat r, GLfloat g, GLfloat b);
     77\li void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation);
     78\li void setSpotDirection(Vector direction);
     79\li void setSpotCutoff(GLfloat cutoff);
     80\li all PNode stuff also works
    8181
    82    To redraw the light use
    83    \li void draw() const; (this is automatically done by the LightManager)
     82To redraw the light use
     83\li void draw() const; (this is automatically done by the LightManager)
    8484
    85    for some nice output just use:
    86    \li void debug() const; (either on LightManager for a resume or on any Light for single information.)
     85for some nice output just use:
     86\li void debug() const; (either on LightManager for a resume or on any Light for single information.)
    8787*/
    8888class LightManager : public BaseObject
    89 {
    90   friend class Light;
     89        {
     90        friend class Light;
    9191
    92  public:
    93   virtual ~LightManager();
    94   /** @returns a Pointer to the only object of this Class */
    95   inline static LightManager* getInstance() { if (!singletonRef) singletonRef = new LightManager();  return singletonRef; };
     92        public:
     93                virtual ~LightManager();
     94                /** @returns a Pointer to the only object of this Class */
     95                inline static LightManager* getInstance() { if (!singletonRef) singletonRef = new LightManager();  return singletonRef; };
    9696
    97   virtual void loadParams(const TiXmlElement* root);
    98   void loadLights(const TiXmlElement* root);
     97                virtual void loadParams(const TiXmlElement* root);
     98                void loadLights(const TiXmlElement* root);
    9999
    100   void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
     100                void setAmbientColor(GLfloat r, GLfloat g, GLfloat b);
     101                // HACK: Assuming r = g = b values
     102                inline GLfloat getAmbientColor() {  return this->ambientColor[0]; }
    101103
    102   Light* getLight(int lightNumber) const;
    103   inline Light* getLight() const { return this->currentLight; };
     104                Light* getLight(int lightNumber) const;
     105                inline Light* getLight() const { return this->currentLight; };
    104106
    105   void draw() const;
     107                void draw() const;
    106108
    107   void debug() const;
     109                void debug() const;
    108110
    109  private:
    110   LightManager();
     111        private:
     112                LightManager();
    111113
    112   int  registerLight(Light* light);
    113   void unregisterLight(Light* light);
     114                int  registerLight(Light* light);
     115                void unregisterLight(Light* light);
    114116
    115  private:
    116   static LightManager*    singletonRef;       //!< This is the LightHandlers Reference.
    117   GLfloat                 ambientColor[4];    //!< The ambient Color of the scene.
     117        private:
     118                static LightManager*    singletonRef;       //!< This is the LightHandlers Reference.
     119                GLfloat                 ambientColor[4];    //!< The ambient Color of the scene.
    118120
    119   Light**                 lights;             //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues.
    120   Light*                  currentLight;       //!< The current Light, we are working with.
     121                Light**                 lights;             //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues.
     122                Light*                  currentLight;       //!< The current Light, we are working with.
    121123
    122124};
  • trunk/src/lib/graphics/shader.cc

    r8037 r8255  
    201201}
    202202
     203void Shader::bindShader(const char* name, const float* value, size_t size)
     204{
     205        if (likely (this->shaderProgram != 0)) {
     206                glUseProgramObjectARB(this->shaderProgram);
     207
     208                unsigned int location = glGetUniformLocationARB(this->shaderProgram, name);
     209                /* This is EXPENSIVE and should be avoided. */
     210
     211                if      (size == 1)  glUniform1fvARB(location, 1, value);
     212                else if (size == 2)  glUniform2fvARB(location, 1, value);
     213                else if (size == 3)  glUniform3fvARB(location, 1, value);
     214                else if (size == 4)  glUniform4fvARB(location, 1, value);
     215                else if (size == 9)  glUniformMatrix3fvARB(location, 1, false, value);
     216                else if (size == 16) glUniformMatrix4fvARB(location, 1, false, value);
     217
     218        }
     219}
     220
    203221void Shader::deactivateShader()
    204222{
  • trunk/src/lib/graphics/shader.h

    r8037 r8255  
    9696  static bool checkShaderAbility();
    9797  void activateShader();
     98  void bindShader(const char* name, const float* value, size_t size);
    9899  static void deactivateShader();
    99100
  • trunk/src/lib/sound/sound_source.cc

    r7810 r8255  
    11/*
    2    orxonox - the future of 3D-vertical-scrollers
    3 
    4    Copyright (C) 2004 orx
    5 
    6    This program is free software; you can redistribute it and/or modify
    7    it under the terms of the GNU General Public License as published by
    8    the Free Software Foundation; either version 2, or (at your option)
    9    any later version.
    10 
    11    ### File Specific:
    12    main-programmer: Benjamin Grauer
    13    co-programmer: ...
     2        orxonox - the future of 3D-vertical-scrollers
     3
     4        Copyright (C) 2004 orx
     5
     6        This program is free software; you can redistribute it and/or modify
     7        it under the terms of the GNU General Public License as published by
     8        the Free Software Foundation; either version 2, or (at your option)
     9        any later version.
     10
     11        ### File Specific:
     12        main-programmer: Benjamin Grauer
     13        co-programmer: ...
    1414*/
    1515
     
    2424namespace OrxSound
    2525{
    26   /**
    27    * @brief creates a SoundSource at position sourceNode with the SoundBuffer buffer
    28    */
    29   SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)
    30   {
    31     this->setClassID(CL_SOUND_SOURCE, "SoundSource");
    32 
    33     // adding the Source to the SourcesList of the SoundEngine
    34     this->buffer = buffer;
    35     this->sourceNode = sourceNode;
    36     this->resident = false;
    37 
    38     this->sourceID = 0;
    39     this->bPlay = false;
    40   }
    41 
    42 
    43   /**
    44    * @brief construct a SoundSource out of the another soundSource
    45    * @param source the Source to create this source from.
    46    *
    47    * Copies the buffer from source to this Source.
    48    * Acquires a new SourceID if source is Playing.
    49    */
    50   SoundSource::SoundSource(const SoundSource& source)
    51   {
    52     this->setClassID(CL_SOUND_SOURCE, "SoundSource");
    53 
    54     // adding the Source to the SourcesList of the SoundEngine
    55     this->buffer = source.buffer;
    56     this->sourceNode = source.sourceNode;
    57     this->resident = source.resident;
    58 
    59     this->sourceID = 0;
    60     if (source.bPlay == true)
    61     {
    62       this->bPlay = true;
    63       SoundEngine::getInstance()->popALSource(this->sourceID);
    64     }
    65     else
    66       this->bPlay = false;
    67   }
    68 
    69 
    70   /**
    71    * @brief paste a copy of the source into this Source.
    72    * @param source the SoundSource to paste into this one.
    73    * @returns a Reference to this Source.
    74    *
    75    */
    76   SoundSource& SoundSource::operator=(const SoundSource& source)
    77   {
    78     this->buffer = source.buffer;
    79     this->sourceNode = sourceNode;
    80     this->resident = source.resident;
    81 
    82     if (source.bPlay)
    83       this->play();
    84     else
    85       this->stop();
    86   }
    87 
    88 
    89   /**
    90    * @brief compares two Sources with each other.
    91    * @param source the Source to compare against this One.
    92    * Two Sources are the same, if the PNodes match, and the Sound Played are the same.
    93    * The alSource must not match, because no two Sources can have the same alSource.
    94    */
    95   bool SoundSource::operator==(const SoundSource& source)
    96   {
    97     return (this->buffer == source.buffer &&
    98             this->bPlay == source.bPlay &&
    99             this->sourceNode == source.sourceNode);
    100   }
    101 
    102 
    103   /**
    104    * @brief deletes a SoundSource
    105    */
    106   SoundSource::~SoundSource()
    107   {
    108     this->stop();
    109     if (this->sourceID != 0)
    110       SoundEngine::getInstance()->pushALSource(this->sourceID);
    111   }
    112 
    113 
    114   /**
    115    * @brief Plays back a SoundSource
    116    */
    117   void SoundSource::play()
    118   {
    119     if (this->buffer && this->retrieveSource())
    120     {
    121       if (this->bPlay)
    122         alSourceStop(this->sourceID);
    123       alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
    124     alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE  );
    125     alSourcePlay(this->sourceID);
    126 
    127       if (DEBUG_LEVEL >= 3)
    128         SoundEngine::checkError("Play Source", __LINE__);
    129       this->bPlay = true;
    130     }
    131   }
    132 
    133 
    134   /**
    135    * @brief Plays back buffer on this Source
    136    * @param buffer the buffer to play back on this Source
    137    */
    138   void SoundSource::play(const SoundBuffer* buffer)
    139   {
    140     if (!this->retrieveSource())
    141     {
    142       PRINTF(3)("No more Free sources (You might consider raising the Source-Count).\n");
    143       return;
    144     }
    145 
    146   alSourceStop(this->sourceID);
    147   alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
    148   alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE  );
    149   alSourcePlay(this->sourceID);
    150 
    151     if (unlikely(this->buffer != NULL))
    152       alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
    153     this->bPlay = true;
    154 
    155     if (DEBUG_LEVEL >= 3)
    156       SoundEngine::checkError("Play Source", __LINE__);
    157   }
    158 
    159 
    160 /**
    161  * @brief Plays and loops buffer on this Source
    162  * @param buffer the buffer to play back on this Source
    163  */
    164 void SoundSource::loop(const SoundBuffer* buffer)
    165 {
    166   if (this->buffer && this->retrieveSource())
    167   {
    168     if (this->bPlay)
    169       alSourceStop(this->sourceID);
    170 
    171     alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
    172     alSourcei (this->sourceID, AL_LOOPING,  AL_TRUE  );
    173     alSourcePlay(this->sourceID);
    174 
    175     if (DEBUG_LEVEL >= 3)
    176       SoundEngine::checkError("Play LoopSource", __LINE__);
    177     this->bPlay = true;
    178   }
     26        /**
     27        * @brief creates a SoundSource at position sourceNode with the SoundBuffer buffer
     28        */
     29        SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)
     30        {
     31                this->setClassID(CL_SOUND_SOURCE, "SoundSource");
     32
     33                // adding the Source to the SourcesList of the SoundEngine
     34                this->buffer = buffer;
     35                this->sourceNode = sourceNode;
     36                this->resident = false;
     37
     38                this->sourceID = 0;
     39                this->bPlay = false;
     40        }
     41
     42
     43        /**
     44        * @brief construct a SoundSource out of the another soundSource
     45        * @param source the Source to create this source from.
     46        *
     47        * Copies the buffer from source to this Source.
     48        * Acquires a new SourceID if source is Playing.
     49        */
     50        SoundSource::SoundSource(const SoundSource& source)
     51        {
     52                this->setClassID(CL_SOUND_SOURCE, "SoundSource");
     53
     54                // adding the Source to the SourcesList of the SoundEngine
     55                this->buffer = source.buffer;
     56                this->sourceNode = source.sourceNode;
     57                this->resident = source.resident;
     58
     59                this->sourceID = 0;
     60                if (source.bPlay == true)
     61                {
     62                        this->bPlay = true;
     63                        SoundEngine::getInstance()->popALSource(this->sourceID);
     64                }
     65                else
     66                        this->bPlay = false;
     67        }
     68
     69
     70        /**
     71        * @brief paste a copy of the source into this Source.
     72        * @param source the SoundSource to paste into this one.
     73        * @returns a Reference to this Source.
     74        *
     75        */
     76        SoundSource& SoundSource::operator=(const SoundSource& source)
     77        {
     78                this->buffer = source.buffer;
     79                this->sourceNode = sourceNode;
     80                this->resident = source.resident;
     81
     82                if (source.bPlay)
     83                        this->play();
     84                else
     85                        this->stop();
     86        }
     87
     88
     89        /**
     90        * @brief compares two Sources with each other.
     91        * @param source the Source to compare against this One.
     92        * Two Sources are the same, if the PNodes match, and the Sound Played are the same.
     93        * The alSource must not match, because no two Sources can have the same alSource.
     94        */
     95        bool SoundSource::operator==(const SoundSource& source)
     96        {
     97                return (this->buffer == source.buffer &&
     98                                                this->bPlay == source.bPlay &&
     99                                                this->sourceNode == source.sourceNode);
     100        }
     101
     102
     103        /**
     104        * @brief deletes a SoundSource
     105        */
     106        SoundSource::~SoundSource()
     107        {
     108                this->stop();
     109                if (this->sourceID != 0)
     110                        SoundEngine::getInstance()->pushALSource(this->sourceID);
     111        }
     112
     113
     114        /**
     115        * @brief Plays back a SoundSource
     116        */
     117        void SoundSource::play()
     118        {
     119                if (this->buffer && this->retrieveSource())
     120                {
     121                        if (this->bPlay)
     122                                alSourceStop(this->sourceID);
     123                       
     124                        alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     125                        alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE);
     126                        alSourcef (this->sourceID, AL_GAIN, 1);
     127                        alSourcePlay(this->sourceID);
     128
     129                        if (DEBUG_LEVEL >= 3)
     130                                SoundEngine::checkError("Play Source", __LINE__);
     131                        this->bPlay = true;
     132                }
     133        }
     134
     135
     136        /**
     137        * @brief Plays back buffer on this Source
     138        * @param buffer the buffer to play back on this Source
     139        */
     140        void SoundSource::play(const SoundBuffer* buffer)
     141        {
     142                if (!this->retrieveSource())
     143                {
     144                        PRINTF(3)("No more Free sources (You might consider raising the Source-Count).\n");
     145                        return;
     146                }
     147
     148                alSourceStop(this->sourceID);
     149                alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     150                alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE);
     151                alSourcef (this->sourceID, AL_GAIN, 1);
     152
     153                alSourcePlay(this->sourceID);
     154
     155                if (unlikely(this->buffer != NULL))
     156                        alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     157                this->bPlay = true;
     158
     159                if (DEBUG_LEVEL >= 3)
     160                        SoundEngine::checkError("Play Source", __LINE__);
     161        }
     162
     163
     164        /**
     165        * @brief Plays back buffer on this Source with gain
     166        * @param buffer the buffer to play back on this Source
     167        */
     168        void SoundSource::play(const SoundBuffer* buffer, float gain)
     169        {
     170                if (!this->retrieveSource())
     171                {
     172                        PRINTF(3)("No more Free sources (You might consider raising the Source-Count).\n");
     173                        return;
     174                }
     175
     176                alSourceStop(this->sourceID);
     177                alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
     178                alSourcei (this->sourceID, AL_LOOPING,  AL_FALSE);
     179                alSourcef (this->sourceID, AL_GAIN, gain);
     180
     181                alSourcePlay(this->sourceID);
     182
     183                if (unlikely(this->buffer != NULL))
     184                        alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     185                this->bPlay = true;
     186
     187                if (DEBUG_LEVEL >= 3)
     188                        SoundEngine::checkError("Play Source", __LINE__);
     189        }
     190
     191
     192        /**
     193        * @brief Plays and loops back a SoundSource
     194        */
     195        void SoundSource::loop()
     196        {
     197                if (this->buffer && this->retrieveSource())
     198                {
     199                        if (this->bPlay)
     200                                alSourceStop(this->sourceID);
     201                       
     202                        alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     203                        alSourcei (this->sourceID, AL_LOOPING,  AL_TRUE);
     204                        alSourcef (this->sourceID, AL_GAIN, 1);
     205                        alSourcePlay(this->sourceID);
     206
     207                        if (DEBUG_LEVEL >= 3)
     208                                SoundEngine::checkError("Play Source", __LINE__);
     209                        this->bPlay = true;
     210                }
     211        }
     212
     213        /**
     214        * @brief Plays and loops buffer on this Source
     215        * @param buffer the buffer to play back on this Source
     216        */
     217        void SoundSource::loop(const SoundBuffer* buffer)
     218        {
     219                if (this->buffer && this->retrieveSource())
     220                {
     221                        if (this->bPlay)
     222                                alSourceStop(this->sourceID);
     223       
     224                        alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     225                        alSourcei (this->sourceID, AL_LOOPING,  AL_TRUE);
     226                        alSourcef (this->sourceID, AL_GAIN, 1);
     227       
     228                        alSourcePlay(this->sourceID);
     229       
     230                        if (DEBUG_LEVEL >= 3)
     231                                SoundEngine::checkError("Loop Source", __LINE__);
     232                        this->bPlay = true;
     233                }
     234        }
     235       
     236       
     237        /**
     238        * @brief Plays and loops buffer on this Source with gain control
     239        * @param buffer the buffer to play back on this Source
     240        */
     241        void SoundSource::loop(const SoundBuffer* buffer, float gain)
     242        {
     243                if (this->buffer && this->retrieveSource())
     244                {
     245                        if (this->bPlay)
     246                                alSourceStop(this->sourceID);
     247       
     248                        alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
     249                        alSourcei (this->sourceID, AL_LOOPING,  AL_TRUE);
     250                        alSourcef (this->sourceID, AL_GAIN, gain);
     251       
     252                        alSourcePlay(this->sourceID);
     253       
     254                        if (DEBUG_LEVEL >= 3)
     255                                SoundEngine::checkError("Loop Source", __LINE__);
     256                        this->bPlay = true;
     257                }
     258        }
     259       
     260       
     261        /**
     262        * @brief Stops playback of a SoundSource
     263        */
     264        void SoundSource::stop()
     265        {
     266                this->bPlay = false;
     267                if (this->sourceID != 0)
     268                {
     269                        this->bPlay = false;
     270                        if (this->sourceID != 0)
     271                        {
     272                                alSourceStop(this->sourceID);
     273                                if (DEBUG_LEVEL >= 3)
     274                                        SoundEngine::checkError("StopSource", __LINE__);
     275                                alSourcei(this->sourceID, AL_BUFFER, 0);
     276                                if (!this->resident)
     277                                        SoundEngine::getInstance()->pushALSource(this->sourceID);
     278                                this->sourceID = 0;
     279                        }
     280                }
     281        }
     282
     283        /**
     284        * @brief Pauses Playback of a SoundSource
     285        */
     286        void SoundSource::pause()
     287        {
     288                alSourcePause(this->sourceID);
     289                if (DEBUG_LEVEL >= 3)
     290                        SoundEngine::checkError("Pause Source", __LINE__);
     291        }
     292
     293
     294        /**
     295        * @brief Rewinds Playback of a SoundSource
     296        */
     297        void SoundSource::rewind()
     298        {
     299                alSourceRewind(this->sourceID);
     300
     301                if (DEBUG_LEVEL >= 3)
     302                        SoundEngine::checkError("Rewind Source", __LINE__);
     303        }
     304
     305
     306        /**
     307        * @brief sets the RolloffFactor of the Sound emitted from the SoundSource
     308        * @param rolloffFactor The Factor described
     309        *
     310        * this tells openAL how fast the Sounds decay outward from the Source
     311        */
     312        void SoundSource::setRolloffFactor(ALfloat rolloffFactor)
     313        {
     314                alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor);
     315
     316                if (DEBUG_LEVEL >= 3)
     317                        SoundEngine::checkError("Set Source Rolloff-factor", __LINE__);
     318        }
     319
     320
     321        /**
     322        * @brief sets the Positional this Source should be attached to.
     323        * @param sourceNode the Source this is attached to.
     324        * If sourceNode == NULL then the Source will be centered, and Audio will be played on all channels.
     325        */
     326        void SoundSource::setSourceNode(const PNode* sourceNode)
     327        {
     328                this->sourceNode = sourceNode;
     329        }
     330
     331        /**
     332        * @brief retrieve a Source.
     333        */
     334        bool SoundSource::retrieveSource()
     335        {
     336                if (this->sourceID != 0)
     337                        return true;
     338                else
     339                {
     340                        SoundEngine::getInstance()->popALSource(this->sourceID);
     341                        if (this->sourceID != 0)
     342                        {
     343                                if (unlikely(this->sourceNode == NULL))
     344                                        resetSource(this->sourceID);
     345                                return true;
     346                        }
     347                }
     348                return false;
     349        }
     350
     351
     352        /**
     353        * @brief reset an alSource to its default Values.
     354        */
     355        void SoundSource::resetSource(ALuint sourceID)
     356        {
     357                alSource3f(sourceID, AL_POSITION,        0.0, 0.0, 0.0);
     358                alSource3f(sourceID, AL_VELOCITY,        0.0, 0.0, 0.0);
     359                alSource3f(sourceID, AL_DIRECTION,       0.0, 0.0, 0.0);
     360                alSourcef (sourceID, AL_ROLLOFF_FACTOR,  0.0          );
     361                //alSourcei (sourceID, AL_SOURCE_RELATIVE, AL_TRUE      );
     362                alSourcef (sourceID, AL_GAIN,            SoundEngine::getInstance()->getEffectsVolume());
     363        }
     364
     365
     366        /**
     367        * @brief Fades in a Source over a time period
     368        * @param duration time perios to fade in
     369        */
     370        void SoundSource::fadein(const SoundBuffer* buffer, ALfloat duration)
     371        {
     372                //if (this->buffer && this->retrieveSource())
     373                //{
     374
     375                for (ALfloat n = 0.0; n < 1.0; n+=.01)
     376                {
     377                        alSourcef(this->sourceID, AL_GAIN, n);
     378                        // sleep(1);
     379                }
     380
     381                //      alSourcePlay(this->sourceID);
     382       
     383                //      if (DEBUG_LEVEL >= 3)
     384                //              SoundEngine::checkError("Loop Source", __LINE__);
     385                //      this->bPlay = true;
     386                //}
     387
     388        }
     389
     390
    179391}
    180 
    181 
    182 /**
    183  * @brief Stops playback of a SoundSource
    184  */
    185 void SoundSource::stop()
    186 {
    187   this->bPlay = false;
    188   if (this->sourceID != 0)
    189   {
    190     this->bPlay = false;
    191     if (this->sourceID != 0)
    192     {
    193       alSourceStop(this->sourceID);
    194       if (DEBUG_LEVEL >= 3)
    195         SoundEngine::checkError("StopSource", __LINE__);
    196       alSourcei(this->sourceID, AL_BUFFER, 0);
    197       if (!this->resident)
    198         SoundEngine::getInstance()->pushALSource(this->sourceID);
    199       this->sourceID = 0;
    200     }
    201   }
    202 }
    203 
    204   /**
    205    * @brief Pauses Playback of a SoundSource
    206    */
    207   void SoundSource::pause()
    208   {
    209     alSourcePause(this->sourceID);
    210     if (DEBUG_LEVEL >= 3)
    211       SoundEngine::checkError("Pause Source", __LINE__);
    212   }
    213 
    214 
    215   /**
    216    * @brief Rewinds Playback of a SoundSource
    217    */
    218   void SoundSource::rewind()
    219   {
    220     alSourceRewind(this->sourceID);
    221 
    222     if (DEBUG_LEVEL >= 3)
    223       SoundEngine::checkError("Rewind Source", __LINE__);
    224   }
    225 
    226 
    227   /**
    228    * @brief sets the RolloffFactor of the Sound emitted from the SoundSource
    229    * @param rolloffFactor The Factor described
    230    *
    231    * this tells openAL how fast the Sounds decay outward from the Source
    232    */
    233   void SoundSource::setRolloffFactor(ALfloat rolloffFactor)
    234   {
    235     alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor);
    236 
    237     if (DEBUG_LEVEL >= 3)
    238       SoundEngine::checkError("Set Source Rolloff-factor", __LINE__);
    239   }
    240 
    241 
    242   /**
    243    * @brief sets the Positional this Source should be attached to.
    244    * @param sourceNode the Source this is attached to.
    245    * If sourceNode == NULL then the Source will be centered, and Audio will be played on all channels.
    246    */
    247   void SoundSource::setSourceNode(const PNode* sourceNode)
    248   {
    249     this->sourceNode = sourceNode;
    250   }
    251 
    252   /**
    253    * @brief retrieve a Source.
    254    */
    255   bool SoundSource::retrieveSource()
    256   {
    257     if (this->sourceID != 0)
    258       return true;
    259     else
    260     {
    261       SoundEngine::getInstance()->popALSource(this->sourceID);
    262       if (this->sourceID != 0)
    263       {
    264         if (unlikely(this->sourceNode == NULL))
    265           resetSource(this->sourceID);
    266         return true;
    267       }
    268     }
    269     return false;
    270   }
    271 
    272 
    273   /**
    274    * @brief reset an alSource to its default Values.
    275    */
    276   void SoundSource::resetSource(ALuint sourceID)
    277   {
    278     alSource3f(sourceID, AL_POSITION,        0.0, 0.0, 0.0);
    279     alSource3f(sourceID, AL_VELOCITY,        0.0, 0.0, 0.0);
    280     alSource3f(sourceID, AL_DIRECTION,       0.0, 0.0, 0.0);
    281     alSourcef (sourceID, AL_ROLLOFF_FACTOR,  0.0          );
    282     //alSourcei (sourceID, AL_SOURCE_RELATIVE, AL_TRUE      );
    283     alSourcef (sourceID, AL_GAIN,            SoundEngine::getInstance()->getEffectsVolume());
    284   }
    285 }
  • trunk/src/lib/sound/sound_source.h

    r7810 r8255  
    11/*!
    2  * @file sound_source.h
    3  * @brief Definition of the SoundSource.
     2* @file sound_source.h
     3* @brief Definition of the SoundSource.
    44*/
    55
     
    1414namespace OrxSound
    1515{
    16   class SoundBuffer;
    17   //! A class that represents a SoundSource
    18   class SoundSource : public BaseObject
    19   {
    20   public:
    21     SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);
    22     SoundSource(const SoundSource& source);
    23     SoundSource& operator=(const SoundSource& source);
    24     bool operator==(const SoundSource& source);
    25 
    26     virtual ~SoundSource();
    27 
    28     // user interaction
    29     void play();
    30     void play(const SoundBuffer* buffer);
    31     void loop();
    32     void loop(const SoundBuffer* buffer);
    33     void stop();
    34     void pause();
    35     void rewind();
    36 
    37     // development functions
    38     /** @returns The ID of this Source */
    39     inline ALuint getID() const { return this->sourceID; };
    40     /** @returns true, if the Source is Playing */
    41     inline bool   isPlaying() const { return this->bPlay; };
    42     void setSourceNode(const PNode* sourceNode);
    43     /** @returns the SoundBuffer of this Source */
    44     inline const SoundBuffer* getBuffer() const { return this->buffer; };
    45     /** @returns the SourceNode of this Source */
    46     inline const PNode* getNode() const { return this->sourceNode; };
    47     /** @param resident if the Source is Resident */
    48     inline void setResident(bool resident) { this->resident = resident; };
    49     /** @returns true if the alSource is Resident */
    50     inline bool isResident() const { return this->resident; };
    51 
    52     void setRolloffFactor(ALfloat rolloffFactor);
    53 
    54     static void resetSource(ALuint sourceID);
    55 
    56   private:
    57     bool retrieveSource();
    58 
    59   private:
    60     bool                   bPlay;                 //!< If the Source is Playing.
    61     bool                   resident;              //!< If the alSource should be resident (if true, the alSource will be returned on deletion).
    62     ALuint                 sourceID;              //!< The ID of the Source
    63     const SoundBuffer*     buffer;                //!< The buffer to play in this source.
    64     const PNode*           sourceNode;            //!< The SourceNode representing the position/velocity... of this source.
    65   };
     16        class SoundBuffer;
     17        //! A class that represents a SoundSource
     18        class SoundSource : public BaseObject
     19        {
     20                public:
     21                        SoundSource(const PNode* sourceNode = NULL, const SoundBuffer* buffer = NULL);
     22                        SoundSource(const SoundSource& source);
     23                        SoundSource& operator=(const SoundSource& source);
     24                        bool operator==(const SoundSource& source);
     25                       
     26                        virtual ~SoundSource();
     27                       
     28                        // user interaction
     29                        void play();
     30                        void play(const SoundBuffer* buffer);
     31                        void play(const SoundBuffer* buffer, float gain);
     32                        void loop();
     33                        void loop(const SoundBuffer* buffer);
     34                        void loop(const SoundBuffer* buffer, float gain);
     35                        void stop();
     36                        void pause();
     37                        void rewind();
     38                        void fadein(const SoundBuffer* buffer, ALfloat duration);
     39                       
     40                       
     41                        // development functions
     42                        /** @returns The ID of this Source */
     43                        inline ALuint getID() const { return this->sourceID; };
     44                        /** @returns true, if the Source is Playing */
     45                        inline bool   isPlaying() const { return this->bPlay; };
     46                        void setSourceNode(const PNode* sourceNode);
     47                        /** @returns the SoundBuffer of this Source */
     48                        inline const SoundBuffer* getBuffer() const { return this->buffer; };
     49                        /** @returns the SourceNode of this Source */
     50                        inline const PNode* getNode() const { return this->sourceNode; };
     51                        /** @param resident if the Source is Resident */
     52                        inline void setResident(bool resident) { this->resident = resident; };
     53                        /** @returns true if the alSource is Resident */
     54                        inline bool isResident() const { return this->resident; };
     55                       
     56                        void setRolloffFactor(ALfloat rolloffFactor);
     57                       
     58                        static void resetSource(ALuint sourceID);
     59               
     60                private:
     61                        bool retrieveSource();
     62                       
     63                private:
     64                        bool                   bPlay;           //!< If the Source is Playing.
     65                        bool                   resident;        //!< If the alSource should be resident (if true, the alSource will be returned on deletion).
     66                        ALuint                 sourceID;        //!< The ID of the Source
     67                        const SoundBuffer*     buffer;          //!< The buffer to play in this source.
     68                        const PNode*           sourceNode;      //!< The SourceNode representing the position/velocity... of this source.
     69        };
    6670}
    6771#endif /* _SOUND_SOURCE_H */
  • trunk/src/story_entities/game_world.cc

    r8190 r8255  
    566566
    567567
    568   AtmosphericEngine::getInstance()->draw();
    569 
    570568  //glEnable(GL_DEPTH_TEST);
    571569  //glEnable(GL_LIGHTING);
     
    583581    this->drawEntityList(State::getObjectManager()->getObjectList(this->dataTank->drawLists[i]));
    584582
    585 
     583  AtmosphericEngine::getInstance()->draw();
     584 
    586585  if( unlikely( this->showBV))
    587586  {
  • trunk/src/world_entities/Makefile.am

    r7155 r8255  
    2828                \
    2929                \
    30                 effects/explosion.cc
     30                effects/explosion.cc \
     31                effects/billboard.cc
    3132
    3233
     
    5657                \
    5758                effects/explosion.h \
     59                effects/billboard.h \
    5860                \
    5961                $(WorldEntities_HEADERS_)
  • trunk/src/world_entities/effects/billboard.cc

    r7810 r8255  
    22   orxonox - the future of 3D-vertical-scrollers
    33
    4    Copyright (C) 2004 orx
     4   Copyright (C) 2006 orx
    55
    66   This program is free software; you can redistribute it and/or modify
     
    99   any later version.
    1010
    11    ### File Specific
    12    main-programmer: Patrick Boenzli
     11### File Specific:
     12   main-programmer: David Hasenfratz
    1313*/
    14 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
    1514
     15#include "billboard.h"
    1616
    17 #include "lightning_bolt.h"
     17#include "util/loading/load_param.h"
     18#include "util/loading/factory.h"
    1819
    19 #include "util/loading/factory.h"
     20#include "graphics_engine.h"
    2021#include "material.h"
    21 
    22 #include "util/loading/resource_manager.h"
    23 
     22#include "glincl.h"
     23#include "state.h"
    2424
    2525
    2626using namespace std;
    2727
    28 CREATE_FACTORY(LightningBolt, CL_LIGHTNING_BOLT);
     28
     29CREATE_FACTORY(Billboard, CL_BILLBOARD);
    2930
    3031
    3132/**
    32  *  standard constructor
    33 */
    34 LightningBolt::LightningBolt (const TiXmlElement* root)
     33 * standart constructor
     34 */
     35Billboard::Billboard (const TiXmlElement* root)
    3536{
    36   this->setClassID(CL_LIGHTNING_BOLT, "LightningBolt");
     37  this->init();
    3738
    38   this->toList(OM_COMMON);
    39 
    40   this->bRender = false;
    41   this->time = 0.0;
    42   this->flashFrequency = 0.6f;
    43   this->flashConstTime = 0.07f;
    44 
    45   this->material = new Material();
    46   this->material->setDiffuseMap("maps/lightning_bolt.png");
    47   //this->offset = Vector(-1440.00, 100.00, 280.00);
    48 
    49   this->setAbsCoor(offset);
    50   this->width = 100.0f;
    51   this->height = 300.0f;
    52   this->bNewCoordinate = false;
    53 
    54   this->seedX = 200.f;
    55   this->seedZ = 500.0f;
    56   this->seedTime = 4.0f;
    57 
    58   this->soundSource.setSourceNode(this);
    59 
    60   //load sound
    61   if (this->thunderBuffer != NULL)
    62     ResourceManager::getInstance()->unload(this->thunderBuffer);
    63   this->thunderBuffer = (SoundBuffer*)ResourceManager::getInstance()->load("sound/thunder.wav", WAV);
     39  if( root)
     40    this->loadParams(root);
    6441}
    6542
    6643
    6744/**
    68  *  standard deconstructor
    69 */
    70 LightningBolt::~LightningBolt ()
     45 * destroys a Billboard
     46 */
     47Billboard::~Billboard ()
    7148{
     49  if (this->material)
     50    delete this->material;
    7251}
    7352
    74 void LightningBolt::activate()
     53
     54/**
     55 * initializes the Billboard
     56 */
     57void Billboard::init()
     58{
     59  this->setClassID(CL_BILLBOARD, "Billboard");
     60  this->setName("Billboard");
     61
     62  this->toList(OM_COMMON);
     63
     64  this->material = new Material();
     65  this->setAbsCoor(0, 0, 0);
     66  //this->setVisibiliy(true);
     67  this->setSize(5, 5);
     68}
     69
     70
     71/**
     72 *  load params
     73 * @param root TiXmlElement object
     74 */
     75void Billboard::loadParams(const TiXmlElement* root)
     76{
     77  /*LoadParam(root, "texture", this->material, Material, setDiffuseMap)
     78      .describe("the texture-file to load onto the Billboard");
     79
     80  LoadParam(root, "size", this, Billboard, setSize)
     81  .describe("the size of the Billboard in Pixels");*/
     82}
     83
     84
     85/**
     86 * sets the size of the Billboard.
     87 * @param size the size in pixels
     88 */
     89void Billboard::setSize(float sizeX, float sizeY)
     90{
     91  this->sizeX = sizeX;
     92  this->sizeY = sizeY;
     93}
     94
     95
     96/**
     97 * sets the material to load
     98 * @param textureFile The texture-file to load
     99 */
     100void Billboard::setTexture(const std::string& textureFile)
     101{
     102  this->material->setDiffuseMap(textureFile);
     103}
     104
     105
     106/**
     107 * ticks the Billboard
     108 * @param dt the time to ticks
     109 */
     110void Billboard::tick(float dt)
    75111{
    76112}
    77113
    78114
    79 void LightningBolt::deactivate()
     115/**
     116 * draws the billboard
     117 */
     118void Billboard::draw() const
    80119{
     120  if( !this->isVisible())
     121    return;
    81122
     123  glPushMatrix();
     124
     125  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
     126  //glTranslatef(0,0,0);
     127  this->material->select();
     128 
     129  const PNode* camera = State::getCameraNode();  //!< @todo MUST be different
     130  Vector cameraPos = camera->getAbsCoor();
     131  Vector cameraTargetPos = State::getCameraTargetNode()->getAbsCoor();
     132  Vector view = cameraTargetPos - cameraPos;
     133  Vector up = Vector(0, 1, 0);
     134  up = camera->getAbsDir().apply(up);
     135  Vector h = up.cross(view);
     136  Vector v = h.cross(view);
     137  h.normalize();
     138  v.normalize();
     139 
     140  v *= sizeX;
     141  h *= sizeY;
     142
     143//v += this->getAbsCoor();
     144    //PRINTF(0)("sizeX: %f sizeY: %f\n", sizeX, sizeY);
     145  glBegin(GL_QUADS);
     146  glTexCoord2f(0.0f, 0.0f);
     147  glVertex3f(this->getAbsCoor().x - h.x - v.x,
     148             this->getAbsCoor().y - h.y - v.y,
     149             this->getAbsCoor().z - h.z - v.z);
     150  glTexCoord2f(1.0f, 0.0f);
     151  glVertex3f( this->getAbsCoor().x + h.x - v.x,
     152              this->getAbsCoor().y + h.y - v.y,
     153              this->getAbsCoor().z + h.z - v.z);
     154  glTexCoord2f(1.0f, 1.0f);
     155  glVertex3f(this->getAbsCoor().x + h.x + v.x,
     156             this->getAbsCoor().y + h.y + v.y,
     157             this->getAbsCoor().z + h.z + v.z);
     158  glTexCoord2f(0.0f, 1.0f);
     159  glVertex3f(this->getAbsCoor().x - h.x + v.x,
     160             this->getAbsCoor().y - h.y + v.y,
     161             this->getAbsCoor().z - h.z + v.z);
     162  glEnd();
     163 
     164 
     165  glPopMatrix();
    82166}
    83 
    84 
    85 /**
    86  *  signal tick, time dependent things will be handled here
    87  * @param time since last tick
    88 */
    89 void LightningBolt::tick (float dt)
    90 {
    91   this->time += dt;
    92 
    93   if( this->time > this->flashFrequency)
    94   {
    95     this->bRender = true;
    96     this->time = 0.0f;
    97     this->soundSource.play(this->thunderBuffer);
    98   }
    99   else if( this->bRender && this->time > this->flashConstTime)
    100   {
    101     this->bRender = false;
    102     this->time = 0.0f;
    103     this->bNewCoordinate = true;
    104   }
    105 
    106   if( this->bNewCoordinate)
    107   {
    108     this->flashFrequency = this->seedTime * (float)rand()/(float)RAND_MAX + 0.1;
    109     this->setAbsCoor( - 800.0f - this->seedX * (float)rand()/(float)RAND_MAX, 250.00, -200.0f + this->seedZ * (float)rand()/(float)RAND_MAX);
    110     this->bNewCoordinate = false;
    111   }
    112 }
    113 
    114 
    115 void LightningBolt::draw() const
    116 {
    117   if( this->bRender)
    118   {
    119 
    120     glPushMatrix();
    121     glTranslatef (this->getAbsCoor ().x,
    122                   this->getAbsCoor ().y,
    123                   this->getAbsCoor ().z);
    124 
    125     glRotatef(90, 0.0f,1.0f,0.0f);
    126 
    127 //     Vector tmpRot = drawPart->orientation.getSpacialAxis();
    128 //     glRotatef (drawPart->orientation.getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    129 
    130 //     glPushAttrib(GL_ENABLE_BIT);
    131 //     glDisable(GL_LIGHTING);
    132 //     glDisable(GL_BLEND);
    133 
    134     this->material->select();
    135 
    136     glBegin(GL_QUADS);
    137     glTexCoord2f(1.0f, 1.0f); glVertex3f(-width/2, -height/2,  0.0f);
    138     glTexCoord2f(0.0f, 1.0f); glVertex3f( width/2, -height/2,  0.0f);
    139     glTexCoord2f(0.0f, 0.0f); glVertex3f( width/2,  height/2,  0.0f);
    140     glTexCoord2f(1.0f, 0.0f); glVertex3f(-width/2,  height/2,  0.0f);
    141     glEnd();
    142 
    143 //     glPopAttrib();
    144 
    145     glPopMatrix();
    146   }
    147 }
    148 
    149 
  • trunk/src/world_entities/effects/billboard.h

    r7810 r8255  
    11/*!
    2  * @file lightning_bolt.h
    3  * @brief a LightningBolt Projectile
     2 * @file billboard.h
    43 */
    54
    6 #ifndef _LIGHTNING_BOLT_H
    7 #define _LIGHTNING_BOLT_H
     5#ifndef _BILLBOARD_H
     6#define _BILLBOARD_H
    87
    98#include "world_entity.h"
    109
    11 #include "sound_buffer.h"
    12 #include "sound_source.h"
     10class Material;
     11class TiXmlElement;
    1312
    14 class Material;
    15 
    16 class LightningBolt : public WorldEntity
     13class Billboard : public WorldEntity
    1714{
    1815  public:
    19     LightningBolt(const TiXmlElement* root = NULL);
    20     virtual ~LightningBolt ();
     16    Billboard(const TiXmlElement* root = NULL);
     17    virtual ~Billboard();
    2118
    22     virtual void activate();
    23     virtual void deactivate();
     19    void init();
     20    void loadParams(const TiXmlElement* root);
    2421
    25     virtual void tick(float time);
     22    void setSize(float sizeX, float sizeY);
     23    void setTexture(const std::string& textureFile);
     24
     25    virtual void tick(float dt);
    2626    virtual void draw() const;
    2727
    2828  private:
    29     float flashFrequency;                   //!< frequency to activate itself
    30     float flashRisingTime;                  //!< time to rise
    31     float flashConstTime;                   //!< time to be drawn
    32     float flashFallTime;                    //!< time to fall
    33 
    34     float time;                             //!< time
    35 
    36     bool  bRender;
    37     bool  bNewCoordinate;
    38     Material*      material;
    39     Vector         offset;
    40     float width;
    41     float height;
    42 
    43     float seedX;
    44     float seedZ;
    45     float seedTime;
    46 
    47     SoundSource    soundSource;
    48     SoundBuffer*   thunderBuffer;
     29    Material*        material;
     30    float sizeX;
     31    float sizeY;
    4932};
    5033
    51 #endif /* _LIGHTNING_BOLT_H */
     34#endif /* _BILLBOARD_H */
  • trunk/src/world_entities/space_ships/helicopter.cc

    r7868 r8255  
    216216  State::getCameraTargetNode()->setParentSoft(this->getWeaponManager().getFixedTarget());
    217217
    218   this->soundSource.loop(this->chopperBuffer);
     218  this->soundSource.loop(this->chopperBuffer, 0.8f);
    219219  // PRINTF(0)( "Playing ChopperSound\n" );
    220220}
Note: See TracChangeset for help on using the changeset viewer.