ShotBounce.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 <actions/ShotBounce.h>
00022 #include <actions/CameraPositionAction.h>
00023 #include <engine/ScorchedContext.h>
00024 #include <engine/ActionController.h>
00025 #include <weapons/WeaponRoller.h>
00026 #include <weapons/AccessoryStore.h>
00027 #ifndef S3D_SERVER
00028         #include <GLEXT/GLState.h>
00029         #include <graph/ModelRenderer.h>
00030         #include <graph/ModelRendererStore.h>
00031         #include <graph/ModelRendererSimulator.h>
00032 #endif
00033 #include <3dsparse/ModelStore.h>
00034 #include <3dsparse/Model.h>
00035 #include <string.h>
00036 
00037 ShotBounce::ShotBounce(WeaponRoller *weapon, 
00038                 FixedVector &startPosition, FixedVector &velocity,
00039                 WeaponFireContext &weaponContext) : 
00040         startPosition_(startPosition),
00041         velocity_(velocity), weapon_(weapon), weaponContext_(weaponContext),
00042         totalTime_(0), 
00043         vPoint_(0), model_(0)
00044 {
00045 }
00046 
00047 void ShotBounce::init()
00048 {
00049         PhysicsParticleInfo info(ParticleTypeBounce, weaponContext_.getPlayerId(), this);
00050         setPhysics(info, startPosition_, velocity_, 
00051                 1, 5, weapon_->getWindFactor(*context_), false, weapon_->getRoll());
00052 
00053         FixedVector lookatPos;
00054         vPoint_ = context_->getViewPoints().getNewViewPoint(weaponContext_.getPlayerId());
00055         context_->getViewPoints().getValues(lookatPos, lookFrom_);
00056 
00057         // Point the action camera at this event
00058         CameraPositionAction *pos = new CameraPositionAction(
00059                 startPosition_, 5, 5);
00060         context_->getActionController().addAction(pos);
00061 }
00062 
00063 ShotBounce::~ShotBounce()
00064 {
00065 #ifndef S3D_SERVER
00066         delete model_;
00067 #endif
00068         if (vPoint_) context_->getViewPoints().releaseViewPoint(vPoint_);
00069 }
00070 
00071 std::string ShotBounce::getActionDetails()
00072 {
00073         return S3D::formatStringBuffer("%i,%i,%i %i,%i,%i %s",
00074                 startPosition_[0].getInternal(), startPosition_[1].getInternal(), startPosition_[2].getInternal(),
00075                 velocity_[0].getInternal(), velocity_[1].getInternal(), velocity_[2].getInternal(),
00076                 weapon_->getParent()->getName());
00077 }
00078 
00079 void ShotBounce::collision(PhysicsParticleObject &position, 
00080         ScorchedCollisionId collisionId)
00081 {
00082         if (!collision_)
00083         {
00084                 doCollision();
00085         }
00086         PhysicsParticleReferenced::collision(position, collisionId);
00087 }
00088 
00089 void ShotBounce::simulate(fixed frameTime, bool &remove)
00090 {
00091         totalTime_ += frameTime;
00092         if (totalTime_ > weapon_->getTime(*context_))
00093         {
00094                 doCollision();
00095                 remove = true;
00096         }
00097 
00098         PhysicsParticleReferenced::simulate(frameTime, remove);
00099 }
00100 
00101 void ShotBounce::draw()
00102 {
00103 #ifndef S3D_SERVER
00104         if (!context_->getServerMode()) 
00105         {
00106                 static float rotMatrix[16];
00107                 getRotationQuat().getOpenGLRotationMatrix(rotMatrix);
00108 
00109                 if (!model_)
00110                 {
00111                         ModelID &id = ((WeaponRoller *) weapon_)->getRollerModelID();
00112                         bool useTexture = (strcmp(id.getSkinName(), "none") != 0);
00113                         model_ = new ModelRendererSimulator(
00114                                 ModelRendererStore::instance()->loadModel(id));
00115                 }
00116 
00117                 if (vPoint_)
00118                 {
00119                         vPoint_->setPosition(getCurrentPosition());
00120                         vPoint_->setLookFrom(lookFrom_);
00121                 }
00122 
00123                 GLState state(GLState::TEXTURE_OFF);
00124                 glPushMatrix();
00125                         glTranslatef(
00126                                 getCurrentPosition()[0].asFloat(), 
00127                                 getCurrentPosition()[1].asFloat(), 
00128                                 getCurrentPosition()[2].asFloat() -
00129                                 model_->getRenderer()->getModel()->getMin()[2] * 0.08f);
00130 
00131                         glMultMatrixf(rotMatrix);
00132                         glScalef(0.08f, 0.08f, 0.08f);
00133                         model_->draw();
00134                 glPopMatrix();
00135         }
00136 #endif // #ifndef S3D_SERVER
00137 }
00138 
00139 void ShotBounce::doCollision()
00140 {
00141         WeaponRoller *proj = (WeaponRoller *) weapon_;
00142         proj->getCollisionAction()->fireWeapon(
00143                 *context_, weaponContext_, getCurrentPosition(), getCurrentVelocity());
00144 }

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