Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/single_player_map/src/lib/collision_reaction/cr_physics_ground_walk.cc @ 8834

Last change on this file since 8834 was 8834, checked in by patrick, 18 years ago

collision reaction rebwork

File size: 4.2 KB
Line 
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#include "debug.h"
29
30#include "aabb.h"
31
32using namespace std;
33
34
35/**
36 *  standard constructor
37 */
38CRPhysicsGroundWalk::CRPhysicsGroundWalk ()
39    : CollisionReaction()
40{
41  this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk");
42}
43
44
45/**
46 *  standard deconstructor
47 */
48CRPhysicsGroundWalk::~CRPhysicsGroundWalk ()
49{}
50
51
52/**
53 * caluculates and applys the reaction to a specific collision
54 *  @param collision the collision
55 */
56void CRPhysicsGroundWalk::reactToCollision(Collision* collision)
57{
58  CollisionEvent* ce = collision->getCollisionEvents().front();
59  Vector normal = ce->getGroundNormal();
60  // normal.normalize();
61
62  // put it back
63  //   PRINTF(0)("putting it back to lastPos: \n");
64  //   this->lastPositions[0].debug();
65  //   PRINTF(0)("current pos:\n");
66  //   collision->getEntityB()->getAbsCoor().debug();
67
68  Vector height;
69  AABB* box = collision->getEntityB()->getModelAABB();
70
71  if( box != NULL)
72  {
73
74    Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
75    PRINTF(0)("height: %f          , model height: %f\n", collPos.y, box->halfLength[1]);
76
77  }
78
79#if 0
80  if( box != NULL)
81    height = ( ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() )*(-1.0f) ;
82  else
83    height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() ;
84
85
86  if( box != NULL) {
87
88
89    if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
90      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
91      return;
92    }
93    if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
94      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
95      return;
96    }
97
98    if(ce->getGroundNormal().len() <= 0.1f) {
99      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
100      return;
101    }
102
103
104    if(ce->getGroundNormal().len() >= 1.4f) {
105      downspeed++;
106      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
107      return;
108    }
109
110
111    if(height.y > box->halfLength[1] + 0.0f ) // Above ground
112    {
113      if(height.y < box->halfLength[1] + 2.3f) // Snap in
114      {
115        downspeed = 0;
116        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() - Vector(0.0,height.y  - box->halfLength[1] - 0.0f,0.0));
117      } else
118      {
119        downspeed++;
120        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
121      }
122
123    }
124    else {
125      if(height.y <  box->halfLength[1] + 0.0f   /* && height.y  >  - 55.0f*/) // below ground
126      {
127        //if(downspeed <= 0) downspeed =1;
128        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, -height.y  +  box->halfLength[1] + 2.0f/* 0.00001 *//*height.y+3.500005 + 10.0*/,0.0));
129        //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0));
130        downspeed = 0;
131      }
132
133    }
134
135  }// if(box!= NULL)
136#endif
137  /*
138  PRINTF(0)("Collision with Ground: \n");
139  collision->getEntityB()->getAbsCoor().debug();
140  collision->getEntityB()->setVelocity(Vector());
141  collision->getEntityB()->setAbsCoor(this->lastPositions[1]);
142
143  */
144
145}
146
147
148
149
150/**
151 * use this to do some collision offline calculations, only called for bContinuousPoll == true
152 */
153void CRPhysicsGroundWalk::update(WorldEntity* owner)
154{
155  for( int i = 9; i > 0; i--) {
156    this->lastPositions[i] = this->lastPositions[i-1];
157    //     PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);
158  }
159  this->lastPositions[0] = owner->getAbsCoor();
160}
161
162
Note: See TracBrowser for help on using the repository browser.