Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/effects/cloud_effect.cc @ 8397

Last change on this file since 8397 was 8255, checked in by bensch, 18 years ago

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

File size: 5.2 KB
RevLine 
[7679]1/*
[7768]2        orxonox - the future of 3D-vertical-scrollers
[7679]3
[7768]4        Copyright (C) 2004 orx
[7679]5
[7768]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.
[7679]10
11### File Specific:
[7768]12        main-programmer: hdavid, amaechler
[8255]13
14        INSPIRED BY http://www.codesampler.com/usersrc/usersrc_6.htm#oglu_sky_dome_shader
[7679]15*/
16
17#include "cloud_effect.h"
18
19#include "util/loading/load_param.h"
20#include "util/loading/factory.h"
[8255]21#include "util/loading/resource_manager.h"
[7679]22
23#include "glincl.h"
[8255]24#include "material.h"
[7795]25#include <math.h>
[8255]26#include "state.h"
27#include "p_node.h"
28#include "shader.h"
29#include "shell_command.h"
[7679]30
31#include "parser/tinyxml/tinyxml.h"
32
[8255]33#include "sglmodel.h"
34
[7679]35using namespace std;
36
[8255]37SHELL_COMMAND(activate, CloudEffect, activateCloud);
38SHELL_COMMAND(deactivate, CloudEffect, deactivateCloud);
39
[7679]40CREATE_FACTORY(CloudEffect, CL_CLOUD_EFFECT);
41
42CloudEffect::CloudEffect(const TiXmlElement* root)
43{
44        this->setClassID(CL_CLOUD_EFFECT, "CloudEffect");
45
46        this->init();
47
48        if (root != NULL)
49                this->loadParams(root);
50
[8255]51        if(cloudActivate)
52                this->activate();
[7679]53}
54
55CloudEffect::~CloudEffect()
56{
57        this->deactivate();
58
[8255]59        delete this->cloudMaterial;
[7784]60
[8255]61        cloudModel.Delete();
62        Shader::unload(this->cloudShader);
[7784]63
[7679]64}
65
66
67bool CloudEffect::init()
68{
[8255]69        PRINTF(1)("Initializing CloudEffect\n");
[7768]70
[8255]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;
[7768]77
[8255]78        this->cloudTexture = "pictures/sky/cloud1.jpg";
[7679]79
[8255]80        cloudModel.Load("sky.sgl");
81        cloudModel.Unitize();
[7768]82
[8255]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");
[7768]89
[8255]90        // Tell the shader the bounding box of the sky dome
91        this->cloudShader->bindShader("bbox", bbox, 4);
[7784]92
[8255]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);
[7768]98
[7679]99}
100
101
[8255]102void CloudEffect::loadParams(const TiXmlElement* root)
[7768]103{
[8255]104        WeatherEffect::loadParams(root);
[7768]105
[8255]106        // LoadParam(root, "speed", this, CloudEffect, setCloudAnimation);
107        // LoadParam(root, "texture", this, CloudEffect, setCloudTexture);
[7768]108
[8255]109        LOAD_PARAM_START_CYCLE(root, element);
110        {
111                LoadParam_CYCLE(element, "option", this, CloudEffect, setCloudOption);
112        }
113        LOAD_PARAM_END_CYCLE(element);
114}
[7768]115
116
[8255]117bool CloudEffect::activate()
[7679]118{
[8255]119        PRINTF(0)( "Activating CloudEffect with Material %s\n", this->cloudTexture.c_str());
[7784]120
[8255]121        this->cloudActivate = true;
122       
[7768]123}
[7679]124
[8255]125bool CloudEffect::deactivate()
[7768]126{
[8255]127        PRINTF(0)("Deactivating CloudEffect\n");
128
129        this->cloudActivate = false;
[7679]130}
[7768]131
[8255]132void CloudEffect::draw() const
[7768]133{
[8255]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();
[7768]150
[8255]151        // ******
[7768]152
[8255]153        glMatrixMode(GL_MODELVIEW);
154        glPushMatrix();
[7768]155
[8255]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);
[7768]164
[8255]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};
[7768]167
[8255]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]);
[7768]171
[8255]172        // Turn off the depth buffer when rendering the background
173        // glDisable(GL_DEPTH_TEST);
[7768]174
[8255]175        this->cloudShader->activateShader();
[7768]176
[8255]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);
[7768]182
[8255]183        glActiveTexture(GL_TEXTURE0 + 0);
184        glActiveTexture(GL_TEXTURE0 + 1);
[7768]185
[8255]186        // Load the cloud texture
187        //glBindTexture(GL_TEXTURE_2D, g_cloud_texture);
188        this->cloudMaterial->select();
[7768]189
[8255]190        // Render the sky dome
191        cloudModel.Render();
[7768]192
[8255]193        // Unselect the shader
194        Shader::deactivateShader();
[7768]195
[8255]196        /* Turn on the depth buffer when rendering the foreground. */
197        // glEnable(GL_DEPTH_TEST);
[7768]198
[8255]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);
210
211        glPopMatrix();
212       
[7768]213}
214
[8255]215void CloudEffect::tick (float dt)
[7768]216{
[8255]217        if (!this->cloudActivate)
218                return;
[7768]219
[8255]220        // Update the timer for scrolling the clouds
221        time = time + ((1.0f / 2000.0f) * cloudScroll);
[7768]222}
[7784]223
Note: See TracBrowser for help on using the repository browser.