Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/lib/collision_reaction/cr_physics_ground_walk.cc @ 9895

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

interface adjustements

File size: 3.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#include "collision_reaction.h"
26
27#include <vector>
28
29#include "debug.h"
30
31#include "aabb.h"
32
33#include "cr_defs.h"
34
35
36namespace CoRe
37{
38
39  ObjectListDefinition(CRPhysicsGroundWalk);
40
41
42  /**
43   *  standard constructor
44   */
45  CRPhysicsGroundWalk::CRPhysicsGroundWalk ()
46      : CollisionReaction()
47  {
48    this->registerObject(this, CRPhysicsGroundWalk::_objectList);
49  }
50
51
52  /**
53   *  standard deconstructor
54   */
55  CRPhysicsGroundWalk::~CRPhysicsGroundWalk ()
56  {}
57
58
59  /**
60   * caluculates and applys the reaction to a specific collision
61   *  @param collision the collision
62   */
63  void CRPhysicsGroundWalk::reactToCollision(Collision* collision)
64  {
65
66    AABB* box = collision->getEntityB()->getModelAABB();
67    WorldEntity* entity = collision->getEntityB();
68
69    if( box == NULL)
70    {
71      PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n");
72      return;
73    }
74
75
76    float CR_MAX_WALK_HEIGHT = 15.0f;
77
78    float height = 0.0f;
79
80
81    const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());
82    std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();
83    for(; it != collisionEvents->end(); it++)
84    {
85
86      CollisionEvent* ce = (*it);
87      Vector normal = ce->getGroundNormal();
88
89      // calculate the collision position
90      Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
91
92      // test the 3 axis differently
93      switch( ce->getType())
94      {
95          /* collision in the Y-AXIS */
96        case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG:
97          // calulate the height above ground
98          height = collPos.len() - box->halfLength[1];
99
100
101          // object is beneath the plane (ground)
102          //         if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing
103          if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT)
104          {
105            entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));
106            entity->setOnGround(true);
107          }
108          // object is already in the wall
109          else if( ce->isInWall())
110          {
111            entity->setAbsCoor(entity->getLastAbsCoor());
112          }
113          else
114          {
115            // entity is not on ground
116            entity->setOnGround(false);
117          }
118          break;
119
120
121      }
122    }
123    //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);
124
125  }
126
127
128
129
130  /**
131   * use this to do some collision offline calculations, only called for bContinuousPoll == true
132   */
133  void CRPhysicsGroundWalk::update(WorldEntity* owner)
134  {}
135
136}
Note: See TracBrowser for help on using the repository browser.