Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

/Users/blackie/Documents/myRepository/phobosengine-vc2005/phobosengine/phobosengine/EffectTest.h

Go to the documentation of this file.
00001 
00002 
00003 #ifndef EFFECTTEST_H
00004 #define EFFECTTEST_H
00005 
00006 
00007 #include "AABB.h"
00008 #include "CoreEngine.h"
00009 #include "DayNightCycle.h"
00010 #include "Light.h"
00011 #include "MathUtils.h"
00012 #include "RenderableObject.h"
00013 #include "Renderer.h"
00014 #include "Sprite.h"
00015 #include "Texture.h"
00016 #include "TextureDatabase.h"
00017 #include "Vector3f.h"
00018 #include "World.h"
00019 
00020 
00021 namespace pge {
00022 
00023 
00024         class EffectTest : public IRenderableObject {
00025 
00026         public:
00027                 //************************************************************************
00028                 //
00029                 // Constructor
00030                 //
00031                 //************************************************************************
00033                 EffectTest(void) {
00034                         initLights();
00035 
00036                         m_timePassed = 0;
00037 
00038                         m_direction0 = Vector3f(1.0f, 0.0f, 0.0f);
00039                         m_direction1 = Vector3f(0.0f, 1.0f, 0.0f);
00040                         m_direction2 = Vector3f(-1.0f, 0.0f, 0.0f);
00041 
00042                         m_boundingBox = NULL;
00043                 }
00044 
00045 
00046                 //************************************************************************
00047                 //
00048                 // Destructor
00049                 //
00050                 //************************************************************************
00052                 virtual ~EffectTest(void) {
00053                 }
00054 
00055 
00056                 //************************************************************************
00057                 //
00058                 // Functions
00059                 //
00060                 //************************************************************************
00061                 //
00062                 //
00063                 //
00064                 bool init(void) {
00065                         return true;
00066                 }
00067 
00068 
00069                 //
00070                 //
00071                 //
00072                 void render(void) {
00073                         if(DayNightCycle::getInstance()->getDayNightCycle() <= 0.1f) {
00074                                 m_sprite0->render();
00075                                 m_sprite1->render();
00076                                 m_sprite2->render();
00077                         }
00078                 }
00079 
00080 
00081                 //
00082                 //
00083                 //
00084                 void timer(unsigned int delay) {
00085                         if(DayNightCycle::getInstance()->getDayNightCycle() <= 0.1f) {
00086                                 //
00087                                 // Variables
00088                                 //
00089                                 float velocity = 0.1f;
00090 
00091 
00092                                 if(m_timePassed >= 400) {
00093                                         float maxChange = 0.5f;
00094 
00095                                         Vector3f dirChange0 = Vector3f(mathutils::random(-maxChange, maxChange),
00096                                                 mathutils::random(-maxChange, maxChange), mathutils::random(-maxChange, maxChange));
00097 
00098                                         Vector3f dirChange1 = Vector3f(mathutils::random(-maxChange, maxChange),
00099                                                 mathutils::random(-maxChange, maxChange), mathutils::random(-maxChange, maxChange));
00100 
00101                                         Vector3f dirChange2 = Vector3f(mathutils::random(-maxChange, maxChange),
00102                                                 mathutils::random(-maxChange, maxChange), mathutils::random(-maxChange, maxChange));
00103 
00104                                         m_direction0 = m_direction0 + dirChange0;
00105                                         m_direction0.normalize();
00106 
00107                                         m_direction1 = m_direction1 + dirChange1;
00108                                         m_direction1.normalize();
00109 
00110                                         m_direction2 = m_direction2 + dirChange2;
00111                                         m_direction2.normalize();
00112 
00113                                         m_timePassed = 0;
00114                                 }
00115                                 m_timePassed += delay;
00116 
00117                                 // Check for bounds.
00118                                 if(!m_boundingBox->isPointInside(m_light0->m_position)) {
00119                                         m_direction0 = m_direction0 * -1.0f;
00120                                 }
00121                                 if(!m_boundingBox->isPointInside(m_light1->m_position)) {
00122                                         m_direction1 = m_direction0 * -1.0f;
00123                                 }
00124                                 if(!m_boundingBox->isPointInside(m_light2->m_position)) {
00125                                         m_direction2 = m_direction0 * -1.0f;
00126                                 }
00127 
00128                                 m_light0->m_position.m_v[0] = m_light0->m_position.m_v[0] + (m_direction0.m_v[0] * velocity);
00129                                 m_light0->m_position.m_v[1] = m_light0->m_position.m_v[1] + (m_direction0.m_v[1] * velocity);
00130                                 m_light0->m_position.m_v[2] = m_light0->m_position.m_v[2] + (m_direction0.m_v[2] * velocity);
00131 
00132                                 m_light1->m_position.m_v[0] = m_light1->m_position.m_v[0] + (m_direction1.m_v[0] * velocity);
00133                                 m_light1->m_position.m_v[1] = m_light1->m_position.m_v[1] + (m_direction1.m_v[1] * velocity);
00134                                 m_light1->m_position.m_v[2] = m_light1->m_position.m_v[2] + (m_direction1.m_v[2] * velocity);
00135 
00136                                 m_light2->m_position.m_v[0] = m_light2->m_position.m_v[0] + (m_direction2.m_v[0] * velocity);
00137                                 m_light2->m_position.m_v[1] = m_light2->m_position.m_v[1] + (m_direction2.m_v[1] * velocity);
00138                                 m_light2->m_position.m_v[2] = m_light2->m_position.m_v[2] + (m_direction2.m_v[2] * velocity);
00139 
00140                                 m_sprite0->setCenter(Vector3f(m_light0->m_position));
00141                                 m_sprite1->setCenter(Vector3f(m_light1->m_position));
00142                                 m_sprite2->setCenter(Vector3f(m_light2->m_position));
00143                         }
00144                 }
00145 
00146 
00147                 //
00148                 //
00149                 //
00150                 void setBoundingBox(AABB *aabb) {
00151                         m_boundingBox = aabb;
00152                 }
00153 
00154 
00155         private:
00156                 //************************************************************************
00157                 //
00158                 // Functions
00159                 //
00160                 //************************************************************************
00161                 //
00162                 //
00163                 //
00164                 void initLights(void) {
00165                         //
00166                         // Variables
00167                         //
00168                         Vector4f lightStartPosition = Vector4f(0.0f, 10.0f, 0.0f, 1.0f);
00169                         World *world = NULL;
00170                         Texture *texture = NULL;
00171 
00172 
00173                         // Get the world.
00174                         world = CoreEngine::getInstance()->getCurrentWorld();
00175 
00176                         // Create the lights and add them to the world.
00177                         m_light0 = new Light();
00178                         m_light1 = new Light();
00179                         m_light2 = new Light();
00180 
00181                         // Light 0, a red light.
00182                         m_light0->m_position = lightStartPosition;
00183                         m_light0->m_diffuse = Vector4f(1.0f, 0.0f, 0.0f, 1.0f);
00184 
00185                         // Light 1, a green light.
00186                         m_light1->m_position = lightStartPosition;
00187                         m_light1->m_diffuse = Vector4f(0.0f, 1.0f, 0.0f, 1.0f);
00188 
00189                         // Light 2, a blue light.
00190                         m_light2->m_position = lightStartPosition;
00191                         m_light2->m_diffuse = Vector4f(0.0f, 0.0f, 1.0f, 1.0f);
00192 
00193                         m_sprite0 = new Sprite(Vector3f(m_light0->m_position), 1.0f);
00194                         m_sprite1 = new Sprite(Vector3f(m_light1->m_position), 1.0f);
00195                         m_sprite2 = new Sprite(Vector3f(m_light2->m_position), 1.0f);
00196 
00197                         texture = TextureDatabase::getInstance()->addTexture("waterparticle_0.tga");
00198 
00199                         m_sprite0->setTexture(texture);
00200                         m_sprite1->setTexture(texture);
00201                         m_sprite2->setTexture(texture);
00202 
00203                         m_sprite0->setColor(Vector4f(1.0f, 0.0f, 0.0f, 1.0f));
00204                         m_sprite1->setColor(Vector4f(0.0f, 1.0f, 0.0f, 1.0f));
00205                         m_sprite2->setColor(Vector4f(0.0f, 0.0f, 1.0f, 1.0f));
00206 
00207                         world->addLight(m_light0);
00208                         world->addLight(m_light1);
00209                         world->addLight(m_light2);
00210                 }
00211 
00212 
00213                 //************************************************************************
00214                 //
00215                 // Variables
00216                 //
00217                 //************************************************************************
00218                 Sprite *m_sprite0;
00219                 Sprite *m_sprite1;
00220                 Sprite *m_sprite2;
00221 
00222                 Light *m_light0;
00223                 Light *m_light1;
00224                 Light *m_light2;
00225 
00226                 Vector3f m_direction0;
00227                 Vector3f m_direction1;
00228                 Vector3f m_direction2;
00229 
00230                 unsigned int m_timePassed;
00231 
00232                 AABB *m_boundingBox;
00233         };
00234 };
00235 
00236 #endif

Generated on Mon Oct 16 12:08:10 2006 for Phobosengine by doxygen 1.3.4