void InitPhysics() { var gravity = new b2Vec2(0.0f, -10.0f); world = new b2World(gravity); world.SetAllowSleeping(true); world.SetContinuousPhysics(true); var def = new b2BodyDef(); def.allowSleep = true; def.position = b2Vec2.Zero; def.type = b2BodyType.b2_staticBody; b2Body groundBody = world.CreateBody(def); groundBody.SetActive(true); b2EdgeShape groundBox = new b2EdgeShape(); groundBox.Set(b2Vec2.Zero, new b2Vec2(900, 100)); b2FixtureDef fd = new b2FixtureDef(); fd.friction = 0.3f; fd.restitution = 0.1f; fd.shape = groundBox; groundBody.CreateFixture(fd); }
void InitPhysics() { CCSize size = Layer.VisibleBoundsWorldspace.Size; var gravity = new b2Vec2(0.0f, -10.0f); world = new b2World(gravity); world.SetAllowSleeping(true); world.SetContinuousPhysics(true); var def = new b2BodyDef(); def.allowSleep = true; def.position = b2Vec2.Zero; def.type = b2BodyType.b2_staticBody; b2Body groundBody = world.CreateBody(def); groundBody.SetActive(true); b2EdgeShape groundBox = new b2EdgeShape(); groundBox.Set(b2Vec2.Zero, new b2Vec2(size.Width / PTM_RATIO, 0)); b2FixtureDef fd = new b2FixtureDef(); fd.shape = groundBox; groundBody.CreateFixture(fd); }
public Test() { m_destructionListener = new DestructionListener(); m_debugDraw = new CCBox2dDraw("fonts/arial-12"); b2Vec2 gravity = new b2Vec2(); gravity.Set(0.0f, -10.0f); m_world = new b2World(gravity); m_bomb = null; m_textLine = 30; m_mouseJoint = null; m_pointCount = 0; m_destructionListener.test = this; m_world.SetDestructionListener(m_destructionListener); m_world.SetContactListener(this); m_world.SetDebugDraw(m_debugDraw); m_world.SetContinuousPhysics(true); m_world.SetWarmStarting(true); m_bombSpawning = false; m_stepCount = 0; b2BodyDef bodyDef = new b2BodyDef(); m_groundBody = m_world.CreateBody(bodyDef); }
public virtual void Step(Settings settings) { float timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f; if (settings.pause) { if (settings.singleStep) { settings.singleStep = false; } else { timeStep = 0.0f; } m_debugDraw.DrawString(5, m_textLine, "****PAUSED****"); m_textLine += 15; } b2DrawFlags flags = 0; if (settings.drawShapes) { flags |= b2DrawFlags.e_shapeBit; } if (settings.drawJoints) { flags |= b2DrawFlags.e_jointBit; } if (settings.drawAABBs) { flags |= b2DrawFlags.e_aabbBit; } if (settings.drawPairs) { flags |= b2DrawFlags.e_pairBit; } if (settings.drawCOMs) { flags |= b2DrawFlags.e_centerOfMassBit; } m_debugDraw.SetFlags(flags); m_world.SetWarmStarting(settings.enableWarmStarting > 0); m_world.SetContinuousPhysics(settings.enableContinuous > 0); m_world.SetSubStepping(settings.enableSubStepping > 0); m_pointCount = 0; m_world.Step(timeStep, settings.velocityIterations, settings.positionIterations); if (timeStep > 0.0f) { ++m_stepCount; } }
public Mouse() { //m_destructionListener = new DestructionListener(); m_debugDraw = new CCBox2dDraw("fonts/arial-16"); b2Vec2 gravity = new b2Vec2(); gravity.Set(500, 500); m_world = new b2World(gravity); m_world.SetAllowSleeping(false); m_world.SetContinuousPhysics(true); m_world.SetDebugDraw(m_debugDraw); m_debugDraw.AppendFlags(b2DrawFlags.e_shapeBit | b2DrawFlags.e_aabbBit | b2DrawFlags.e_centerOfMassBit | b2DrawFlags.e_jointBit | b2DrawFlags.e_pairBit); m_world.SetContinuousPhysics(true); m_world.SetWarmStarting(true); }
public b2World box2dWorld() { if (null == _world) { var gravity = new b2Vec2(0.0f, -10.0f); _world = new b2World(gravity); _world.SetAllowSleeping(true); _world.SetContinuousPhysics(true); _debugDraw = new LHBox2dDraw("fonts/MarkerFelt-16"); _world.SetDebugDraw(_debugDraw); _debugDraw.AppendFlags(b2DrawFlags.e_shapeBit); Schedule(t => { _world.Step(t, 8, 1); }); } return(_world); }
private void initPhysics() { CCSize s = Layer.VisibleBoundsWorldspace.Size; var gravity = new b2Vec2(0.0f, -10.0f); _world = new b2World(gravity); float debugWidth = s.Width / PTM_RATIO * 2f; float debugHeight = s.Height / PTM_RATIO * 2f; //CCBox2dDraw debugDraw = new CCBox2dDraw(new b2Vec2(debugWidth / 2f + 10, s.Height - debugHeight - 10), 2); //debugDraw.AppendFlags(b2DrawFlags.e_shapeBit); //_world.SetDebugDraw(debugDraw); _world.SetAllowSleeping(true); _world.SetContinuousPhysics(true); //m_debugDraw = new GLESDebugDraw( PTM_RATIO ); //world->SetDebugDraw(m_debugDraw); //uint32 flags = 0; //flags += b2Draw::e_shapeBit; // flags += b2Draw::e_jointBit; // flags += b2Draw::e_aabbBit; // flags += b2Draw::e_pairBit; // flags += b2Draw::e_centerOfMassBit; //m_debugDraw->SetFlags(flags); // Call the body factory which allocates memory for the ground body // from a pool and creates the ground box shape (also from a pool). // The body is also added to the world. b2BodyDef def = new b2BodyDef(); def.allowSleep = true; def.position = b2Vec2.Zero; def.type = b2BodyType.b2_staticBody; b2Body groundBody = _world.CreateBody(def); groundBody.SetActive(true); // Define the ground box shape. // bottom b2EdgeShape groundBox = new b2EdgeShape(); groundBox.Set(b2Vec2.Zero, new b2Vec2(s.Width / PTM_RATIO, 0)); b2FixtureDef fd = new b2FixtureDef(); fd.shape = groundBox; groundBody.CreateFixture(fd); // top groundBox = new b2EdgeShape(); groundBox.Set(new b2Vec2(0, s.Height / PTM_RATIO), new b2Vec2(s.Width / PTM_RATIO, s.Height / PTM_RATIO)); fd.shape = groundBox; groundBody.CreateFixture(fd); // left groundBox = new b2EdgeShape(); groundBox.Set(new b2Vec2(0, s.Height / PTM_RATIO), b2Vec2.Zero); fd.shape = groundBox; groundBody.CreateFixture(fd); // right groundBox = new b2EdgeShape(); groundBox.Set(new b2Vec2(s.Width / PTM_RATIO, s.Height / PTM_RATIO), new b2Vec2(s.Width / PTM_RATIO, 0)); fd.shape = groundBox; groundBody.CreateFixture(fd); // _world.Dump(); }
void InitPhysics() { CCSize s = Layer.VisibleBoundsWorldspace.Size; //world def var gravity = new b2Vec2(0.0f, 0.0f); world = new b2World(gravity); world.SetAllowSleeping(true); world.SetContinuousPhysics(true); //body def var balldef = new b2BodyDef(); balldef.type = b2BodyType.b2_dynamicBody; balldef.position.Set(s.Width * 0.5f / PTM_RATIO, s.Height * 0.8f / PTM_RATIO); ball = world.CreateBody(balldef); //shape def b2CircleShape ballshape = new b2CircleShape(); ballshape.Radius = 50f / PTM_RATIO; //fixture def b2FixtureDef ballfixture = new b2FixtureDef(); ballfixture.shape = ballshape; ballfixture.density = 1f; ballfixture.friction = 0.2f; ballfixture.restitution = 0.0f; ball.CreateFixture(ballfixture); //ball.SetTransform(new b2Vec2(8, 8), 1); //this doesn't work ball.LinearVelocity = new b2Vec2(0, 10); //ball.AngularVelocity = 1; //CCPhysicsSprite doesn't update angle //sprite def sprite = new CCPhysicsSprite(new CCTexture2D("ball.png"), new CCRect(0, 0, 100, 100), PTM_RATIO); sprite.Position = new CCPoint(balldef.position.x, balldef.position.y); sprite.PhysicsBody = ball; AddChild(sprite); ///////////////////// ball 2 var fixedballdef = new b2BodyDef(); fixedballdef.type = b2BodyType.b2_staticBody; fixedballdef.position.Set(s.Width * 0.5f / PTM_RATIO, s.Height * 0.5f / PTM_RATIO); ball2 = world.CreateBody(fixedballdef); ball2.CreateFixture(ballfixture); sprite2 = new CCPhysicsSprite(new CCTexture2D("ball.png"), new CCRect(0, 0, 100, 100), PTM_RATIO); sprite2.Position = new CCPoint(fixedballdef.position.x, fixedballdef.position.y); sprite2.PhysicsBody = ball2; AddChild(sprite2); ///////////////////// ball 3 fixedballdef.position.Set(s.Width * 0.75f / PTM_RATIO, s.Height * 0.75f / PTM_RATIO); ball3 = world.CreateBody(fixedballdef); ball3.CreateFixture(ballfixture); sprite3 = new CCPhysicsSprite(new CCTexture2D("ball.png"), new CCRect(0, 0, 100, 100), PTM_RATIO); sprite3.Position = new CCPoint(fixedballdef.position.x, fixedballdef.position.y); sprite3.PhysicsBody = ball3; AddChild(sprite3); ballmass = ball.Mass; ball2mass = ball2.Mass; ball3mass = ball3.Mass; //put walls up var edge = new b2EdgeShape(); edge.Set(new b2Vec2(0f, s.Height / PTM_RATIO), new b2Vec2(s.Width / PTM_RATIO, s.Height / PTM_RATIO)); var wallfixture = new b2FixtureDef(); wallfixture.shape = edge; var walldef = new b2BodyDef(); walldef.type = b2BodyType.b2_staticBody; var wall = world.CreateBody(walldef); wall.CreateFixture(wallfixture); edge.Set(new b2Vec2(s.Width / PTM_RATIO, s.Height / PTM_RATIO), new b2Vec2(s.Width / PTM_RATIO, 0f)); var wall2 = world.CreateBody(walldef); wall2.CreateFixture(wallfixture); edge.Set(new b2Vec2(0f, 0f), new b2Vec2(s.Width / PTM_RATIO, 0f)); var wall3 = world.CreateBody(walldef); wall3.CreateFixture(wallfixture); edge.Set(new b2Vec2(0f, 0f), new b2Vec2(0f, s.Height / PTM_RATIO)); var wall4 = world.CreateBody(walldef); wall4.CreateFixture(wallfixture); // Console.WriteLine("position of body ball2 {0}", ball2.Position); // Console.WriteLine("position of body sprite2 {0}", sprite2.Position); // Console.WriteLine("anchor point of body sprite {0}", sprite.AnchorPoint); // Console.WriteLine("content size of sprite {0}", sprite.ContentSize); // Console.WriteLine("content size of sprite2 {0}", sprite2.ContentSize); //sprite.UpdateBallTransform(); // var def = new b2BodyDef (); // def.allowSleep = true; // def.position = b2Vec2.Zero; // def.type = b2BodyType.b2_staticBody; // b2Body groundBody = world.CreateBody (def); // groundBody.SetActive (true); // // b2EdgeShape groundBox = new b2EdgeShape (); // groundBox.Set (b2Vec2.Zero, new b2Vec2 (s.Width / PTM_RATIO, 0)); // b2FixtureDef fd = new b2FixtureDef (); // fd.shape = groundBox; // groundBody.CreateFixture (fd); }
private void InitPhysics() { _gravity = new b2Vec2(0.0f, GRAVITY); _world = new b2World(b2Vec2.Zero); _world.SetAllowSleeping(true); _world.SetContinuousPhysics(true); _contactListener = new ContactListener(this); _world.SetContactListener(_contactListener); var wallDef = new b2BodyDef(); wallDef.allowSleep = true; wallDef.position = b2Vec2.Zero; wallDef.type = b2BodyType.b2_staticBody; //Floor b2Body floorBody = _world.CreateBody(wallDef); floorBody.SetActive(true); b2EdgeShape floorShape = new b2EdgeShape(); floorShape.Set(b2Vec2.Zero, new b2Vec2(_gameWidth / App.PTM_RATIO, 0)); b2FixtureDef floorFixture = new b2FixtureDef(); floorFixture.friction = WALL_FRICTION; floorFixture.restitution = WALL_RECOIL; floorFixture.shape = floorShape; floorBody.CreateFixture(floorFixture); _contactListener.Floor = floorBody; //Left Wall b2Body leftWallBody = _world.CreateBody(wallDef); leftWallBody.SetActive(true); b2EdgeShape leftWallShape = new b2EdgeShape(); //Go up very high so skip PTM_RATIO leftWallShape.Set(b2Vec2.Zero, new b2Vec2(0, _gameHeight)); b2FixtureDef leftWallFixture = new b2FixtureDef(); leftWallFixture.friction = WALL_FRICTION; leftWallFixture.restitution = WALL_RECOIL; leftWallFixture.shape = leftWallShape; leftWallBody.CreateFixture(leftWallFixture); //Right Wall b2Body rightWallBody = _world.CreateBody(wallDef); rightWallBody.SetActive(true); b2EdgeShape rightWallShape = new b2EdgeShape(); //Go up very high so skip PTM_RATIO rightWallShape.Set(new b2Vec2(_gameWidth / App.PTM_RATIO, 0), new b2Vec2(_gameWidth / App.PTM_RATIO, _gameHeight)); b2FixtureDef rightWallFixture = new b2FixtureDef(); rightWallFixture.friction = WALL_FRICTION; rightWallFixture.restitution = WALL_RECOIL; rightWallFixture.shape = rightWallShape; rightWallBody.CreateFixture(rightWallFixture); }