| 412 | //----------------------------------------------------------------------------- |
| 413 | |
| 414 | bool VPathEditor::updateSelection( const Gui3DMouseEvent &pEvent ) |
| 415 | { |
| 416 | const Point3F pt0 = pEvent.pos; |
| 417 | const Point3F pt1 = pEvent.pos + pEvent.vec * gProjectDistance; |
| 418 | |
| 419 | RayInfo ri; |
| 420 | if ( !gServerContainer.collideBox( pt0, pt1, MarkerObjectType, &ri ) ) |
| 421 | { |
| 422 | // No Object. |
| 423 | return false; |
| 424 | } |
| 425 | |
| 426 | VPath *path = dynamic_cast<VPath*>( ri.object ); |
| 427 | if ( !path ) |
| 428 | { |
| 429 | // No Path Object. |
| 430 | return false; |
| 431 | } |
| 432 | |
| 433 | // No Node. |
| 434 | S32 nodeIndex = -1; |
| 435 | |
| 436 | for ( VPathNodeIterator itr = path->mNodeList.begin(); itr != path->mNodeList.end(); itr++ ) |
| 437 | { |
| 438 | VPathNode *node = ( *itr ); |
| 439 | |
| 440 | Point3F projPosition; |
| 441 | project( node->getWorldPosition(), &projPosition ); |
| 442 | |
| 443 | if ( projPosition.z <= 0.0f ) |
| 444 | { |
| 445 | continue; |
| 446 | } |
| 447 | |
| 448 | const Point2I rectHalfSize( 8, 8 ); |
| 449 | const Point2I screenPosition( ( S32 )projPosition.x, ( S32 )projPosition.y ); |
| 450 | const RectI screenRect( screenPosition - rectHalfSize, 2 * rectHalfSize ); |
| 451 | |
| 452 | // Mouse Close Enough? |
| 453 | if ( screenRect.pointInRect( pEvent.mousePoint ) ) |
| 454 | { |
| 455 | // Select Node. |
| 456 | nodeIndex = ( itr - path->mNodeList.begin() ); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | // Set Selection. |
| 461 | updateSelection( path, nodeIndex ); |
| 462 | |
| 463 | // Valid Selection. |
| 464 | return true; |
| 465 | } |
| 466 | |
| 467 | void VPathEditor::updateSelection( VPath *pPathObject, const S32 &pNodeIndex ) |
| 468 | { |
no test coverage detected