MCPcopy Create free account
hub / github.com/cinder/Cinder / addGear

Method addGear

samples/FallingGears/src/SceneController.cpp:217–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217void 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
257ci::gl::TextureRef SceneController::getRandomGearTex() const
258{

Callers 2

mouseDownMethod · 0.80
mouseDragMethod · 0.80

Calls 13

getWindowWidthFunction · 0.85
pointsToMetersFunction · 0.85
randFloatFunction · 0.85
stringFunction · 0.85
makeBodySharedFunction · 0.85
backMethod · 0.80
CreateFixtureMethod · 0.80
b2Vec2Class · 0.50
getWidthMethod · 0.45
SetMethod · 0.45
push_backMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected