00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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 }