Changeset 8190 in orxonox.OLD for trunk/src/world_entities/world_entity.cc
- Timestamp:
- Jun 7, 2006, 3:00:01 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/world_entity.cc
r8186 r8190 32 32 #include "camera.h" 33 33 34 #include "cr_engine.h"35 34 #include "collision_handle.h" 35 #include "collision_event.h" 36 37 #include <stdarg.h> 36 38 37 39 … … 59 61 this->healthMax = 1.0f; 60 62 this->health = 1.0f; 63 this->damage = 0.0f; // no damage dealt by a default entity 61 64 this->scaling = 1.0f; 62 65 … … 68 71 this->objectListIterator = NULL; 69 72 73 // reset all collision handles to NULL == unsubscribed state 74 for(int i = 0; i < CREngine::CR_NUMBER; ++i) 75 this->collisionHandles[i] = NULL; 76 this->bReactive = false; 77 78 // registering default reactions: 79 this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY); 80 this->subscribeReaction(CREngine::CR_PHYSICS_GROUND, CL_TERRAIN); 81 70 82 this->toList(OM_NULL); 71 83 … … 91 103 if (this->healthWidget != NULL) 92 104 delete this->healthWidget; 105 106 this->unsubscribeReaction(); 93 107 } 94 108 … … 249 263 * subscribes this world entity to a collision reaction 250 264 * @param type the type of reaction to subscribe to 265 * @param target1 a filter target (classID) 266 */ 267 void WorldEntity::subscribeReaction(CREngine::CRType type, long target1) 268 { 269 this->subscribeReaction(type); 270 271 // add the target filter 272 this->collisionHandles[type]->addTarget(target1); 273 } 274 275 276 /** 277 * subscribes this world entity to a collision reaction 278 * @param type the type of reaction to subscribe to 279 * @param target1 a filter target (classID) 280 */ 281 void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2) 282 { 283 this->subscribeReaction(type); 284 285 // add the target filter 286 this->collisionHandles[type]->addTarget(target1); 287 this->collisionHandles[type]->addTarget(target2); 288 } 289 290 291 /** 292 * subscribes this world entity to a collision reaction 293 * @param type the type of reaction to subscribe to 294 * @param target1 a filter target (classID) 295 */ 296 void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3) 297 { 298 this->subscribeReaction(type); 299 300 // add the target filter 301 this->collisionHandles[type]->addTarget(target1); 302 this->collisionHandles[type]->addTarget(target2); 303 this->collisionHandles[type]->addTarget(target3); 304 } 305 306 307 /** 308 * subscribes this world entity to a collision reaction 309 * @param type the type of reaction to subscribe to 310 * @param target1 a filter target (classID) 311 */ 312 void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4) 313 { 314 this->subscribeReaction(type); 315 316 // add the target filter 317 this->collisionHandles[type]->addTarget(target1); 318 this->collisionHandles[type]->addTarget(target2); 319 this->collisionHandles[type]->addTarget(target3); 320 this->collisionHandles[type]->addTarget(target4); 321 } 322 323 324 /** 325 * subscribes this world entity to a collision reaction 326 * @param type the type of reaction to subscribe to 251 327 * @param nrOfTargets number of target filters 252 328 * @param ... the targets as classIDs 253 329 */ 254 void WorldEntity::subscribeReaction(CREngine::CRType type, int nrOfTargets, ...) 255 {} 330 void WorldEntity::subscribeReaction(CREngine::CRType type) 331 { 332 if( this->collisionHandles[type] != NULL) { 333 PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n"); 334 return; 335 } 336 337 this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type); 338 339 // now there is at least one collision reaction subscribed 340 this->bReactive = true; 341 } 342 343 344 /** 345 * unsubscribes a specific reaction from the worldentity 346 * @param type the reaction to unsubscribe 347 */ 348 void WorldEntity::unsubscribeReaction(CREngine::CRType type) 349 { 350 if( this->collisionHandles[type] == NULL) 351 return; 352 353 CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]); 354 this->collisionHandles[type] = NULL; 355 356 // check if there is still any handler registered 357 for(int i = 0; i < CREngine::CR_NUMBER; ++i) 358 { 359 if( this->collisionHandles[i] != NULL) 360 { 361 this->bReactive = true; 362 return; 363 } 364 } 365 this->bReactive = false; 366 } 367 368 369 /** 370 * unsubscribes all collision reactions 371 */ 372 void WorldEntity::unsubscribeReaction() 373 { 374 for( int i = 0; i < CREngine::CR_NUMBER; i++) 375 this->unsubscribeReaction((CREngine::CRType)i); 376 377 // there are no reactions subscribed from now on 378 this->bReactive = false; 379 } 380 381 382 /** 383 * registers a new collision event to this world entity 384 * @param entityA entity of the collision 385 * @param entityB entity of the collision 386 * @param bvA colliding bounding volume of entityA 387 * @param bvB colliding bounding volume of entityA 388 */ 389 bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) 390 { 391 // is there any handler listening? 392 if( !this->bReactive) 393 return false; 394 395 // get a collision event 396 CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject(); 397 assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h 398 c->collide(entityA, entityB, bvA, bvB); 399 400 for( int i = 0; i < CREngine::CR_NUMBER; ++i) 401 if( this->collisionHandles[i] != NULL) 402 this->collisionHandles[i]->registerCollisionEvent(c); 403 } 404 405 406 /** 407 * registers a new collision event to this woeld entity 408 * @param entity the entity that collides 409 * @param plane it stands on 410 * @param position it collides on the plane 411 */ 412 bool WorldEntity::registerCollision(WorldEntity* entity, Plane* plane, Vector position) 413 { 414 // is there any handler listening? 415 if( !this->bReactive) 416 return false; 417 418 // get a collision event 419 CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject(); 420 assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h 421 c->collide(entity, plane, position); 422 423 for( int i = 0; i < CREngine::CR_NUMBER; ++i) 424 if( this->collisionHandles[i] != NULL) 425 this->collisionHandles[i]->registerCollisionEvent(c); 426 } 256 427 257 428 … … 324 495 void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2) 325 496 { 326 497 327 498 // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassName() ); 328 499 329 500 Vector v = this->getAbsDirX(); 330 501 v.x *= 10; … … 332 503 v.z *= 10; 333 504 Vector u = this->getAbsDirY(); 334 505 335 506 if(feet.x == (u.x+this->getAbsCoor().x) && feet.y == u.y +this->getAbsCoor().y && feet.z == this->getAbsCoor().z) 336 507 { 337 508 338 509 this->setAbsCoor(ray_2 - v); 339 510 } … … 342 513 if(ray_1.x == this->getAbsCoor().x + v.x && ray_1.y == this->getAbsCoor().y + v.y + 0.1 && ray_1.z ==this->getAbsCoor().z + v.z) 343 514 { 344 this->setAbsCoor(feet -u ); 345 } 346 347 this->setAbsCoor(ray_2 - v); 348 515 this->setAbsCoor(feet -u ); 516 } 517 518 this->setAbsCoor(ray_2 - v); 519 349 520 } 350 521 }
Note: See TracChangeset
for help on using the changeset viewer.