void Board::InitDemo() { physics->SetIterations(20); physics->SetSteps(1); physics->ResizeStaticHash(40.0f,1000); physics->ResizeActiveHash(40.0f,1000); PhysicsObject* obj = physics->CreateStaticObject(); obj->AddSegmentShape(SexyVector2(0,470), SexyVector2(640, 470), 0.0f,1.0f,1.0f); float radius = 15.0f; obj = physics->CreateObject(10.0f, physics->ComputeMomentForCircle(10.0f, 0.0f, radius, SexyVector2(0.0f,0.0f))); obj->SetPosition(SexyVector2(320, 455)); obj->AddCircleShape(radius, SexyVector2(0,0), 1.0f,1.0f); int num = 4; SexyVector2 verts[] = { SexyVector2(-15,-15), SexyVector2(-15, 15), SexyVector2( 15, 15), SexyVector2( 15,-15), }; int i,j; for(i=0; i<14; i++){ for(j=0; j<=i; j++){ PhysicsObject* obj = physics->CreateObject(1.0f, physics->ComputeMomentForPoly(1.0f, num, verts, SexyVector2(0.0f,0.0f))); obj->AddPolyShape(num, verts, SexyVector2(0.0f,0.0f),0.0f,0.4f); obj->SetPosition(SexyVector2(300 + j*32 - i*16, i*32)); } } }
void Board::InitDemo() { physics->SetSteps(3); physics->ResizeStaticHash(50.0f,999); physics->ResizeActiveHash(50.0f,999); physics->SetGravity(SexyVector2(0,300)); PhysicsObject* obj = physics->CreateStaticObject(); obj->AddSegmentShape(SexyVector2(0,470), SexyVector2(640, 470), 0.0f,1.0f,1.0f); obj = physics->CreateStaticObject(); obj->AddSegmentShape(SexyVector2(0,325), SexyVector2(250, 490), 0.0f,1.0f,1.0f); obj = physics->CreateStaticObject(); obj->AddSegmentShape(SexyVector2(300,495), SexyVector2(660, 375), 0.0f,1.0f,1.0f); obj = physics->CreateStaticObject(); obj->AddSegmentShape(SexyVector2(640,0), SexyVector2(640, 480), 0.0f,1.0f,1.0f); PhysicsObject* static_obj = physics->CreateStaticObject(); PhysicsObject* static_obj2 = physics->CreateStaticObject(); static_obj2->SetPosition(SexyVector2(440,200)); PhysicsObject* obj1 = MakeBox(SexyVector2(460,200)); PhysicsObject* obj2 = MakeBox(SexyVector2(500,200)); PhysicsObject* obj3 = MakeBox(SexyVector2(540,200)); PhysicsObject* obj4 = MakeBox(SexyVector2(580,200)); physics->CreatePivotJoint(static_obj2, obj1, SexyVector2(440,200)); physics->CreatePivotJoint(static_obj2, obj2, SexyVector2(440,200)); physics->CreatePivotJoint(static_obj2, obj3, SexyVector2(440,200)); physics->CreatePivotJoint(static_obj2, obj4, SexyVector2(440,200)); obj1 = MakeBox(SexyVector2(220,180)); obj2 = MakeBox(SexyVector2(260,180)); obj3 = MakeBox(SexyVector2(300,180)); obj4 = MakeBox(SexyVector2(340,180)); float max = 25.0f; float min = 10.0f; physics->CreateSlideJoint(static_obj, obj1, SexyVector2(195,180), SexyVector2(-15,0), min,max); physics->CreateSlideJoint(obj1, obj2, SexyVector2(15,0), SexyVector2(-15,0), min,max); physics->CreateSlideJoint(obj2, obj3, SexyVector2(15,0), SexyVector2(-15,0), min,max); physics->CreateSlideJoint(obj3, obj4, SexyVector2(15,0), SexyVector2(-15,0), min,max); physics->CreateSlideJoint(obj4, static_obj, SexyVector2(15,0), SexyVector2(355,180), min,max); obj1 = MakeBox(SexyVector2(320,10)); obj2 = MakeBox(SexyVector2(360,10)); obj3 = MakeBox(SexyVector2(400,10)); obj4 = MakeBox(SexyVector2(440,10)); physics->CreatePinJoint(static_obj, obj1, SexyVector2(195,10), SexyVector2(-15,0)); physics->CreatePinJoint(obj1, obj2, SexyVector2(15,0), SexyVector2(-15,0)); physics->CreatePinJoint(obj2, obj3, SexyVector2(15,0), SexyVector2(-15,0)); physics->CreatePinJoint(obj3, obj4, SexyVector2(15,0), SexyVector2(-15,0)); physics->CreatePinJoint(obj4, static_obj, SexyVector2(15,0), SexyVector2(355,10)); int num = 4; SexyVector2 verts[] = { SexyVector2(-20,-15), SexyVector2(-20, 15), SexyVector2( 20, 15), SexyVector2( 20,-15), }; chassis = physics->CreateObject(1.0f, physics->ComputeMomentForPoly(1.0f, num, verts, SexyVector2(0.0f,0.0f))); chassis->AddPolyShape(num, verts, SexyVector2(0.0f,0.0f),0.0f,1.0f); chassis->SetPosition(SexyVector2(60, 250)); float radius = 15; float wheel_mass = 0.3; SexyVector2 offset = SexyVector2(radius + 30, 25); wheel1 = physics->CreateObject(10.0f, physics->ComputeMomentForCircle(wheel_mass, 0.0f, radius, SexyVector2(0.0f,0.0f))); wheel1->SetPosition(chassis->GetPosition() + offset); wheel1->AddCircleShape(radius, SexyVector2(0,0),0.0f,2.5f); wheel1->SetVelocity(chassis->GetVelocity()); physics->CreatePinJoint(chassis, wheel1, SexyVector2(0,0), SexyVector2(0,0)); wheel2 = physics->CreateObject(10.0f, physics->ComputeMomentForCircle(wheel_mass, 0.0f, radius, SexyVector2(0.0f,0.0f))); wheel2->SetPosition(chassis->GetPosition() + SexyVector2(-offset.x, offset.y)); wheel2->AddCircleShape(radius, SexyVector2(0,0),0.0f,2.5f); wheel2->SetVelocity(chassis->GetVelocity()); physics->CreatePinJoint(chassis, wheel2, SexyVector2(0,0), SexyVector2(0,0)); }