[8200] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 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. |
---|
| 10 | |
---|
| 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" |
---|
| 25 | |
---|
[8288] | 26 | #include <vector> |
---|
| 27 | |
---|
[8200] | 28 | using namespace std; |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | /** |
---|
| 32 | * standard constructor |
---|
| 33 | */ |
---|
| 34 | CRPhysicsGroundWalk::CRPhysicsGroundWalk () |
---|
| 35 | : CollisionReaction() |
---|
| 36 | { |
---|
[8203] | 37 | this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk"); |
---|
[8200] | 38 | } |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | /** |
---|
| 42 | * standard deconstructor |
---|
| 43 | */ |
---|
| 44 | CRPhysicsGroundWalk::~CRPhysicsGroundWalk () |
---|
| 45 | { |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * caluculates and applys the reaction to a specific collision |
---|
| 51 | * @param collision the collision |
---|
| 52 | */ |
---|
| 53 | void CRPhysicsGroundWalk::reactToCollision(Collision* collision) |
---|
| 54 | { |
---|
[8323] | 55 | // CollisionEvent* ce = collision->getCollisionEvents().front(); |
---|
| 56 | // Vector normal = ce->getGroundNormal(); |
---|
| 57 | // normal.normalize(); |
---|
| 58 | // |
---|
| 59 | // Vector position = ce->getCollisionPosition(); |
---|
[8288] | 60 | |
---|
[8323] | 61 | |
---|
| 62 | if( this->lastPosition != collision->getEntityB()->getAbsCoor()) |
---|
| 63 | { |
---|
[8288] | 64 | // put it back |
---|
[8323] | 65 | PRINTF(0)("putting it back to: \n"); |
---|
| 66 | this->lastPosition.debug(); |
---|
| 67 | |
---|
| 68 | collision->getEntityB()->setVelocity(Vector()); |
---|
[8288] | 69 | // collision->getEntityB()->setAbsCoorSoft(this->lastPosition, 0.1); |
---|
[8323] | 70 | collision->getEntityB()->setAbsCoor(this->lastPosition); |
---|
| 71 | } |
---|
[8256] | 72 | } |
---|
[8200] | 73 | |
---|
[8256] | 74 | |
---|
| 75 | |
---|
| 76 | /** |
---|
| 77 | * use this to do some collision offline calculations, only called for bContinuousPoll == true |
---|
| 78 | */ |
---|
| 79 | void CRPhysicsGroundWalk::update(WorldEntity* owner) |
---|
| 80 | { |
---|
| 81 | this->lastPosition = owner->getAbsCoor(); |
---|
| 82 | this->lastDirection = owner->getAbsDir(); |
---|
[8323] | 83 | PRINTF(0)("no collision: saving location: \n"); |
---|
| 84 | this->lastPosition.debug(); |
---|
[8200] | 85 | } |
---|
| 86 | |
---|
[8256] | 87 | |
---|