I integrated Biped into the latest cocos2d trunk and the latest Box2D. I find this Biped sample is very useful, I don’t know why it is excluded in the latest Box2D.
Do you guys want to have it?
BipedTest/Box2D in cocos2d
(8 posts) (8 voices)-
Posted 2 years ago #
-
I'd sure like to see it.... I'm just getting into Box 2d, and the more samples, the better!
Thanks,
Brad
Posted 2 years ago # -
Having trouble finding the biped samples, is this in the 0.81 rc? Or on github?? Scoured the 0.8's svn for it w/ no luck. Any help?
Thanks.
Posted 2 years ago # -
I went through all the Box2D Tests yesterday... tests like SliderCrank, TheoJansen, Dominos, etc are all awesome. We're just missing a biped or ragdoll test.
For instance, this one for AS3
Posted 1 year ago # -
^ They are no longer part of the test bed so somebody needs to port them to Box2d 2.1 before they can be included with cocos2d.
http://code.google.com/p/box2d/source/browse/#svn%2Ftrunk%2FBox2D%2FTestbed%2FTests
Posted 1 year ago # -
This is not a direct port of the entire test, but I translated most of what I required from the C++ code to work in my iPhone project... the only thing that is missing are the creation of rigid steps on the left and the right, and the creation of multiple dolls.
I have posted here to help out anyone else who searches for ragdoll iphone cocos2d box2d biped and however many other search terms I used to try and find this bit of code originally.....
CGSize winSize = [CCDirector sharedDirector].winSize; // Create a world b2Vec2 gravity = b2Vec2(0.0f, -10.0f); bool doSleep = true; _world = new b2World(gravity, doSleep); _world->SetContinuousPhysics(true); GLESDebugDraw *m_debugDraw = new GLESDebugDraw(PTM_RATIO); _world->SetDebugDraw(m_debugDraw); uint32 flags = 0; flags += b2DebugDraw::e_shapeBit; // flags += b2DebugDraw::e_jointBit; // flags += b2DebugDraw::e_aabbBit; // flags += b2DebugDraw::e_pairBit; // flags += b2DebugDraw::e_centerOfMassBit; m_debugDraw->SetFlags(flags); // Create edges around the entire screen b2BodyDef groundBodyDef; groundBodyDef.position.Set(0,0); b2Body *groundBody = _world->CreateBody(&groundBodyDef); b2PolygonShape groundBox; b2FixtureDef boxShapeDef; boxShapeDef.shape = &groundBox; groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(winSize.width/PTM_RATIO, 0)); groundBody->CreateFixture(&boxShapeDef); groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(0, winSize.height/PTM_RATIO)); groundBody->CreateFixture(&boxShapeDef); groundBox.SetAsEdge(b2Vec2(0, winSize.height/PTM_RATIO), b2Vec2(winSize.width/PTM_RATIO, winSize.height/PTM_RATIO)); groundBody->CreateFixture(&boxShapeDef); groundBox.SetAsEdge(b2Vec2(winSize.width/PTM_RATIO, winSize.height/PTM_RATIO), b2Vec2(winSize.width/PTM_RATIO, 0)); groundBody->CreateFixture(&boxShapeDef); //////////////// b2BodyDef bd; b2CircleShape circ; b2FixtureDef fixtureDef; b2PolygonShape box; b2RevoluteJointDef jd; float startX = 200.0; float startY = 600.0; // BODIES // Set these to dynamic bodies bd.type = b2_dynamicBody; // Head circ.m_radius = 25.0/PTM_RATIO; fixtureDef.shape = ˆ fixtureDef.density = 1.0; fixtureDef.friction = 0.4; fixtureDef.restitution = 0.3; bd.position.Set(startX / PTM_RATIO, startY / PTM_RATIO); CCSprite *headSprite = [CCSprite spriteWithFile:@"GirlHead.png"]; [self addChild:headSprite]; bd.userData = headSprite; b2Body *head = _world->CreateBody(&bd); head->CreateFixture(&fixtureDef); //if (i == 0){ //head->ApplyLinearImpulse(b2Vec2(random() * 100 - 50, random() * 100 - 50), head->GetWorldCenter()); //} // Torso1 box.SetAsBox(30 / PTM_RATIO, 20 / PTM_RATIO); fixtureDef.shape = &box; fixtureDef.density = 1.0; fixtureDef.friction = 0.4; fixtureDef.restitution = 0.1; bd.position.Set(startX / PTM_RATIO, (startY - 56) / PTM_RATIO); b2Body *torso1 = _world->CreateBody(&bd); torso1->CreateFixture(&fixtureDef); // Torso2 box.SetAsBox(30 / PTM_RATIO, 20 / PTM_RATIO); fixtureDef.shape = &box; bd.position.Set(startX / PTM_RATIO, (startY - 86) / PTM_RATIO); b2Body *torso2 = _world->CreateBody(&bd); torso2->CreateFixture(&fixtureDef); // Torso3 box.SetAsBox(30 / PTM_RATIO, 20 / PTM_RATIO); fixtureDef.shape = &box; bd.position.Set(startX / PTM_RATIO, (startY - 116) / PTM_RATIO); b2Body *torso3 = _world->CreateBody(&bd); torso3->CreateFixture(&fixtureDef); // UpperArm fixtureDef.density = 1.0; fixtureDef.friction = 0.4; fixtureDef.restitution = 0.1; // L box.SetAsBox(36/PTM_RATIO, 13/PTM_RATIO); fixtureDef.shape = &box; bd.position.Set((startX - 60) / PTM_RATIO, (startY - 40) / PTM_RATIO); b2Body *upperArmL = _world->CreateBody(&bd); upperArmL->CreateFixture(&fixtureDef); // R box.SetAsBox(36/PTM_RATIO, 13/ PTM_RATIO); fixtureDef.shape = &box; bd.position.Set((startX + 60) / PTM_RATIO, (startY - 40) / PTM_RATIO); b2Body *upperArmR = _world->CreateBody(&bd); upperArmR->CreateFixture(&fixtureDef); // LowerArm fixtureDef.density = 1.0; fixtureDef.friction = 0.4; fixtureDef.restitution = 0.1; // L box.SetAsBox(34 / PTM_RATIO, 12 / PTM_RATIO); fixtureDef.shape = &box; bd.position.Set((startX - 114) / PTM_RATIO, (startY - 40) / PTM_RATIO); b2Body *lowerArmL = _world->CreateBody(&bd); lowerArmL->CreateFixture(&fixtureDef); // R box.SetAsBox(34 / PTM_RATIO, 12 / PTM_RATIO); fixtureDef.shape = &box; bd.position.Set((startX + 114) / PTM_RATIO, (startY - 40) / PTM_RATIO); b2Body *lowerArmR = _world->CreateBody(&bd); lowerArmR->CreateFixture(&fixtureDef); // UpperLeg fixtureDef.density = 1.0; fixtureDef.friction = 0.4; fixtureDef.restitution = 0.1; // L box.SetAsBox(15 / PTM_RATIO, 44 / PTM_RATIO); fixtureDef.shape = &box; bd.position.Set((startX - 16) / PTM_RATIO, (startY - 170) / PTM_RATIO); b2Body *upperLegL = _world->CreateBody(&bd); upperLegL->CreateFixture(&fixtureDef); // R box.SetAsBox(15 / PTM_RATIO, 44 / PTM_RATIO); fixtureDef.shape = &box; bd.position.Set((startX + 16) / PTM_RATIO, (startY - 170) / PTM_RATIO); b2Body *upperLegR = _world->CreateBody(&bd); upperLegR->CreateFixture(&fixtureDef); // LowerLeg fixtureDef.density = 1.0; fixtureDef.friction = 0.4; fixtureDef.restitution = 0.1; // L box.SetAsBox(12 / PTM_RATIO, 40 / PTM_RATIO); fixtureDef.shape = &box; bd.position.Set((startX - 16) / PTM_RATIO, (startY - 240) / PTM_RATIO); b2Body *lowerLegL = _world->CreateBody(&bd); lowerLegL->CreateFixture(&fixtureDef); // R box.SetAsBox(12 / PTM_RATIO, 40 / PTM_RATIO); fixtureDef.shape = &box; bd.position.Set((startX + 16) / PTM_RATIO, (startY - 240) / PTM_RATIO); b2Body *lowerLegR = _world->CreateBody(&bd); lowerLegR->CreateFixture(&fixtureDef); // JOINTS jd.enableLimit = true; // Head to shoulders jd.lowerAngle = -40 / (180/M_PI); jd.upperAngle = 40 / (180/M_PI); jd.Initialize(torso1, head, b2Vec2(startX / PTM_RATIO, (startY - 30) / PTM_RATIO)); _world->CreateJoint(&jd); // Upper arm to shoulders // L jd.lowerAngle = -85 / (180/M_PI); jd.upperAngle = 130 / (180/M_PI); jd.Initialize(torso1, upperArmL, b2Vec2((startX - 36) / PTM_RATIO, (startY - 40) / PTM_RATIO)); _world->CreateJoint(&jd); // R jd.lowerAngle = -130 / (180/M_PI); jd.upperAngle = 85 / (180/M_PI); jd.Initialize(torso1, upperArmR, b2Vec2((startX + 36) / PTM_RATIO, (startY - 40) / PTM_RATIO)); _world->CreateJoint(&jd); // Lower arm to upper arm // L jd.lowerAngle = -130 / (180/M_PI); jd.upperAngle = 10 / (180/M_PI); jd.Initialize(upperArmL, lowerArmL, b2Vec2((startX - 90) / PTM_RATIO, (startY - 40) / PTM_RATIO)); _world->CreateJoint(&jd); // R jd.lowerAngle = -10 / (180/M_PI); jd.upperAngle = 130 / (180/M_PI); jd.Initialize(upperArmR, lowerArmR, b2Vec2((startX + 90) / PTM_RATIO, (startY - 40) / PTM_RATIO)); _world->CreateJoint(&jd); // Shoulders/stomach jd.lowerAngle = -15 / (180/M_PI); jd.upperAngle = 15 / (180/M_PI); jd.Initialize(torso1, torso2, b2Vec2(startX / PTM_RATIO, (startY - 70) / PTM_RATIO)); _world->CreateJoint(&jd); // Stomach/hips jd.Initialize(torso2, torso3, b2Vec2(startX / PTM_RATIO, (startY - 100) / PTM_RATIO)); _world->CreateJoint(&jd); // Torso to upper leg // L jd.lowerAngle = -25 / (180/M_PI); jd.upperAngle = 45 / (180/M_PI); jd.Initialize(torso3, upperLegL, b2Vec2((startX - 16) / PTM_RATIO, (startY - 114) / PTM_RATIO)); _world->CreateJoint(&jd); // R jd.lowerAngle = -45 / (180/M_PI); jd.upperAngle = 25 / (180/M_PI); jd.Initialize(torso3, upperLegR, b2Vec2((startX + 16) / PTM_RATIO, (startY - 114) / PTM_RATIO)); _world->CreateJoint(&jd); // Upper leg to lower leg // L jd.lowerAngle = -25 / (180/M_PI); jd.upperAngle = 115 / (180/M_PI); jd.Initialize(upperLegL, lowerLegL, b2Vec2((startX - 16) / PTM_RATIO, (startY - 210) / PTM_RATIO)); _world->CreateJoint(&jd); // R jd.lowerAngle = -115 / (180/M_PI); jd.upperAngle = 25 / (180/M_PI); jd.Initialize(upperLegR, lowerLegR, b2Vec2((startX + 16) / PTM_RATIO, (startY - 210) / PTM_RATIO)); _world->CreateJoint(&jd);Posted 1 year ago # -
The above code worked for me.
Thanks! It was hard to find a good rag doll example.
Posted 4 months ago # -
If you want, you can check find Box2d examples I implemented here: https://github.com/YannickL/Box2D-Examples (here is the biped example).
Posted 4 months ago #
Reply
You must log in to post.