Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Ground walk

File:
1 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();
Note: See TracChangeset for help on using the changeset viewer.