Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 2, 2006, 1:36:13 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the single_player_map branche back
merged with command:
svn merge -r8896:HEAD https://svn.orxonox.net/orxonox/branches/single_player_map .
no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/importer/bsp_manager.cc

    r8894 r9003  
    11/*
    22   orxonox - the future of 3D-vertical-scrollers
    3  
     3
    44   Copyright (C) 2006 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: bottac@ee.ethz.ch
    13  
     13
    1414   Inspired by:
    1515   Rendering Q3 Maps by Morgan McGuire                  http://graphics.cs.brown.edu/games/quake/quake3.html
    1616   Unofficial Quake 3 Map Specs by Kekoa Proudfoot      http://graphics.stanford.edu/~kekoa/q3/
    17  
     17
    1818   Collision detection adapted from:
    1919   Quake 3 Collision Detection by Nathan Ostgard        http://www.devmaster.net/articles/quake3collision/
     
    6969BspManager::BspManager(const TiXmlElement* root)
    7070{
    71  
    72  
     71
     72
    7373  if( root != NULL)
    7474    this->loadParams(root);
    75  
     75
    7676  CDEngine::getInstance()->setBSPModel(this);
    7777} */
    7878
    79 void BspManager::load(const char* fileName, float scale)
     79BspManager::~BspManager()
     80{
     81  if(this->bspFile)
     82    delete this->bspFile;
     83}
     84
     85int BspManager::load(const char* fileName, float scale)
    8086{
    8187  // open a BSP file
     88
     89
    8290  this->bspFile = new BspFile();
    8391  this->bspFile->scale =  scale;
    84   this->bspFile->read(ResourceManager::getFullName(fileName).c_str());
     92  if(this->bspFile->read(ResourceManager::getFullName(fileName).c_str()) == -1)
     93    return -1;
     94
    8595  this->bspFile->build_tree();
    8696  this->root  = this->bspFile->get_root();
     
    8898
    8999  this->outputFraction = 1.0f;
     100
     101  return 0;
    90102}
    91103/*
     
    99111  this->root  = this->bspFile->get_root();
    100112  this->alreadyVisible = new bool [this->bspFile->numFaces];
    101  
     113
    102114  CDEngine::getInstance()->setBSPModel(this);
    103115}
     
    962974  Vector dest = worldEntity->getAbsCoor() - upDir*40.0f; //
    963975  Vector dest1 = position + forwardDir*4.0f;
    964   Vector dest2 = position2 + forwardDir;
     976  Vector dest2 = position2 + forwardDir*4.0;
    965977  dest = position - Vector(0.0, 40.0,0.0);
    966978  Vector out = dest;
     
    974986
    975987  if( box != NULL) {
    976     position = worldEntity->getAbsCoor() +  box->center; // + box->axis[1] * box->halfLength[1];
    977     dest     = worldEntity->getAbsCoor() +  box->center - box->axis[1] * box->halfLength[1] * 40.0;
    978 
    979     position1 = worldEntity->getAbsCoor() +  box->center + box->axis[0] * box->halfLength[0] * 2.0f;
    980     dest1     = worldEntity->getAbsCoor() +  box->center - box->axis[0] * box->halfLength[0] *2.0f;
    981 
    982 
    983     position2 = worldEntity->getAbsCoor() +  box->center + box->axis[2] * box->halfLength[2] * 2.0f;
    984     dest2     = worldEntity->getAbsCoor() +  box->center - box->axis[2] * box->halfLength[2] * 2.0f;
     988    position = worldEntity->getAbsCoor() +  box->center + Vector(0.0, 1.0, 0.0) * box->halfLength[1];
     989    dest     = worldEntity->getAbsCoor() +  box->center - Vector(0.0, 1.0, 0.0) * (box->halfLength[1] + BSP_Y_OFFSET);
     990
     991    position1 = worldEntity->getAbsCoor() +  box->center - worldEntity->getAbsDirX() * (box->halfLength[0]  + BSP_X_OFFSET);
     992    dest1     = worldEntity->getAbsCoor() +  box->center + worldEntity->getAbsDirX() * (box->halfLength[0]  + BSP_X_OFFSET);
     993
     994    position2 = worldEntity->getAbsCoor() +  box->center - worldEntity->getAbsDirZ() * (box->halfLength[2]  + BSP_Z_OFFSET);
     995    dest2     = worldEntity->getAbsCoor() +  box->center + worldEntity->getAbsDirZ() * (box->halfLength[2]  + BSP_Z_OFFSET);
    985996
    986997  } else {
     
    9891000  }
    9901001
     1002
     1003//   PRINTF(0)("x and v\n");
     1004//   worldEntity->getAbsDirX().debug();
     1005//   worldEntity->getAbsDirV().debug();
    9911006
    9921007
     
    10351050  plane* testPlane = this->collPlane;
    10361051
    1037 
    10381052  bool xCollision = false;
    10391053  bool zCollision = false;
    1040   if(!SolidFlag) {
     1054
    10411055
    10421056    // 2nd Collision Detection
     
    10481062    this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 );
    10491063
    1050     if(!this->outputAllSolid != 1.0f) {
     1064    if(this->outputFraction < 1.0f) {
    10511065      out.x = dest1.x + (dest1.x -position1.x) * this->outputFraction;
     1066      dest1 = position1 + (dest1 -position1) * this->outputFraction;
    10521067      xCollision = true;
    10531068      testPlane = this->collPlane;
    10541069    }
    1055     if(this->outputAllSolid) {
     1070    if(this->outputAllSolid ) {
     1071
     1072      this->collPlane = new plane;
     1073      this->collPlane->x = 0.0f;
     1074      this->collPlane->y = 0.0f;
     1075      this->collPlane->z = 0.0f;
     1076      testPlane = this->collPlane;
    10561077      SolidFlag = true;
    1057       xCollision = true; 
     1078      xCollision = true;
    10581079    }
    10591080    //out.z = this->outputFraction;
    10601081
    1061     if(!SolidFlag) {
     1082
    10621083
    10631084      // 3rd Collision Detection
     
    10671088      this->inputStart =  position2;
    10681089      this->inputEnd =   dest2;
     1090
    10691091      this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 );
    10701092      //out.x = this->outputFraction;
    10711093
    1072       if(this->outputFraction != 1.0f ) {
     1094      if(this->outputFraction < 1.0f ) {
    10731095        out.z = out.z = dest2.z + (dest2.z -position2.z) * this->outputFraction;
     1096        dest2 = position2 + (dest2 -position2) * this->outputFraction;
    10741097        zCollision = true;
    10751098        testPlane = this->collPlane;
    10761099
    10771100      }
    1078       if(this->outputAllSolid) {
    1079           SolidFlag = true;
    1080           zCollision = true;   
     1101      if(this->outputAllSolid ) {
     1102        this->collPlane = new plane;
     1103        this->collPlane->x = 0.0f;
     1104        this->collPlane->y = 0.0f;
     1105        this->collPlane->z = 0.0f;
     1106        testPlane = this->collPlane;
     1107
     1108        SolidFlag = true;
     1109        zCollision = true;
    10811110      }
    1082     }
    1083   }//end if
     1111
     1112  //end if
    10841113  /*
    10851114  This is how you would calculate the Coordinates where worldEntity Collided with the BSP world.
     
    10911120  // Return the normal here: Normal's stored in this->collPlane;
    10921121  if( collision) {
    1093     PRINTF(5)("We got a collision!! Are you sure: outputFraction = %f\n", this->outputFraction);
    1094     worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y || (xCollision ? COLLISION_TYPE_AXIS_X :0) | (zCollision ? COLLISION_TYPE_AXIS_Z :0), this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
    1095   } else {
    1096     if(xCollision || zCollision) {
    1097 
    1098       worldEntity->registerCollision((xCollision ? COLLISION_TYPE_AXIS_X :0) | (zCollision ? COLLISION_TYPE_AXIS_Z :0) , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
    1099     }
    1100 
    1101   }
     1122    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
     1123}
     1124  if(xCollision) {
     1125    worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z),dest1 , SolidFlag);
     1126  }
     1127  if(zCollision) {
     1128    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), dest2 , SolidFlag);
     1129  }
     1130
     1131
    11021132  //else  worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y, this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest, false);
    11031133
Note: See TracChangeset for help on using the changeset viewer.