Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 4, 2006, 11:18:41 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the Presentation back

File:
1 edited

Legend:

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

    r9061 r9110  
    960960  this->outputFraction = 1.0f;
    961961
     962
     963  this->checkCollisionX(worldEntity);
     964  this->checkCollisionY(worldEntity);
     965  this->checkCollisionZ(worldEntity);
     966
     967
     968#if 0
    962969  // Retrieve Bounding box
    963970  AABB* box = worldEntity->getModelAABB();
     
    985992
    986993
     994  plane* testPlane;
     995
     996  bool xCollision = false;
     997  bool zCollision = false;
     998
    987999
    9881000  float height = 40;
     
    9981010    dest1     = worldEntity->getAbsCoor() +  box->center + dirX * (box->halfLength[0]  + BSP_X_OFFSET);
    9991011    dest2     = worldEntity->getAbsCoor() -  box->center + dirX * (box->halfLength[0]  + BSP_X_OFFSET);
    1000    
     1012
    10011013    Vector dirZ =  worldEntity->getAbsDirZ(); dirX.y = 0.0f; dirZ.normalize();
    10021014    //position2 = worldEntity->getAbsCoor() +  box->center - dirZ * (box->halfLength[2]  + BSP_Z_OFFSET);
     
    10091021
    10101022
    1011 //   PRINTF(0)("x and v\n");
    1012 //   worldEntity->getAbsDirX().debug();
    1013 //   worldEntity->getAbsDirV().debug();
    1014 
    1015 
    1016   // 1st Ray
     1023
     1024  // 1st Ray: Y RAY
    10171025  this->inputStart =  position;
    10181026  this->inputEnd =   dest;
     
    10521060      this->out = out;
    10531061    }
    1054 
    1055 
    1056   }
    1057 
    1058   plane* testPlane = this->collPlane;
    1059 
    1060   bool xCollision = false;
    1061   bool zCollision = false;
     1062  }
     1063    testPlane = this->collPlane;
     1064
     1065
    10621066  bool xCollisionNeg = false;
    10631067  bool zCollisionNeg = false;
    1064  
    1065 
    1066 
    1067     // 2nd Collision Detection
     1068
     1069
     1070
     1071    // 2nd Collision Detection X-RAY
    10681072    this->outputStartsOut = true;
    10691073    this->outputAllSolid = false;
     
    10931097
    10941098
    1095       // 3rd Collision Detection
     1099      // 3rd Collision Detection Z-RAY
    10961100      this->outputStartsOut = true;
    10971101      this->outputAllSolid = false;
     
    11211125      }
    11221126
    1123   //end if
    1124   /*
    1125   This is how you would calculate the Coordinates where worldEntity Collided with the BSP world.
    1126   out.x = position1.x + (dest.x -position1.x) * this->outputFraction;
    1127   out.z = position1.z + (dest.z -position1.z) * this->outputFraction;
    1128   */
    1129 
    11301127
    11311128  // Return the normal here: Normal's stored in this->collPlane;
    11321129  if( collision) {
    1133     worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
     1130    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), out, SolidFlag);
    11341131}
    11351132  if(xCollision) {
    11361133    worldEntity->registerCollision(COLLISION_TYPE_AXIS_X , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z),dest1 , SolidFlag);
    11371134  }
    1138  
     1135
    11391136  if(zCollision) {
    11401137    worldEntity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent, worldEntity, Vector(testPlane->x, testPlane->y, testPlane->z), dest2 , SolidFlag);
    11411138  }
    1142 
    1143 
    1144   //else  worldEntity->registerCollision(COLLISION_TYPE_AXIS_Y, this->parent, worldEntity, Vector(0.0, 2.0, 0.0), dest, false);
    1145 
    1146 }
     1139#endif
     1140
     1141}
     1142
     1143
     1144
     1145/**
     1146 * check the collision in the x direction (forward, backward)
     1147 */
     1148void BspManager::checkCollisionX(WorldEntity* entity)
     1149{
     1150  // Retrieve Bounding box
     1151  AABB* box = entity->getModelAABB();
     1152
     1153
     1154  plane*            testPlane          = NULL;  //!< the collision test plane
     1155
     1156  Vector            forward;                    //!< left collision ray
     1157  Vector            backward;                   //!< right collision ray
     1158  Vector            collPos;                    //!< the collision position
     1159
     1160  bool              xCollisionForward  = false; //!< flag true if right collision
     1161  bool              xCollisionBackward = false; //!< flag true if left collision
     1162  bool              SolidFlag          = false; //!< flag set true if solid
     1163
     1164  Vector            position;                   //!< current position of the entity
     1165  Vector            dirX;                       //!< direction x
     1166
     1167  position = entity->getAbsCoor();
     1168  dirX =  entity->getAbsDirX(); dirX.y = 0.0f; dirX.normalize();
     1169
     1170  // calculate the rays
     1171  if( box != NULL)
     1172  {
     1173    forward  = entity->getAbsCoor() +  box->center + dirX * (box->halfLength[0]  + BSP_X_OFFSET);
     1174    backward = entity->getAbsCoor() +  box->center - dirX * (box->halfLength[0]  + BSP_X_OFFSET);
     1175  }
     1176  else
     1177  {
     1178    forward  = position + dirX * 4.0f;
     1179    backward = position + Vector(0.0, 1.0, 0.0) + dirX * 4.0;
     1180  }
     1181
     1182
     1183  /*   X Ray forward  */
     1184  // init some member variables before collision check
     1185  this->outputStartsOut = true;
     1186  this->outputAllSolid = false;
     1187  this->outputFraction = 1.0f;
     1188  this->inputStart =  position;
     1189  this->inputEnd =   forward;
     1190  this->checkCollisionRayN(this->root, 0.0f, 1.0f, &position, &forward );
     1191
     1192  // collision occured
     1193  if( this->outputFraction < 1.0f)
     1194  {
     1195    collPos = position + (forward - position) * this->outputFraction;
     1196    xCollisionForward = true;
     1197    testPlane = this->collPlane;
     1198  }
     1199  if(this->outputAllSolid )
     1200  {
     1201    this->collPlane = new plane;
     1202    this->collPlane->x = 0.0f;
     1203    this->collPlane->y = 0.0f;
     1204    this->collPlane->z = 0.0f;
     1205    testPlane = this->collPlane;
     1206    SolidFlag = true;
     1207    xCollisionForward = true;
     1208  }
     1209
     1210  // collision registration
     1211  if( xCollisionForward)
     1212  {
     1213    entity->registerCollision(COLLISION_TYPE_AXIS_X ,
     1214                              this->parent, entity,
     1215                              Vector(testPlane->x, testPlane->y, testPlane->z),
     1216                              collPos,
     1217                              SolidFlag);
     1218  }
     1219
     1220
     1221
     1222  /*   X Ray backward  */
     1223  // init some member variables before collision check
     1224  this->outputStartsOut = true;
     1225  this->outputAllSolid = false;
     1226  this->outputFraction = 1.0f;
     1227  this->inputStart =  position;
     1228  this->inputEnd =   backward;
     1229  this->checkCollisionRayN(this->root, 0.0f, 1.0f, &position, &backward );
     1230
     1231  // collision occured
     1232  if( this->outputFraction < 1.0f)
     1233  {
     1234    collPos = position + (backward - position) * this->outputFraction;
     1235    xCollisionBackward = true;
     1236    testPlane = this->collPlane;
     1237  }
     1238  if( this->outputAllSolid)
     1239  {
     1240    this->collPlane = new plane;
     1241    this->collPlane->x = 0.0f;
     1242    this->collPlane->y = 0.0f;
     1243    this->collPlane->z = 0.0f;
     1244    testPlane = this->collPlane;
     1245    SolidFlag = true;
     1246    xCollisionBackward = true;
     1247  }
     1248
     1249  // collision registration
     1250  if( xCollisionBackward)
     1251  {
     1252    entity->registerCollision(COLLISION_TYPE_AXIS_X_NEG ,
     1253                              this->parent, entity,
     1254                              Vector(testPlane->x, testPlane->y, testPlane->z),
     1255                              collPos,
     1256                              SolidFlag);
     1257  }
     1258}
     1259
     1260
     1261/**
     1262 * check the collision in the z direction (up, down)
     1263 */
     1264void BspManager::checkCollisionY(WorldEntity* entity)
     1265{
     1266
     1267  // Retrieve Bounding box
     1268  AABB* box = entity->getModelAABB();
     1269
     1270
     1271  plane*            testPlane          = NULL;  //!< the collision test plane
     1272
     1273  Vector            up;                         //!< up collision ray
     1274  Vector            down;                       //!< down collision ray
     1275  Vector            collPos;                    //!< the collision position
     1276
     1277  bool              yCollisionUp       = false; //!< flag true if right collision
     1278  bool              yCollisionDown     = false; //!< flag true if left collision
     1279  bool              SolidFlag          = false; //!< flag set true if solid
     1280
     1281  Vector            position;                   //!< current position of the entity
     1282  Vector            dirY;                       //!< direction x
     1283
     1284  position = entity->getAbsCoor();
     1285  collPos = position;
     1286  dirY =  Vector(0.0, 1.0, 0.0);
     1287
     1288  // calculate the rays
     1289  if( box != NULL)
     1290  {
     1291    up   = position +  box->center + dirY * (box->halfLength[1]/*  + BSP_Y_OFFSET*/);
     1292    down = position +  box->center - dirY * (box->halfLength[1]  + BSP_Y_OFFSET);
     1293  }
     1294  else
     1295  {
     1296    up   = position + dirY * 4.0f;
     1297    down = position + Vector(0.0, 1.0, 0.0) + dirY * 4.0;
     1298  }
     1299
     1300
     1301
     1302
     1303  /*   Y Ray up */
     1304  // init some member variables before collision check
     1305  this->inputStart = position;
     1306  this->inputEnd   = up;
     1307  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &up );
     1308
     1309  if( !this->outputStartsOut )
     1310  {
     1311    this->collPlane = new plane;
     1312    this->collPlane->x = 0.0f;
     1313    this->collPlane->y = 0.0f;
     1314    this->collPlane->z = 0.0f;
     1315    yCollisionUp = true;
     1316  }
     1317  else
     1318  {
     1319    if( this->outputFraction == 1.0f)
     1320    {
     1321      if( this->outputAllSolid )
     1322      {
     1323        this->collPlane = new plane;
     1324        this->collPlane->x = 0.0f;
     1325        this->collPlane->y = 0.0f;
     1326        this->collPlane->z = 0.0f;
     1327        yCollisionUp = true;
     1328        SolidFlag = true;
     1329      }
     1330      else
     1331      {
     1332        yCollisionUp = false;
     1333        collPos = up;
     1334      }
     1335    }
     1336    else
     1337    {
     1338      yCollisionUp = true;
     1339      collPos = position + (up - position) * this->outputFraction;
     1340      this->out = collPos;        // why this????
     1341    }
     1342  }
     1343  testPlane = this->collPlane;
     1344
     1345  // collision registration
     1346  if( yCollisionUp)
     1347  {
     1348    entity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent,
     1349                              entity,
     1350                              Vector(testPlane->x, testPlane->y, testPlane->z),
     1351                              collPos, SolidFlag);
     1352  }
     1353
     1354
     1355
     1356
     1357  /*   Y Ray down */
     1358  // init some member variables before collision check
     1359  this->inputStart = position;
     1360  this->inputEnd   = down;
     1361  this->checkCollisionRayN(this->root,0.0f,1.0f, &position, &down );
     1362
     1363  if( !this->outputStartsOut )
     1364  {
     1365    this->collPlane = new plane;
     1366    this->collPlane->x = 0.0f;
     1367    this->collPlane->y = 0.0f;
     1368    this->collPlane->z = 0.0f;
     1369    yCollisionDown = true;
     1370  }
     1371  else
     1372  {
     1373    if( this->outputFraction == 1.0f)
     1374    {
     1375      if( this->outputAllSolid )
     1376      {
     1377        this->collPlane = new plane;
     1378        this->collPlane->x = 0.0f;
     1379        this->collPlane->y = 0.0f;
     1380        this->collPlane->z = 0.0f;
     1381        yCollisionDown = true;
     1382        SolidFlag = true;
     1383      }
     1384      else
     1385      {
     1386        yCollisionDown = false;
     1387        collPos = down;
     1388      }
     1389    }
     1390    else
     1391    {
     1392      yCollisionDown = true;
     1393      collPos = position + (down - position) * this->outputFraction;
     1394      this->out = collPos;        // why this????
     1395    }
     1396  }
     1397  testPlane = this->collPlane;
     1398
     1399  // collision registration
     1400  if( yCollisionDown)
     1401  {
     1402    entity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent,
     1403                              entity,
     1404                              Vector(testPlane->x, testPlane->y, testPlane->z),
     1405                              collPos, SolidFlag);
     1406  }
     1407
     1408
     1409}
     1410
     1411
     1412
     1413
     1414/**
     1415 * check the collision in the z direction (left, right)
     1416 */
     1417void BspManager::checkCollisionZ(WorldEntity* entity)
     1418{
     1419  // Retrieve Bounding box
     1420  AABB* box = entity->getModelAABB();
     1421
     1422
     1423  plane*            testPlane          = NULL;  //!< the collision test plane
     1424
     1425  Vector            right;                      //!< right collision ray
     1426  Vector            left;                       //!< left collision ray
     1427  Vector            collPos;                    //!< the collision position
     1428
     1429  bool              zCollisionRight    = false; //!< flag true if right collision
     1430  bool              zCollisionLeft     = false; //!< flag true if left collision
     1431  bool              SolidFlag          = false; //!< flag set true if solid
     1432
     1433  Vector            position;                   //!< current position of the entity
     1434  Vector            dirZ;                       //!< direction x
     1435
     1436  position = entity->getAbsCoor();
     1437  dirZ =  entity->getAbsDirZ(); dirZ.y = 0.0f; dirZ.normalize();
     1438
     1439  // calculate the rays
     1440  if( box != NULL)
     1441  {
     1442    right = entity->getAbsCoor() +  box->center + dirZ * (box->halfLength[2]  + BSP_Z_OFFSET);
     1443    left  = entity->getAbsCoor() +  box->center - dirZ * (box->halfLength[2]  + BSP_Z_OFFSET);
     1444  }
     1445  else
     1446  {
     1447    right = position + dirZ * 4.0f;
     1448    left  = position + Vector(0.0, 1.0, 0.0) + dirZ * 4.0;
     1449  }
     1450
     1451
     1452  /*   Z Ray right */
     1453  // init some member variables before collision check
     1454  this->outputStartsOut = true;
     1455  this->outputAllSolid = false;
     1456  this->outputFraction = 1.0f;
     1457  this->inputStart =  position;
     1458  this->inputEnd =   right;
     1459  this->checkCollisionRayN(this->root, 0.0f, 1.0f, &position, &right );
     1460
     1461
     1462  // collision occured
     1463  if( this->outputFraction < 1.0f )
     1464  {
     1465    collPos = position + (right - position) * this->outputFraction;
     1466    zCollisionRight = true;
     1467    testPlane = this->collPlane;
     1468  }
     1469  if(this->outputAllSolid )
     1470  {
     1471    this->collPlane = new plane;
     1472    this->collPlane->x = 0.0f;
     1473    this->collPlane->y = 0.0f;
     1474    this->collPlane->z = 0.0f;
     1475    testPlane = this->collPlane;
     1476
     1477    SolidFlag = true;
     1478    zCollisionRight = true;
     1479  }
     1480
     1481
     1482  if( zCollisionRight) {
     1483    entity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent,
     1484                              entity,
     1485                              Vector(testPlane->x, testPlane->y, testPlane->z),
     1486                              collPos , SolidFlag);
     1487  }
     1488
     1489
     1490
     1491  /*   Z Ray left */
     1492  // init some member variables before collision check
     1493  this->outputStartsOut = true;
     1494  this->outputAllSolid = false;
     1495  this->outputFraction = 1.0f;
     1496  this->inputStart =  position;
     1497  this->inputEnd =    left;
     1498  this->checkCollisionRayN(this->root, 0.0f, 1.0f, &position, &left);
     1499
     1500
     1501  // collision occured
     1502  if( this->outputFraction < 1.0f )
     1503  {
     1504    collPos = position + (left - position) * this->outputFraction;
     1505    zCollisionLeft = true;
     1506    testPlane = this->collPlane;
     1507  }
     1508  if(this->outputAllSolid )
     1509  {
     1510    this->collPlane = new plane;
     1511    this->collPlane->x = 0.0f;
     1512    this->collPlane->y = 0.0f;
     1513    this->collPlane->z = 0.0f;
     1514    testPlane = this->collPlane;
     1515
     1516    SolidFlag = true;
     1517    zCollisionLeft = true;
     1518  }
     1519
     1520
     1521  if( zCollisionLeft) {
     1522    entity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this->parent,
     1523                              entity,
     1524                              Vector(testPlane->x, testPlane->y, testPlane->z),
     1525                              collPos , SolidFlag);
     1526  }
     1527
     1528}
     1529
     1530
    11471531
    11481532
Note: See TracChangeset for help on using the changeset viewer.