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 | |
---|
26 | #include <vector> |
---|
27 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * standard constructor |
---|
33 | */ |
---|
34 | CRPhysicsGroundWalk::CRPhysicsGroundWalk () |
---|
35 | : CollisionReaction() |
---|
36 | { |
---|
37 | this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk"); |
---|
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 | { |
---|
55 | CollisionEvent* ce = collision->getCollisionEvents().front(); |
---|
56 | Vector normal = ce->getGroundNormal(); |
---|
57 | // normal.normalize(); |
---|
58 | |
---|
59 | // put it back |
---|
60 | // PRINTF(0)("putting it back to lastPos: \n"); |
---|
61 | // this->lastPositions[0].debug(); |
---|
62 | // PRINTF(0)("current pos:\n"); |
---|
63 | // collision->getEntityB()->getAbsCoor().debug(); |
---|
64 | |
---|
65 | |
---|
66 | Vector height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor(); |
---|
67 | if(ce->getGroundNormal().len() <= 0.1f) |
---|
68 | { |
---|
69 | collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor()); |
---|
70 | return; |
---|
71 | } |
---|
72 | if(height.y < -3.6) |
---|
73 | { |
---|
74 | downspeed++; |
---|
75 | collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.03*downspeed,0.0)); |
---|
76 | |
---|
77 | } |
---|
78 | else |
---|
79 | { |
---|
80 | if(height.y > -3.5 && height.y < 3.9) |
---|
81 | { |
---|
82 | //if(downspeed <= 0) downspeed =1; |
---|
83 | collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,height.y+3.55,0.0)); |
---|
84 | //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0)); |
---|
85 | } |
---|
86 | downspeed = 0; |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | /* |
---|
91 | PRINTF(0)("Collision with Ground: \n"); |
---|
92 | collision->getEntityB()->getAbsCoor().debug(); |
---|
93 | collision->getEntityB()->setVelocity(Vector()); |
---|
94 | collision->getEntityB()->setAbsCoor(this->lastPositions[1]); |
---|
95 | |
---|
96 | */ |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | |
---|
102 | /** |
---|
103 | * use this to do some collision offline calculations, only called for bContinuousPoll == true |
---|
104 | */ |
---|
105 | void CRPhysicsGroundWalk::update(WorldEntity* owner) |
---|
106 | { |
---|
107 | for( int i = 9; i > 0; i--) { |
---|
108 | this->lastPositions[i] = this->lastPositions[i-1]; |
---|
109 | // PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z); |
---|
110 | } |
---|
111 | this->lastPositions[0] = owner->getAbsCoor(); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|