Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8714 in orxonox.OLD


Ignore:
Timestamp:
Jun 22, 2006, 1:40:09 PM (18 years ago)
Author:
bottac
Message:

Ground walk

Location:
branches/bsp_model/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/bsp_model/src/lib/collision_reaction/cr_physics_ground_walk.cc

    r8699 r8714  
    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
     
    2424#include "cr_physics_ground_walk.h"
    2525
    26 #include "aabb.h"
    27 
    28 #include "debug.h"
    29 
    3026#include <vector>
    3127
     
    3733 */
    3834CRPhysicsGroundWalk::CRPhysicsGroundWalk ()
    39   : CollisionReaction()
     35    : CollisionReaction()
    4036{
    4137  this->setClassID(CL_CR_PHYSICS_GROUND_WALK, "CRPhysicsGroundWalk");
     
    4743 */
    4844CRPhysicsGroundWalk::~CRPhysicsGroundWalk ()
    49 {
    50 }
     45{}
    5146
    5247
     
    5954  CollisionEvent* ce = collision->getCollisionEvents().front();
    6055  Vector normal = ce->getGroundNormal();
     56  // normal.normalize();
    6157
    62   AABB* box = ce->getEntityB()->getModelAABB();
     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();
    6363
    64   Vector center = ce->getEntityB()->getAbsCoor() /*+ box->center*/;
    65   Vector collisionPos = ce->getCollisionPosition() - center;
    6664
    67   float objSize = box->halfLength[1];
     65  Vector height = ce->getCollisionPosition() - collision->getEntityB()->getAbsCoor();
    6866
    69   if( normal.len() <= 0.1f)
    70   {
     67  if(ce->getCollisionPosition().x <= 0.9 && ce->getGroundNormal().len() <= 1.4f) {
    7168    collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
    7269    return;
    7370  }
    74 
    75   if( collisionPos.y <= -(objSize + 0.1f))
    76   {
     71  if(ce->getGroundNormal().len() <= 0.1f) {
     72    collision->getEntityB()->setAbsCoor(collision->getEntityB()->getLastAbsCoor());
     73    return;
     74  }
     75  if(ce->getGroundNormal().len() >= 1.4f) {
    7776    downspeed++;
    78     collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0, -0.03 * downspeed, 0.0));
    79   }
    80   else
    81   {
    82     if( collisionPos.y > -objSize  &&
    83         collisionPos.y < (objSize + 0.4))
    84     {
    85       //if(downspeed <= 0) downspeed =1;
    86       collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() +
    87                                           Vector(0.0, collisionPos.y + objSize + 0.1, 0.0));
    88     }
    89       downspeed = 0;
     77    collision->getEntityB()->setAbsCoor(collision->getEntityB()->getAbsCoor() + Vector(0.0,-0.08*downspeed,0.0));
     78    return;
    9079  }
    9180
    9281
     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  */
    93114}
    94115
     
    103124  for( int i = 9; i > 0; i--) {
    104125    this->lastPositions[i] = this->lastPositions[i-1];
    105 //     PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);
     126    //     PRINTF(0)("lastPosition[%i]: %f, %f, %f\n", i, lastPositions[i].x, lastPositions[i].y, lastPositions[i].z);
    106127  }
    107128  this->lastPositions[0] = owner->getAbsCoor();
  • branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc

    r8699 r8714  
    4141#include "world_entity.h"
    4242
    43 #include "aabb.h"
    44 
    4543#include "util/loading/load_param.h"
    4644#include "util/loading/factory.h"
     
    842840        this->checkBrushRayN(&curBrush);
    843841      if(curBrush.n_brushsides <=0) this->outputAllSolid = true;
    844     }
     842    }
     843   
    845844    return;
    846845  }
     
    909908
    910909}
     910
     911float BspManager::checkPatchAltitude(BspTreeNode* node)
     912{
     913  leaf& curLeaf = this->bspFile->leaves[node->leafIndex];
     914  for(int i = 0; i < curLeaf.n_leaffaces ; i++)
     915  {
     916   
     917  }
     918  return 10.0f;
     919}
     920
    911921void BspManager::checkCollisionBox(void)
    912922{
     
    944954  this->outputFraction = 1.0f;
    945955
    946   AABB* box = worldEntity->getModelAABB();
    947 
    948 
    949   Vector forwardDir;
    950   Vector upDir;
     956
     957
     958
     959  Vector forwardDir = worldEntity->getAbsDirX();
     960
     961
     962  Vector upDir = worldEntity->getAbsDirY();
     963  upDir.x = 0.0;
     964  upDir.y = 1.0;
     965  upDir.z = 0.0;
    951966  Vector dest;
    952   Vector position;
    953   Vector out;
    954   float height;
    955 
    956   if( box != NULL)
    957   {
    958     forwardDir = worldEntity->getAbsDirX();
    959     forwardDir = forwardDir * box->halfLength[0];
    960 
    961     upDir = Vector(0,1,0) * box->halfLength[1];
    962 
    963     position = worldEntity->getAbsCoor() + box->center + box->axis[1] * box->halfLength[1];
    964     dest     = worldEntity->getAbsCoor() + box->center - box->axis[1] * box->halfLength[1];
    965     out      = dest;
    966 
    967     height = box->halfLength[1];
    968   }
    969   else
    970   {
    971     forwardDir = worldEntity->getAbsDirX();
    972     forwardDir = forwardDir * 8.0f;
    973 
    974     upDir = worldEntity->getAbsDirY();
    975     upDir.x = 0.0;
    976     upDir.y = 1.0;
    977     upDir.z = 0.0;
    978     dest;
    979 
    980     position = worldEntity->getAbsCoor() + upDir*5.0f;
    981     dest = worldEntity->getAbsCoor() - upDir*40.0f; //
    982     out = dest;
    983 
    984     height = 40;
    985   }
     967  /*
     968  dest.x  += forwardDir.x;
     969  dest.y  += forwardDir.y;
     970  dest.z  += forwardDir.z;
     971  */
     972  Vector position = worldEntity->getAbsCoor() + upDir*10.0f ;
     973  dest = worldEntity->getAbsCoor() - upDir*40.0f; //
     974  Vector out = dest;
    986975
    987976
     
    989978
    990979  bool collision = false;
    991   Vector position1 = position + Vector(0.0,0.1,0.0);
    992   Vector position2 = position + Vector(0.0,0.2,0.0);
    993   Vector dest1 = position1 + forwardDir;
     980  Vector position1 = position; // + Vector(0.0,0.6,0.0);
     981  Vector position2 = position + Vector(0.0,1.0,0.0);
     982  Vector dest1 = position + forwardDir*4.0f;
    994983  Vector dest2 = position2 + forwardDir;
    995 //   dest = position - Vector(0.0, 40.0,0.0);
     984  dest = position - Vector(0.0, 40.0,0.0);
    996985  Vector out1;
    997986  Vector out2;
    998987
    999988
    1000 
     989  float height = 40;
    1001990
    1002991  this->inputStart =  position;
    1003992  this->inputEnd =   dest;
    1004993  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
     994 
     995
    1005996
    1006997//   PRINTF(0)(" checking collision: %s, solid = %i, fraction = %f\n", worldEntity->getClassName(), this->outputAllSolid, this->outputFraction);
    1007998//   PRINTF(0)("checking collision!! Pos.Coords: %f , %f , %f\n", position.x , position.y, position.z);
    1008999//   PRINTF(0)("checking collision!! Dest.Coords: %f , %f , %f\n", dest.x , dest.y, dest.z);
     1000
    10091001//   position1.debug();
    10101002
     
    10521044
    10531045  }
     1046 
     1047  plane* testPlane = this->collPlane;
     1048 
     1049  this->outputStartsOut = true;
     1050  this->outputAllSolid = false;
     1051  this->outputFraction = 1.0f;
     1052  this->inputStart =  position;
     1053  this->inputEnd =   dest1;
     1054  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest1 );
     1055  out.x = this->outputFraction;
     1056  out.z = this->outputFraction;
     1057 
     1058  /*
     1059  out.x = position1.x + (dest.x -position1.x) * this->outputFraction;
     1060 
     1061  out.z = position1.z + (dest.z -position1.z) * this->outputFraction;
     1062  */
     1063 
     1064 
    10541065  // Return the normal here: Normal's stored in this->collPlane;
    10551066  if( collision) {
    10561067    PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction);
    1057     worldEntity->registerCollision(this->parent, worldEntity, Vector(this->collPlane->x, this->collPlane->y, this->collPlane->z), out);
    1058   }
    1059   else  worldEntity->registerCollision(this->parent, worldEntity, Vector(0.0, 1.0, 0.0), dest);
     1068    worldEntity->registerCollision(this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out);
     1069  }
     1070  else  worldEntity->registerCollision(this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest);
    10601071
    10611072}
  • branches/bsp_model/src/lib/graphics/importer/bsp_manager.h

    r8490 r8714  
    7373  void  checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
    7474  void  checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
    75   void TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
     75  void  TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
    7676  void  checkCollisionBox(void);
    7777  void  checkBrushRay(brush* curBrush);
    7878  void  checkBrushRayN(brush* curBrush);
    79   void   checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd);
     79  void  checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd);
     80  float  checkPatchAltitude(BspTreeNode* node); //! To be implemented...
    8081
    8182  void drawDebugCube(Vector* cam);
  • branches/bsp_model/src/story_entities/game_world.cc

    r8490 r8714  
    300300    this->tick ();
    301301
     302   
     303    /* update the state */
     304    this->update ();
     305
     306   
    302307    /* collision detection */
    303308    this->collisionDetection ();
     
    305310    this->collisionReaction ();
    306311
     312    /* check the game rules */
     313    this->checkGameRules();
     314   
    307315    /* update the state */
    308316    this->update ();
    309 
    310     /* check the game rules */
    311     this->checkGameRules();
    312317    /* draw everything */
    313318    this->display ();
  • branches/bsp_model/src/world_entities/creatures/md2_creature.cc

    r8685 r8714  
    112112  this->cameraConnNode.addChild(State::getCameraNode());
    113113  State::getCameraTargetNode()->setRelCoor(10,0,0);
     114 
    114115
    115116
     
    171172  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
    172173
    173   this->getWeaponManager().getFixedTarget()->setRelCoor(10,0,0);
     174  this->getWeaponManager().getFixedTarget()->setRelCoor(0,0,0);
    174175
    175176}
     
    190191  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( true);
    191192
    192   State::getCameraNode()->setParentSoft(&this->cameraConnNode);
    193   State::getCameraNode()->setRelCoorSoft(-10, 0,0);
     193  State::getCameraNode()->setParent(&this->cameraConnNode);
     194  State::getCameraNode()->setRelCoor(0, 0,0);
    194195  State::getCameraTargetNode()->setParentSoft(&this->cameraConnNode);
    195196
     
    281282//    this->cameraConnNode.setRelDir(mouseDirY);
    282283
     284  this->cameraConnNode.setRelDir(mouseDirY);
    283285  this->setAbsDir(this->mouseDirX);
    284286}
     
    343345  }
    344346
    345   velocity = accel * 20.0f;
     347  velocity = accel * 40.0f;
    346348  //rot.normalize();
    347349  //this->setRelDirSoft(Quaternion(rotVal, rot), 5);
  • branches/bsp_model/src/world_entities/playable.cc

    r8686 r8714  
    6565
    6666  this->bDead = false;
     67 
     68  this->subscribeReaction(CREngine::CR_PHYSICS_GROUND_WALK, CL_BSP_ENTITY);
    6769
    6870  registerVar( new SynchronizeableInt( &score, &score, "score" ) );
Note: See TracChangeset for help on using the changeset viewer.