Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8894 in orxonox.OLD for trunk/src/lib/collision_reaction


Ignore:
Timestamp:
Jun 29, 2006, 12:19:48 AM (18 years ago)
Author:
patrick
Message:

merged the branche single_player_map with the trunk

Location:
trunk/src/lib/collision_reaction
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/collision_reaction/collision_event.h

    r8490 r8894  
    99#include "vector.h"
    1010
     11#include "cr_defs.h"
     12
     13
    1114class WorldEntity;
    1215class BoundingVolume;
    1316class Plane;
     17
    1418
    1519
     
    2226
    2327  /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */
    24   inline void collide(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
    25   { this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
     28  inline void collide(int type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
     29  { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; }
    2630  /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */
    27   inline void collide(WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position)
    28   { this->entityA = entity; this->entityB = groundEntity, this->groundNormal = normal; this->position = position; }
     31  inline void collide(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall)
     32  { this->collisionType = type; this->entityA = entity; this->entityB = groundEntity, this->groundNormal = normal; this->position = position; this->bInWall = bInWall; }
    2933
    3034
     
    4448  inline Vector getCollisionPosition() { return this->position; }
    4549
     50  /** @return the type of the collision */
     51  inline int getType() { return this->collisionType; }
     52
     53  /** @return true if the entity is in the wall */
     54  inline bool isInWall() { return this->bInWall; }
     55
     56
    4657 private:
    4758  WorldEntity*      entityA;                       //!< the collision body A
     
    5364  Vector            groundNormal;                  //!< the ground plane with which it collides (only for bsp-model collisions
    5465  Vector            position;                      //!< position of the collision on the ground plane
     66
     67  bool              bInWall;                       //!< true if is in wall
     68  int               collisionType;                 //!< collision type
    5569};
    5670
  • trunk/src/lib/collision_reaction/cr_defs.h

    r8190 r8894  
    2828
    2929
     30//!< the collision axis x collision event
     31#define COLLISION_TYPE_AXIS_X   1
     32//!< the collision axis y collision event
     33#define COLLISION_TYPE_AXIS_Y   2
     34//!< the collision axis z collision event
     35#define COLLISION_TYPE_AXIS_Z   4
     36//!< the collision is a obb collision
     37#define COLLISION_TYPE_OBB      8
     38
    3039
    3140#endif /* _NETWORK_MANAGER */
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r8796 r8894  
    11/*
    22   orxonox - the future of 3D-vertical-scrollers
    3  
     3
    44   Copyright (C) 2004 orx
    5  
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 2, or (at your option)
    99   any later version.
    10  
     10
    1111   ### File Specific:
    1212   main-programmer: Patrick Boenzli
     
    2626#include <vector>
    2727
     28#include "debug.h"
     29
    2830#include "aabb.h"
     31
     32#include "cr_defs.h"
    2933
    3034using namespace std;
     
    6468  //   collision->getEntityB()->getAbsCoor().debug();
    6569
    66   Vector height;
     70  float height;
    6771  AABB* box = collision->getEntityB()->getModelAABB();
    68  
    69  
    70  
    71   if(box!=NULL)
     72  WorldEntity* entity = collision->getEntityB();
     73
     74  // collision position maths
     75  Vector collPos =  collision->getEntityB()->getAbsCoor()  + box->center - ce->getCollisionPosition();
     76
     77  float CR_MAX_WALK_HEIGHT = 2.0f;
     78  float CR_THRESHOLD = 0.2f;
     79
     80  if( box == NULL)
     81  {
     82    PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n");
     83    return;
     84  }
     85
     86
     87  switch( ce->getType())
     88  {
     89    case COLLISION_TYPE_AXIS_Y:
     90
     91      height = collPos.y - box->halfLength[1];
     92     // PRINTF(0)("height: %f          , model height: %f\n", height, box->halfLength[1]);
     93     // PRINTF(0)(" ground normal: %f, %f, %f\n", normal.x, normal.y, normal.z);
     94
     95      // object is beneath the plane (ground)
     96      if( height <= 0.0f )
     97      {
     98        entity->shiftCoor(Vector(0, -height, 0));
     99      }
     100      // object is already in the wall
     101      else if( ce->isInWall())
     102      {
     103        entity->setAbsCoor(entity->getLastAbsCoor());
     104      }
     105      break;
     106
     107
     108    case COLLISION_TYPE_AXIS_X:
     109    case COLLISION_TYPE_AXIS_Z:
     110      break;
     111
     112    }
     113
     114
     115
     116
     117
     118
     119
     120
     121#if 0
     122  if( box != NULL)
    72123    height = ( ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() )*(-1.0f) ;
    73124  else
    74125    height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor() ;
    75126
    76   if(box!=NULL) {
     127
     128  if( box != NULL) {
    77129
    78130
     
    90142      return;
    91143    }
    92    
    93    
     144
     145
    94146    if(ce->getGroundNormal().len() >= 1.4f) {
    95147      downspeed++;
     
    101153    if(height.y > box->halfLength[1] + 0.0f ) // Above ground
    102154    {
    103       if(height.y < box->halfLength[1] + 1.3f) // Snap in
     155      if(height.y < box->halfLength[1] + 2.3f) // Snap in
    104156      {
    105157        downspeed = 0;
     
    116168      {
    117169        //if(downspeed <= 0) downspeed =1;
    118         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));
     170        collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, -height.y  +  box->halfLength[1] + 2.0f,0.0));
    119171        //collision->getEntityB()->setVelocity(Vector(0.0,0.0,0.0));
    120172        downspeed = 0;
     
    124176
    125177  }// if(box!= NULL)
     178#endif
    126179  /*
    127180  PRINTF(0)("Collision with Ground: \n");
     
    131184
    132185  */
     186
    133187}
    134188
     
    141195void CRPhysicsGroundWalk::update(WorldEntity* owner)
    142196{
    143   for( int i = 9; i > 0; i--) {
    144     this->lastPositions[i] = this->lastPositions[i-1];
    145     //     PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);
    146   }
    147   this->lastPositions[0] = owner->getAbsCoor();
     197
    148198}
    149199
  • trunk/src/lib/collision_reaction/cr_physics_ground_walk.h

    r8724 r8894  
    2323    virtual void update(WorldEntity* entity);
    2424
     25
    2526  private:
    26     Vector       lastPosition;                //!< vector with the last valid position
    27     Vector       afterLastPosition;           //!< vector for the after last
    28     Quaternion   lastDirection;               //!< quat with the last valid direction
    29 
    30     Vector       lastPositions[10];           //!< last 10 positions
    3127    float        downspeed;
    3228};
Note: See TracChangeset for help on using the changeset viewer.