TargetRendererImplTarget.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/TargetRendererImplTarget.h>
00022 #include <target/TargetLife.h>
00023 #include <target/TargetState.h>
00024 #include <landscape/Landscape.h>
00025 #include <landscape/ShadowMap.h>
00026 #include <GLEXT/GLCameraFrustum.h>
00027 #include <GLEXT/GLState.h>
00028 #include <client/ScorchedClient.h>
00029 #include <engine/ActionController.h>
00030 #include <graph/ModelRendererStore.h>
00031 #include <graph/OptionsDisplay.h>
00032 #include <float.h>
00033 
00034 TargetRendererImplTarget::TargetRendererImplTarget(Target *target,
00035         ModelID model, ModelID burntModel, 
00036         float scale, float color) :
00037         TargetRendererImpl(target),
00038         modelId_(model), burntModelId_(burntModel),
00039         target_(target),
00040         burnt_(false),
00041         shieldHit_(0.0f), totalTime_(0.0f),
00042         targetTips_(target),
00043         scale_(scale), color_(color)
00044 {
00045         modelRenderer_ = new ModelRendererSimulator(
00046                 ModelRendererStore::instance()->loadModel(model));
00047         burntModelRenderer_ = new ModelRendererSimulator(
00048                 ModelRendererStore::instance()->loadModel(burntModel));
00049 
00050         if (burntModelId_.getType()[0] == 'T' ||
00051                 modelId_.getType()[0] == 'T')
00052         {
00053                 tree_ = true;
00054         }
00055 }
00056 
00057 TargetRendererImplTarget::~TargetRendererImplTarget()
00058 {
00059         delete modelRenderer_;
00060         delete burntModelRenderer_;
00061 }
00062 
00063 void TargetRendererImplTarget::simulate(float frameTime)
00064 {
00065         totalTime_ += frameTime;
00066         if (shieldHit_ > 0.0f)
00067         {
00068                 shieldHit_ -= frameTime / 25.0f;
00069                 if (shieldHit_ < 0.0f) shieldHit_ = 0.0f;
00070         }
00071 
00072         if (burnt_) burntModelRenderer_->simulate(frameTime * 20.0f);
00073         else modelRenderer_->simulate(frameTime * 20.0f);
00074 }
00075 
00076 void TargetRendererImplTarget::render(float distance)
00077 {
00078         createParticle();
00079 
00080         float size = 2.0f;
00081         float fade = 1.0f;
00082         if (!tree_)
00083         {
00084                 storeTarget2DPos();
00085 
00086                 size = getTargetSize();
00087                 fade = getTargetFade(distance, size * 2.0f);
00088 
00089                 // Draw texture shadows (if hardware shadows aren't on)
00090                 if (target_->getTargetState().getDisplayShadow() &&
00091                         Landscape::instance()->getShadowMap().shouldAddShadow())
00092                 {
00093                         Landscape::instance()->getShadowMap().addCircle(
00094                                 target_->getLife().getFloatPosition()[0], 
00095                                 target_->getLife().getFloatPosition()[1], 
00096                                 target_->getLife().getSize().Max().asFloat() + 2.0f,
00097                                 fade);
00098                 }
00099 
00100                 // Draw the target model
00101                 glColor4f(color_, color_, color_, fade);
00102         }
00103 
00104         // Generate and cache the OpenGL transform matrix
00105         if (!matrixCached_)
00106         {
00107                 cachedMatrix_.identity();
00108                 cachedMatrix_.translate(
00109                         target_->getLife().getFloatPosition()[0], 
00110                         target_->getLife().getFloatPosition()[1], 
00111                         target_->getLife().getFloatPosition()[2]);
00112                 cachedMatrix_.multiply(target_->getLife().getFloatRotMatrix());
00113                 cachedMatrix_.scale(scale_, scale_, scale_);
00114 
00115                 matrixCached_ = true;
00116         }
00117 
00118         glPushMatrix();
00119                 glMultMatrixf(cachedMatrix_);
00120                 if (burnt_) burntModelRenderer_->drawBottomAligned(distance, fade);
00121                 else modelRenderer_->drawBottomAligned(distance, fade);
00122         glPopMatrix();
00123 }
00124 
00125 void TargetRendererImplTarget::render2D(float distance)
00126 {
00127         // Add the tooltip that displays the tank info
00128         GLWToolTip::instance()->addToolTip(&targetTips_.targetTip,
00129                 float(posX_) - 10.0f, float(posY_) - 10.0f, 20.0f, 20.0f);
00130 }
00131 
00132 void TargetRendererImplTarget::renderShadow(float distance)
00133 {
00134         if (!GLCameraFrustum::instance()->
00135                 sphereInFrustum(target_->getLife().getFloatPosition(), 
00136                 4.0f / 2.0f,
00137                 GLCameraFrustum::FrustrumRed))
00138         {
00139                 return;
00140         }
00141 
00142         glPushMatrix();
00143                 glTranslatef(
00144                         target_->getLife().getFloatPosition()[0], 
00145                         target_->getLife().getFloatPosition()[1], 
00146                         target_->getLife().getFloatPosition()[2]);
00147                 glMultMatrixf(target_->getLife().getFloatRotMatrix());
00148                 glScalef(scale_, scale_, scale_);
00149                 if (burnt_) burntModelRenderer_->drawBottomAligned(FLT_MAX, 1.0f, false);
00150                 else modelRenderer_->drawBottomAligned(FLT_MAX, 1.0f, false);
00151         glPopMatrix();
00152 }
00153 
00154 void TargetRendererImplTarget::drawParticle(float distance)
00155 {
00156         if (!getVisible()) return;
00157 
00158         drawParachute();
00159         drawShield(shieldHit_, totalTime_);
00160 }
00161 
00162 void TargetRendererImplTarget::shieldHit()
00163 {
00164         shieldHit_ = 0.25f;
00165 }
00166 
00167 void TargetRendererImplTarget::fired()
00168 {
00169 }
00170 
00171 void TargetRendererImplTarget::targetBurnt()
00172 {
00173         burnt_ = true;
00174 }

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