Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9080 in orxonox.OLD


Ignore:
Timestamp:
Jul 4, 2006, 12:51:03 AM (18 years ago)
Author:
patrick
Message:

collision reactin bsp manager interface rework

Location:
branches/presentation/src/lib/graphics/importer
Files:
2 edited

Legend:

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

    r9065 r9080  
    960960  this->outputFraction = 1.0f;
    961961
     962
    962963  // Retrieve Bounding box
    963964  AABB* box = worldEntity->getModelAABB();
     
    11351136
    11361137
     1138
     1139/**
     1140 * check the collision in the x direction (forward, backward)
     1141 */
     1142void BspManager::checkCollisionX(WorldEntity* entity)
     1143{
     1144  // Retrieve Bounding box
     1145  AABB* box = worldEntity->getModelAABB();
     1146
     1147
     1148  Vector forwardDir = Vector(0.0,0.0,1.0);
     1149  Vector upDir = Vector(0.0,1.0,0.0);
     1150  Vector position = worldEntity->getAbsCoor();
     1151
     1152  bool SolidFlag = false;
     1153  bool collision = false;
     1154  Vector position1 = position;
     1155  Vector position2 = position + Vector(0.0,1.0,0.0);
     1156  Vector position3 = position;
     1157  Vector position4 = position + Vector(0.0,1.0,0.0);
     1158  Vector dest = worldEntity->getAbsCoor() - upDir*40.0f; //
     1159
     1160  Vector dest3 = position + forwardDir*4.0f;
     1161  Vector dest4 = position2 + forwardDir*4.0;
     1162  dest = position - Vector(0.0, 40.0,0.0);
     1163  Vector out = dest;
     1164  Vector out1;
     1165  Vector out2;
     1166
     1167
     1168  plane* testPlane;
     1169
     1170  bool xCollision = false;
     1171  bool zCollision = false;
     1172
     1173  Vector            left;                       //!< left collision ray
     1174  Vector            right;                      //!< right collision ray
     1175
     1176  float height = 40;
     1177
     1178  Vector dirX =  worldEntity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize();
     1179
     1180  if( box != NULL)
     1181  {
     1182    left  = worldEntity->getAbsCoor() +  box->center + dirX * (box->halfLength[0]  + BSP_X_OFFSET);
     1183    right = worldEntity->getAbsCoor() -  box->center + dirX * (box->halfLength[0]  + BSP_X_OFFSET);
     1184  }
     1185  else
     1186  {
     1187    left  = position + forwardDir*4.0f;
     1188    right = position2 + forwardDir*4.0;
     1189  }
     1190
     1191    //
     1192//     dest1
     1193//     dest2
     1194
     1195
     1196
     1197  // 1st Ray: Y RAY
     1198  this->inputStart =  position;
     1199  this->inputEnd =   dest;
     1200  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &dest );
     1201
     1202
     1203  //
     1204  if(!this->outputStartsOut ) {
     1205    this->collPlane = new plane;
     1206    this->collPlane->x = 0.0f;
     1207    this->collPlane->y = 0.0f;
     1208    this->collPlane->z = 0.0f;
     1209    collision = true;
     1210  } else {
     1211
     1212    if( this->outputFraction == 1.0f) {
     1213      if(this->outputAllSolid ) {
     1214        this->collPlane = new plane;
     1215        this->collPlane->x = 0.0f;
     1216        this->collPlane->y = 0.0f;
     1217        this->collPlane->z = 0.0f;
     1218        collision = true;
     1219        SolidFlag = true;
     1220      } else
     1221        collision = false;
     1222
     1223
     1224        out = dest;
     1225
     1226    } else {
     1227      collision = true;
     1228      out.x = position.x + (dest.x -position.x) * this->outputFraction;
     1229      out.y = position.y + (dest.y -position.y) * this->outputFraction;
     1230      out.z = position.z + (dest.z -position.z) * this->outputFraction;
     1231
     1232      Vector out3 = out + Vector(height*this->collPlane->x,height*this->collPlane->y,height*this->collPlane->z);
     1233      this->out = out;
     1234    }
     1235  }
     1236  testPlane = this->collPlane;
     1237
     1238
     1239  bool xCollisionNeg = false;
     1240  bool zCollisionNeg = false;
     1241
     1242
     1243
     1244    // 2nd Collision Detection X-RAY
     1245  this->outputStartsOut = true;
     1246  this->outputAllSolid = false;
     1247  this->outputFraction = 1.0f;
     1248  this->inputStart =  position1;
     1249  this->inputEnd =   dest1;
     1250  this->checkCollisionRayN(this->root,0.0f,1.0f, &position1, &dest1 );
     1251
     1252  if(this->outputFraction < 1.0f) {
     1253    out.x = dest1.x + (dest1.x -position1.x) * this->outputFraction;
     1254    dest1 = position1 + (dest1 -position1) * this->outputFraction;
     1255    xCollision = true;
     1256    testPlane = this->collPlane;
     1257  }
     1258  if(this->outputAllSolid ) {
     1259
     1260    this->collPlane = new plane;
     1261    this->collPlane->x = 0.0f;
     1262    this->collPlane->y = 0.0f;
     1263    this->collPlane->z = 0.0f;
     1264    testPlane = this->collPlane;
     1265    SolidFlag = true;
     1266    xCollision = true;
     1267  }
     1268    //out.z = this->outputFraction;
     1269
     1270
     1271
     1272      // 3rd Collision Detection Z-RAY
     1273  this->outputStartsOut = true;
     1274  this->outputAllSolid = false;
     1275  this->outputFraction = 1.0f;
     1276  this->inputStart =  position2;
     1277  this->inputEnd =   dest2;
     1278
     1279  this->checkCollisionRayN(this->root,0.0f,1.0f, &position2, &dest2 );
     1280      //out.x = this->outputFraction;
     1281
     1282  if(this->outputFraction < 1.0f ) {
     1283    out.z = out.z = dest2.z + (dest2.z -position2.z) * this->outputFraction;
     1284    dest2 = position2 + (dest2 -position2) * this->outputFraction;
     1285    zCollision = true;
     1286    testPlane = this->collPlane;
     1287
     1288  }
     1289  if(this->outputAllSolid ) {
     1290    this->collPlane = new plane;
     1291    this->collPlane->x = 0.0f;
     1292    this->collPlane->y = 0.0f;
     1293    this->collPlane->z = 0.0f;
     1294    testPlane = this->collPlane;
     1295
     1296    SolidFlag = true;
     1297    zCollision = true;
     1298  }
     1299
     1300
     1301  // Return the normal here: Normal's stored in this->collPlane;
     1302  if( collision) {
     1303    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
     1304  }
     1305  if(xCollision) {
     1306    worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z),dest1 , SolidFlag);
     1307  }
     1308
     1309  if(zCollision) {
     1310    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), dest2 , SolidFlag);
     1311  }
     1312}
     1313
     1314/**
     1315 * check the collision in the y direction (up, down)
     1316 */
     1317void BspManager::checkCollisionY(WorldEntity* entity)
     1318{
     1319
     1320}
     1321
     1322
     1323/**
     1324 * check the collision in the z direction (left, right)
     1325 */
     1326void BspManager::checkCollisionZ(WorldEntity* entity)
     1327{
     1328
     1329}
     1330
     1331
     1332
     1333
     1334
    11371335void  BspManager::checkCollision(BspTreeNode* node, Vector* cam)
    11381336{
  • branches/presentation/src/lib/graphics/importer/bsp_manager.h

    r9061 r9080  
    7979
    8080private:
    81   // Functions
     81  // collision functions
    8282  BspTreeNode* getLeaf(BspTreeNode*  node,   Vector* cam) ;  //!< Traverses the tree
    8383  void  checkCollision(BspTreeNode* node, Vector* cam); //!< Obsolete. Use this function for debugging only!
    8484  void  checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
    8585  void  checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end);
    86   void  TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
     86
     87  void checkCollisionX(WorldEntity* entity);
     88  void checkCollisionY(WorldEntity* entity);
     89  void checkCollisionZ(WorldEntity* entity);
     90
    8791  void  checkCollisionBox(void);
    8892  void  checkBrushRay(brush* curBrush);
    8993  void  checkBrushRayN(brush* curBrush);
    9094  void  checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd);
    91   float  checkPatchAltitude(BspTreeNode* node); //! To be implemented...
     95  float checkPatchAltitude(BspTreeNode* node); //! To be implemented...
    9296
     97  void  TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs );
     98
     99
     100  // visibility functions
    93101  void drawDebugCube(Vector* cam);
    94102  bool isAlreadyVisible(int Face);
Note: See TracChangeset for help on using the changeset viewer.