TargetParticleRenderer.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 <tankgraph/TargetParticleRenderer.h>
00022 #include <tankgraph/TargetRendererImpl.h>
00023 #include <graph/Particle.h>
00024 #include <target/TargetContainer.h>
00025 #include <target/TargetLife.h>
00026 #include <client/ScorchedClient.h>
00027 
00028 TargetParticleRenderer *TargetParticleRenderer::getInstance()
00029 {
00030         static TargetParticleRenderer instance_;
00031         return &instance_;
00032 }
00033 
00034 void TargetParticleRenderer::simulateParticle(Particle &particle, float time)
00035 {
00036         Target *target =
00037                 ScorchedClient::instance()->getTargetContainer().getTargetById(
00038                         ((TargetParticleUserData *) particle.userData_)->playerId_);
00039         if (target)
00040         {
00041                 // Target and particle alive
00042                 particle.life_ = 1000.0f; // Alive
00043                 particle.position_ = target->getLife().getFloatPosition();
00044         }
00045         else
00046         {
00047                 // Target expired but particle has not
00048                 particle.life_ = 0.0f; // Dead
00049         }
00050 }
00051 
00052 void TargetParticleRenderer::renderParticle(Particle &particle)
00053 {
00054         Target *target =
00055                 ScorchedClient::instance()->getTargetContainer().getTargetById(
00056                         ((TargetParticleUserData *) particle.userData_)->playerId_);
00057         if (target)
00058         {
00059                 TargetRenderer *renderer = target->getRenderer();
00060                 if (renderer)
00061                 {
00062                         TargetRendererImpl *rendererImpl =
00063                                 (TargetRendererImpl *) renderer;
00064                         rendererImpl->drawParticle(particle.distance_);
00065                         glDepthMask(GL_FALSE);
00066                 }
00067         }
00068 }
00069 
00070 void TargetParticleRenderer::recycleParticle(Particle &particle)
00071 {
00072         Target *target =
00073                 ScorchedClient::instance()->getTargetContainer().getTargetById(
00074                         ((TargetParticleUserData *) particle.userData_)->playerId_);
00075         if (target)
00076         {
00077                 TargetRendererImpl *renderer = (TargetRendererImpl *)
00078                         target->getRenderer();
00079                 if (renderer)
00080                 {
00081                         // Particle expired but Target has not
00082                         renderer->setMakeParticle();
00083                 }
00084         }
00085 }

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