| 528 | } |
| 529 | |
| 530 | void PhysicsDemoRayCast::update(float /*delta*/) |
| 531 | { |
| 532 | float L = 150.0f; |
| 533 | Vec2 point1 = VisibleRect::center(); |
| 534 | Vec2 d(L * cosf(_angle), L * sinf(_angle)); |
| 535 | Vec2 point2 = point1 + d; |
| 536 | |
| 537 | removeChild(_node); |
| 538 | _node = DrawNode::create(); |
| 539 | switch (_mode) |
| 540 | { |
| 541 | case 0: |
| 542 | { |
| 543 | Vec2 point3 = point2; |
| 544 | auto func = AX_CALLBACK_3(PhysicsDemoRayCast::anyRay, this); |
| 545 | |
| 546 | _physicsWorld->rayCast(func, point1, point2, &point3); |
| 547 | _node->drawSegment(point1, point3, 0.5f, STATIC_COLOR); |
| 548 | |
| 549 | if (point2 != point3) |
| 550 | { |
| 551 | _node->drawDot(point3, 2, Color4F(1.0f, 1.0f, 1.0f, 1.0f)); |
| 552 | } |
| 553 | addChild(_node); |
| 554 | |
| 555 | break; |
| 556 | } |
| 557 | case 1: |
| 558 | { |
| 559 | Vec2 point3 = point2; |
| 560 | float friction = 1.0f; |
| 561 | PhysicsRayCastCallbackFunc func = [&point3, &friction](PhysicsWorld& /*world*/, const PhysicsRayCastInfo& info, |
| 562 | void* /*data*/) -> bool { |
| 563 | if (friction > info.fraction) |
| 564 | { |
| 565 | point3 = info.contact; |
| 566 | friction = info.fraction; |
| 567 | } |
| 568 | |
| 569 | return true; |
| 570 | }; |
| 571 | |
| 572 | _physicsWorld->rayCast(func, point1, point2, nullptr); |
| 573 | _node->drawSegment(point1, point3, 1, STATIC_COLOR); |
| 574 | |
| 575 | if (point2 != point3) |
| 576 | { |
| 577 | _node->drawDot(point3, 2, Color4F(1.0f, 1.0f, 1.0f, 1.0f)); |
| 578 | } |
| 579 | addChild(_node); |
| 580 | |
| 581 | break; |
| 582 | } |
| 583 | case 2: |
| 584 | { |
| 585 | # define MAX_MULTI_RAYCAST_NUM 5 |
| 586 | Vec2 points[MAX_MULTI_RAYCAST_NUM]; |
| 587 | int num = 0; |
nothing calls this directly
no test coverage detected