| 215 | } |
| 216 | |
| 217 | void SceneController::addGear( const vec2 &pos ) |
| 218 | { |
| 219 | float wallDeadZoneWidth = mParams.mWallInset + mParams.mWallWidth / 2; |
| 220 | if( pos.x < wallDeadZoneWidth || pos.x > ( app::getWindowWidth() - wallDeadZoneWidth ) ) |
| 221 | return; |
| 222 | |
| 223 | vec2 posScaled = pointsToMeters( pos ); |
| 224 | |
| 225 | auto imageTex = getRandomGearTex(); |
| 226 | const float radius = mParams.mGearScale * imageTex->getWidth() / 2.0f; |
| 227 | |
| 228 | b2BodyDef bodyDef; |
| 229 | bodyDef.type = b2_dynamicBody; |
| 230 | bodyDef.allowSleep = false; |
| 231 | bodyDef.position.Set( posScaled.x, posScaled.y ); |
| 232 | |
| 233 | const float velMax = 5; |
| 234 | bodyDef.linearVelocity = b2Vec2( randFloat( -velMax, velMax ), randFloat( -velMax, 0 ) ); |
| 235 | |
| 236 | b2CircleShape shape; |
| 237 | shape.m_radius = pointsToMeters( radius ); |
| 238 | |
| 239 | b2FixtureDef fixtureDef; |
| 240 | fixtureDef.shape = &shape; |
| 241 | fixtureDef.density = 1.0f; |
| 242 | fixtureDef.friction = 1.0f; |
| 243 | fixtureDef.restitution = 0.4f; |
| 244 | |
| 245 | mGears.push_back( make_shared<Gear>( mAudio ) ); |
| 246 | auto &gear = mGears.back(); |
| 247 | gear->mTag = string( "gear" ); |
| 248 | gear->mIdentifier = mGearIdentifierTab++; |
| 249 | gear->mImageTex = imageTex; |
| 250 | gear->mRadius = radius; |
| 251 | |
| 252 | gear->mBody = box2d::makeBodyShared( mWorld.get(), bodyDef ); |
| 253 | gear->mBody->CreateFixture( &fixtureDef ); |
| 254 | gear->mBody->SetUserData( gear.get() ); |
| 255 | } |
| 256 | |
| 257 | ci::gl::TextureRef SceneController::getRandomGearTex() const |
| 258 | { |
no test coverage detected