Changeset 10042 for code/branches/turretFS14
- Timestamp:
- Apr 29, 2014, 11:16:16 AM (11 years ago)
- Location:
- code/branches/turretFS14
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/turretFS14/data/levels/turretTest.oxw
r10039 r10042 34 34 35 35 36 < SpaceShip position="-100,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" /> … … 58 58 59 59 </attached> 60 </SpaceShip> 60 </SpaceShip> --> 61 <StaticEntity position="100,0,0"> 62 <attached> 63 <Model mesh="sphere.mesh" position="20,0,0" scale=1/> 61 64 62 <SpaceShip position="100,0,0" yaw=0 pitch=0> 65 <Model mesh="sphere.mesh" position="0,25,0" scale=1.5/> 66 67 <Model mesh="sphere.mesh" position="0,0,30" scale=2/> 68 </attached> 69 </StaticEntity> 70 <SpaceShip position="100,0,0" yaw=0 pitch=90> 63 71 <attached> 64 72 <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" /> … … 73 81 </templates> 74 82 <controller> 75 <TurretController team= 9/>83 <TurretController team=10 /> 76 84 </controller> 77 85 </Turret> 78 86 79 <Model mesh="sphere.mesh" position="20,0,0" scale=1/>80 87 81 <Model mesh="sphere.mesh" position="0,25,0" scale=1/>82 83 <Model mesh="sphere.mesh" position="0,0,30" scale=1/>84 88 85 89 </attached> -
code/branches/turretFS14/src/modules/objects/Turret.cc
r10039 r10042 113 113 this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_; 114 114 115 //physics don't work when attached :( 116 //this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 115 117 116 pitch(Degree(localAngularAcceleration_.x() /10000), WorldEntity::World);117 yaw(Degree(localAngularAcceleration_.y() /10000), WorldEntity::World);118 roll(Degree(localAngularAcceleration_.z() /10000), WorldEntity::World);118 pitch(Degree(localAngularAcceleration_.x()*dt/1000), WorldEntity::World); 119 yaw(Degree(localAngularAcceleration_.y()*dt/1000), WorldEntity::World); 120 roll(Degree(localAngularAcceleration_.z()*dt/1000), WorldEntity::World); 119 121 120 122 this->localAngularAcceleration_.setValue(0, 0, 0); -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
r10039 r10042 47 47 this->maxYaw_ = 90; 48 48 this->gotOrient_ = false; 49 orxout() << "Constructor " << this << endl;50 49 } 51 50 … … 95 94 } 96 95 97 bool TurretController::isInRange(Vector3 position) 98 { 96 bool TurretController::isInRange(const Vector3 &position) 97 { 98 //Check distance 99 99 Vector3 distance = position - this->getControllableEntity()->getWorldPosition(); 100 100 if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_)) … … 103 103 } 104 104 105 //Check pitch 105 106 Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_); 106 107 Vector3 dirProjected = dir; … … 114 115 } 115 116 117 //Check yaw 116 118 dirProjected = dir; 117 119 dirProjected.y = 0; … … 126 128 } 127 129 130 void TurretController::aimAtPositionRot(const Vector3 &position) 131 { 132 133 Vector3 currDir = this->getControllableEntity()->getWorldOrientation() * WorldEntity::FRONT; 134 Vector3 targetDir = position - this->getControllableEntity()->getWorldPosition(); 135 136 Quaternion rot = currDir.getRotationTo(targetDir); 137 138 //Don't make the rotation instantaneous 139 rot = Quaternion::Slerp(0.1, Quaternion::IDENTITY, rot); 140 141 this->getControllableEntity()->rotate(rot, WorldEntity::World); 142 } 143 144 145 void TurretController::aimAtTargetRot() 146 { 147 this->aimAtPositionRot(this->target_->getWorldPosition()); 148 } 149 150 bool TurretController::isLookingAtTargetNew(float angle) const 151 { 152 return (getAngle(this->getControllableEntity()->getWorldPosition(), this->getControllableEntity()->getWorldOrientation() * WorldEntity::FRONT, this->target_->getWorldPosition()) < angle); 153 } 154 128 155 void TurretController::tick(float dt) 129 156 { 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 165 if (!this->isActive() || !this->getControllableEntity()) 166 return; 167 this->searchTarget(); 168 if(target_) 169 { 170 this->aimAtTarget(); 171 //this->getControllableEntity()->lookAt(this->targetPosition_); 172 //It says move, but really it only turns 173 this->moveToTargetPosition(); 174 if(this->isLookingAtTarget(Degree(5).valueRadians())) 175 { 176 orxout() << 42 << endl; 177 } 178 } 157 if(!gotOrient_) 158 { 159 this->startOrient_ = this->getControllableEntity()->getOrientation(); 160 this->localXStart_ = this->startOrient_ * this->localX_; 161 this->localXStart_.normalise(); 162 this->localX_ = this->localXStart_; 163 this->localYStart_ = this->startOrient_ * this->localY_; 164 this->localYStart_.normalise(); 165 this->localY_ = this->localYStart_; 166 this->localZStart_ = this->startOrient_ * this->localZ_; 167 this->localZStart_.normalise(); 168 this->localZ_ = this->localZStart_; 169 170 //startDir should always be (0,0,-1) 171 this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_); 172 173 this->gotOrient_ = true; 174 175 } 176 177 WorldEntity* parent = this->getControllableEntity()->getParent(); 178 if(parent) 179 { 180 Quaternion parentrot = parent->getOrientation(); 181 this->localX_ = parentrot * this->localXStart_; 182 this->localY_ = parentrot * this->localYStart_; 183 this->localZ_ = parentrot * this->localZStart_; 184 } 185 186 187 188 if (!this->isActive() || !this->getControllableEntity()) 189 return; 190 191 this->searchTarget(); 192 if(target_) 193 { 194 this->aimAtTarget(); 195 //this->getControllableEntity()->lookAt(this->targetPosition_); 196 //It says move, but really it only turns 197 this->aimAtTargetRot(); 198 if(this->isLookingAtTargetNew(Degree(5).valueRadians())) 199 { 200 orxout() << 42 << endl; 201 } 202 } 179 203 } 180 204 } -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
r10039 r10042 56 56 Vector3 localX_; 57 57 Vector3 localXStart_; 58 59 void aimAtPositionRot(const Vector3 &position); 60 void aimAtTargetRot(); 58 61 void searchTarget(); 59 bool isInRange(Vector3 position); 62 bool isInRange(const Vector3 &position); 63 bool isLookingAtTargetNew(float angle) const; 60 64 }; 61 65 }
Note: See TracChangeset
for help on using the changeset viewer.