[8200] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[8894] | 3 | |
---|
[8200] | 4 | Copyright (C) 2004 orx |
---|
[8894] | 5 | |
---|
[8200] | 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[8894] | 10 | |
---|
[8200] | 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_COLLISION_REACTION |
---|
| 17 | |
---|
| 18 | #include "collision.h" |
---|
| 19 | #include "collision_event.h" |
---|
| 20 | |
---|
| 21 | #include "physics_interface.h" |
---|
| 22 | |
---|
| 23 | #include "world_entity.h" |
---|
| 24 | #include "cr_physics_ground_walk.h" |
---|
[9003] | 25 | #include "collision_reaction.h" |
---|
[8200] | 26 | |
---|
[8288] | 27 | #include <vector> |
---|
| 28 | |
---|
[8894] | 29 | #include "debug.h" |
---|
| 30 | |
---|
[8796] | 31 | #include "aabb.h" |
---|
| 32 | |
---|
[8894] | 33 | #include "cr_defs.h" |
---|
| 34 | |
---|
[8200] | 35 | |
---|
| 36 | |
---|
[9406] | 37 | |
---|
[8200] | 38 | /** |
---|
| 39 | * standard constructor |
---|
| 40 | */ |
---|
| 41 | CRPhysicsGroundWalk::CRPhysicsGroundWalk () |
---|
[8724] | 42 | : CollisionReaction() |
---|
[8200] | 43 | { |
---|
[8203] | 44 | this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk"); |
---|
[8200] | 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * standard deconstructor |
---|
| 50 | */ |
---|
| 51 | CRPhysicsGroundWalk::~CRPhysicsGroundWalk () |
---|
[8724] | 52 | {} |
---|
[8200] | 53 | |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * caluculates and applys the reaction to a specific collision |
---|
| 57 | * @param collision the collision |
---|
| 58 | */ |
---|
| 59 | void CRPhysicsGroundWalk::reactToCollision(Collision* collision) |
---|
| 60 | { |
---|
[8288] | 61 | |
---|
[8796] | 62 | AABB* box = collision->getEntityB()->getModelAABB(); |
---|
[8894] | 63 | WorldEntity* entity = collision->getEntityB(); |
---|
| 64 | |
---|
| 65 | if( box == NULL) |
---|
| 66 | { |
---|
| 67 | PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n"); |
---|
| 68 | return; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | |
---|
[9110] | 72 | float CR_MAX_WALK_HEIGHT = 15.0f; |
---|
[9003] | 73 | |
---|
[9110] | 74 | float height = 0.0f; |
---|
[9003] | 75 | |
---|
| 76 | |
---|
| 77 | const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); |
---|
| 78 | std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); |
---|
| 79 | for(; it != collisionEvents->end(); it++) |
---|
[8894] | 80 | { |
---|
| 81 | |
---|
[9003] | 82 | CollisionEvent* ce = (*it); |
---|
| 83 | Vector normal = ce->getGroundNormal(); |
---|
[8894] | 84 | |
---|
[9003] | 85 | // calculate the collision position |
---|
| 86 | Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition(); |
---|
[8894] | 87 | |
---|
[9003] | 88 | // test the 3 axis differently |
---|
| 89 | switch( ce->getType()) |
---|
| 90 | { |
---|
[9110] | 91 | /* collision in the Y-AXIS */ |
---|
[9061] | 92 | case COLLISION_TYPE_AXIS_Y_NEG: |
---|
[9003] | 93 | // calulate the height above ground |
---|
[9110] | 94 | height = collPos.len() - box->halfLength[1]; |
---|
[8894] | 95 | |
---|
| 96 | |
---|
[9003] | 97 | // object is beneath the plane (ground) |
---|
[9110] | 98 | // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing |
---|
| 99 | if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) |
---|
[9003] | 100 | { |
---|
[9061] | 101 | entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); |
---|
[9003] | 102 | entity->setOnGround(true); |
---|
| 103 | } |
---|
| 104 | // object is already in the wall |
---|
| 105 | else if( ce->isInWall()) |
---|
| 106 | { |
---|
| 107 | entity->setAbsCoor(entity->getLastAbsCoor()); |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
| 111 | // entity is not on ground |
---|
| 112 | entity->setOnGround(false); |
---|
| 113 | } |
---|
| 114 | break; |
---|
[8894] | 115 | |
---|
| 116 | |
---|
[9003] | 117 | } |
---|
| 118 | } |
---|
| 119 | //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side); |
---|
[8894] | 120 | |
---|
[8256] | 121 | } |
---|
[8200] | 122 | |
---|
[8256] | 123 | |
---|
| 124 | |
---|
[8724] | 125 | |
---|
[8256] | 126 | /** |
---|
| 127 | * use this to do some collision offline calculations, only called for bContinuousPoll == true |
---|
| 128 | */ |
---|
| 129 | void CRPhysicsGroundWalk::update(WorldEntity* owner) |
---|
[9003] | 130 | {} |
---|
[8894] | 131 | |
---|
[8200] | 132 | |
---|