Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8829 was 8829, checked in by snellen, 18 years ago

continued working on turning:turning doesn't quite work

File size: 4.0 KB
RevLine 
[8200]1/*
2   orxonox - the future of 3D-vertical-scrollers
[8812]3
[8200]4   Copyright (C) 2004 orx
[8812]5
[8200]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.
[8812]10
[8200]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
[8824]28#include "debug.h"
29
[8796]30#include "aabb.h"
31
[8200]32using namespace std;
33
34
35/**
36 *  standard constructor
37 */
38CRPhysicsGroundWalk::CRPhysicsGroundWalk ()
[8724]39    : CollisionReaction()
[8200]40{
[8203]41  this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk");
[8200]42}
43
44
45/**
46 *  standard deconstructor
47 */
48CRPhysicsGroundWalk::~CRPhysicsGroundWalk ()
[8724]49{}
[8200]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{
[8334]58  CollisionEvent* ce = collision->getCollisionEvents().front();
59  Vector normal = ce->getGroundNormal();
[8724]60  // normal.normalize();
[8288]61
62  // put it back
[8724]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();
[8323]67
[8796]68  Vector height;
69  AABB* box = collision->getEntityB()->getModelAABB();
[8812]70
71
[8824]72  if( box != NULL)
[8796]73    height = ( ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() )*(-1.0f) ;
74  else
75    height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() ;
[8724]76
77
[8824]78  if( box != NULL) {
[8724]79
[8824]80
[8796]81    if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
82      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
83      return;
84    }
85    if(ce->getCollisionPosition().z <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
86      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
87      return;
88    }
[8724]89
[8796]90    if(ce->getGroundNormal().len() <= 0.1f) {
91      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
92      return;
93    }
[8812]94
95
[8796]96    if(ce->getGroundNormal().len() >= 1.4f) {
[8724]97      downspeed++;
98      collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
[8796]99      return;
[8724]100    }
101
[8796]102
103    if(height.y > box->halfLength[1] + 0.0f ) // Above ground
[8724]104    {
[8812]105      if(height.y < box->halfLength[1] + 2.3f) // Snap in
[8796]106      {
107        downspeed = 0;
108        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() - Vector(0.0,height.- box->halfLength[1] - 0.0f,0.0));
109      } else
110      {
111        downspeed++;
112        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
113      }
114
[8724]115    }
[8796]116    else {
117      if(height.y <  box->halfLength[1] + 0.0f   /* && height.y  >  - 55.0f*/) // below ground
118      {
119        //if(downspeed <= 0) downspeed =1;
120        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, -height.+  box->halfLength[1] + 2.0f/* 0.00001 *//*height.y+3.500005 + 10.0*/,0.0));
121        //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0));
122        downspeed = 0;
123      }
[8724]124
[8796]125    }
[8724]126
[8796]127  }// if(box!= NULL)
[8829]128
[8724]129  /*
[8341]130  PRINTF(0)("Collision with Ground: \n");
131  collision->getEntityB()->getAbsCoor().debug();
[8724]132  collision->getEntityB()->setVelocity(Vector());
133  collision->getEntityB()->setAbsCoor(this->lastPositions[1]);
[8341]134
[8724]135  */
[8812]136
[8256]137}
[8200]138
[8256]139
140
[8724]141
[8256]142/**
143 * use this to do some collision offline calculations, only called for bContinuousPoll == true
144 */
145void CRPhysicsGroundWalk::update(WorldEntity* owner)
146{
[8337]147  for( int i = 9; i > 0; i--) {
[8336]148    this->lastPositions[i] = this->lastPositions[i-1];
[8724]149    //     PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);
[8337]150  }
[8336]151  this->lastPositions[0] = owner->getAbsCoor();
[8200]152}
153
[8256]154
Note: See TracBrowser for help on using the repository browser.