Changeset 10681 in orxonox.OLD for branches/adm
- Timestamp:
- Jun 9, 2007, 12:06:51 AM (18 years ago)
- Location:
- branches/adm/src/world_entities/npcs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/adm/src/world_entities/npcs/adm_turret.cc
r10679 r10681 67 67 .describe("The filename of the World Entity, that is to be shot at") 68 68 .defaultValues(""); 69 70 LoadParam(root, "type", this, AdmTurret, setType) 71 .describe("floor|ceil"); 69 72 70 73 LoadParamXML(root, "Cannons", this, AdmTurret, addCannons) … … 74 77 75 78 } 79 // this->removeNodeFlags( PNODE_ALL ); 80 // this->addNodeFlags( PNODE_ROTATE_AND_MOVE ); 76 81 77 //HACK this is really ugly because if you move the AdmTurret its cannons wont follow 78 if ( this->cannons ) 79 this->cannons->setParent( NullParent::getNullParent() ); 82 if ( this->isCeil ) 83 { 84 Vector a = this->sensor->getRelCoor(); 85 this->sensor->setRelCoor( -a.x, -a.y, -a.z ); 86 a = this->cannons->getRelCoor(); 87 this->cannons->setRelCoor( -a.x, -a.y, -a.z ); 88 } 80 89 } 81 90 … … 96 105 } 97 106 107 void AdmTurret::setType( const std::string& type ) 108 { 109 if ( type == "floor" ) 110 { 111 this->isCeil = false; 112 return; 113 } 114 115 if ( type == "ceil" ) 116 { 117 this->isCeil = true; 118 return; 119 } 120 121 //invalid argument 122 PRINTF(1)("%s is not a valid type for AdmTurret\n", type.c_str()); 123 assert("false"); 124 } 125 98 126 void AdmTurret::init() 99 127 { 100 128 this->registerObject(this, AdmTurret::_objectList); 101 129 102 //this->removeNodeFlags( 7 ); 130 this->bodyAngle = this->cannonAngle = 0.0f; 131 this->isActive = true; 132 this->range = 400; 133 this->isCeil = false; 103 134 } 104 135 … … 112 143 113 144 Vector playerPos = this->myTarget->getAbsCoor(); 114 this->moveTowards( playerPos - ( this->cannons->getAbsCoor() ), dt); 145 Vector ds = playerPos - ( this->cannons->getAbsCoor() ); 146 if ( isActive && ds.len() <= range ) 147 this->moveTowards( ds, dt); 148 else 149 this->moveTowards( Vector(0, -1, 0), dt ); 115 150 } 116 151 … … 216 251 void AdmTurret::moveTowards( Vector targetDir, float dt ) 217 252 { 218 #if 0 219 static Quaternion mrot = this->getAbsDir(); 220 Quaternion ry( dt, Vector(0, 1, 0) ); 221 mrot *= ry; 222 this->setAbsDir(mrot); 223 224 static Quaternion rot = this->cannons->getAbsDir(); 225 Quaternion rx( dt, Vector( 0, 0, 1 ) ); 226 rot *= rx; 227 this->cannons->setAbsDir(rot*mrot); 228 return; 229 #endif 230 231 232 233 234 Quaternion cur = this->getAbsDir(); 235 236 Quaternion ry( dt, cur.inverse().apply( Vector( 0, 1, 0 ) ) ); 237 238 Quaternion tmp1 = cur * ry; 239 Quaternion tmp2 = cur * ry.inverse(); 240 241 bool usetmp1 = false; 242 Quaternion r1; 243 if ( tmp1.apply( Vector(1, 0, 0) ).dot(targetDir) < tmp2.apply( Vector(1, 0, 0)).dot(targetDir) ) 253 if ( this->cannons->getParent() != NullParent::getNullParent() ) 254 this->cannons->setParent( NullParent::getNullParent() ); 255 256 targetDir.normalize(); 257 258 float dAngle = dt; 259 260 float bestResult = -1.0f; 261 Quaternion bestBodyRot; 262 Quaternion bestCannonRot; 263 float bestBodyAngle = 0.0f; 264 float bestCannonAngle = 0.0f; 265 266 // Quaternion baseRot(0, Vector); 267 // if ( isCeil ) 268 // { 269 // printf( "ceil\n" ); 270 // baseRot = Quaternion( PI/2, Vector( 0, 0, 1 ) ); 271 // } 272 273 for ( int dBodyAngle = -1; dBodyAngle<2; dBodyAngle++ ) 244 274 { 245 usetmp1 = true; 246 cur = tmp1; 247 r1 = ry; 275 for ( int dCannonAngle = -1; dCannonAngle<2; dCannonAngle++ ) 276 { 277 float bodyAngle = this->bodyAngle + dBodyAngle*dAngle; 278 float cannonAngle = this->cannonAngle + dCannonAngle*dAngle; 279 280 while ( bodyAngle > 2*PI ) 281 bodyAngle -= 2*PI; 282 while ( bodyAngle < 0 ) 283 bodyAngle += 2*PI; 284 while ( cannonAngle > 2*PI ) 285 cannonAngle -= 2*PI; 286 while ( cannonAngle < 0 ) 287 cannonAngle += 2*PI; 288 289 Quaternion bodyRot( bodyAngle, Vector( 0, 1, 0 ) ); 290 Quaternion cannonRot( cannonAngle, Vector( 0, 0, 1) ); 291 292 // bodyRot = baseRot * bodyRot; 293 // cannonRot = baseRot * cannonRot; 294 295 float result = (bodyRot * cannonRot).apply( Vector( -1, 0, 0 ) ).dot( targetDir ); 296 297 if ( result > bestResult ) 298 { 299 bestResult = result; 300 bestBodyRot = bodyRot; 301 bestBodyAngle = bodyAngle; 302 bestCannonRot = cannonRot; 303 bestCannonAngle = cannonAngle; 304 } 305 } 248 306 } 249 else 250 { 251 cur = tmp2; 252 r1 = ry.inverse(); 253 } 254 255 this->setAbsDir( cur ); 256 257 258 Quaternion cur2 = this->cannons->getAbsDir(); 259 Quaternion rx( dt, cur.inverse().apply( Vector( 0, 0, 1 ) ) ); 260 Quaternion rr( dt, cur2.inverse().apply( Vector( 0, 1, 0 ) ) ); 261 if ( !usetmp1 ) 262 rr = rr.inverse(); 263 264 265 tmp1 = cur2 * rx; 266 tmp2 = cur2 * rx.inverse(); 267 268 Quaternion dec; 269 Quaternion r2; 270 if ( tmp1.apply( Vector(-1, 0, 0) ).dot(targetDir) > tmp2.apply( Vector(-1, 0, 0) ).dot(targetDir) ) 271 { 272 r2 = rx; 273 dec = tmp1; 274 } 275 else 276 { 277 r2 = rx.inverse(); 278 dec = tmp2; 279 } 280 281 float dp = dec.apply( Vector(-1, 0, 0) ).dot(Vector(0, 1, 0)); 282 if ( dp > -0.9 && dp < 0.9 ) 283 { 284 cur2 = dec; 285 } 286 287 this->cannons->setAbsDir( cur2 ); 288 289 290 291 } 307 308 this->bodyAngle = bestBodyAngle; 309 this->cannonAngle = bestCannonAngle; 310 311 this->setAbsDir( bestBodyRot ); 312 this->cannons->setAbsDir( bestBodyRot * bestCannonRot ); 313 } -
branches/adm/src/world_entities/npcs/adm_turret.h
r10677 r10681 44 44 45 45 void moveTowards( Vector targetDir, float dt ); 46 47 float bodyAngle; 48 float cannonAngle; 49 50 bool isActive; 51 float range; 52 53 bool isCeil; 54 void setType( const std::string& type ); 46 55 47 56 };
Note: See TracChangeset
for help on using the changeset viewer.