Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc @ 8774

Last change on this file since 8774 was 8724, checked in by bensch, 18 years ago

merged the bsp-model-stuff back here

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