ExplosionNukeRenderer.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <sprites/ExplosionNukeRenderer.h>
00022 #include <sprites/ExplosionTextures.h>
00023 #include <client/ScorchedClient.h>
00024 #include <common/Defines.h>
00025 #include <graph/OptionsDisplay.h>
00026 #include <landscape/Landscape.h>
00027 #include <landscapemap/LandscapeMaps.h>
00028 #include <math.h>
00029 
00030 static const int AlphaSteps = int(ExplosionNukeRenderer_STEPS * 0.9f);
00031 
00032 ExplosionNukeRendererEntry::ExplosionNukeRendererEntry(
00033         Vector &position, float size) :
00034         totalTime_(0.0f), size_(size),
00035         startPosition_(position), cloudRotation_(0.0f)
00036 {
00037         float rot = RAND * 3.14f * 2.0f;
00038         float width = RAND * 0.5f + 1.0f;
00039     
00040         cloudRotation_ = RAND * 360.0f;
00041         rotation_[0] = getFastSin(rot) * width;
00042         rotation_[1] = getFastCos(rot) * width;
00043 }
00044 
00045 ExplosionNukeRendererEntry::~ExplosionNukeRendererEntry()
00046 {
00047 }
00048 
00049 void ExplosionNukeRendererEntry::simulate(Particle *particle, float time)
00050 {
00051         totalTime_ += time;
00052         cloudRotation_ += time * 5.0f;
00053 
00054         int position = int((totalTime_ / (16.0f / 3.0f)) * 
00055                 float(ExplosionNukeRenderer_STEPS));
00056         if (position >= ExplosionNukeRenderer_STEPS)
00057                 position = ExplosionNukeRenderer_STEPS - 1;
00058 
00059         float z = ExplosionNukeRenderer::positions_[position][2] * (10.0f + size_) / 30.0f;
00060         float w = ExplosionNukeRenderer::positions_[position][0] + (size_ / 2.0f);
00061         particle->position_[0] = startPosition_[0] + rotation_[0] * w;
00062         particle->position_[1] = startPosition_[1] + rotation_[1] * w;
00063         particle->position_[2] = startPosition_[2] + z;
00064 }
00065 
00066 Vector *ExplosionNukeRenderer::positions_ = 0;
00067 
00068 ExplosionNukeRenderer::ExplosionNukeRenderer(Vector &position, float size) 
00069         : totalTime_(0.0f), time_(0.0f), position_(position), size_(size)
00070 {
00071         position_[2] -= size_;
00072         float height = ScorchedClient::instance()->getLandscapeMaps().
00073                 getGroundMaps().getHeight((int) position_[0], (int) position_[1]).asFloat();
00074         if (position_[2] < height) position_[2] = height;
00075 
00076         if (!positions_)
00077         {
00078                 positions_ = new Vector[ExplosionNukeRenderer_STEPS];
00079 
00080                 float zPos = 0.0f;
00081                 float width = 0.0f;
00082                 float widthAdd = 0.0f;
00083 
00084                 for (int i=0; i<ExplosionNukeRenderer_STEPS; i++)
00085                 {
00086                         Vector pos;
00087                         pos[0] = width;
00088                         pos[1] = 0.0f;
00089                         pos[2] = zPos;
00090 
00091                         if (i > (ExplosionNukeRenderer_STEPS * (0.3f))){
00092                                 width += 0.5f;
00093                                 
00094                         }else{ 
00095                                 
00096                                 zPos += 2.0f;
00097                         }
00098 
00099                         positions_[i] = pos;
00100                 }
00101         }
00102 
00103         emitter_.setAttributes(
00104                 5.0f, 5.0f, // Life
00105                 0.2f, 0.5f, // Mass
00106                 0.01f, 0.02f, // Friction
00107                 Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, 0.0f, 0.0f), // Velocity
00108                 Vector(1.0f, 1.0f, 1.0f), 0.3f, // StartColor1
00109                 Vector(1.0f, 1.0f, 1.0f), 0.2f, // StartColor2
00110                 Vector(1.0f, 1.0f, 1.0f), 0.0f, // EndColor1
00111                 Vector(1.0f, 1.0f, 1.0f), 0.0f, // EndColor2
00112                 2.0f, 2.0f, 3.0f, 3.0f, // Start Size
00113                 4.0f, 4.0f, 6.0f, 6.0f, // EndSize
00114                 Vector(0.0f, 0.0f, 100.0f), // Gravity
00115                 false,
00116                 false);
00117 }
00118 
00119 ExplosionNukeRenderer::~ExplosionNukeRenderer()
00120 {
00121 }
00122 
00123 void ExplosionNukeRenderer::draw(Action *action)
00124 {
00125 }
00126 
00127 void ExplosionNukeRenderer::simulate(Action *action, float frameTime, bool &remove)
00128 {
00129         float AddSmokeTime = 0.08f;
00130         int SmokesPerTime = 14;
00131         if (OptionsDisplay::instance()->getEffectsDetail() == 0) 
00132         {
00133                 SmokesPerTime = 8;
00134         }
00135         else if (OptionsDisplay::instance()->getEffectsDetail() == 2) 
00136         {
00137                 SmokesPerTime = 18;
00138         }
00139 
00140         totalTime_ += frameTime;
00141         time_ += frameTime;
00142         
00143         while (time_ > AddSmokeTime)
00144         {
00145                 time_ -= AddSmokeTime;
00146 
00147                 // Add any new entries
00148                 if (totalTime_ > 1.25f)
00149                 {
00150                         if (totalTime_ < 2.25f)
00151                         {
00152                                 emitter_.emitMushroom(
00153                                         position_,
00154                                         ScorchedClient::instance()->getParticleEngine(),
00155                                         SmokesPerTime,
00156                                         size_);
00157                         }
00158                         else remove = true;
00159                 }
00160         }
00161 }

Generated on Mon Feb 16 15:14:47 2009 for Scorched3D by  doxygen 1.5.3