Changeset 10039 for code/branches
- Timestamp:
- Apr 17, 2014, 4:05:06 PM (11 years ago)
- Location:
- code/branches/turretFS14
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt
r10031 r10039 49 49 <BlinkingBillboard position="-17,-1.5,0" material="Examples/Flare" colour="0.5, 1.0, 0.3" amplitude=0.1 frequency=0.5 phase=180 quadratic=1 /> 50 50 51 <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>51 <!-- <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000> 52 52 <templates> 53 53 <Template link=spaceshipturrettest /> … … 56 56 <TurretController team=10 /> 57 57 </controller> 58 </Turret> 58 </Turret> --> 59 59 60 60 </attached> -
code/branches/turretFS14/data/levels/turretTest.oxw
r10031 r10039 34 34 35 35 36 < MovableEntity position="0,0,0" yaw=0 pitch=0>36 <SpaceShip position="-100,0,0" yaw=0 pitch=0> 37 37 <attached> 38 38 <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" /> … … 42 42 <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" /> 43 43 44 < !-- <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>44 <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000> 45 45 <templates> 46 46 <Template link=spaceshipturrettest /> … … 49 49 <TurretController team=10 /> 50 50 </controller> 51 </Turret> -->51 </Turret> 52 52 53 53 <Model mesh="sphere.mesh" position="20,0,0" scale=1/> … … 58 58 59 59 </attached> 60 </ MovableEntity>60 </SpaceShip> 61 61 62 <SpaceShip position="100,0,0" yaw=0 pitch=0> 63 <attached> 64 <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" /> 65 <Model position="0,0,0" mesh="turretSocketIn.mesh" scale3D="10,10,10" /> 66 <Model position="0,0,0" mesh="turretSocketTop.mesh" scale3D="10,10,10" /> 67 <Model position="0,0,0" mesh="turretSocketLeft.mesh" scale3D="10,10,10" /> 68 <Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" /> 62 69 70 <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000> 71 <templates> 72 <Template link=spaceshipturrettest /> 73 </templates> 74 <controller> 75 <TurretController team=9 /> 76 </controller> 77 </Turret> 78 79 <Model mesh="sphere.mesh" position="20,0,0" scale=1/> 80 81 <Model mesh="sphere.mesh" position="0,25,0" scale=1/> 82 83 <Model mesh="sphere.mesh" position="0,0,30" scale=1/> 84 85 </attached> 86 </SpaceShip> 63 87 64 88 -
code/branches/turretFS14/src/libraries/core/input/InputManager.cc
r9667 r10039 175 175 176 176 if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen()) 177 { 177 { // HACK MARTIN for debugging, changed values here to true 178 178 if (CommandLineParser::getValue("keyboard_no_grab").get<bool>()) 179 179 paramList.insert(StringPair("x11_keyboard_grab", "false")); 180 180 else 181 paramList.insert(StringPair("x11_keyboard_grab", " true"));182 paramList.insert(StringPair("x11_mouse_grab", " true"));183 paramList.insert(StringPair("x11_mouse_hide", " true"));181 paramList.insert(StringPair("x11_keyboard_grab", "false")); 182 paramList.insert(StringPair("x11_mouse_grab", "false")); 183 paramList.insert(StringPair("x11_mouse_hide", "false")); 184 184 } 185 185 else -
code/branches/turretFS14/src/modules/objects/Turret.cc
r10031 r10039 44 44 { 45 45 RegisterObject(Turret); 46 this->startOrient_ = Quaternion::IDENTITY;47 this->startDir_ = Vector3::ZERO;48 this->localZ_ = Vector3::UNIT_Z;49 this->localY_ = Vector3::UNIT_Y;50 this->localX_ = Vector3::UNIT_X;51 this->maxPitch_ = 0;52 this->maxYaw_ = 0;53 this->attackRadius_ = 200;54 this->gotOrient_ = false;55 46 this->rotationThrust_ = 50; 56 47 … … 110 101 } 111 102 112 bool Turret::isInRange(Vector3 position)113 {114 Vector3 distance = position - this->getPosition();115 if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))116 {117 return false;118 }119 120 Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);121 Vector3 dirProjected = dir;122 dirProjected.x = 0;123 Vector3 startDirProjected = this->startDir_;124 startDirProjected.x = 0;125 Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();126 if(angle > this->maxPitch_)127 {128 return false;129 }130 131 dirProjected = dir;132 dirProjected.y = 0;133 startDirProjected = this->startDir_;134 startDirProjected.y = 0;135 angle = startDirProjected.angleBetween(dirProjected).valueDegrees();136 if(angle > this->maxYaw_)137 {138 return false;139 }140 return true;141 }142 143 103 void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode) 144 104 { 145 XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);146 XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);147 XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode);148 105 SUPER(Turret, XMLPort, xmlelement, mode); 149 106 } … … 153 110 SUPER(Turret, tick, dt); 154 111 155 if(!gotOrient_) 156 { 157 this->startOrient_ = this->getOrientation(); 158 this->localX_ = this->startOrient_ * this->localX_; 159 this->localX_.normalise(); 160 this->localY_ = this->startOrient_ * this->localY_; 161 this->localY_.normalise(); 162 this->localZ_ = this->startOrient_ * this->localZ_; 163 this->localZ_.normalise(); 112 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 113 this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_; 164 114 165 //startDir should always be (0,0,-1)166 this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);167 115 168 this->gotOrient_ = true; 169 } 116 pitch(Degree(localAngularAcceleration_.x()/10000), WorldEntity::World); 117 yaw(Degree(localAngularAcceleration_.y()/10000), WorldEntity::World); 118 roll(Degree(localAngularAcceleration_.z()/10000), WorldEntity::World); 170 119 171 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;172 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);173 120 this->localAngularAcceleration_.setValue(0, 0, 0); 174 121 } 175 176 122 } -
code/branches/turretFS14/src/modules/objects/Turret.h
r10031 r10039 54 54 virtual void tick(float dt); 55 55 56 virtual bool isInRange(Vector3 position);57 58 inline void setMaxPitch(Ogre::Real pitch)59 {this->maxPitch_ = pitch;}60 61 inline Ogre::Real getMaxPitch()62 {return this->maxPitch_;}63 64 inline void setMaxYaw(Ogre::Real yaw)65 {this->maxYaw_ = yaw;}66 67 inline Ogre::Real getMaxYaw()68 {return this->maxYaw_;}69 70 inline void setAttackRadius(float radius)71 {this->attackRadius_ = radius;}72 73 inline float getAttackRadius()74 {return this->attackRadius_;}75 76 56 77 57 private: 78 bool gotOrient_;79 Ogre::Real maxPitch_;80 Ogre::Real maxYaw_;81 float attackRadius_;82 Quaternion startOrient_;83 Vector3 startDir_;84 Vector3 localZ_;85 Vector3 localY_;86 Vector3 localX_;87 58 float rotationThrust_; 88 59 … … 92 63 93 64 #endif 94 -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
r10031 r10039 38 38 { 39 39 RegisterObject(TurretController); 40 this->startOrient_ = Quaternion::IDENTITY; 41 this->startDir_ = Vector3::ZERO; 42 this->localZ_ = Vector3::UNIT_Z; 43 this->localY_ = Vector3::UNIT_Y; 44 this->localX_ = Vector3::UNIT_X; 45 this->attackRadius_ = 200; 46 this->maxPitch_ = 90; 47 this->maxYaw_ = 90; 48 this->gotOrient_ = false; 49 orxout() << "Constructor " << this << endl; 40 50 } 41 51 … … 48 58 { 49 59 Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity()); 50 if(target_ && t urret->isInRange(target_->getPosition()))60 if(target_ && this->isInRange(target_->getWorldPosition())) 51 61 { 52 62 return; … … 62 72 { 63 73 Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget()); 64 if(parenttarget && t urret->isInRange(parenttarget->getPosition()))74 if(parenttarget && this->isInRange(parenttarget->getWorldPosition())) 65 75 { 66 76 this->setTarget(parenttarget); … … 76 86 continue; 77 87 78 if(t urret->isInRange(entity->getPosition()))88 if(this->isInRange(entity->getWorldPosition())) 79 89 { 80 90 this->setTarget(entity); … … 85 95 } 86 96 97 bool TurretController::isInRange(Vector3 position) 98 { 99 Vector3 distance = position - this->getControllableEntity()->getWorldPosition(); 100 if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_)) 101 { 102 return false; 103 } 104 105 Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_); 106 Vector3 dirProjected = dir; 107 dirProjected.x = 0; 108 Vector3 startDirProjected = this->startDir_; 109 startDirProjected.x = 0; 110 Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees(); 111 if(angle > this->maxPitch_) 112 { 113 return false; 114 } 115 116 dirProjected = dir; 117 dirProjected.y = 0; 118 startDirProjected = this->startDir_; 119 startDirProjected.y = 0; 120 angle = startDirProjected.angleBetween(dirProjected).valueDegrees(); 121 if(angle > this->maxYaw_) 122 { 123 return false; 124 } 125 return true; 126 } 127 87 128 void TurretController::tick(float dt) 88 129 { 130 131 132 if(!gotOrient_) 133 { 134 this->startOrient_ = this->getControllableEntity()->getOrientation(); 135 this->localXStart_ = this->startOrient_ * this->localX_; 136 this->localXStart_.normalise(); 137 this->localX_ = this->localXStart_; 138 this->localYStart_ = this->startOrient_ * this->localY_; 139 this->localYStart_.normalise(); 140 this->localY_ = this->localYStart_; 141 this->localZStart_ = this->startOrient_ * this->localZ_; 142 this->localZStart_.normalise(); 143 this->localZ_ = this->localZStart_; 144 145 //startDir should always be (0,0,-1) 146 this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_); 147 148 this->gotOrient_ = true; 149 } 150 151 //orxout() << "Controller " << this; 152 //orxout() << "\tControllable Entity " << this->getControllableEntity() << endl; 153 WorldEntity* parent = this->getControllableEntity()->getParent(); 154 if(parent) 155 { 156 Quaternion parentrot = parent->getOrientation(); 157 this->localX_ = parentrot * this->localXStart_; 158 this->localY_ = parentrot * this->localYStart_; 159 this->localZ_ = parentrot * this->localZStart_; 160 } 161 162 orxout() << this->getControllableEntity()->getWorldPosition() << endl; 163 164 89 165 if (!this->isActive() || !this->getControllableEntity()) 90 166 return; 91 167 this->searchTarget(); 92 this->getControllableEntity()->rotatePitch(0.2); 93 /*if(target_) 168 if(target_) 94 169 { 95 170 this->aimAtTarget(); 171 //this->getControllableEntity()->lookAt(this->targetPosition_); 96 172 //It says move, but really it only turns 97 173 this->moveToTargetPosition(); … … 100 176 orxout() << 42 << endl; 101 177 } 102 } */178 } 103 179 } 104 180 } -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
r10031 r10039 44 44 45 45 private: 46 bool gotOrient_; 47 float attackRadius_; 48 Ogre::Real maxPitch_; 49 Ogre::Real maxYaw_; 50 Quaternion startOrient_; 51 Vector3 startDir_; 52 Vector3 localZ_; 53 Vector3 localZStart_; 54 Vector3 localY_; 55 Vector3 localYStart_; 56 Vector3 localX_; 57 Vector3 localXStart_; 46 58 void searchTarget(); 59 bool isInRange(Vector3 position); 47 60 }; 48 61 } -
code/branches/turretFS14/src/orxonox/controllers/ArtificialController.cc
r9667 r10039 94 94 static const float hardcoded_projectile_speed = 1250; 95 95 96 this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->get Position(), hardcoded_projectile_speed, this->target_->getPosition(), this->target_->getVelocity());96 this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity()); 97 97 this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO); 98 98 -
code/branches/turretFS14/src/orxonox/controllers/FormationController.cc
r9800 r10039 277 277 } 278 278 279 Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->get Position(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);280 float distance = (target - this->getControllableEntity()->get Position()).length();279 Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getWorldPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 280 float distance = (target - this->getControllableEntity()->getWorldPosition()).length(); 281 281 float rotateX = clamp(coord.x * 10, -1.0f, 1.0f); 282 282 float rotateY = clamp(coord.y * 10, -1.0f, 1.0f); -
code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc
r10031 r10039 414 414 else if (this->isDynamic()) 415 415 { 416 //hacky hack, really shouldn't do that 416 417 //orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl; 417 418 //return false;
Note: See TracChangeset
for help on using the changeset viewer.