- Timestamp:
- Nov 15, 2009, 1:15:42 PM (15 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/particles2/src/modules/weapons/projectiles/Rocket.cc
r6059 r6065 31 31 #include "core/XMLPort.h" 32 32 #include "BulletDynamics/Dynamics/btRigidBody.h" 33 #include "worldentities/pawns/Pawn.h" 34 #include "graphics/ParticleSpawner.h" 35 #include "graphics/Model.h" 36 #include "objects/collisionshapes/ConeCollisionShape.h" 33 37 34 38 namespace orxonox … … 43 47 Rocket::Rocket(BaseObject* creator) : ControllableEntity(creator) 44 48 { 45 this->myController_ = 0;46 // put your code in here:47 49 RegisterObject(Rocket);// - register the Rocket class to the core 48 50 49 this->localLinearAcceleration_.setValue(0, 0, 0); 50 this->localAngularAcceleration_.setValue(0, 0, 0); 51 this->primaryThrust_ = 100; 52 this->auxilaryThrust_ = 100; 53 this->rotationThrust_ = 10; 51 this->setCollisionType(WorldEntity::Kinematic); 52 this->setVelocity(0,0,-100); 53 this->model_ = new Model(this); 54 this->model_->setMeshSource("can.mesh"); 55 this->attach(this->model_); 56 this->lifetime_ = 100; 54 57 55 this->setCollisionType(WorldEntity::Kinematic); 56 57 this->myController_ = new RocketController(static_cast<BaseObject*>(this)); //!< Creates a new controller and passes our this pointer to it as creator. 58 if (GameMode::isMaster()) 59 { 60 this->enableCollisionCallback(); 61 this->setCollisionResponse(false); 62 this->setCollisionType(Kinematic); 63 64 this->collisionShape_ = new ConeCollisionShape(this); 65 this->collisionShape_->setRadius(3); 66 this->collisionShape_->setHeight(500); 67 this->attachCollisionShape(this->collisionShape_); 68 69 this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&Rocket::destroyObject, this))); 70 } 58 71 } 59 72 … … 64 77 Rocket::~Rocket() 65 78 { 66 if( this->myController_ != NULL ) 67 this->myController_->destroy(); 79 if(this->isInitialized()) 80 { 81 this->collisionShape_->destroy(); 82 this->model_->destroy(); 83 } 68 84 } 69 85 … … 76 92 // this calls the XMLPort function of the parent class 77 93 SUPER(Rocket, XMLPort, xmlelement, mode); 78 79 // put your code in here: 80 XMLPortParam(Rocket, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode); 81 //XMLPortParam(Rocket, "auxilaryThrust", setAuxilaryThrust, getAuxilaryThrust, xmlelement, mode); 82 //XMLPortParam(Rocket, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode); 83 // make sure you add the variables primaryThrust_, auxilaryThrust_ and rotationThrust_ to xmlport 84 // make sure that the set- and get-functions exist. 85 // variables can be added by the following command 86 // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunction, getFunction, xmlelement, mode) 87 94 } 95 96 void Rocket::setOwner(Pawn* owner) 97 { 98 this->owner_ = owner; 88 99 } 89 100 … … 98 109 SUPER(Rocket, tick, dt); 99 110 100 //if (this->hasLocalController()) 101 //{ 102 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_); 103 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_); 104 if (this->localLinearAcceleration_.z() > 0) 105 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_); 106 else 107 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 108 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 109 this->localLinearAcceleration_.setValue(0, 0, 0); 110 111 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 112 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 113 this->localAngularAcceleration_.setValue(0, 0, 0); 114 //} 111 this->setAngularVelocity(this->localAngularVelocity_); 115 112 } 116 113 117 /** 118 @brief 119 Moves the Rocket in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector. 120 @param value 121 The vector determining the amount of the movement. 122 */ 123 void Rocket::moveFrontBack(const Vector2& value) 114 bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint) 124 115 { 125 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x); 116 if (!this->bDestroy_ && GameMode::isMaster()) 117 { 118 if (otherObject == this->owner_) 119 return false; 120 121 this->bDestroy_ = true; 122 123 if (this->owner_) 124 { 125 { 126 ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); 127 effect->setPosition(this->getPosition()); 128 effect->setOrientation(this->getOrientation()); 129 effect->setDestroyAfterLife(true); 130 effect->setSource("Orxonox/explosion3"); 131 effect->setLifetime(2.0f); 132 } 133 { 134 ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator()); 135 effect->setPosition(this->getPosition()); 136 effect->setOrientation(this->getOrientation()); 137 effect->setDestroyAfterLife(true); 138 effect->setSource("Orxonox/smoke4"); 139 effect->setLifetime(3.0f); 140 } 141 } 142 143 float dmg = this->damage_; 144 if (this->owner_) 145 dmg = this->owner_->getPickups().processModifiers(ModifierType::Damage, dmg, false); 146 147 Pawn* victim = orxonox_cast<Pawn*>(otherObject); 148 if (victim) 149 victim->damage(dmg, this->owner_); 150 } 151 return false; 126 152 } 127 128 /** 129 @brief 130 Moves the Rocket in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector. 131 @param value 132 The vector determining the amount of the movement. 133 */ 134 void Rocket::moveRightLeft(const Vector2& value) 153 154 void Rocket::destroyObject() 135 155 { 136 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x); 137 } 138 139 /** 140 @brief 141 Moves the Rocket in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector. 142 @param value 143 The vector determining the amount of the movement. 144 */ 145 void Rocket::moveUpDown(const Vector2& value) 146 { 147 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x); 156 if (GameMode::isMaster()) 157 this->destroy(); 148 158 } 149 159 … … 156 166 void Rocket::rotateYaw(const Vector2& value) 157 167 { 158 this->localAngular Acceleration_.setY(this->localAngularAcceleration_.y() - value.x);168 this->localAngularVelocity_.y = value.x; 159 169 } 160 170 … … 167 177 void Rocket::rotatePitch(const Vector2& value) 168 178 { 169 this->localAngular Acceleration_.setX(this->localAngularAcceleration_.x() + value.x);179 this->localAngularVelocity_.x = value.x; 170 180 } 171 181 … … 178 188 void Rocket::rotateRoll(const Vector2& value) 179 189 { 180 this->localAngular Acceleration_.setZ(this->localAngularAcceleration_.z() + value.x);190 this->localAngularVelocity_.z = value.x; 181 191 } 182 192
Note: See TracChangeset
for help on using the changeset viewer.