Changeset 3043 for code/branches/netp3/src/orxonox/objects/worldentities
- Timestamp:
- May 24, 2009, 10:38:06 PM (16 years ago)
- Location:
- code/branches/netp3/src/orxonox/objects/worldentities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/netp3/src/orxonox/objects/worldentities/PongBall.cc
r2896 r3043 32 32 #include "core/CoreIncludes.h" 33 33 #include "core/GameMode.h" 34 #include "objects/worldentities/PongBat.h"35 34 #include "objects/gametypes/Gametype.h" 36 35 … … 47 46 this->speed_ = 0; 48 47 this->bat_ = 0; 48 this->batID_ = new unsigned int[2]; 49 this->batID_[0] = OBJECTID_UNKNOWN; 50 this->batID_[1] = OBJECTID_UNKNOWN; 49 51 this->relMercyOffset_ = 0.05; 52 53 this->registerVariables(); 54 } 55 56 void PongBall::registerVariables() 57 { 58 registerVariable( this->batID_[0] ); 59 registerVariable( this->batID_[1], variableDirection::toclient, new NetworkCallback<PongBall>( this, &PongBall::applyBats) ); 50 60 } 51 61 … … 119 129 this->setPosition(position); 120 130 } 131 else 132 { 133 Vector3 position = this->getPosition(); 134 Vector3 velocity = this->getVelocity(); 135 136 if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2) 137 { 138 velocity.z = -velocity.z; 139 140 if (position.z > this->fieldHeight_ / 2) 141 position.z = this->fieldHeight_ / 2; 142 if (position.z < -this->fieldHeight_ / 2) 143 position.z = -this->fieldHeight_ / 2; 144 } 145 146 if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2) 147 { 148 float distance = 0; 149 150 if (this->bat_) 151 { 152 if (position.x > this->fieldWidth_ / 2 && this->bat_[1]) 153 { 154 distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2); 155 if (fabs(distance) <= 1) 156 { 157 position.x = this->fieldWidth_ / 2; 158 velocity.x = -velocity.x; 159 velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_; 160 } 161 } 162 if (position.x < -this->fieldWidth_ / 2 && this->bat_[0]) 163 { 164 distance = (position.z - this->bat_[0]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10) / 2); 165 if (fabs(distance) <= 1) 166 { 167 position.x = -this->fieldWidth_ / 2; 168 velocity.x = -velocity.x; 169 velocity.z = distance * distance * sgn(distance) * PongBall::MAX_REL_Z_VELOCITY * this->speed_; 170 } 171 } 172 } 173 } 174 175 if (velocity != this->getVelocity()) 176 this->setVelocity(velocity); 177 if (position != this->getPosition()) 178 this->setPosition(position); 179 } 121 180 } 122 181 -
code/branches/netp3/src/orxonox/objects/worldentities/PongBall.h
r2885 r3043 33 33 34 34 #include "objects/worldentities/MovableEntity.h" 35 #include "objects/worldentities/PongBat.h" 35 36 36 37 namespace orxonox … … 43 44 44 45 virtual void tick(float dt); 46 47 void registerVariables(); 45 48 46 49 void setFieldDimension(float width, float height) … … 61 64 62 65 void setBats(PongBat** bats) 63 { this->bat_ = bats; } 66 { this->bat_ = bats; this->batID_[0] = this->bat_[0]->getObjectID(); this->batID_[1] = this->bat_[1]->getObjectID(); } 67 68 void applyBats() 69 { if(!this->bat_) this->bat_ = new PongBat*[2]; if(this->batID_[0] != OBJECTID_UNKNOWN) this->bat_[0] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[0])); if(this->batID_[1] != OBJECTID_UNKNOWN) this->bat_[1] = dynamic_cast<PongBat*>(Synchronisable::getSynchronisable(this->batID_[1])); } 64 70 65 71 static const float MAX_REL_Z_VELOCITY; … … 71 77 float batlength_; 72 78 PongBat** bat_; 79 unsigned int* batID_; 73 80 float relMercyOffset_; 74 81 };
Note: See TracChangeset
for help on using the changeset viewer.