投稿

2月, 2013の投稿を表示しています

Box2Dで作ったオブジェクトをiOSの加速度に対応させるの巻!

```obj-c #import #import @interface HomeViewController (){ b2World *world; NSTimer *timer; } @end @implementation ViewController - (void)loadView { [super loadView]; acc = [UIAccelerometer sharedAccelerometer]; acc.updateInterval = 1.0f / 10.0f; acc.delegate = self; // 通知を開始させたい時に実行する } - (void)createPhysicsWorld { CGSize screenSize = self.view.bounds.size; b2Vec2 gravity; gravity.Set(0.0f, -9.81f); world = new b2World(gravity); world->SetContinuousPhysics(true); b2BodyDef groundBodyDef; groundBodyDef.position.Set(0, 0); b2Body* groundBody = world->CreateBody(&groundBodyDef); b2EdgeShape groundBox; groundBox.Set(b2Vec2(0, 0), b2Vec2(screenSize.width/PTMRatio, 0)); groundBody->CreateFixture(&groundBox, 0); groundBox.Set(b2Vec2(0,screenSize.height/PTMRatio), b2Vec2(0,0)); groundBody->CreateFixture(&groundBox, 0); groundBox.Set(b2Vec2(screenSize.wi