| 311 | } |
| 312 | |
| 313 | void demo3Create() { |
| 314 | defaultDrawOptions(); |
| 315 | |
| 316 | createJointAndBody(); |
| 317 | |
| 318 | mWindow->setTitle( "eepp - Physics - Sensor" ); |
| 319 | |
| 320 | Shape::resetShapeIdCounter(); |
| 321 | |
| 322 | mSpace = Physics::Space::New(); |
| 323 | mSpace->setIterations( 10 ); |
| 324 | mSpace->setGravity( cVectNew( 0, 100 ) ); |
| 325 | |
| 326 | Body* staticBody = mSpace->getStaticBody(); |
| 327 | Shape* shape; |
| 328 | |
| 329 | emitterInstance.queue = 5; |
| 330 | emitterInstance.blocked = 0; |
| 331 | emitterInstance.position = cVectNew( mWindow->getWidth() / 2, 150 ); |
| 332 | |
| 333 | shape = mSpace->addShape( ShapeCircle::New( staticBody, 15.0f, emitterInstance.position ) ); |
| 334 | shape->setSensor( 1 ); |
| 335 | shape->setCollisionType( BLOCKING_SENSOR_TYPE ); |
| 336 | shape->setData( &emitterInstance ); |
| 337 | |
| 338 | // Create our catch sensor to requeue the balls when they reach the bottom of the screen |
| 339 | shape = mSpace->addShape( |
| 340 | ShapeSegment::New( staticBody, cVectNew( -4000, 600 ), cVectNew( 4000, 600 ), 15.0f ) ); |
| 341 | shape->setSensor( 1 ); |
| 342 | shape->setCollisionType( CATCH_SENSOR_TYPE ); |
| 343 | shape->setData( &emitterInstance ); |
| 344 | |
| 345 | Space::CollisionHandler handler; |
| 346 | handler.a = BLOCKING_SENSOR_TYPE; |
| 347 | handler.b = BALL_TYPE; |
| 348 | handler.begin = &blockerBegin; |
| 349 | handler.separate = &blockerSeparate; |
| 350 | mSpace->addCollisionHandler( handler ); |
| 351 | |
| 352 | handler.reset(); // Reset all the values and the callbacks ( set the callbacks as !IsSet() |
| 353 | |
| 354 | handler.a = CATCH_SENSOR_TYPE; |
| 355 | handler.b = BALL_TYPE; |
| 356 | handler.begin = &catcherBarBegin; |
| 357 | mSpace->addCollisionHandler( handler ); |
| 358 | } |
| 359 | |
| 360 | void demo3Update() { |
| 361 | if ( !emitterInstance.blocked && emitterInstance.queue ) { |
nothing calls this directly
no test coverage detected