@@ -392,20 +392,44 @@ MainWindow::parseCommandLine()
392
392
void
393
393
MainWindow::test ()
394
394
{
395
+ this ->distanceCoordinate ->point .setNum (0 );
396
+ this ->distanceLineSet ->coordIndex .setNum (0 );
397
+ this ->distanceCoordinate ->point .setNum (0 );
398
+
399
+ this ->depthCoordinate ->point .setNum (0 );
400
+ this ->depthLineSet ->coordIndex .setNum (0 );
401
+ this ->depthCoordinate ->point .setNum (0 );
402
+
403
+ rl::sg::Body* body = this ->collisionScene ->getModel (this ->model )->getBody (this ->body );
404
+
395
405
if (rl::sg::SimpleScene* simpleScene = dynamic_cast <rl::sg::SimpleScene*>(this ->collisionScene .get ()))
396
406
{
397
- bool test = simpleScene->isColliding ();
407
+ std::size_t collisions = 0 ;
408
+
409
+ for (rl::sg::Scene::Iterator i = this ->collisionScene ->begin (); i != this ->collisionScene ->end (); ++i)
410
+ {
411
+ for (rl::sg::Model::Iterator j = (*i)->begin (); j != (*i)->end (); ++j)
412
+ {
413
+ if (body != *j)
414
+ {
415
+ if (simpleScene->areColliding (body, *j))
416
+ {
417
+ ++collisions;
418
+ }
419
+ }
420
+ }
421
+ }
422
+
423
+ this ->simpleLabel ->setText (" Collisions: " + QString::number (collisions));
398
424
399
- if (test )
425
+ if (collisions > 0 )
400
426
{
401
- this ->simpleLabel ->setText (" Collision: true" );
402
427
this ->viewer ->setBackgroundColor (SbColor (0.5 , 0 , 0 ));
403
428
this ->gradientBackground ->color0 .setValue (0 .5f , 0 .0f , 0 .0f );
404
429
this ->gradientBackground ->color1 .setValue (1 .0f , 1 .0f , 1 .0f );
405
430
}
406
431
else
407
432
{
408
- this ->simpleLabel ->setText (" Collision: false" );
409
433
this ->viewer ->setBackgroundColor (SbColor (0 , 0 , 0 ));
410
434
this ->gradientBackground ->color0 .setValue (0 .8f , 0 .8f , 0 .8f );
411
435
this ->gradientBackground ->color1 .setValue (1 .0f , 1 .0f , 1 .0f );
@@ -414,23 +438,33 @@ MainWindow::test()
414
438
415
439
if (rl::sg::DistanceScene* distanceScene = dynamic_cast <rl::sg::DistanceScene*>(this ->collisionScene .get ()))
416
440
{
417
- this -> distanceCoordinate -> point . setNum ( 0 );
418
- this -> distanceLineSet -> coordIndex . setNum ( 0 );
419
- this -> distanceCoordinate -> point . setNum ( 0 );
441
+ rl::math::Vector3 point1 = rl::math::Vector3::Zero ( );
442
+ rl::math::Vector3 point2 = rl::math::Vector3::Zero ( );
443
+ rl::math::Real distance = std::numeric_limits<rl::math::Real>:: max ( );
420
444
421
- rl::math::Vector3 point1;
422
- rl::math::Vector3 point2;
423
-
424
- rl::math::Real distance = distanceScene->distance (
425
- this ->collisionScene ->getModel (0 )->getBody (0 ),
426
- this ->collisionScene ->getModel (1 )->getBody (0 ),
427
- point1,
428
- point2
429
- );
445
+ for (rl::sg::Scene::Iterator i = this ->collisionScene ->begin (); i != this ->collisionScene ->end (); ++i)
446
+ {
447
+ for (rl::sg::Model::Iterator j = (*i)->begin (); j != (*i)->end (); ++j)
448
+ {
449
+ if (body != *j)
450
+ {
451
+ rl::math::Vector3 tmpPoint1;
452
+ rl::math::Vector3 tmpPoint2;
453
+ rl::math::Real tmpDistance = distanceScene->distance (body, *j, tmpPoint1, tmpPoint2);
454
+
455
+ if (tmpDistance < distance)
456
+ {
457
+ distance = tmpDistance;
458
+ point1 = tmpPoint1;
459
+ point2 = tmpPoint2;
460
+ }
461
+ }
462
+ }
463
+ }
430
464
431
465
this ->distanceLabel ->setText (" Distance: " + QString::number (distance));
432
466
433
- if (distance > std::numeric_limits<rl::math::Real>::epsilon ())
467
+ if (distance > 0 && distance < std::numeric_limits<rl::math::Real>::max ())
434
468
{
435
469
this ->distanceCoordinate ->point .set1Value (
436
470
this ->distanceCoordinate ->point .getNum (),
@@ -462,23 +496,33 @@ MainWindow::test()
462
496
463
497
if (rl::sg::DepthScene* depthScene = dynamic_cast <rl::sg::DepthScene*>(this ->collisionScene .get ()))
464
498
{
465
- this -> depthCoordinate -> point . setNum ( 0 );
466
- this -> depthLineSet -> coordIndex . setNum ( 0 );
467
- this -> depthCoordinate -> point . setNum ( 0 ) ;
499
+ rl::math::Vector3 point1 = rl::math::Vector3::Zero ( );
500
+ rl::math::Vector3 point2 = rl::math::Vector3::Zero ( );
501
+ rl::math::Real depth = 0 ;
468
502
469
- rl::math::Vector3 point1;
470
- rl::math::Vector3 point2;
471
-
472
- rl::math::Real depth = depthScene->depth (
473
- this ->collisionScene ->getModel (0 )->getBody (0 ),
474
- this ->collisionScene ->getModel (1 )->getBody (0 ),
475
- point1,
476
- point2
477
- );
503
+ for (rl::sg::Scene::Iterator i = this ->collisionScene ->begin (); i != this ->collisionScene ->end (); ++i)
504
+ {
505
+ for (rl::sg::Model::Iterator j = (*i)->begin (); j != (*i)->end (); ++j)
506
+ {
507
+ if (body != *j)
508
+ {
509
+ rl::math::Vector3 tmpPoint1;
510
+ rl::math::Vector3 tmpPoint2;
511
+ rl::math::Real tmpDepth = depthScene->depth (body, *j, tmpPoint1, tmpPoint2);
512
+
513
+ if (tmpDepth > depth)
514
+ {
515
+ depth = tmpDepth;
516
+ point1 = tmpPoint1;
517
+ point2 = tmpPoint2;
518
+ }
519
+ }
520
+ }
521
+ }
478
522
479
523
this ->depthLabel ->setText (" Depth: " + QString::number (depth));
480
524
481
- if (depth > std::numeric_limits<rl::math::Real>:: epsilon () )
525
+ if (depth > 0 )
482
526
{
483
527
this ->depthCoordinate ->point .set1Value (
484
528
this ->depthCoordinate ->point .getNum (),
0 commit comments