objects = {
/* Begin PBXBuildFile section */
- 491330C81372616300DFB46D /* Box2D.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913307B1372616300DFB46D /* Box2D.h */; };
- 491330C91372616300DFB46D /* b2BroadPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913307D1372616300DFB46D /* b2BroadPhase.cpp */; };
- 491330CA1372616300DFB46D /* b2BroadPhase.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913307E1372616300DFB46D /* b2BroadPhase.h */; };
- 491330CB1372616300DFB46D /* b2CollideCircle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913307F1372616300DFB46D /* b2CollideCircle.cpp */; };
- 491330CC1372616300DFB46D /* b2CollidePolygon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330801372616300DFB46D /* b2CollidePolygon.cpp */; };
- 491330CD1372616300DFB46D /* b2Collision.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330811372616300DFB46D /* b2Collision.cpp */; };
- 491330CE1372616300DFB46D /* b2Collision.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330821372616300DFB46D /* b2Collision.h */; };
- 491330CF1372616300DFB46D /* b2Distance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330831372616300DFB46D /* b2Distance.cpp */; };
- 491330D01372616300DFB46D /* b2Distance.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330841372616300DFB46D /* b2Distance.h */; };
- 491330D11372616300DFB46D /* b2DynamicTree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330851372616300DFB46D /* b2DynamicTree.cpp */; };
- 491330D21372616300DFB46D /* b2DynamicTree.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330861372616300DFB46D /* b2DynamicTree.h */; };
- 491330D31372616300DFB46D /* b2TimeOfImpact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330871372616300DFB46D /* b2TimeOfImpact.cpp */; };
- 491330D41372616300DFB46D /* b2TimeOfImpact.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330881372616300DFB46D /* b2TimeOfImpact.h */; };
- 491330D51372616300DFB46D /* b2CircleShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913308A1372616300DFB46D /* b2CircleShape.cpp */; };
- 491330D61372616300DFB46D /* b2CircleShape.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913308B1372616300DFB46D /* b2CircleShape.h */; };
- 491330D71372616300DFB46D /* b2PolygonShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913308C1372616300DFB46D /* b2PolygonShape.cpp */; };
- 491330D81372616300DFB46D /* b2PolygonShape.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913308D1372616300DFB46D /* b2PolygonShape.h */; };
- 491330D91372616300DFB46D /* b2Shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913308E1372616300DFB46D /* b2Shape.h */; };
- 491330DA1372616300DFB46D /* b2BlockAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330901372616300DFB46D /* b2BlockAllocator.cpp */; };
- 491330DB1372616300DFB46D /* b2BlockAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330911372616300DFB46D /* b2BlockAllocator.h */; };
- 491330DC1372616300DFB46D /* b2Math.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330921372616300DFB46D /* b2Math.cpp */; };
- 491330DD1372616300DFB46D /* b2Math.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330931372616300DFB46D /* b2Math.h */; };
- 491330DE1372616300DFB46D /* b2Settings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330941372616300DFB46D /* b2Settings.cpp */; };
- 491330DF1372616300DFB46D /* b2Settings.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330951372616300DFB46D /* b2Settings.h */; };
- 491330E01372616300DFB46D /* b2StackAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330961372616300DFB46D /* b2StackAllocator.cpp */; };
- 491330E11372616300DFB46D /* b2StackAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330971372616300DFB46D /* b2StackAllocator.h */; };
- 491330E21372616300DFB46D /* b2Body.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330991372616300DFB46D /* b2Body.cpp */; };
- 491330E31372616300DFB46D /* b2Body.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913309A1372616300DFB46D /* b2Body.h */; };
- 491330E41372616300DFB46D /* b2ContactManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913309B1372616300DFB46D /* b2ContactManager.cpp */; };
- 491330E51372616300DFB46D /* b2ContactManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913309C1372616300DFB46D /* b2ContactManager.h */; };
- 491330E61372616300DFB46D /* b2Fixture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913309D1372616300DFB46D /* b2Fixture.cpp */; };
- 491330E71372616300DFB46D /* b2Fixture.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913309E1372616300DFB46D /* b2Fixture.h */; };
- 491330E81372616300DFB46D /* b2Island.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913309F1372616300DFB46D /* b2Island.cpp */; };
- 491330E91372616300DFB46D /* b2Island.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330A01372616300DFB46D /* b2Island.h */; };
- 491330EA1372616300DFB46D /* b2TimeStep.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330A11372616300DFB46D /* b2TimeStep.h */; };
- 491330EB1372616300DFB46D /* b2World.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330A21372616300DFB46D /* b2World.cpp */; };
- 491330EC1372616300DFB46D /* b2World.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330A31372616300DFB46D /* b2World.h */; };
- 491330ED1372616300DFB46D /* b2WorldCallbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330A41372616300DFB46D /* b2WorldCallbacks.cpp */; };
- 491330EE1372616300DFB46D /* b2WorldCallbacks.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330A51372616300DFB46D /* b2WorldCallbacks.h */; };
- 491330EF1372616300DFB46D /* b2CircleContact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330A71372616300DFB46D /* b2CircleContact.cpp */; };
- 491330F01372616300DFB46D /* b2CircleContact.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330A81372616300DFB46D /* b2CircleContact.h */; };
- 491330F11372616300DFB46D /* b2Contact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330A91372616300DFB46D /* b2Contact.cpp */; };
- 491330F21372616300DFB46D /* b2Contact.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330AA1372616300DFB46D /* b2Contact.h */; };
- 491330F31372616300DFB46D /* b2ContactSolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330AB1372616300DFB46D /* b2ContactSolver.cpp */; };
- 491330F41372616300DFB46D /* b2ContactSolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330AC1372616300DFB46D /* b2ContactSolver.h */; };
- 491330F51372616300DFB46D /* b2PolygonAndCircleContact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330AD1372616300DFB46D /* b2PolygonAndCircleContact.cpp */; };
- 491330F61372616300DFB46D /* b2PolygonAndCircleContact.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330AE1372616300DFB46D /* b2PolygonAndCircleContact.h */; };
- 491330F71372616300DFB46D /* b2PolygonContact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330AF1372616300DFB46D /* b2PolygonContact.cpp */; };
- 491330F81372616300DFB46D /* b2PolygonContact.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330B01372616300DFB46D /* b2PolygonContact.h */; };
- 491330F91372616300DFB46D /* b2TOISolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330B11372616300DFB46D /* b2TOISolver.cpp */; };
- 491330FA1372616300DFB46D /* b2TOISolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330B21372616300DFB46D /* b2TOISolver.h */; };
- 491330FB1372616300DFB46D /* b2DistanceJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330B41372616300DFB46D /* b2DistanceJoint.cpp */; };
- 491330FC1372616300DFB46D /* b2DistanceJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330B51372616300DFB46D /* b2DistanceJoint.h */; };
- 491330FD1372616300DFB46D /* b2FrictionJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330B61372616300DFB46D /* b2FrictionJoint.cpp */; };
- 491330FE1372616300DFB46D /* b2FrictionJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330B71372616300DFB46D /* b2FrictionJoint.h */; };
- 491330FF1372616300DFB46D /* b2GearJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330B81372616300DFB46D /* b2GearJoint.cpp */; };
- 491331001372616300DFB46D /* b2GearJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330B91372616300DFB46D /* b2GearJoint.h */; };
- 491331011372616300DFB46D /* b2Joint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330BA1372616300DFB46D /* b2Joint.cpp */; };
- 491331021372616300DFB46D /* b2Joint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330BB1372616300DFB46D /* b2Joint.h */; };
- 491331031372616300DFB46D /* b2LineJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330BC1372616300DFB46D /* b2LineJoint.cpp */; };
- 491331041372616300DFB46D /* b2LineJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330BD1372616300DFB46D /* b2LineJoint.h */; };
- 491331051372616300DFB46D /* b2MouseJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330BE1372616300DFB46D /* b2MouseJoint.cpp */; };
- 491331061372616300DFB46D /* b2MouseJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330BF1372616300DFB46D /* b2MouseJoint.h */; };
- 491331071372616300DFB46D /* b2PrismaticJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330C01372616300DFB46D /* b2PrismaticJoint.cpp */; };
- 491331081372616300DFB46D /* b2PrismaticJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330C11372616300DFB46D /* b2PrismaticJoint.h */; };
- 491331091372616300DFB46D /* b2PulleyJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330C21372616300DFB46D /* b2PulleyJoint.cpp */; };
- 4913310A1372616300DFB46D /* b2PulleyJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330C31372616300DFB46D /* b2PulleyJoint.h */; };
- 4913310B1372616300DFB46D /* b2RevoluteJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330C41372616300DFB46D /* b2RevoluteJoint.cpp */; };
- 4913310C1372616300DFB46D /* b2RevoluteJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330C51372616300DFB46D /* b2RevoluteJoint.h */; };
- 4913310D1372616300DFB46D /* b2WeldJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491330C61372616300DFB46D /* b2WeldJoint.cpp */; };
- 4913310E1372616300DFB46D /* b2WeldJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 491330C71372616300DFB46D /* b2WeldJoint.h */; };
49133123137262F200DFB46D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49133122137262F200DFB46D /* Foundation.framework */; };
491331281372630700DFB46D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 491331271372630700DFB46D /* UIKit.framework */; };
+ 4913344213727CB100DFB46D /* Box2D.h in Headers */ = {isa = PBXBuildFile; fileRef = 491333F513727CB100DFB46D /* Box2D.h */; };
+ 4913344313727CB100DFB46D /* b2BroadPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491333F713727CB100DFB46D /* b2BroadPhase.cpp */; };
+ 4913344413727CB100DFB46D /* b2BroadPhase.h in Headers */ = {isa = PBXBuildFile; fileRef = 491333F813727CB100DFB46D /* b2BroadPhase.h */; };
+ 4913344513727CB100DFB46D /* b2CollideCircle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491333F913727CB100DFB46D /* b2CollideCircle.cpp */; };
+ 4913344613727CB100DFB46D /* b2CollidePolygon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491333FA13727CB100DFB46D /* b2CollidePolygon.cpp */; };
+ 4913344713727CB100DFB46D /* b2Collision.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491333FB13727CB100DFB46D /* b2Collision.cpp */; };
+ 4913344813727CB100DFB46D /* b2Collision.h in Headers */ = {isa = PBXBuildFile; fileRef = 491333FC13727CB100DFB46D /* b2Collision.h */; };
+ 4913344913727CB100DFB46D /* b2Distance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491333FD13727CB100DFB46D /* b2Distance.cpp */; };
+ 4913344A13727CB100DFB46D /* b2Distance.h in Headers */ = {isa = PBXBuildFile; fileRef = 491333FE13727CB100DFB46D /* b2Distance.h */; };
+ 4913344B13727CB100DFB46D /* b2DynamicTree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 491333FF13727CB100DFB46D /* b2DynamicTree.cpp */; };
+ 4913344C13727CB100DFB46D /* b2DynamicTree.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913340013727CB100DFB46D /* b2DynamicTree.h */; };
+ 4913344D13727CB100DFB46D /* b2TimeOfImpact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913340113727CB100DFB46D /* b2TimeOfImpact.cpp */; };
+ 4913344E13727CB100DFB46D /* b2TimeOfImpact.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913340213727CB100DFB46D /* b2TimeOfImpact.h */; };
+ 4913344F13727CB100DFB46D /* b2CircleShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913340413727CB100DFB46D /* b2CircleShape.cpp */; };
+ 4913345013727CB100DFB46D /* b2CircleShape.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913340513727CB100DFB46D /* b2CircleShape.h */; };
+ 4913345113727CB100DFB46D /* b2PolygonShape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913340613727CB100DFB46D /* b2PolygonShape.cpp */; };
+ 4913345213727CB100DFB46D /* b2PolygonShape.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913340713727CB100DFB46D /* b2PolygonShape.h */; };
+ 4913345313727CB100DFB46D /* b2Shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913340813727CB100DFB46D /* b2Shape.h */; };
+ 4913345413727CB100DFB46D /* b2BlockAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913340A13727CB100DFB46D /* b2BlockAllocator.cpp */; };
+ 4913345513727CB100DFB46D /* b2BlockAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913340B13727CB100DFB46D /* b2BlockAllocator.h */; };
+ 4913345613727CB100DFB46D /* b2Math.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913340C13727CB100DFB46D /* b2Math.cpp */; };
+ 4913345713727CB100DFB46D /* b2Math.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913340D13727CB100DFB46D /* b2Math.h */; };
+ 4913345813727CB100DFB46D /* b2Settings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913340E13727CB100DFB46D /* b2Settings.cpp */; };
+ 4913345913727CB100DFB46D /* b2Settings.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913340F13727CB100DFB46D /* b2Settings.h */; };
+ 4913345A13727CB100DFB46D /* b2StackAllocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913341013727CB100DFB46D /* b2StackAllocator.cpp */; };
+ 4913345B13727CB100DFB46D /* b2StackAllocator.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913341113727CB100DFB46D /* b2StackAllocator.h */; };
+ 4913345C13727CB100DFB46D /* b2Body.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913341313727CB100DFB46D /* b2Body.cpp */; };
+ 4913345D13727CB100DFB46D /* b2Body.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913341413727CB100DFB46D /* b2Body.h */; };
+ 4913345E13727CB100DFB46D /* b2ContactManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913341513727CB100DFB46D /* b2ContactManager.cpp */; };
+ 4913345F13727CB100DFB46D /* b2ContactManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913341613727CB100DFB46D /* b2ContactManager.h */; };
+ 4913346013727CB100DFB46D /* b2Fixture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913341713727CB100DFB46D /* b2Fixture.cpp */; };
+ 4913346113727CB100DFB46D /* b2Fixture.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913341813727CB100DFB46D /* b2Fixture.h */; };
+ 4913346213727CB100DFB46D /* b2Island.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913341913727CB100DFB46D /* b2Island.cpp */; };
+ 4913346313727CB100DFB46D /* b2Island.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913341A13727CB100DFB46D /* b2Island.h */; };
+ 4913346413727CB100DFB46D /* b2TimeStep.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913341B13727CB100DFB46D /* b2TimeStep.h */; };
+ 4913346513727CB100DFB46D /* b2World.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913341C13727CB100DFB46D /* b2World.cpp */; };
+ 4913346613727CB100DFB46D /* b2World.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913341D13727CB100DFB46D /* b2World.h */; };
+ 4913346713727CB100DFB46D /* b2WorldCallbacks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913341E13727CB100DFB46D /* b2WorldCallbacks.cpp */; };
+ 4913346813727CB100DFB46D /* b2WorldCallbacks.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913341F13727CB100DFB46D /* b2WorldCallbacks.h */; };
+ 4913346913727CB100DFB46D /* b2CircleContact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913342113727CB100DFB46D /* b2CircleContact.cpp */; };
+ 4913346A13727CB100DFB46D /* b2CircleContact.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913342213727CB100DFB46D /* b2CircleContact.h */; };
+ 4913346B13727CB100DFB46D /* b2Contact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913342313727CB100DFB46D /* b2Contact.cpp */; };
+ 4913346C13727CB100DFB46D /* b2Contact.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913342413727CB100DFB46D /* b2Contact.h */; };
+ 4913346D13727CB100DFB46D /* b2ContactSolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913342513727CB100DFB46D /* b2ContactSolver.cpp */; };
+ 4913346E13727CB100DFB46D /* b2ContactSolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913342613727CB100DFB46D /* b2ContactSolver.h */; };
+ 4913346F13727CB100DFB46D /* b2PolygonAndCircleContact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913342713727CB100DFB46D /* b2PolygonAndCircleContact.cpp */; };
+ 4913347013727CB100DFB46D /* b2PolygonAndCircleContact.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913342813727CB100DFB46D /* b2PolygonAndCircleContact.h */; };
+ 4913347113727CB100DFB46D /* b2PolygonContact.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913342913727CB100DFB46D /* b2PolygonContact.cpp */; };
+ 4913347213727CB100DFB46D /* b2PolygonContact.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913342A13727CB100DFB46D /* b2PolygonContact.h */; };
+ 4913347313727CB100DFB46D /* b2TOISolver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913342B13727CB100DFB46D /* b2TOISolver.cpp */; };
+ 4913347413727CB100DFB46D /* b2TOISolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913342C13727CB100DFB46D /* b2TOISolver.h */; };
+ 4913347513727CB100DFB46D /* b2DistanceJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913342E13727CB100DFB46D /* b2DistanceJoint.cpp */; };
+ 4913347613727CB100DFB46D /* b2DistanceJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913342F13727CB100DFB46D /* b2DistanceJoint.h */; };
+ 4913347713727CB100DFB46D /* b2FrictionJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913343013727CB100DFB46D /* b2FrictionJoint.cpp */; };
+ 4913347813727CB100DFB46D /* b2FrictionJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913343113727CB100DFB46D /* b2FrictionJoint.h */; };
+ 4913347913727CB100DFB46D /* b2GearJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913343213727CB100DFB46D /* b2GearJoint.cpp */; };
+ 4913347A13727CB100DFB46D /* b2GearJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913343313727CB100DFB46D /* b2GearJoint.h */; };
+ 4913347B13727CB100DFB46D /* b2Joint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913343413727CB100DFB46D /* b2Joint.cpp */; };
+ 4913347C13727CB100DFB46D /* b2Joint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913343513727CB100DFB46D /* b2Joint.h */; };
+ 4913347D13727CB100DFB46D /* b2LineJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913343613727CB100DFB46D /* b2LineJoint.cpp */; };
+ 4913347E13727CB100DFB46D /* b2LineJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913343713727CB100DFB46D /* b2LineJoint.h */; };
+ 4913347F13727CB100DFB46D /* b2MouseJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913343813727CB100DFB46D /* b2MouseJoint.cpp */; };
+ 4913348013727CB100DFB46D /* b2MouseJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913343913727CB100DFB46D /* b2MouseJoint.h */; };
+ 4913348113727CB100DFB46D /* b2PrismaticJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913343A13727CB100DFB46D /* b2PrismaticJoint.cpp */; };
+ 4913348213727CB100DFB46D /* b2PrismaticJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913343B13727CB100DFB46D /* b2PrismaticJoint.h */; };
+ 4913348313727CB100DFB46D /* b2PulleyJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913343C13727CB100DFB46D /* b2PulleyJoint.cpp */; };
+ 4913348413727CB100DFB46D /* b2PulleyJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913343D13727CB100DFB46D /* b2PulleyJoint.h */; };
+ 4913348513727CB100DFB46D /* b2RevoluteJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913343E13727CB100DFB46D /* b2RevoluteJoint.cpp */; };
+ 4913348613727CB100DFB46D /* b2RevoluteJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913343F13727CB100DFB46D /* b2RevoluteJoint.h */; };
+ 4913348713727CB100DFB46D /* b2WeldJoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4913344013727CB100DFB46D /* b2WeldJoint.cpp */; };
+ 4913348813727CB100DFB46D /* b2WeldJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913344113727CB100DFB46D /* b2WeldJoint.h */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
4913305F1372610400DFB46D /* libBox2D.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBox2D.a; sourceTree = BUILT_PRODUCTS_DIR; };
- 4913307B1372616300DFB46D /* Box2D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Box2D.h; sourceTree = "<group>"; };
- 4913307D1372616300DFB46D /* b2BroadPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2BroadPhase.cpp; sourceTree = "<group>"; };
- 4913307E1372616300DFB46D /* b2BroadPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2BroadPhase.h; sourceTree = "<group>"; };
- 4913307F1372616300DFB46D /* b2CollideCircle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CollideCircle.cpp; sourceTree = "<group>"; };
- 491330801372616300DFB46D /* b2CollidePolygon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CollidePolygon.cpp; sourceTree = "<group>"; };
- 491330811372616300DFB46D /* b2Collision.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Collision.cpp; sourceTree = "<group>"; };
- 491330821372616300DFB46D /* b2Collision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Collision.h; sourceTree = "<group>"; };
- 491330831372616300DFB46D /* b2Distance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Distance.cpp; sourceTree = "<group>"; };
- 491330841372616300DFB46D /* b2Distance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Distance.h; sourceTree = "<group>"; };
- 491330851372616300DFB46D /* b2DynamicTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2DynamicTree.cpp; sourceTree = "<group>"; };
- 491330861372616300DFB46D /* b2DynamicTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2DynamicTree.h; sourceTree = "<group>"; };
- 491330871372616300DFB46D /* b2TimeOfImpact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2TimeOfImpact.cpp; sourceTree = "<group>"; };
- 491330881372616300DFB46D /* b2TimeOfImpact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TimeOfImpact.h; sourceTree = "<group>"; };
- 4913308A1372616300DFB46D /* b2CircleShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CircleShape.cpp; sourceTree = "<group>"; };
- 4913308B1372616300DFB46D /* b2CircleShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2CircleShape.h; sourceTree = "<group>"; };
- 4913308C1372616300DFB46D /* b2PolygonShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonShape.cpp; sourceTree = "<group>"; };
- 4913308D1372616300DFB46D /* b2PolygonShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonShape.h; sourceTree = "<group>"; };
- 4913308E1372616300DFB46D /* b2Shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Shape.h; sourceTree = "<group>"; };
- 491330901372616300DFB46D /* b2BlockAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2BlockAllocator.cpp; sourceTree = "<group>"; };
- 491330911372616300DFB46D /* b2BlockAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2BlockAllocator.h; sourceTree = "<group>"; };
- 491330921372616300DFB46D /* b2Math.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Math.cpp; sourceTree = "<group>"; };
- 491330931372616300DFB46D /* b2Math.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Math.h; sourceTree = "<group>"; };
- 491330941372616300DFB46D /* b2Settings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Settings.cpp; sourceTree = "<group>"; };
- 491330951372616300DFB46D /* b2Settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Settings.h; sourceTree = "<group>"; };
- 491330961372616300DFB46D /* b2StackAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2StackAllocator.cpp; sourceTree = "<group>"; };
- 491330971372616300DFB46D /* b2StackAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2StackAllocator.h; sourceTree = "<group>"; };
- 491330991372616300DFB46D /* b2Body.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Body.cpp; sourceTree = "<group>"; };
- 4913309A1372616300DFB46D /* b2Body.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Body.h; sourceTree = "<group>"; };
- 4913309B1372616300DFB46D /* b2ContactManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2ContactManager.cpp; sourceTree = "<group>"; };
- 4913309C1372616300DFB46D /* b2ContactManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2ContactManager.h; sourceTree = "<group>"; };
- 4913309D1372616300DFB46D /* b2Fixture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Fixture.cpp; sourceTree = "<group>"; };
- 4913309E1372616300DFB46D /* b2Fixture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Fixture.h; sourceTree = "<group>"; };
- 4913309F1372616300DFB46D /* b2Island.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Island.cpp; sourceTree = "<group>"; };
- 491330A01372616300DFB46D /* b2Island.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Island.h; sourceTree = "<group>"; };
- 491330A11372616300DFB46D /* b2TimeStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TimeStep.h; sourceTree = "<group>"; };
- 491330A21372616300DFB46D /* b2World.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2World.cpp; sourceTree = "<group>"; };
- 491330A31372616300DFB46D /* b2World.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2World.h; sourceTree = "<group>"; };
- 491330A41372616300DFB46D /* b2WorldCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2WorldCallbacks.cpp; sourceTree = "<group>"; };
- 491330A51372616300DFB46D /* b2WorldCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2WorldCallbacks.h; sourceTree = "<group>"; };
- 491330A71372616300DFB46D /* b2CircleContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CircleContact.cpp; sourceTree = "<group>"; };
- 491330A81372616300DFB46D /* b2CircleContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2CircleContact.h; sourceTree = "<group>"; };
- 491330A91372616300DFB46D /* b2Contact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Contact.cpp; sourceTree = "<group>"; };
- 491330AA1372616300DFB46D /* b2Contact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Contact.h; sourceTree = "<group>"; };
- 491330AB1372616300DFB46D /* b2ContactSolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2ContactSolver.cpp; sourceTree = "<group>"; };
- 491330AC1372616300DFB46D /* b2ContactSolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2ContactSolver.h; sourceTree = "<group>"; };
- 491330AD1372616300DFB46D /* b2PolygonAndCircleContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonAndCircleContact.cpp; sourceTree = "<group>"; };
- 491330AE1372616300DFB46D /* b2PolygonAndCircleContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonAndCircleContact.h; sourceTree = "<group>"; };
- 491330AF1372616300DFB46D /* b2PolygonContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonContact.cpp; sourceTree = "<group>"; };
- 491330B01372616300DFB46D /* b2PolygonContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonContact.h; sourceTree = "<group>"; };
- 491330B11372616300DFB46D /* b2TOISolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2TOISolver.cpp; sourceTree = "<group>"; };
- 491330B21372616300DFB46D /* b2TOISolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TOISolver.h; sourceTree = "<group>"; };
- 491330B41372616300DFB46D /* b2DistanceJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2DistanceJoint.cpp; sourceTree = "<group>"; };
- 491330B51372616300DFB46D /* b2DistanceJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2DistanceJoint.h; sourceTree = "<group>"; };
- 491330B61372616300DFB46D /* b2FrictionJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2FrictionJoint.cpp; sourceTree = "<group>"; };
- 491330B71372616300DFB46D /* b2FrictionJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2FrictionJoint.h; sourceTree = "<group>"; };
- 491330B81372616300DFB46D /* b2GearJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2GearJoint.cpp; sourceTree = "<group>"; };
- 491330B91372616300DFB46D /* b2GearJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2GearJoint.h; sourceTree = "<group>"; };
- 491330BA1372616300DFB46D /* b2Joint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Joint.cpp; sourceTree = "<group>"; };
- 491330BB1372616300DFB46D /* b2Joint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Joint.h; sourceTree = "<group>"; };
- 491330BC1372616300DFB46D /* b2LineJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2LineJoint.cpp; sourceTree = "<group>"; };
- 491330BD1372616300DFB46D /* b2LineJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2LineJoint.h; sourceTree = "<group>"; };
- 491330BE1372616300DFB46D /* b2MouseJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MouseJoint.cpp; sourceTree = "<group>"; };
- 491330BF1372616300DFB46D /* b2MouseJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MouseJoint.h; sourceTree = "<group>"; };
- 491330C01372616300DFB46D /* b2PrismaticJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PrismaticJoint.cpp; sourceTree = "<group>"; };
- 491330C11372616300DFB46D /* b2PrismaticJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PrismaticJoint.h; sourceTree = "<group>"; };
- 491330C21372616300DFB46D /* b2PulleyJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PulleyJoint.cpp; sourceTree = "<group>"; };
- 491330C31372616300DFB46D /* b2PulleyJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PulleyJoint.h; sourceTree = "<group>"; };
- 491330C41372616300DFB46D /* b2RevoluteJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2RevoluteJoint.cpp; sourceTree = "<group>"; };
- 491330C51372616300DFB46D /* b2RevoluteJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2RevoluteJoint.h; sourceTree = "<group>"; };
- 491330C61372616300DFB46D /* b2WeldJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2WeldJoint.cpp; sourceTree = "<group>"; };
- 491330C71372616300DFB46D /* b2WeldJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2WeldJoint.h; sourceTree = "<group>"; };
49133122137262F200DFB46D /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
491331271372630700DFB46D /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
+ 491333F513727CB100DFB46D /* Box2D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Box2D.h; sourceTree = "<group>"; };
+ 491333F713727CB100DFB46D /* b2BroadPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2BroadPhase.cpp; sourceTree = "<group>"; };
+ 491333F813727CB100DFB46D /* b2BroadPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2BroadPhase.h; sourceTree = "<group>"; };
+ 491333F913727CB100DFB46D /* b2CollideCircle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CollideCircle.cpp; sourceTree = "<group>"; };
+ 491333FA13727CB100DFB46D /* b2CollidePolygon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CollidePolygon.cpp; sourceTree = "<group>"; };
+ 491333FB13727CB100DFB46D /* b2Collision.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Collision.cpp; sourceTree = "<group>"; };
+ 491333FC13727CB100DFB46D /* b2Collision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Collision.h; sourceTree = "<group>"; };
+ 491333FD13727CB100DFB46D /* b2Distance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Distance.cpp; sourceTree = "<group>"; };
+ 491333FE13727CB100DFB46D /* b2Distance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Distance.h; sourceTree = "<group>"; };
+ 491333FF13727CB100DFB46D /* b2DynamicTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2DynamicTree.cpp; sourceTree = "<group>"; };
+ 4913340013727CB100DFB46D /* b2DynamicTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2DynamicTree.h; sourceTree = "<group>"; };
+ 4913340113727CB100DFB46D /* b2TimeOfImpact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2TimeOfImpact.cpp; sourceTree = "<group>"; };
+ 4913340213727CB100DFB46D /* b2TimeOfImpact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TimeOfImpact.h; sourceTree = "<group>"; };
+ 4913340413727CB100DFB46D /* b2CircleShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CircleShape.cpp; sourceTree = "<group>"; };
+ 4913340513727CB100DFB46D /* b2CircleShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2CircleShape.h; sourceTree = "<group>"; };
+ 4913340613727CB100DFB46D /* b2PolygonShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonShape.cpp; sourceTree = "<group>"; };
+ 4913340713727CB100DFB46D /* b2PolygonShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonShape.h; sourceTree = "<group>"; };
+ 4913340813727CB100DFB46D /* b2Shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Shape.h; sourceTree = "<group>"; };
+ 4913340A13727CB100DFB46D /* b2BlockAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2BlockAllocator.cpp; sourceTree = "<group>"; };
+ 4913340B13727CB100DFB46D /* b2BlockAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2BlockAllocator.h; sourceTree = "<group>"; };
+ 4913340C13727CB100DFB46D /* b2Math.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Math.cpp; sourceTree = "<group>"; };
+ 4913340D13727CB100DFB46D /* b2Math.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Math.h; sourceTree = "<group>"; };
+ 4913340E13727CB100DFB46D /* b2Settings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Settings.cpp; sourceTree = "<group>"; };
+ 4913340F13727CB100DFB46D /* b2Settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Settings.h; sourceTree = "<group>"; };
+ 4913341013727CB100DFB46D /* b2StackAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2StackAllocator.cpp; sourceTree = "<group>"; };
+ 4913341113727CB100DFB46D /* b2StackAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2StackAllocator.h; sourceTree = "<group>"; };
+ 4913341313727CB100DFB46D /* b2Body.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Body.cpp; sourceTree = "<group>"; };
+ 4913341413727CB100DFB46D /* b2Body.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Body.h; sourceTree = "<group>"; };
+ 4913341513727CB100DFB46D /* b2ContactManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2ContactManager.cpp; sourceTree = "<group>"; };
+ 4913341613727CB100DFB46D /* b2ContactManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2ContactManager.h; sourceTree = "<group>"; };
+ 4913341713727CB100DFB46D /* b2Fixture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Fixture.cpp; sourceTree = "<group>"; };
+ 4913341813727CB100DFB46D /* b2Fixture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Fixture.h; sourceTree = "<group>"; };
+ 4913341913727CB100DFB46D /* b2Island.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Island.cpp; sourceTree = "<group>"; };
+ 4913341A13727CB100DFB46D /* b2Island.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Island.h; sourceTree = "<group>"; };
+ 4913341B13727CB100DFB46D /* b2TimeStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TimeStep.h; sourceTree = "<group>"; };
+ 4913341C13727CB100DFB46D /* b2World.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2World.cpp; sourceTree = "<group>"; };
+ 4913341D13727CB100DFB46D /* b2World.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2World.h; sourceTree = "<group>"; };
+ 4913341E13727CB100DFB46D /* b2WorldCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2WorldCallbacks.cpp; sourceTree = "<group>"; };
+ 4913341F13727CB100DFB46D /* b2WorldCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2WorldCallbacks.h; sourceTree = "<group>"; };
+ 4913342113727CB100DFB46D /* b2CircleContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CircleContact.cpp; sourceTree = "<group>"; };
+ 4913342213727CB100DFB46D /* b2CircleContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2CircleContact.h; sourceTree = "<group>"; };
+ 4913342313727CB100DFB46D /* b2Contact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Contact.cpp; sourceTree = "<group>"; };
+ 4913342413727CB100DFB46D /* b2Contact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Contact.h; sourceTree = "<group>"; };
+ 4913342513727CB100DFB46D /* b2ContactSolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2ContactSolver.cpp; sourceTree = "<group>"; };
+ 4913342613727CB100DFB46D /* b2ContactSolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2ContactSolver.h; sourceTree = "<group>"; };
+ 4913342713727CB100DFB46D /* b2PolygonAndCircleContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonAndCircleContact.cpp; sourceTree = "<group>"; };
+ 4913342813727CB100DFB46D /* b2PolygonAndCircleContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonAndCircleContact.h; sourceTree = "<group>"; };
+ 4913342913727CB100DFB46D /* b2PolygonContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonContact.cpp; sourceTree = "<group>"; };
+ 4913342A13727CB100DFB46D /* b2PolygonContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonContact.h; sourceTree = "<group>"; };
+ 4913342B13727CB100DFB46D /* b2TOISolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2TOISolver.cpp; sourceTree = "<group>"; };
+ 4913342C13727CB100DFB46D /* b2TOISolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TOISolver.h; sourceTree = "<group>"; };
+ 4913342E13727CB100DFB46D /* b2DistanceJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2DistanceJoint.cpp; sourceTree = "<group>"; };
+ 4913342F13727CB100DFB46D /* b2DistanceJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2DistanceJoint.h; sourceTree = "<group>"; };
+ 4913343013727CB100DFB46D /* b2FrictionJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2FrictionJoint.cpp; sourceTree = "<group>"; };
+ 4913343113727CB100DFB46D /* b2FrictionJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2FrictionJoint.h; sourceTree = "<group>"; };
+ 4913343213727CB100DFB46D /* b2GearJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2GearJoint.cpp; sourceTree = "<group>"; };
+ 4913343313727CB100DFB46D /* b2GearJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2GearJoint.h; sourceTree = "<group>"; };
+ 4913343413727CB100DFB46D /* b2Joint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Joint.cpp; sourceTree = "<group>"; };
+ 4913343513727CB100DFB46D /* b2Joint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Joint.h; sourceTree = "<group>"; };
+ 4913343613727CB100DFB46D /* b2LineJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2LineJoint.cpp; sourceTree = "<group>"; };
+ 4913343713727CB100DFB46D /* b2LineJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2LineJoint.h; sourceTree = "<group>"; };
+ 4913343813727CB100DFB46D /* b2MouseJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MouseJoint.cpp; sourceTree = "<group>"; };
+ 4913343913727CB100DFB46D /* b2MouseJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MouseJoint.h; sourceTree = "<group>"; };
+ 4913343A13727CB100DFB46D /* b2PrismaticJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PrismaticJoint.cpp; sourceTree = "<group>"; };
+ 4913343B13727CB100DFB46D /* b2PrismaticJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PrismaticJoint.h; sourceTree = "<group>"; };
+ 4913343C13727CB100DFB46D /* b2PulleyJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PulleyJoint.cpp; sourceTree = "<group>"; };
+ 4913343D13727CB100DFB46D /* b2PulleyJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PulleyJoint.h; sourceTree = "<group>"; };
+ 4913343E13727CB100DFB46D /* b2RevoluteJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2RevoluteJoint.cpp; sourceTree = "<group>"; };
+ 4913343F13727CB100DFB46D /* b2RevoluteJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2RevoluteJoint.h; sourceTree = "<group>"; };
+ 4913344013727CB100DFB46D /* b2WeldJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2WeldJoint.cpp; sourceTree = "<group>"; };
+ 4913344113727CB100DFB46D /* b2WeldJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2WeldJoint.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
491330541372610400DFB46D = {
isa = PBXGroup;
children = (
- 4913307A1372616300DFB46D /* Box2D */,
+ 491333F413727CB100DFB46D /* Box2D */,
491331291372630F00DFB46D /* Frameworks */,
491330601372610400DFB46D /* Products */,
);
name = Products;
sourceTree = "<group>";
};
- 4913307A1372616300DFB46D /* Box2D */ = {
+ 491331291372630F00DFB46D /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 491331271372630700DFB46D /* UIKit.framework */,
+ 49133122137262F200DFB46D /* Foundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 491333F413727CB100DFB46D /* Box2D */ = {
isa = PBXGroup;
children = (
- 4913307B1372616300DFB46D /* Box2D.h */,
- 4913307C1372616300DFB46D /* Collision */,
- 4913308F1372616300DFB46D /* Common */,
- 491330981372616300DFB46D /* Dynamics */,
+ 491333F513727CB100DFB46D /* Box2D.h */,
+ 491333F613727CB100DFB46D /* Collision */,
+ 4913340913727CB100DFB46D /* Common */,
+ 4913341213727CB100DFB46D /* Dynamics */,
);
name = Box2D;
- path = src/Box2D;
+ path = "../../../../tanks-ios/libs/box2d/src/Box2D";
sourceTree = "<group>";
};
- 4913307C1372616300DFB46D /* Collision */ = {
+ 491333F613727CB100DFB46D /* Collision */ = {
isa = PBXGroup;
children = (
- 4913307D1372616300DFB46D /* b2BroadPhase.cpp */,
- 4913307E1372616300DFB46D /* b2BroadPhase.h */,
- 4913307F1372616300DFB46D /* b2CollideCircle.cpp */,
- 491330801372616300DFB46D /* b2CollidePolygon.cpp */,
- 491330811372616300DFB46D /* b2Collision.cpp */,
- 491330821372616300DFB46D /* b2Collision.h */,
- 491330831372616300DFB46D /* b2Distance.cpp */,
- 491330841372616300DFB46D /* b2Distance.h */,
- 491330851372616300DFB46D /* b2DynamicTree.cpp */,
- 491330861372616300DFB46D /* b2DynamicTree.h */,
- 491330871372616300DFB46D /* b2TimeOfImpact.cpp */,
- 491330881372616300DFB46D /* b2TimeOfImpact.h */,
- 491330891372616300DFB46D /* Shapes */,
+ 491333F713727CB100DFB46D /* b2BroadPhase.cpp */,
+ 491333F813727CB100DFB46D /* b2BroadPhase.h */,
+ 491333F913727CB100DFB46D /* b2CollideCircle.cpp */,
+ 491333FA13727CB100DFB46D /* b2CollidePolygon.cpp */,
+ 491333FB13727CB100DFB46D /* b2Collision.cpp */,
+ 491333FC13727CB100DFB46D /* b2Collision.h */,
+ 491333FD13727CB100DFB46D /* b2Distance.cpp */,
+ 491333FE13727CB100DFB46D /* b2Distance.h */,
+ 491333FF13727CB100DFB46D /* b2DynamicTree.cpp */,
+ 4913340013727CB100DFB46D /* b2DynamicTree.h */,
+ 4913340113727CB100DFB46D /* b2TimeOfImpact.cpp */,
+ 4913340213727CB100DFB46D /* b2TimeOfImpact.h */,
+ 4913340313727CB100DFB46D /* Shapes */,
);
path = Collision;
sourceTree = "<group>";
};
- 491330891372616300DFB46D /* Shapes */ = {
+ 4913340313727CB100DFB46D /* Shapes */ = {
isa = PBXGroup;
children = (
- 4913308A1372616300DFB46D /* b2CircleShape.cpp */,
- 4913308B1372616300DFB46D /* b2CircleShape.h */,
- 4913308C1372616300DFB46D /* b2PolygonShape.cpp */,
- 4913308D1372616300DFB46D /* b2PolygonShape.h */,
- 4913308E1372616300DFB46D /* b2Shape.h */,
+ 4913340413727CB100DFB46D /* b2CircleShape.cpp */,
+ 4913340513727CB100DFB46D /* b2CircleShape.h */,
+ 4913340613727CB100DFB46D /* b2PolygonShape.cpp */,
+ 4913340713727CB100DFB46D /* b2PolygonShape.h */,
+ 4913340813727CB100DFB46D /* b2Shape.h */,
);
path = Shapes;
sourceTree = "<group>";
};
- 4913308F1372616300DFB46D /* Common */ = {
+ 4913340913727CB100DFB46D /* Common */ = {
isa = PBXGroup;
children = (
- 491330901372616300DFB46D /* b2BlockAllocator.cpp */,
- 491330911372616300DFB46D /* b2BlockAllocator.h */,
- 491330921372616300DFB46D /* b2Math.cpp */,
- 491330931372616300DFB46D /* b2Math.h */,
- 491330941372616300DFB46D /* b2Settings.cpp */,
- 491330951372616300DFB46D /* b2Settings.h */,
- 491330961372616300DFB46D /* b2StackAllocator.cpp */,
- 491330971372616300DFB46D /* b2StackAllocator.h */,
+ 4913340A13727CB100DFB46D /* b2BlockAllocator.cpp */,
+ 4913340B13727CB100DFB46D /* b2BlockAllocator.h */,
+ 4913340C13727CB100DFB46D /* b2Math.cpp */,
+ 4913340D13727CB100DFB46D /* b2Math.h */,
+ 4913340E13727CB100DFB46D /* b2Settings.cpp */,
+ 4913340F13727CB100DFB46D /* b2Settings.h */,
+ 4913341013727CB100DFB46D /* b2StackAllocator.cpp */,
+ 4913341113727CB100DFB46D /* b2StackAllocator.h */,
);
path = Common;
sourceTree = "<group>";
};
- 491330981372616300DFB46D /* Dynamics */ = {
+ 4913341213727CB100DFB46D /* Dynamics */ = {
isa = PBXGroup;
children = (
- 491330991372616300DFB46D /* b2Body.cpp */,
- 4913309A1372616300DFB46D /* b2Body.h */,
- 4913309B1372616300DFB46D /* b2ContactManager.cpp */,
- 4913309C1372616300DFB46D /* b2ContactManager.h */,
- 4913309D1372616300DFB46D /* b2Fixture.cpp */,
- 4913309E1372616300DFB46D /* b2Fixture.h */,
- 4913309F1372616300DFB46D /* b2Island.cpp */,
- 491330A01372616300DFB46D /* b2Island.h */,
- 491330A11372616300DFB46D /* b2TimeStep.h */,
- 491330A21372616300DFB46D /* b2World.cpp */,
- 491330A31372616300DFB46D /* b2World.h */,
- 491330A41372616300DFB46D /* b2WorldCallbacks.cpp */,
- 491330A51372616300DFB46D /* b2WorldCallbacks.h */,
- 491330A61372616300DFB46D /* Contacts */,
- 491330B31372616300DFB46D /* Joints */,
+ 4913341313727CB100DFB46D /* b2Body.cpp */,
+ 4913341413727CB100DFB46D /* b2Body.h */,
+ 4913341513727CB100DFB46D /* b2ContactManager.cpp */,
+ 4913341613727CB100DFB46D /* b2ContactManager.h */,
+ 4913341713727CB100DFB46D /* b2Fixture.cpp */,
+ 4913341813727CB100DFB46D /* b2Fixture.h */,
+ 4913341913727CB100DFB46D /* b2Island.cpp */,
+ 4913341A13727CB100DFB46D /* b2Island.h */,
+ 4913341B13727CB100DFB46D /* b2TimeStep.h */,
+ 4913341C13727CB100DFB46D /* b2World.cpp */,
+ 4913341D13727CB100DFB46D /* b2World.h */,
+ 4913341E13727CB100DFB46D /* b2WorldCallbacks.cpp */,
+ 4913341F13727CB100DFB46D /* b2WorldCallbacks.h */,
+ 4913342013727CB100DFB46D /* Contacts */,
+ 4913342D13727CB100DFB46D /* Joints */,
);
path = Dynamics;
sourceTree = "<group>";
};
- 491330A61372616300DFB46D /* Contacts */ = {
+ 4913342013727CB100DFB46D /* Contacts */ = {
isa = PBXGroup;
children = (
- 491330A71372616300DFB46D /* b2CircleContact.cpp */,
- 491330A81372616300DFB46D /* b2CircleContact.h */,
- 491330A91372616300DFB46D /* b2Contact.cpp */,
- 491330AA1372616300DFB46D /* b2Contact.h */,
- 491330AB1372616300DFB46D /* b2ContactSolver.cpp */,
- 491330AC1372616300DFB46D /* b2ContactSolver.h */,
- 491330AD1372616300DFB46D /* b2PolygonAndCircleContact.cpp */,
- 491330AE1372616300DFB46D /* b2PolygonAndCircleContact.h */,
- 491330AF1372616300DFB46D /* b2PolygonContact.cpp */,
- 491330B01372616300DFB46D /* b2PolygonContact.h */,
- 491330B11372616300DFB46D /* b2TOISolver.cpp */,
- 491330B21372616300DFB46D /* b2TOISolver.h */,
+ 4913342113727CB100DFB46D /* b2CircleContact.cpp */,
+ 4913342213727CB100DFB46D /* b2CircleContact.h */,
+ 4913342313727CB100DFB46D /* b2Contact.cpp */,
+ 4913342413727CB100DFB46D /* b2Contact.h */,
+ 4913342513727CB100DFB46D /* b2ContactSolver.cpp */,
+ 4913342613727CB100DFB46D /* b2ContactSolver.h */,
+ 4913342713727CB100DFB46D /* b2PolygonAndCircleContact.cpp */,
+ 4913342813727CB100DFB46D /* b2PolygonAndCircleContact.h */,
+ 4913342913727CB100DFB46D /* b2PolygonContact.cpp */,
+ 4913342A13727CB100DFB46D /* b2PolygonContact.h */,
+ 4913342B13727CB100DFB46D /* b2TOISolver.cpp */,
+ 4913342C13727CB100DFB46D /* b2TOISolver.h */,
);
path = Contacts;
sourceTree = "<group>";
};
- 491330B31372616300DFB46D /* Joints */ = {
+ 4913342D13727CB100DFB46D /* Joints */ = {
isa = PBXGroup;
children = (
- 491330B41372616300DFB46D /* b2DistanceJoint.cpp */,
- 491330B51372616300DFB46D /* b2DistanceJoint.h */,
- 491330B61372616300DFB46D /* b2FrictionJoint.cpp */,
- 491330B71372616300DFB46D /* b2FrictionJoint.h */,
- 491330B81372616300DFB46D /* b2GearJoint.cpp */,
- 491330B91372616300DFB46D /* b2GearJoint.h */,
- 491330BA1372616300DFB46D /* b2Joint.cpp */,
- 491330BB1372616300DFB46D /* b2Joint.h */,
- 491330BC1372616300DFB46D /* b2LineJoint.cpp */,
- 491330BD1372616300DFB46D /* b2LineJoint.h */,
- 491330BE1372616300DFB46D /* b2MouseJoint.cpp */,
- 491330BF1372616300DFB46D /* b2MouseJoint.h */,
- 491330C01372616300DFB46D /* b2PrismaticJoint.cpp */,
- 491330C11372616300DFB46D /* b2PrismaticJoint.h */,
- 491330C21372616300DFB46D /* b2PulleyJoint.cpp */,
- 491330C31372616300DFB46D /* b2PulleyJoint.h */,
- 491330C41372616300DFB46D /* b2RevoluteJoint.cpp */,
- 491330C51372616300DFB46D /* b2RevoluteJoint.h */,
- 491330C61372616300DFB46D /* b2WeldJoint.cpp */,
- 491330C71372616300DFB46D /* b2WeldJoint.h */,
+ 4913342E13727CB100DFB46D /* b2DistanceJoint.cpp */,
+ 4913342F13727CB100DFB46D /* b2DistanceJoint.h */,
+ 4913343013727CB100DFB46D /* b2FrictionJoint.cpp */,
+ 4913343113727CB100DFB46D /* b2FrictionJoint.h */,
+ 4913343213727CB100DFB46D /* b2GearJoint.cpp */,
+ 4913343313727CB100DFB46D /* b2GearJoint.h */,
+ 4913343413727CB100DFB46D /* b2Joint.cpp */,
+ 4913343513727CB100DFB46D /* b2Joint.h */,
+ 4913343613727CB100DFB46D /* b2LineJoint.cpp */,
+ 4913343713727CB100DFB46D /* b2LineJoint.h */,
+ 4913343813727CB100DFB46D /* b2MouseJoint.cpp */,
+ 4913343913727CB100DFB46D /* b2MouseJoint.h */,
+ 4913343A13727CB100DFB46D /* b2PrismaticJoint.cpp */,
+ 4913343B13727CB100DFB46D /* b2PrismaticJoint.h */,
+ 4913343C13727CB100DFB46D /* b2PulleyJoint.cpp */,
+ 4913343D13727CB100DFB46D /* b2PulleyJoint.h */,
+ 4913343E13727CB100DFB46D /* b2RevoluteJoint.cpp */,
+ 4913343F13727CB100DFB46D /* b2RevoluteJoint.h */,
+ 4913344013727CB100DFB46D /* b2WeldJoint.cpp */,
+ 4913344113727CB100DFB46D /* b2WeldJoint.h */,
);
path = Joints;
sourceTree = "<group>";
};
- 491331291372630F00DFB46D /* Frameworks */ = {
- isa = PBXGroup;
- children = (
- 491331271372630700DFB46D /* UIKit.framework */,
- 49133122137262F200DFB46D /* Foundation.framework */,
- );
- name = Frameworks;
- sourceTree = "<group>";
- };
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
- 491330C81372616300DFB46D /* Box2D.h in Headers */,
- 491330CA1372616300DFB46D /* b2BroadPhase.h in Headers */,
- 491330CE1372616300DFB46D /* b2Collision.h in Headers */,
- 491330D01372616300DFB46D /* b2Distance.h in Headers */,
- 491330D21372616300DFB46D /* b2DynamicTree.h in Headers */,
- 491330D41372616300DFB46D /* b2TimeOfImpact.h in Headers */,
- 491330D61372616300DFB46D /* b2CircleShape.h in Headers */,
- 491330D81372616300DFB46D /* b2PolygonShape.h in Headers */,
- 491330D91372616300DFB46D /* b2Shape.h in Headers */,
- 491330DB1372616300DFB46D /* b2BlockAllocator.h in Headers */,
- 491330DD1372616300DFB46D /* b2Math.h in Headers */,
- 491330DF1372616300DFB46D /* b2Settings.h in Headers */,
- 491330E11372616300DFB46D /* b2StackAllocator.h in Headers */,
- 491330E31372616300DFB46D /* b2Body.h in Headers */,
- 491330E51372616300DFB46D /* b2ContactManager.h in Headers */,
- 491330E71372616300DFB46D /* b2Fixture.h in Headers */,
- 491330E91372616300DFB46D /* b2Island.h in Headers */,
- 491330EA1372616300DFB46D /* b2TimeStep.h in Headers */,
- 491330EC1372616300DFB46D /* b2World.h in Headers */,
- 491330EE1372616300DFB46D /* b2WorldCallbacks.h in Headers */,
- 491330F01372616300DFB46D /* b2CircleContact.h in Headers */,
- 491330F21372616300DFB46D /* b2Contact.h in Headers */,
- 491330F41372616300DFB46D /* b2ContactSolver.h in Headers */,
- 491330F61372616300DFB46D /* b2PolygonAndCircleContact.h in Headers */,
- 491330F81372616300DFB46D /* b2PolygonContact.h in Headers */,
- 491330FA1372616300DFB46D /* b2TOISolver.h in Headers */,
- 491330FC1372616300DFB46D /* b2DistanceJoint.h in Headers */,
- 491330FE1372616300DFB46D /* b2FrictionJoint.h in Headers */,
- 491331001372616300DFB46D /* b2GearJoint.h in Headers */,
- 491331021372616300DFB46D /* b2Joint.h in Headers */,
- 491331041372616300DFB46D /* b2LineJoint.h in Headers */,
- 491331061372616300DFB46D /* b2MouseJoint.h in Headers */,
- 491331081372616300DFB46D /* b2PrismaticJoint.h in Headers */,
- 4913310A1372616300DFB46D /* b2PulleyJoint.h in Headers */,
- 4913310C1372616300DFB46D /* b2RevoluteJoint.h in Headers */,
- 4913310E1372616300DFB46D /* b2WeldJoint.h in Headers */,
+ 4913344213727CB100DFB46D /* Box2D.h in Headers */,
+ 4913344413727CB100DFB46D /* b2BroadPhase.h in Headers */,
+ 4913344813727CB100DFB46D /* b2Collision.h in Headers */,
+ 4913344A13727CB100DFB46D /* b2Distance.h in Headers */,
+ 4913344C13727CB100DFB46D /* b2DynamicTree.h in Headers */,
+ 4913344E13727CB100DFB46D /* b2TimeOfImpact.h in Headers */,
+ 4913345013727CB100DFB46D /* b2CircleShape.h in Headers */,
+ 4913345213727CB100DFB46D /* b2PolygonShape.h in Headers */,
+ 4913345313727CB100DFB46D /* b2Shape.h in Headers */,
+ 4913345513727CB100DFB46D /* b2BlockAllocator.h in Headers */,
+ 4913345713727CB100DFB46D /* b2Math.h in Headers */,
+ 4913345913727CB100DFB46D /* b2Settings.h in Headers */,
+ 4913345B13727CB100DFB46D /* b2StackAllocator.h in Headers */,
+ 4913345D13727CB100DFB46D /* b2Body.h in Headers */,
+ 4913345F13727CB100DFB46D /* b2ContactManager.h in Headers */,
+ 4913346113727CB100DFB46D /* b2Fixture.h in Headers */,
+ 4913346313727CB100DFB46D /* b2Island.h in Headers */,
+ 4913346413727CB100DFB46D /* b2TimeStep.h in Headers */,
+ 4913346613727CB100DFB46D /* b2World.h in Headers */,
+ 4913346813727CB100DFB46D /* b2WorldCallbacks.h in Headers */,
+ 4913346A13727CB100DFB46D /* b2CircleContact.h in Headers */,
+ 4913346C13727CB100DFB46D /* b2Contact.h in Headers */,
+ 4913346E13727CB100DFB46D /* b2ContactSolver.h in Headers */,
+ 4913347013727CB100DFB46D /* b2PolygonAndCircleContact.h in Headers */,
+ 4913347213727CB100DFB46D /* b2PolygonContact.h in Headers */,
+ 4913347413727CB100DFB46D /* b2TOISolver.h in Headers */,
+ 4913347613727CB100DFB46D /* b2DistanceJoint.h in Headers */,
+ 4913347813727CB100DFB46D /* b2FrictionJoint.h in Headers */,
+ 4913347A13727CB100DFB46D /* b2GearJoint.h in Headers */,
+ 4913347C13727CB100DFB46D /* b2Joint.h in Headers */,
+ 4913347E13727CB100DFB46D /* b2LineJoint.h in Headers */,
+ 4913348013727CB100DFB46D /* b2MouseJoint.h in Headers */,
+ 4913348213727CB100DFB46D /* b2PrismaticJoint.h in Headers */,
+ 4913348413727CB100DFB46D /* b2PulleyJoint.h in Headers */,
+ 4913348613727CB100DFB46D /* b2RevoluteJoint.h in Headers */,
+ 4913348813727CB100DFB46D /* b2WeldJoint.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 491330C91372616300DFB46D /* b2BroadPhase.cpp in Sources */,
- 491330CB1372616300DFB46D /* b2CollideCircle.cpp in Sources */,
- 491330CC1372616300DFB46D /* b2CollidePolygon.cpp in Sources */,
- 491330CD1372616300DFB46D /* b2Collision.cpp in Sources */,
- 491330CF1372616300DFB46D /* b2Distance.cpp in Sources */,
- 491330D11372616300DFB46D /* b2DynamicTree.cpp in Sources */,
- 491330D31372616300DFB46D /* b2TimeOfImpact.cpp in Sources */,
- 491330D51372616300DFB46D /* b2CircleShape.cpp in Sources */,
- 491330D71372616300DFB46D /* b2PolygonShape.cpp in Sources */,
- 491330DA1372616300DFB46D /* b2BlockAllocator.cpp in Sources */,
- 491330DC1372616300DFB46D /* b2Math.cpp in Sources */,
- 491330DE1372616300DFB46D /* b2Settings.cpp in Sources */,
- 491330E01372616300DFB46D /* b2StackAllocator.cpp in Sources */,
- 491330E21372616300DFB46D /* b2Body.cpp in Sources */,
- 491330E41372616300DFB46D /* b2ContactManager.cpp in Sources */,
- 491330E61372616300DFB46D /* b2Fixture.cpp in Sources */,
- 491330E81372616300DFB46D /* b2Island.cpp in Sources */,
- 491330EB1372616300DFB46D /* b2World.cpp in Sources */,
- 491330ED1372616300DFB46D /* b2WorldCallbacks.cpp in Sources */,
- 491330EF1372616300DFB46D /* b2CircleContact.cpp in Sources */,
- 491330F11372616300DFB46D /* b2Contact.cpp in Sources */,
- 491330F31372616300DFB46D /* b2ContactSolver.cpp in Sources */,
- 491330F51372616300DFB46D /* b2PolygonAndCircleContact.cpp in Sources */,
- 491330F71372616300DFB46D /* b2PolygonContact.cpp in Sources */,
- 491330F91372616300DFB46D /* b2TOISolver.cpp in Sources */,
- 491330FB1372616300DFB46D /* b2DistanceJoint.cpp in Sources */,
- 491330FD1372616300DFB46D /* b2FrictionJoint.cpp in Sources */,
- 491330FF1372616300DFB46D /* b2GearJoint.cpp in Sources */,
- 491331011372616300DFB46D /* b2Joint.cpp in Sources */,
- 491331031372616300DFB46D /* b2LineJoint.cpp in Sources */,
- 491331051372616300DFB46D /* b2MouseJoint.cpp in Sources */,
- 491331071372616300DFB46D /* b2PrismaticJoint.cpp in Sources */,
- 491331091372616300DFB46D /* b2PulleyJoint.cpp in Sources */,
- 4913310B1372616300DFB46D /* b2RevoluteJoint.cpp in Sources */,
- 4913310D1372616300DFB46D /* b2WeldJoint.cpp in Sources */,
+ 4913344313727CB100DFB46D /* b2BroadPhase.cpp in Sources */,
+ 4913344513727CB100DFB46D /* b2CollideCircle.cpp in Sources */,
+ 4913344613727CB100DFB46D /* b2CollidePolygon.cpp in Sources */,
+ 4913344713727CB100DFB46D /* b2Collision.cpp in Sources */,
+ 4913344913727CB100DFB46D /* b2Distance.cpp in Sources */,
+ 4913344B13727CB100DFB46D /* b2DynamicTree.cpp in Sources */,
+ 4913344D13727CB100DFB46D /* b2TimeOfImpact.cpp in Sources */,
+ 4913344F13727CB100DFB46D /* b2CircleShape.cpp in Sources */,
+ 4913345113727CB100DFB46D /* b2PolygonShape.cpp in Sources */,
+ 4913345413727CB100DFB46D /* b2BlockAllocator.cpp in Sources */,
+ 4913345613727CB100DFB46D /* b2Math.cpp in Sources */,
+ 4913345813727CB100DFB46D /* b2Settings.cpp in Sources */,
+ 4913345A13727CB100DFB46D /* b2StackAllocator.cpp in Sources */,
+ 4913345C13727CB100DFB46D /* b2Body.cpp in Sources */,
+ 4913345E13727CB100DFB46D /* b2ContactManager.cpp in Sources */,
+ 4913346013727CB100DFB46D /* b2Fixture.cpp in Sources */,
+ 4913346213727CB100DFB46D /* b2Island.cpp in Sources */,
+ 4913346513727CB100DFB46D /* b2World.cpp in Sources */,
+ 4913346713727CB100DFB46D /* b2WorldCallbacks.cpp in Sources */,
+ 4913346913727CB100DFB46D /* b2CircleContact.cpp in Sources */,
+ 4913346B13727CB100DFB46D /* b2Contact.cpp in Sources */,
+ 4913346D13727CB100DFB46D /* b2ContactSolver.cpp in Sources */,
+ 4913346F13727CB100DFB46D /* b2PolygonAndCircleContact.cpp in Sources */,
+ 4913347113727CB100DFB46D /* b2PolygonContact.cpp in Sources */,
+ 4913347313727CB100DFB46D /* b2TOISolver.cpp in Sources */,
+ 4913347513727CB100DFB46D /* b2DistanceJoint.cpp in Sources */,
+ 4913347713727CB100DFB46D /* b2FrictionJoint.cpp in Sources */,
+ 4913347913727CB100DFB46D /* b2GearJoint.cpp in Sources */,
+ 4913347B13727CB100DFB46D /* b2Joint.cpp in Sources */,
+ 4913347D13727CB100DFB46D /* b2LineJoint.cpp in Sources */,
+ 4913347F13727CB100DFB46D /* b2MouseJoint.cpp in Sources */,
+ 4913348113727CB100DFB46D /* b2PrismaticJoint.cpp in Sources */,
+ 4913348313727CB100DFB46D /* b2PulleyJoint.cpp in Sources */,
+ 4913348513727CB100DFB46D /* b2RevoluteJoint.cpp in Sources */,
+ 4913348713727CB100DFB46D /* b2WeldJoint.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
4913323913726B1F00DFB46D /* BodyTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913320E13726B1F00DFB46D /* BodyTypes.h */; };
4913323A13726B1F00DFB46D /* Breakable.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913320F13726B1F00DFB46D /* Breakable.h */; };
4913323B13726B1F00DFB46D /* Bridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321013726B1F00DFB46D /* Bridge.h */; };
- 4913323C13726B1F00DFB46D /* BulletTest.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321113726B1F00DFB46D /* BulletTest.h */; };
4913323D13726B1F00DFB46D /* Cantilever.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321213726B1F00DFB46D /* Cantilever.h */; };
- 4913323E13726B1F00DFB46D /* Car.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321313726B1F00DFB46D /* Car.h */; };
4913323F13726B1F00DFB46D /* Chain.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321413726B1F00DFB46D /* Chain.h */; };
4913324013726B1F00DFB46D /* CharacterCollision.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321513726B1F00DFB46D /* CharacterCollision.h */; };
4913324113726B1F00DFB46D /* CollisionFiltering.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321613726B1F00DFB46D /* CollisionFiltering.h */; };
4913324713726B1F00DFB46D /* Dominos.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321C13726B1F00DFB46D /* Dominos.h */; };
4913324813726B1F00DFB46D /* DynamicTreeTest.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321D13726B1F00DFB46D /* DynamicTreeTest.h */; };
4913324913726B1F00DFB46D /* EdgeShapes.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321E13726B1F00DFB46D /* EdgeShapes.h */; };
- 4913324A13726B1F00DFB46D /* EdgeTest.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913321F13726B1F00DFB46D /* EdgeTest.h */; };
4913324B13726B1F00DFB46D /* Gears.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322013726B1F00DFB46D /* Gears.h */; };
4913324C13726B1F00DFB46D /* LineJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322113726B1F00DFB46D /* LineJoint.h */; };
4913324D13726B1F00DFB46D /* OneSidedPlatform.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322213726B1F00DFB46D /* OneSidedPlatform.h */; };
- 4913324E13726B1F00DFB46D /* Pinball.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322313726B1F00DFB46D /* Pinball.h */; };
4913324F13726B1F00DFB46D /* PolyCollision.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322413726B1F00DFB46D /* PolyCollision.h */; };
4913325013726B1F00DFB46D /* PolyShapes.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322513726B1F00DFB46D /* PolyShapes.h */; };
4913325113726B1F00DFB46D /* Prismatic.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322613726B1F00DFB46D /* Prismatic.h */; };
4913325213726B1F00DFB46D /* Pulleys.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322713726B1F00DFB46D /* Pulleys.h */; };
4913325313726B1F00DFB46D /* Pyramid.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322813726B1F00DFB46D /* Pyramid.h */; };
4913325413726B1F00DFB46D /* RayCast.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322913726B1F00DFB46D /* RayCast.h */; };
- 4913325513726B1F00DFB46D /* Revolute.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322A13726B1F00DFB46D /* Revolute.h */; };
- 4913325613726B1F00DFB46D /* Rope.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322B13726B1F00DFB46D /* Rope.h */; };
- 4913325713726B1F00DFB46D /* RopeJoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322C13726B1F00DFB46D /* RopeJoint.h */; };
4913325813726B1F00DFB46D /* SensorTest.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322D13726B1F00DFB46D /* SensorTest.h */; };
4913325913726B1F00DFB46D /* ShapeEditing.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322E13726B1F00DFB46D /* ShapeEditing.h */; };
4913325A13726B1F00DFB46D /* SliderCrank.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913322F13726B1F00DFB46D /* SliderCrank.h */; };
4913325B13726B1F00DFB46D /* SphereStack.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913323013726B1F00DFB46D /* SphereStack.h */; };
4913325C13726B1F00DFB46D /* TheoJansen.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913323113726B1F00DFB46D /* TheoJansen.h */; };
- 4913325D13726B1F00DFB46D /* Tiles.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913323213726B1F00DFB46D /* Tiles.h */; };
4913325E13726B1F00DFB46D /* TimeOfImpact.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913323313726B1F00DFB46D /* TimeOfImpact.h */; };
4913325F13726B1F00DFB46D /* VaryingFriction.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913323413726B1F00DFB46D /* VaryingFriction.h */; };
4913326013726B1F00DFB46D /* VaryingRestitution.h in Headers */ = {isa = PBXBuildFile; fileRef = 4913323513726B1F00DFB46D /* VaryingRestitution.h */; };
4913320E13726B1F00DFB46D /* BodyTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BodyTypes.h; sourceTree = "<group>"; };
4913320F13726B1F00DFB46D /* Breakable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Breakable.h; sourceTree = "<group>"; };
4913321013726B1F00DFB46D /* Bridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Bridge.h; sourceTree = "<group>"; };
- 4913321113726B1F00DFB46D /* BulletTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BulletTest.h; sourceTree = "<group>"; };
4913321213726B1F00DFB46D /* Cantilever.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cantilever.h; sourceTree = "<group>"; };
- 4913321313726B1F00DFB46D /* Car.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Car.h; sourceTree = "<group>"; };
4913321413726B1F00DFB46D /* Chain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Chain.h; sourceTree = "<group>"; };
4913321513726B1F00DFB46D /* CharacterCollision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CharacterCollision.h; sourceTree = "<group>"; };
4913321613726B1F00DFB46D /* CollisionFiltering.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollisionFiltering.h; sourceTree = "<group>"; };
4913321C13726B1F00DFB46D /* Dominos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Dominos.h; sourceTree = "<group>"; };
4913321D13726B1F00DFB46D /* DynamicTreeTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicTreeTest.h; sourceTree = "<group>"; };
4913321E13726B1F00DFB46D /* EdgeShapes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EdgeShapes.h; sourceTree = "<group>"; };
- 4913321F13726B1F00DFB46D /* EdgeTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EdgeTest.h; sourceTree = "<group>"; };
4913322013726B1F00DFB46D /* Gears.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Gears.h; sourceTree = "<group>"; };
4913322113726B1F00DFB46D /* LineJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineJoint.h; sourceTree = "<group>"; };
4913322213726B1F00DFB46D /* OneSidedPlatform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OneSidedPlatform.h; sourceTree = "<group>"; };
- 4913322313726B1F00DFB46D /* Pinball.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pinball.h; sourceTree = "<group>"; };
4913322413726B1F00DFB46D /* PolyCollision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyCollision.h; sourceTree = "<group>"; };
4913322513726B1F00DFB46D /* PolyShapes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyShapes.h; sourceTree = "<group>"; };
4913322613726B1F00DFB46D /* Prismatic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prismatic.h; sourceTree = "<group>"; };
4913322713726B1F00DFB46D /* Pulleys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pulleys.h; sourceTree = "<group>"; };
4913322813726B1F00DFB46D /* Pyramid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pyramid.h; sourceTree = "<group>"; };
4913322913726B1F00DFB46D /* RayCast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RayCast.h; sourceTree = "<group>"; };
- 4913322A13726B1F00DFB46D /* Revolute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Revolute.h; sourceTree = "<group>"; };
- 4913322B13726B1F00DFB46D /* Rope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Rope.h; sourceTree = "<group>"; };
- 4913322C13726B1F00DFB46D /* RopeJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RopeJoint.h; sourceTree = "<group>"; };
4913322D13726B1F00DFB46D /* SensorTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SensorTest.h; sourceTree = "<group>"; };
4913322E13726B1F00DFB46D /* ShapeEditing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShapeEditing.h; sourceTree = "<group>"; };
4913322F13726B1F00DFB46D /* SliderCrank.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SliderCrank.h; sourceTree = "<group>"; };
4913323013726B1F00DFB46D /* SphereStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SphereStack.h; sourceTree = "<group>"; };
4913323113726B1F00DFB46D /* TheoJansen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TheoJansen.h; sourceTree = "<group>"; };
- 4913323213726B1F00DFB46D /* Tiles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tiles.h; sourceTree = "<group>"; };
4913323313726B1F00DFB46D /* TimeOfImpact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TimeOfImpact.h; sourceTree = "<group>"; };
4913323413726B1F00DFB46D /* VaryingFriction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VaryingFriction.h; sourceTree = "<group>"; };
4913323513726B1F00DFB46D /* VaryingRestitution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VaryingRestitution.h; sourceTree = "<group>"; };
4913320E13726B1F00DFB46D /* BodyTypes.h */,
4913320F13726B1F00DFB46D /* Breakable.h */,
4913321013726B1F00DFB46D /* Bridge.h */,
- 4913321113726B1F00DFB46D /* BulletTest.h */,
4913321213726B1F00DFB46D /* Cantilever.h */,
- 4913321313726B1F00DFB46D /* Car.h */,
4913321413726B1F00DFB46D /* Chain.h */,
4913321513726B1F00DFB46D /* CharacterCollision.h */,
4913321613726B1F00DFB46D /* CollisionFiltering.h */,
4913321C13726B1F00DFB46D /* Dominos.h */,
4913321D13726B1F00DFB46D /* DynamicTreeTest.h */,
4913321E13726B1F00DFB46D /* EdgeShapes.h */,
- 4913321F13726B1F00DFB46D /* EdgeTest.h */,
4913322013726B1F00DFB46D /* Gears.h */,
4913322113726B1F00DFB46D /* LineJoint.h */,
4913322213726B1F00DFB46D /* OneSidedPlatform.h */,
- 4913322313726B1F00DFB46D /* Pinball.h */,
4913322413726B1F00DFB46D /* PolyCollision.h */,
4913322513726B1F00DFB46D /* PolyShapes.h */,
4913322613726B1F00DFB46D /* Prismatic.h */,
4913322713726B1F00DFB46D /* Pulleys.h */,
4913322813726B1F00DFB46D /* Pyramid.h */,
4913322913726B1F00DFB46D /* RayCast.h */,
- 4913322A13726B1F00DFB46D /* Revolute.h */,
- 4913322B13726B1F00DFB46D /* Rope.h */,
- 4913322C13726B1F00DFB46D /* RopeJoint.h */,
4913322D13726B1F00DFB46D /* SensorTest.h */,
4913322E13726B1F00DFB46D /* ShapeEditing.h */,
4913322F13726B1F00DFB46D /* SliderCrank.h */,
4913323013726B1F00DFB46D /* SphereStack.h */,
4913323113726B1F00DFB46D /* TheoJansen.h */,
- 4913323213726B1F00DFB46D /* Tiles.h */,
4913323313726B1F00DFB46D /* TimeOfImpact.h */,
4913323413726B1F00DFB46D /* VaryingFriction.h */,
4913323513726B1F00DFB46D /* VaryingRestitution.h */,
4913323913726B1F00DFB46D /* BodyTypes.h in Headers */,
4913323A13726B1F00DFB46D /* Breakable.h in Headers */,
4913323B13726B1F00DFB46D /* Bridge.h in Headers */,
- 4913323C13726B1F00DFB46D /* BulletTest.h in Headers */,
4913323D13726B1F00DFB46D /* Cantilever.h in Headers */,
- 4913323E13726B1F00DFB46D /* Car.h in Headers */,
4913323F13726B1F00DFB46D /* Chain.h in Headers */,
4913324013726B1F00DFB46D /* CharacterCollision.h in Headers */,
4913324113726B1F00DFB46D /* CollisionFiltering.h in Headers */,
4913324713726B1F00DFB46D /* Dominos.h in Headers */,
4913324813726B1F00DFB46D /* DynamicTreeTest.h in Headers */,
4913324913726B1F00DFB46D /* EdgeShapes.h in Headers */,
- 4913324A13726B1F00DFB46D /* EdgeTest.h in Headers */,
4913324B13726B1F00DFB46D /* Gears.h in Headers */,
4913324C13726B1F00DFB46D /* LineJoint.h in Headers */,
4913324D13726B1F00DFB46D /* OneSidedPlatform.h in Headers */,
- 4913324E13726B1F00DFB46D /* Pinball.h in Headers */,
4913324F13726B1F00DFB46D /* PolyCollision.h in Headers */,
4913325013726B1F00DFB46D /* PolyShapes.h in Headers */,
4913325113726B1F00DFB46D /* Prismatic.h in Headers */,
4913325213726B1F00DFB46D /* Pulleys.h in Headers */,
4913325313726B1F00DFB46D /* Pyramid.h in Headers */,
4913325413726B1F00DFB46D /* RayCast.h in Headers */,
- 4913325513726B1F00DFB46D /* Revolute.h in Headers */,
- 4913325613726B1F00DFB46D /* Rope.h in Headers */,
- 4913325713726B1F00DFB46D /* RopeJoint.h in Headers */,
4913325813726B1F00DFB46D /* SensorTest.h in Headers */,
4913325913726B1F00DFB46D /* ShapeEditing.h in Headers */,
4913325A13726B1F00DFB46D /* SliderCrank.h in Headers */,
4913325B13726B1F00DFB46D /* SphereStack.h in Headers */,
4913325C13726B1F00DFB46D /* TheoJansen.h in Headers */,
- 4913325D13726B1F00DFB46D /* Tiles.h in Headers */,
4913325E13726B1F00DFB46D /* TimeOfImpact.h in Headers */,
4913325F13726B1F00DFB46D /* VaryingFriction.h in Headers */,
4913326013726B1F00DFB46D /* VaryingRestitution.h in Headers */,
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)];
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
-
- //[self setMultipleTouchEnabled:YES];
}
//printf("Screen touched %f,%f -> %f,%f\n",touchLocation.x,touchLocation.y,worldPosition.x,worldPosition.y);
lastScreenTouch=touchLocation;
lastWorldTouch=worldPosition;
- b2Vec2 p = b2Vec2(lastWorldTouch.x,lastWorldTouch.y);
- test->MouseDown(p);
- //test->ShiftMouseDown(p);
+ test->MouseDown(b2Vec2(lastWorldTouch.x,lastWorldTouch.y));
if (!test->m_mouseJoint) panning=true;
}
// This class implements debug drawing callbacks that are invoked
// inside b2World::Step.
-class GLESDebugDraw : public b2Draw
+class GLESDebugDraw : public b2DebugDraw
{
public:
void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color);
TestEntry* e = g_testEntries;
e+=indexPath.row;
- cell.textLabel.text = [NSString stringWithUTF8String:e->name];
+ [cell setText:[NSString stringWithCString:e->name]];
return cell;
}
struct Settings
{
Settings() :
- viewCenter(0.0f, 20.0f),
- hz(60.0f),
- velocityIterations(8),
- positionIterations(3),
- drawShapes(1),
- drawJoints(1),
- drawAABBs(0),
- drawPairs(0),
- drawContactPoints(0),
- drawContactNormals(0),
- drawContactForces(0),
- drawFrictionForces(0),
- drawCOMs(0),
- drawStats(0),
- enableWarmStarting(1),
- enableContinuous(1),
- enableSubStepping(0),
- pause(0),
- singleStep(0)
- {}
-
- b2Vec2 viewCenter;
+ hz(60.0f),
+ velocityIterations(10),
+ positionIterations(4),
+ drawStats(0),
+ drawShapes(1),
+ drawJoints(1),
+ drawAABBs(0),
+ drawPairs(0),
+ drawContactPoints(0),
+ drawContactNormals(0),
+ drawContactForces(0),
+ drawFrictionForces(0),
+ drawCOMs(0),
+ enableWarmStarting(1),
+ enableContinuous(1),
+ pause(0),
+ singleStep(0)
+ {}
+
float32 hz;
int32 velocityIterations;
int32 positionIterations;
int32 drawStats;
int32 enableWarmStarting;
int32 enableContinuous;
- int32 enableSubStepping;
int32 pause;
int32 singleStep;
};
/*
-* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com
*
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_bombSpawning = false;
-
+
m_stepCount = 0;
-
+
b2BodyDef bodyDef;
m_groundBody = m_world->CreateBody(&bodyDef);
}
void Test::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
{
const b2Manifold* manifold = contact->GetManifold();
-
+
if (manifold->pointCount == 0)
{
return;
}
-
+
b2Fixture* fixtureA = contact->GetFixtureA();
b2Fixture* fixtureB = contact->GetFixtureB();
-
+
b2PointState state1[b2_maxManifoldPoints], state2[b2_maxManifoldPoints];
b2GetPointStates(state1, state2, oldManifold, manifold);
-
+
b2WorldManifold worldManifold;
contact->GetWorldManifold(&worldManifold);
-
+
for (int32 i = 0; i < manifold->pointCount && m_pointCount < k_maxContactPoints; ++i)
{
ContactPoint* cp = m_points + m_pointCount;
}
class QueryCallback : public b2QueryCallback
-{
-public:
- QueryCallback(const b2Vec2& point)
- {
- m_point = point;
- m_fixture = NULL;
- }
-
- bool ReportFixture(b2Fixture* fixture)
{
- b2Body* body = fixture->GetBody();
- if (body->GetType() == b2_dynamicBody)
+ public:
+ QueryCallback(const b2Vec2& point)
{
- bool inside = fixture->TestPoint(m_point);
- if (inside)
+ m_point = point;
+ m_fixture = NULL;
+ }
+
+ bool ReportFixture(b2Fixture* fixture)
+ {
+ b2Body* body = fixture->GetBody();
+ if (body->GetType() == b2_dynamicBody)
{
- m_fixture = fixture;
-
- // We are done, terminate the query.
- return false;
+ bool inside = fixture->TestPoint(m_point);
+ if (inside)
+ {
+ m_fixture = fixture;
+
+ // We are done, terminate the query.
+ return false;
+ }
}
+
+ // Continue the query.
+ return true;
}
+
+ b2Vec2 m_point;
+ b2Fixture* m_fixture;
+ };
- // Continue the query.
- return true;
- }
-
- b2Vec2 m_point;
- b2Fixture* m_fixture;
-};
void Test::MouseDown(const b2Vec2& p)
{
{
return;
}
-
+
// Make a small box.
b2AABB aabb;
b2Vec2 d;
d.Set(0.001f, 0.001f);
aabb.lowerBound = p - d;
aabb.upperBound = p + d;
-
+
// Query the world for overlapping shapes.
QueryCallback callback(p);
m_world->QueryAABB(&callback, aabb);
-
+
if (callback.m_fixture)
{
b2Body* body = callback.m_fixture->GetBody();
m_bombSpawnPoint = worldPt;
m_bombSpawning = true;
}
-
+
void Test::CompleteBombSpawn(const b2Vec2& p)
{
if (m_bombSpawning == false)
{
return;
}
-
+
const float multiplier = 30.0f;
b2Vec2 vel = m_bombSpawnPoint - p;
vel *= multiplier;
{
return;
}
-
+
SpawnBomb(p);
}
m_world->DestroyBody(m_bomb);
m_bomb = NULL;
}
-
+
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position = position;
b2CircleShape circle;
circle.m_radius = 0.3f;
-
+
b2FixtureDef fd;
fd.shape = &circle;
fd.density = 20.0f;
- fd.restitution = 0.0f;
+ fd.restitution = 0.1f;
b2Vec2 minV = position - b2Vec2(0.3f,0.3f);
b2Vec2 maxV = position + b2Vec2(0.3f,0.3f);
b2AABB aabb;
aabb.lowerBound = minV;
aabb.upperBound = maxV;
-
+
m_bomb->CreateFixture(&fd);
}
void Test::Step(Settings* settings)
{
float32 timeStep = settings->hz > 0.0f ? 1.0f / settings->hz : float32(0.0f);
-
+
if (settings->pause)
{
if (settings->singleStep)
{
timeStep = 0.0f;
}
-
+
m_debugDraw.DrawString(5, m_textLine, "****PAUSED****");
m_textLine += 15;
}
-
+
uint32 flags = 0;
- flags += settings->drawShapes * b2Draw::e_shapeBit;
- flags += settings->drawJoints * b2Draw::e_jointBit;
- flags += settings->drawAABBs * b2Draw::e_aabbBit;
- flags += settings->drawPairs * b2Draw::e_pairBit;
- flags += settings->drawCOMs * b2Draw::e_centerOfMassBit;
+ flags += settings->drawShapes * b2DebugDraw::e_shapeBit;
+ flags += settings->drawJoints * b2DebugDraw::e_jointBit;
+ flags += settings->drawAABBs * b2DebugDraw::e_aabbBit;
+ flags += settings->drawPairs * b2DebugDraw::e_pairBit;
+ flags += settings->drawCOMs * b2DebugDraw::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);
-
+
m_world->DrawDebugData();
-
+
if (timeStep > 0.0f)
{
++m_stepCount;
}
-
+
if (settings->drawStats)
{
m_debugDraw.DrawString(5, m_textLine, "bodies/contacts/joints/proxies = %d/%d/%d",
- m_world->GetBodyCount(), m_world->GetContactCount(), m_world->GetJointCount(), m_world->GetProxyCount());
+ m_world->GetBodyCount(), m_world->GetContactCount(), m_world->GetJointCount(), m_world->GetProxyCount());
m_textLine += 15;
+
+// m_debugDraw.DrawString(5, m_textLine, "heap bytes = %d", b2_byteCount);
+// m_textLine += 15;
}
-
+
if (m_mouseJoint)
{
- b2Vec2 p1 = m_mouseJoint->GetAnchorB();
- b2Vec2 p2 = m_mouseJoint->GetTarget();
-
- glPointSize(4.0f);
- glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
- GLbyte verts1[2 * 3] = {
- p1.x, p1.y, 0.0f,
- p2.x, p2.y, 0.0f
- };
- glVertexPointer(3, GL_BYTE, 0, verts1);
- glDrawArrays(GL_POINTS, 0, 2);
- glPointSize(1.0f);
-
- glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
- GLbyte verts2[2 * 3] = {
- p1.x, p1.y, 0.0f,
- p2.x, p2.y, 0.0f
- };
- glVertexPointer(3, GL_BYTE, 0, verts2);
- glDrawArrays(GL_LINES, 0, 2);
+// b2Body* body = m_mouseJoint->GetBodyB();
+// b2Vec2 p1 = body->GetWorldPoint(m_mouseJoint->m_localAnchor);
+// b2Vec2 p2 = m_mouseJoint->m_target;
+//
+// glPointSize(4.0f);
+// glColor3f(0.0f, 1.0f, 0.0f);
+// glBegin(GL_POINTS);
+// glVertex2f(p1.x, p1.y);
+// glVertex2f(p2.x, p2.y);
+// glEnd();
+// glPointSize(1.0f);
+//
+// glColor3f(0.8f, 0.8f, 0.8f);
+// glBegin(GL_LINES);
+// glVertex2f(p1.x, p1.y);
+// glVertex2f(p2.x, p2.y);
+// glEnd();
}
if (m_bombSpawning)
{
- glPointSize(4.0f);
- glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
- glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
- GLbyte verts1[1 * 3] = {
- m_bombSpawnPoint.x, m_bombSpawnPoint.y, 0.0f
- };
- glVertexPointer(3, GL_BYTE, 0, verts1);
- glDrawArrays(GL_POINTS, 0, 1);
-
- glColor4f(0.8f, 0.8f, 0.8f, 1.0f);
- GLbyte verts2[2 * 3] = {
- m_mouseWorld.x, m_mouseWorld.y, 0.0f,
- m_bombSpawnPoint.x, m_bombSpawnPoint.y, 0.0f
- };
- glVertexPointer(3, GL_BYTE, 0, verts2);
- glDrawArrays(GL_LINES, 0, 2);
+// glPointSize(4.0f);
+// glColor3f(0.0f, 0.0f, 1.0f);
+// glBegin(GL_POINTS);
+// glColor3f(0.0f, 0.0f, 1.0f);
+// glVertex2f(m_bombSpawnPoint.x, m_bombSpawnPoint.y);
+// glEnd();
+//
+// glColor3f(0.8f, 0.8f, 0.8f);
+// glBegin(GL_LINES);
+// glVertex2f(m_mouseWorld.x, m_mouseWorld.y);
+// glVertex2f(m_bombSpawnPoint.x, m_bombSpawnPoint.y);
+// glEnd();
}
-
+
if (settings->drawContactPoints)
{
//const float32 k_impulseScale = 0.1f;
const float32 k_axisScale = 0.3f;
-
+
for (int32 i = 0; i < m_pointCount; ++i)
{
ContactPoint* point = m_points + i;
-
+
if (point->state == b2_addState)
{
// Add
// Persist
m_debugDraw.DrawPoint(point->position, 5.0f, b2Color(0.3f, 0.3f, 0.95f));
}
-
+
if (settings->drawContactNormals == 1)
{
b2Vec2 p1 = point->position;
b2Vec2 p2 = p1 + k_axisScale * point->normal;
- m_debugDraw.DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.9f));
+ m_debugDraw.DrawSegment(p1, p2, b2Color(0.4f, 0.9f, 0.4f));
}
else if (settings->drawContactForces == 1)
{
//b2Vec2 p2 = p1 + k_forceScale * point->normalForce * point->normal;
//DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f));
}
-
+
if (settings->drawFrictionForces == 1)
{
//b2Vec2 tangent = b2Cross(point->normal, 1.0f);
-/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include "iPhoneTest.h"\r
-#include <cstring>\r
-using namespace std;\r
-\r
-#include "ApplyForce.h"\r
-#include "BodyTypes.h"\r
-#include "Breakable.h"\r
-#include "Bridge.h"\r
-#include "BulletTest.h"\r
-#include "Cantilever.h"\r
-#include "Car.h"\r
-#include "ContinuousTest.h"\r
-#include "Chain.h"\r
-#include "CharacterCollision.h"\r
-#include "CollisionFiltering.h"\r
-#include "CollisionProcessing.h"\r
-#include "CompoundShapes.h"\r
-#include "Confined.h"\r
-#include "DistanceTest.h"\r
-#include "Dominos.h"\r
-#include "DynamicTreeTest.h"\r
-#include "EdgeShapes.h"\r
-#include "EdgeTest.h"\r
-#include "Gears.h"\r
-#include "OneSidedPlatform.h"\r
-#include "Pinball.h"\r
-#include "PolyCollision.h"\r
-#include "PolyShapes.h"\r
-#include "Prismatic.h"\r
-#include "Pulleys.h"\r
-#include "Pyramid.h"\r
-#include "RayCast.h"\r
-#include "Revolute.h"\r
-#include "Rope.h"\r
-#include "RopeJoint.h"\r
-#include "SensorTest.h"\r
-#include "ShapeEditing.h"\r
-#include "SliderCrank.h"\r
-#include "SphereStack.h"\r
-#include "TheoJansen.h"\r
-#include "Tiles.h"\r
-#include "TimeOfImpact.h"\r
-#include "VaryingFriction.h"\r
-#include "VaryingRestitution.h"\r
-#include "VerticalStack.h"\r
-#include "Web.h"\r
-\r
-TestEntry g_testEntries[] =\r
-{\r
- {"Pulleys", Pulleys::Create},\r
- {"SphereStack", SphereStack::Create},\r
- {"Tiles", Tiles::Create},\r
- {"Polygon Shapes", PolyShapes::Create},\r
- {"Rope", Rope::Create},\r
- {"Web", Web::Create},\r
- {"Car", Car::Create},\r
- {"Vertical Stack", VerticalStack::Create},\r
- {"RopeJoint", RopeJoint::Create},\r
- {"Character Collision", CharacterCollision::Create},\r
- {"Edge Test", EdgeTest::Create},\r
- {"One-Sided Platform", OneSidedPlatform::Create},\r
- {"Pinball", Pinball::Create},\r
- {"Bullet Test", BulletTest::Create},\r
- {"Continuous Test", ContinuousTest::Create},\r
- {"Time of Impact", TimeOfImpact::Create},\r
- {"Ray-Cast", RayCast::Create},\r
- {"Confined", Confined::Create},\r
- {"Pyramid", Pyramid::Create},\r
- {"Varying Restitution", VaryingRestitution::Create},\r
- {"Theo Jansen's Walker", TheoJansen::Create},\r
- {"Body Types", BodyTypes::Create},\r
- {"Prismatic", Prismatic::Create},\r
- {"Edge Shapes", EdgeShapes::Create},\r
- {"PolyCollision", PolyCollision::Create},\r
- {"Apply Force", ApplyForce::Create},\r
- {"Cantilever", Cantilever::Create},\r
- {"Bridge", Bridge::Create},\r
- {"Breakable", Breakable::Create},\r
- {"Chain", Chain::Create},\r
- {"Collision Filtering", CollisionFiltering::Create},\r
- {"Collision Processing", CollisionProcessing::Create},\r
- {"Compound Shapes", CompoundShapes::Create},\r
- {"Distance Test", DistanceTest::Create},\r
- {"Dominos", Dominos::Create},\r
- {"Dynamic Tree", DynamicTreeTest::Create},\r
- {"Gears", Gears::Create},\r
- {"Revolute", Revolute::Create},\r
- {"Sensor Test", SensorTest::Create},\r
- {"Shape Editing", ShapeEditing::Create},\r
- {"Slider Crank", SliderCrank::Create},\r
- {"Varying Friction", VaryingFriction::Create},\r
- {NULL, NULL}\r
-};\r
+/*
+ * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ */
+
+#include "iPhoneTest.h"
+//#include "GLES-Render.h"
+
+#include "ApplyForce.h"
+#include "BodyTypes.h"
+
+#include "Breakable.h"
+#include "Bridge.h"
+#include "Chain.h"
+#include "CollisionFiltering.h"
+#include "CollisionProcessing.h"
+#include "CompoundShapes.h"
+#include "Confined.h"
+#include "DistanceTest.h"
+#include "Dominos.h"
+#include "DynamicTreeTest.h"
+#include "Gears.h"
+#include "LineJoint.h"
+#include "OneSidedPlatform.h"
+#include "PolyCollision.h"
+#include "PolyShapes.h"
+#include "Prismatic.h"
+#include "Pulleys.h"
+#include "Pyramid.h"
+#include "RayCast.h"
+#include "Revolute.h"
+#include "SensorTest.h"
+#include "ShapeEditing.h"
+#include "SliderCrank.h"
+#include "SphereStack.h"
+#include "TheoJansen.h"
+#include "TimeOfImpact.h"
+#include "VaryingFriction.h"
+#include "VaryingRestitution.h"
+#include "VerticalStack.h"
+#include "Web.h"
+
+TestEntry g_testEntries[] =
+{
+{"Body Types", BodyTypes::Create},
+{"SphereStack", SphereStack::Create},
+{"Vertical Stack", VerticalStack::Create},
+{"Confined", Confined::Create},
+{"Bridge", Bridge::Create},
+{"Breakable", Breakable::Create},
+{"Varying Restitution", VaryingRestitution::Create},
+{"Ray-Cast", RayCast::Create},
+{"Pyramid", Pyramid::Create},
+{"PolyCollision", PolyCollision::Create},
+{"One-Sided Platform", OneSidedPlatform::Create},
+{"Apply Force", ApplyForce::Create},
+{"Chain", Chain::Create},
+{"Collision Filtering", CollisionFiltering::Create},
+{"Collision Processing", CollisionProcessing::Create},
+{"Compound Shapes", CompoundShapes::Create},
+{"Distance Test", DistanceTest::Create},
+{"Dominos", Dominos::Create},
+{"Dynamic Tree", DynamicTreeTest::Create},
+{"Gears", Gears::Create},
+{"Line Joint", LineJoint::Create},
+{"Polygon Shapes", PolyShapes::Create},
+{"Prismatic", Prismatic::Create},
+{"Pulleys", Pulleys::Create},
+{"Revolute", Revolute::Create},
+{"Sensor Test", SensorTest::Create},
+{"Shape Editing", ShapeEditing::Create},
+{"Slider Crank", SliderCrank::Create},
+{"Theo Jansen's Walker", TheoJansen::Create},
+{"Time of Impact", TimeOfImpact::Create},
+{"Varying Friction", VaryingFriction::Create},
+{"Web", Web::Create},
+{NULL, NULL}
+
+};
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
// These include files constitute the main Box2D API\r
\r
#include <Box2D/Common/b2Settings.h>\r
-#include <Box2D/Common/b2Draw.h>\r
-#include <Box2D/Common/b2Timer.h>\r
\r
#include <Box2D/Collision/Shapes/b2CircleShape.h>\r
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>\r
-#include <Box2D/Collision/Shapes/b2LoopShape.h>\r
#include <Box2D/Collision/Shapes/b2PolygonShape.h>\r
\r
#include <Box2D/Collision/b2BroadPhase.h>\r
#include <Box2D/Dynamics/Joints/b2DistanceJoint.h>\r
#include <Box2D/Dynamics/Joints/b2FrictionJoint.h>\r
#include <Box2D/Dynamics/Joints/b2GearJoint.h>\r
-#include <Box2D/Dynamics/Joints/b2WheelJoint.h>\r
+#include <Box2D/Dynamics/Joints/b2LineJoint.h>\r
#include <Box2D/Dynamics/Joints/b2MouseJoint.h>\r
#include <Box2D/Dynamics/Joints/b2PrismaticJoint.h>\r
#include <Box2D/Dynamics/Joints/b2PulleyJoint.h>\r
#include <Box2D/Dynamics/Joints/b2RevoluteJoint.h>\r
-#include <Box2D/Dynamics/Joints/b2RopeJoint.h>\r
#include <Box2D/Dynamics/Joints/b2WeldJoint.h>\r
\r
-#include <Box2D/Rope/b2Rope.h>\r
-\r
#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
#include <Box2D/Collision/Shapes/b2CircleShape.h>\r
#include <new>\r
-using namespace std;\r
\r
b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const\r
{\r
return clone;\r
}\r
\r
-int32 b2CircleShape::GetChildCount() const\r
-{\r
- return 1;\r
-}\r
-\r
bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) const\r
{\r
b2Vec2 center = transform.position + b2Mul(transform.R, m_p);\r
// From Section 3.1.2\r
// x = s + a * r\r
// norm(x) = radius\r
-bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,\r
- const b2Transform& transform, int32 childIndex) const\r
+bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& transform) const\r
{\r
- B2_NOT_USED(childIndex);\r
-\r
b2Vec2 position = transform.position + b2Mul(transform.R, m_p);\r
b2Vec2 s = input.p1 - position;\r
float32 b = b2Dot(s, s) - m_radius * m_radius;\r
return false;\r
}\r
\r
-void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const\r
+void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform) const\r
{\r
- B2_NOT_USED(childIndex);\r
-\r
b2Vec2 p = transform.position + b2Mul(transform.R, m_p);\r
aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius);\r
aabb->upperBound.Set(p.x + m_radius, p.y + m_radius);\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/// Implement b2Shape.\r
b2Shape* Clone(b2BlockAllocator* allocator) const;\r
\r
- /// @see b2Shape::GetChildCount\r
- int32 GetChildCount() const;\r
-\r
/// Implement b2Shape.\r
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;\r
\r
/// Implement b2Shape.\r
- bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,\r
- const b2Transform& transform, int32 childIndex) const;\r
+ bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& transform) const;\r
\r
/// @see b2Shape::ComputeAABB\r
- void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;\r
+ void ComputeAABB(b2AABB* aabb, const b2Transform& transform) const;\r
\r
/// @see b2Shape::ComputeMass\r
void ComputeMass(b2MassData* massData, float32 density) const;\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>\r
-#include <new>\r
-using namespace std;\r
-\r
-void b2EdgeShape::Set(const b2Vec2& v1, const b2Vec2& v2)\r
-{\r
- m_vertex1 = v1;\r
- m_vertex2 = v2;\r
- m_hasVertex0 = false;\r
- m_hasVertex3 = false;\r
-}\r
-\r
-b2Shape* b2EdgeShape::Clone(b2BlockAllocator* allocator) const\r
-{\r
- void* mem = allocator->Allocate(sizeof(b2EdgeShape));\r
- b2EdgeShape* clone = new (mem) b2EdgeShape;\r
- *clone = *this;\r
- return clone;\r
-}\r
-\r
-int32 b2EdgeShape::GetChildCount() const\r
-{\r
- return 1;\r
-}\r
-\r
-bool b2EdgeShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const\r
-{\r
- B2_NOT_USED(xf);\r
- B2_NOT_USED(p);\r
- return false;\r
-}\r
-\r
-// p = p1 + t * d\r
-// v = v1 + s * e\r
-// p1 + t * d = v1 + s * e\r
-// s * e - t * d = p1 - v1\r
-bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,\r
- const b2Transform& xf, int32 childIndex) const\r
-{\r
- B2_NOT_USED(childIndex);\r
-\r
- // Put the ray into the edge's frame of reference.\r
- b2Vec2 p1 = b2MulT(xf.R, input.p1 - xf.position);\r
- b2Vec2 p2 = b2MulT(xf.R, input.p2 - xf.position);\r
- b2Vec2 d = p2 - p1;\r
-\r
- b2Vec2 v1 = m_vertex1;\r
- b2Vec2 v2 = m_vertex2;\r
- b2Vec2 e = v2 - v1;\r
- b2Vec2 normal(e.y, -e.x);\r
- normal.Normalize();\r
-\r
- // q = p1 + t * d\r
- // dot(normal, q - v1) = 0\r
- // dot(normal, p1 - v1) + t * dot(normal, d) = 0\r
- float32 numerator = b2Dot(normal, v1 - p1);\r
- float32 denominator = b2Dot(normal, d);\r
-\r
- if (denominator == 0.0f)\r
- {\r
- return false;\r
- }\r
-\r
- float32 t = numerator / denominator;\r
- if (t < 0.0f || 1.0f < t)\r
- {\r
- return false;\r
- }\r
-\r
- b2Vec2 q = p1 + t * d;\r
-\r
- // q = v1 + s * r\r
- // s = dot(q - v1, r) / dot(r, r)\r
- b2Vec2 r = v2 - v1;\r
- float32 rr = b2Dot(r, r);\r
- if (rr == 0.0f)\r
- {\r
- return false;\r
- }\r
-\r
- float32 s = b2Dot(q - v1, r) / rr;\r
- if (s < 0.0f || 1.0f < s)\r
- {\r
- return false;\r
- }\r
-\r
- output->fraction = t;\r
- if (numerator > 0.0f)\r
- {\r
- output->normal = -normal;\r
- }\r
- else\r
- {\r
- output->normal = normal;\r
- }\r
- return true;\r
-}\r
-\r
-void b2EdgeShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const\r
-{\r
- B2_NOT_USED(childIndex);\r
-\r
- b2Vec2 v1 = b2Mul(xf, m_vertex1);\r
- b2Vec2 v2 = b2Mul(xf, m_vertex2);\r
-\r
- b2Vec2 lower = b2Min(v1, v2);\r
- b2Vec2 upper = b2Max(v1, v2);\r
-\r
- b2Vec2 r(m_radius, m_radius);\r
- aabb->lowerBound = lower - r;\r
- aabb->upperBound = upper + r;\r
-}\r
-\r
-void b2EdgeShape::ComputeMass(b2MassData* massData, float32 density) const\r
-{\r
- B2_NOT_USED(density);\r
-\r
- massData->mass = 0.0f;\r
- massData->center = 0.5f * (m_vertex1 + m_vertex2);\r
- massData->I = 0.0f;\r
-}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef B2_EDGE_SHAPE_H\r
-#define B2_EDGE_SHAPE_H\r
-\r
-#include <Box2D/Collision/Shapes/b2Shape.h>\r
-\r
-/// A line segment (edge) shape. These can be connected in chains or loops\r
-/// to other edge shapes. The connectivity information is used to ensure\r
-/// correct contact normals.\r
-class b2EdgeShape : public b2Shape\r
-{\r
-public:\r
- b2EdgeShape();\r
-\r
- /// Set this as an isolated edge.\r
- void Set(const b2Vec2& v1, const b2Vec2& v2);\r
-\r
- /// Implement b2Shape.\r
- b2Shape* Clone(b2BlockAllocator* allocator) const;\r
-\r
- /// @see b2Shape::GetChildCount\r
- int32 GetChildCount() const;\r
-\r
- /// @see b2Shape::TestPoint\r
- bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;\r
-\r
- /// Implement b2Shape.\r
- bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,\r
- const b2Transform& transform, int32 childIndex) const;\r
-\r
- /// @see b2Shape::ComputeAABB\r
- void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;\r
-\r
- /// @see b2Shape::ComputeMass\r
- void ComputeMass(b2MassData* massData, float32 density) const;\r
- \r
- /// These are the edge vertices\r
- b2Vec2 m_vertex1, m_vertex2;\r
-\r
- /// Optional adjacent vertices. These are used for smooth collision.\r
- b2Vec2 m_vertex0, m_vertex3;\r
- bool m_hasVertex0, m_hasVertex3;\r
-};\r
-\r
-inline b2EdgeShape::b2EdgeShape()\r
-{\r
- m_type = e_edge;\r
- m_radius = b2_polygonRadius;\r
- m_hasVertex0 = false;\r
- m_hasVertex3 = false;\r
-}\r
-\r
-#endif\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Collision/Shapes/b2LoopShape.h>\r
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>\r
-#include <new>\r
-#include <cstring>\r
-using namespace std;\r
-\r
-b2LoopShape::~b2LoopShape()\r
-{\r
- b2Free(m_vertices);\r
- m_vertices = NULL;\r
- m_count = 0;\r
-}\r
-\r
-void b2LoopShape::Create(const b2Vec2* vertices, int32 count)\r
-{\r
- b2Assert(m_vertices == NULL && m_count == 0);\r
- b2Assert(count >= 2);\r
- m_count = count;\r
- m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2));\r
- memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2));\r
-}\r
-\r
-b2Shape* b2LoopShape::Clone(b2BlockAllocator* allocator) const\r
-{\r
- void* mem = allocator->Allocate(sizeof(b2LoopShape));\r
- b2LoopShape* clone = new (mem) b2LoopShape;\r
- clone->Create(m_vertices, m_count);\r
- return clone;\r
-}\r
-\r
-int32 b2LoopShape::GetChildCount() const\r
-{\r
- return m_count;\r
-}\r
-\r
-void b2LoopShape::GetChildEdge(b2EdgeShape* edge, int32 index) const\r
-{\r
- b2Assert(2 <= m_count);\r
- b2Assert(0 <= index && index < m_count);\r
- edge->m_type = b2Shape::e_edge;\r
- edge->m_radius = m_radius;\r
- edge->m_hasVertex0 = true;\r
- edge->m_hasVertex3 = true;\r
-\r
- int32 i0 = index - 1 >= 0 ? index - 1 : m_count - 1;\r
- int32 i1 = index;\r
- int32 i2 = index + 1 < m_count ? index + 1 : 0;\r
- int32 i3 = index + 2;\r
- while (i3 >= m_count)\r
- {\r
- i3 -= m_count;\r
- }\r
-\r
- edge->m_vertex0 = m_vertices[i0];\r
- edge->m_vertex1 = m_vertices[i1];\r
- edge->m_vertex2 = m_vertices[i2];\r
- edge->m_vertex3 = m_vertices[i3];\r
-}\r
-\r
-bool b2LoopShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const\r
-{\r
- B2_NOT_USED(xf);\r
- B2_NOT_USED(p);\r
- return false;\r
-}\r
-\r
-bool b2LoopShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,\r
- const b2Transform& xf, int32 childIndex) const\r
-{\r
- b2Assert(childIndex < m_count);\r
-\r
- b2EdgeShape edgeShape;\r
-\r
- int32 i1 = childIndex;\r
- int32 i2 = childIndex + 1;\r
- if (i2 == m_count)\r
- {\r
- i2 = 0;\r
- }\r
-\r
- edgeShape.m_vertex1 = m_vertices[i1];\r
- edgeShape.m_vertex2 = m_vertices[i2];\r
-\r
- return edgeShape.RayCast(output, input, xf, 0);\r
-}\r
-\r
-void b2LoopShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const\r
-{\r
- b2Assert(childIndex < m_count);\r
-\r
- int32 i1 = childIndex;\r
- int32 i2 = childIndex + 1;\r
- if (i2 == m_count)\r
- {\r
- i2 = 0;\r
- }\r
-\r
- b2Vec2 v1 = b2Mul(xf, m_vertices[i1]);\r
- b2Vec2 v2 = b2Mul(xf, m_vertices[i2]);\r
-\r
- aabb->lowerBound = b2Min(v1, v2);\r
- aabb->upperBound = b2Max(v1, v2);\r
-}\r
-\r
-void b2LoopShape::ComputeMass(b2MassData* massData, float32 density) const\r
-{\r
- B2_NOT_USED(density);\r
-\r
- massData->mass = 0.0f;\r
- massData->center.SetZero();\r
- massData->I = 0.0f;\r
-}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef B2_LOOP_SHAPE_H\r
-#define B2_LOOP_SHAPE_H\r
-\r
-#include <Box2D/Collision/Shapes/b2Shape.h>\r
-\r
-class b2EdgeShape;\r
-\r
-/// A loop shape is a free form sequence of line segments that form a circular list.\r
-/// The loop may cross upon itself, but this is not recommended for smooth collision.\r
-/// The loop has double sided collision, so you can use inside and outside collision.\r
-/// Therefore, you may use any winding order.\r
-/// Since there may be many vertices, they are allocated using b2Alloc.\r
-class b2LoopShape : public b2Shape\r
-{\r
-public:\r
- b2LoopShape();\r
-\r
- /// The destructor frees the vertices using b2Free.\r
- ~b2LoopShape();\r
-\r
- /// Create the loop shape, copy all vertices.\r
- void Create(const b2Vec2* vertices, int32 count);\r
-\r
- /// Implement b2Shape. Vertices are cloned using b2Alloc.\r
- b2Shape* Clone(b2BlockAllocator* allocator) const;\r
-\r
- /// @see b2Shape::GetChildCount\r
- int32 GetChildCount() const;\r
-\r
- /// Get a child edge.\r
- void GetChildEdge(b2EdgeShape* edge, int32 index) const;\r
-\r
- /// This always return false.\r
- /// @see b2Shape::TestPoint\r
- bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;\r
-\r
- /// Implement b2Shape.\r
- bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,\r
- const b2Transform& transform, int32 childIndex) const;\r
-\r
- /// @see b2Shape::ComputeAABB\r
- void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;\r
-\r
- /// Chains have zero mass.\r
- /// @see b2Shape::ComputeMass\r
- void ComputeMass(b2MassData* massData, float32 density) const;\r
-\r
- /// Get the number of vertices.\r
- int32 GetCount() const { return m_count; }\r
-\r
- /// Get the vertices (read-only).\r
- const b2Vec2& GetVertex(int32 index) const\r
- {\r
- b2Assert(0 <= index && index < m_count);\r
- return m_vertices[index];\r
- }\r
-\r
- /// Get the vertices (read-only).\r
- const b2Vec2* GetVertices() const { return m_vertices; }\r
-\r
-protected:\r
-\r
- /// The vertices. Owned by this class.\r
- b2Vec2* m_vertices;\r
-\r
- /// The vertex count.\r
- int32 m_count;\r
-};\r
-\r
-inline b2LoopShape::b2LoopShape()\r
-{\r
- m_type = e_loop;\r
- m_radius = b2_polygonRadius;\r
- m_vertices = NULL;\r
- m_count = 0;\r
-}\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
}\r
}\r
\r
-int32 b2PolygonShape::GetChildCount() const\r
+void b2PolygonShape::SetAsEdge(const b2Vec2& v1, const b2Vec2& v2)\r
{\r
- return 1;\r
+ m_vertexCount = 2;\r
+ m_vertices[0] = v1;\r
+ m_vertices[1] = v2;\r
+ m_centroid = 0.5f * (v1 + v2);\r
+ m_normals[0] = b2Cross(v2 - v1, 1.0f);\r
+ m_normals[0].Normalize();\r
+ m_normals[1] = -m_normals[0];\r
}\r
\r
static b2Vec2 ComputeCentroid(const b2Vec2* vs, int32 count)\r
{\r
- b2Assert(count >= 3);\r
+ b2Assert(count >= 2);\r
\r
b2Vec2 c; c.Set(0.0f, 0.0f);\r
float32 area = 0.0f;\r
\r
+ if (count == 2)\r
+ {\r
+ c = 0.5f * (vs[0] + vs[1]);\r
+ return c;\r
+ }\r
+\r
// pRef is the reference point for forming triangles.\r
// It's location doesn't change the result (except for rounding error).\r
b2Vec2 pRef(0.0f, 0.0f);\r
\r
void b2PolygonShape::Set(const b2Vec2* vertices, int32 count)\r
{\r
- b2Assert(3 <= count && count <= b2_maxPolygonVertices);\r
+ b2Assert(2 <= count && count <= b2_maxPolygonVertices);\r
m_vertexCount = count;\r
\r
// Copy vertices.\r
return true;\r
}\r
\r
-bool b2PolygonShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,\r
- const b2Transform& xf, int32 childIndex) const\r
+bool b2PolygonShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& xf) const\r
{\r
- B2_NOT_USED(childIndex);\r
-\r
// Put the ray into the polygon's frame of reference.\r
b2Vec2 p1 = b2MulT(xf.R, input.p1 - xf.position);\r
b2Vec2 p2 = b2MulT(xf.R, input.p2 - xf.position);\r
b2Vec2 d = p2 - p1;\r
\r
- float32 lower = 0.0f, upper = input.maxFraction;\r
-\r
- int32 index = -1;\r
-\r
- for (int32 i = 0; i < m_vertexCount; ++i)\r
+ if (m_vertexCount == 2)\r
{\r
- // p = p1 + a * d\r
- // dot(normal, p - v) = 0\r
- // dot(normal, p1 - v) + a * dot(normal, d) = 0\r
- float32 numerator = b2Dot(m_normals[i], m_vertices[i] - p1);\r
- float32 denominator = b2Dot(m_normals[i], d);\r
+ b2Vec2 v1 = m_vertices[0];\r
+ b2Vec2 v2 = m_vertices[1];\r
+ b2Vec2 normal = m_normals[0];\r
+\r
+ // q = p1 + t * d\r
+ // dot(normal, q - v1) = 0\r
+ // dot(normal, p1 - v1) + t * dot(normal, d) = 0\r
+ float32 numerator = b2Dot(normal, v1 - p1);\r
+ float32 denominator = b2Dot(normal, d);\r
\r
if (denominator == 0.0f)\r
- { \r
- if (numerator < 0.0f)\r
- {\r
- return false;\r
- }\r
+ {\r
+ return false;\r
+ }\r
+ \r
+ float32 t = numerator / denominator;\r
+ if (t < 0.0f || 1.0f < t)\r
+ {\r
+ return false;\r
+ }\r
+\r
+ b2Vec2 q = p1 + t * d;\r
+\r
+ // q = v1 + s * r\r
+ // s = dot(q - v1, r) / dot(r, r)\r
+ b2Vec2 r = v2 - v1;\r
+ float32 rr = b2Dot(r, r);\r
+ if (rr == 0.0f)\r
+ {\r
+ return false;\r
+ }\r
+\r
+ float32 s = b2Dot(q - v1, r) / rr;\r
+ if (s < 0.0f || 1.0f < s)\r
+ {\r
+ return false;\r
+ }\r
+\r
+ output->fraction = t;\r
+ if (numerator > 0.0f)\r
+ {\r
+ output->normal = -normal;\r
}\r
else\r
{\r
- // Note: we want this predicate without division:\r
- // lower < numerator / denominator, where denominator < 0\r
- // Since denominator < 0, we have to flip the inequality:\r
- // lower < numerator / denominator <==> denominator * lower > numerator.\r
- if (denominator < 0.0f && numerator < lower * denominator)\r
+ output->normal = normal;\r
+ }\r
+ return true;\r
+ }\r
+ else\r
+ {\r
+ float32 lower = 0.0f, upper = input.maxFraction;\r
+\r
+ int32 index = -1;\r
+\r
+ for (int32 i = 0; i < m_vertexCount; ++i)\r
+ {\r
+ // p = p1 + a * d\r
+ // dot(normal, p - v) = 0\r
+ // dot(normal, p1 - v) + a * dot(normal, d) = 0\r
+ float32 numerator = b2Dot(m_normals[i], m_vertices[i] - p1);\r
+ float32 denominator = b2Dot(m_normals[i], d);\r
+\r
+ if (denominator == 0.0f)\r
+ { \r
+ if (numerator < 0.0f)\r
+ {\r
+ return false;\r
+ }\r
+ }\r
+ else\r
{\r
- // Increase lower.\r
- // The segment enters this half-space.\r
- lower = numerator / denominator;\r
- index = i;\r
+ // Note: we want this predicate without division:\r
+ // lower < numerator / denominator, where denominator < 0\r
+ // Since denominator < 0, we have to flip the inequality:\r
+ // lower < numerator / denominator <==> denominator * lower > numerator.\r
+ if (denominator < 0.0f && numerator < lower * denominator)\r
+ {\r
+ // Increase lower.\r
+ // The segment enters this half-space.\r
+ lower = numerator / denominator;\r
+ index = i;\r
+ }\r
+ else if (denominator > 0.0f && numerator < upper * denominator)\r
+ {\r
+ // Decrease upper.\r
+ // The segment exits this half-space.\r
+ upper = numerator / denominator;\r
+ }\r
}\r
- else if (denominator > 0.0f && numerator < upper * denominator)\r
+\r
+ // The use of epsilon here causes the assert on lower to trip\r
+ // in some cases. Apparently the use of epsilon was to make edge\r
+ // shapes work, but now those are handled separately.\r
+ //if (upper < lower - b2_epsilon)\r
+ if (upper < lower)\r
{\r
- // Decrease upper.\r
- // The segment exits this half-space.\r
- upper = numerator / denominator;\r
+ return false;\r
}\r
}\r
\r
- // The use of epsilon here causes the assert on lower to trip\r
- // in some cases. Apparently the use of epsilon was to make edge\r
- // shapes work, but now those are handled separately.\r
- //if (upper < lower - b2_epsilon)\r
- if (upper < lower)\r
+ b2Assert(0.0f <= lower && lower <= input.maxFraction);\r
+\r
+ if (index >= 0)\r
{\r
- return false;\r
+ output->fraction = lower;\r
+ output->normal = b2Mul(xf.R, m_normals[index]);\r
+ return true;\r
}\r
}\r
\r
- b2Assert(0.0f <= lower && lower <= input.maxFraction);\r
-\r
- if (index >= 0)\r
- {\r
- output->fraction = lower;\r
- output->normal = b2Mul(xf.R, m_normals[index]);\r
- return true;\r
- }\r
-\r
return false;\r
}\r
\r
-void b2PolygonShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const\r
+void b2PolygonShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf) const\r
{\r
- B2_NOT_USED(childIndex);\r
-\r
b2Vec2 lower = b2Mul(xf, m_vertices[0]);\r
b2Vec2 upper = lower;\r
\r
//\r
// The rest of the derivation is handled by computer algebra.\r
\r
- b2Assert(m_vertexCount >= 3);\r
+ b2Assert(m_vertexCount >= 2);\r
+\r
+ // A line segment has zero mass.\r
+ if (m_vertexCount == 2)\r
+ {\r
+ massData->center = 0.5f * (m_vertices[0] + m_vertices[1]);\r
+ massData->mass = 0.0f;\r
+ massData->I = 0.0f;\r
+ return;\r
+ }\r
\r
b2Vec2 center; center.Set(0.0f, 0.0f);\r
float32 area = 0.0f;\r
float32 I = 0.0f;\r
\r
- // s is the reference point for forming triangles.\r
+ // pRef is the reference point for forming triangles.\r
// It's location doesn't change the result (except for rounding error).\r
- b2Vec2 s(0.0f, 0.0f);\r
-\r
+ b2Vec2 pRef(0.0f, 0.0f);\r
+#if 0\r
// This code would put the reference point inside the polygon.\r
for (int32 i = 0; i < m_vertexCount; ++i)\r
{\r
- s += m_vertices[i];\r
+ pRef += m_vertices[i];\r
}\r
- s *= 1.0f / m_vertexCount;\r
+ pRef *= 1.0f / count;\r
+#endif\r
\r
const float32 k_inv3 = 1.0f / 3.0f;\r
\r
for (int32 i = 0; i < m_vertexCount; ++i)\r
{\r
// Triangle vertices.\r
- b2Vec2 e1 = m_vertices[i] - s;\r
- b2Vec2 e2 = i + 1 < m_vertexCount ? m_vertices[i+1] - s : m_vertices[0] - s;\r
+ b2Vec2 p1 = pRef;\r
+ b2Vec2 p2 = m_vertices[i];\r
+ b2Vec2 p3 = i + 1 < m_vertexCount ? m_vertices[i+1] : m_vertices[0];\r
+\r
+ b2Vec2 e1 = p2 - p1;\r
+ b2Vec2 e2 = p3 - p1;\r
\r
float32 D = b2Cross(e1, e2);\r
\r
area += triangleArea;\r
\r
// Area weighted centroid\r
- center += triangleArea * k_inv3 * (e1 + e2);\r
+ center += triangleArea * k_inv3 * (p1 + p2 + p3);\r
\r
+ float32 px = p1.x, py = p1.y;\r
float32 ex1 = e1.x, ey1 = e1.y;\r
float32 ex2 = e2.x, ey2 = e2.y;\r
\r
- float32 intx2 = ex1*ex1 + ex2*ex1 + ex2*ex2;\r
- float32 inty2 = ey1*ey1 + ey2*ey1 + ey2*ey2;\r
+ float32 intx2 = k_inv3 * (0.25f * (ex1*ex1 + ex2*ex1 + ex2*ex2) + (px*ex1 + px*ex2)) + 0.5f*px*px;\r
+ float32 inty2 = k_inv3 * (0.25f * (ey1*ey1 + ey2*ey1 + ey2*ey2) + (py*ey1 + py*ey2)) + 0.5f*py*py;\r
\r
- I += (0.25f * k_inv3 * D) * (intx2 + inty2);\r
+ I += D * (intx2 + inty2);\r
}\r
\r
// Total mass\r
// Center of mass\r
b2Assert(area > b2_epsilon);\r
center *= 1.0f / area;\r
- massData->center = center + s;\r
+ massData->center = center;\r
\r
// Inertia tensor relative to the local origin.\r
- massData->I = density * I + massData->mass * b2Dot(s, s);\r
+ massData->I = density * I;\r
}\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
/// A convex polygon. It is assumed that the interior of the polygon is to\r
/// the left of each edge.\r
-/// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices.\r
-/// In most cases you should not need many vertices for a convex polygon.\r
class b2PolygonShape : public b2Shape\r
{\r
public:\r
/// Implement b2Shape.\r
b2Shape* Clone(b2BlockAllocator* allocator) const;\r
\r
- /// @see b2Shape::GetChildCount\r
- int32 GetChildCount() const;\r
-\r
/// Copy vertices. This assumes the vertices define a convex polygon.\r
/// It is assumed that the exterior is the the right of each edge.\r
- /// The count must be in the range [3, b2_maxPolygonVertices].\r
void Set(const b2Vec2* vertices, int32 vertexCount);\r
\r
/// Build vertices to represent an axis-aligned box.\r
/// @param angle the rotation of the box in local coordinates.\r
void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle);\r
\r
+ /// Set this as a single edge.\r
+ void SetAsEdge(const b2Vec2& v1, const b2Vec2& v2);\r
+\r
/// @see b2Shape::TestPoint\r
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;\r
\r
/// Implement b2Shape.\r
- bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,\r
- const b2Transform& transform, int32 childIndex) const;\r
+ bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& transform) const;\r
\r
/// @see b2Shape::ComputeAABB\r
- void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;\r
+ void ComputeAABB(b2AABB* aabb, const b2Transform& transform) const;\r
\r
/// @see b2Shape::ComputeMass\r
void ComputeMass(b2MassData* massData, float32 density) const;\r
\r
+ /// Get the supporting vertex index in the given direction.\r
+ int32 GetSupport(const b2Vec2& d) const;\r
+\r
+ /// Get the supporting vertex in the given direction.\r
+ const b2Vec2& GetSupportVertex(const b2Vec2& d) const;\r
+\r
/// Get the vertex count.\r
int32 GetVertexCount() const { return m_vertexCount; }\r
\r
m_centroid.SetZero();\r
}\r
\r
+inline int32 b2PolygonShape::GetSupport(const b2Vec2& d) const\r
+{\r
+ int32 bestIndex = 0;\r
+ float32 bestValue = b2Dot(m_vertices[0], d);\r
+ for (int32 i = 1; i < m_vertexCount; ++i)\r
+ {\r
+ float32 value = b2Dot(m_vertices[i], d);\r
+ if (value > bestValue)\r
+ {\r
+ bestIndex = i;\r
+ bestValue = value;\r
+ }\r
+ }\r
+\r
+ return bestIndex;\r
+}\r
+\r
+inline const b2Vec2& b2PolygonShape::GetSupportVertex(const b2Vec2& d) const\r
+{\r
+ int32 bestIndex = 0;\r
+ float32 bestValue = b2Dot(m_vertices[0], d);\r
+ for (int32 i = 1; i < m_vertexCount; ++i)\r
+ {\r
+ float32 value = b2Dot(m_vertices[i], d);\r
+ if (value > bestValue)\r
+ {\r
+ bestIndex = i;\r
+ bestValue = value;\r
+ }\r
+ }\r
+\r
+ return m_vertices[bestIndex];\r
+}\r
+\r
inline const b2Vec2& b2PolygonShape::GetVertex(int32 index) const\r
{\r
b2Assert(0 <= index && index < m_vertexCount);\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
/// A shape is used for collision detection. You can create a shape however you like.\r
/// Shapes used for simulation in b2World are created automatically when a b2Fixture\r
-/// is created. Shapes may encapsulate a one or more child shapes.\r
+/// is created.\r
class b2Shape\r
{\r
public:\r
{\r
e_unknown= -1,\r
e_circle = 0,\r
- e_edge = 1,\r
- e_polygon = 2,\r
- e_loop = 3,\r
- e_typeCount = 4\r
+ e_polygon = 1,\r
+ e_typeCount = 2,\r
};\r
\r
b2Shape() { m_type = e_unknown; }\r
/// @return the shape type.\r
Type GetType() const;\r
\r
- /// Get the number of child primitives.\r
- virtual int32 GetChildCount() const = 0;\r
-\r
/// Test a point for containment in this shape. This only works for convex shapes.\r
/// @param xf the shape world transform.\r
/// @param p a point in world coordinates.\r
virtual bool TestPoint(const b2Transform& xf, const b2Vec2& p) const = 0;\r
\r
- /// Cast a ray against a child shape.\r
+ /// Cast a ray against this shape.\r
/// @param output the ray-cast results.\r
/// @param input the ray-cast input parameters.\r
/// @param transform the transform to be applied to the shape.\r
- /// @param childIndex the child shape index\r
- virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,\r
- const b2Transform& transform, int32 childIndex) const = 0;\r
+ virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& transform) const = 0;\r
\r
- /// Given a transform, compute the associated axis aligned bounding box for a child shape.\r
+ /// Given a transform, compute the associated axis aligned bounding box for this shape.\r
/// @param aabb returns the axis aligned box.\r
/// @param xf the world transform of the shape.\r
- /// @param childIndex the child shape\r
- virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const = 0;\r
+ virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf) const = 0;\r
\r
/// Compute the mass properties of this shape using its dimensions and density.\r
/// The inertia tensor is computed about the local origin.\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
#include <Box2D/Collision/b2BroadPhase.h>\r
#include <cstring>\r
-using namespace std;\r
\r
b2BroadPhase::b2BroadPhase()\r
{\r
}\r
}\r
\r
-void b2BroadPhase::TouchProxy(int32 proxyId)\r
-{\r
- BufferMove(proxyId);\r
-}\r
-\r
void b2BroadPhase::BufferMove(int32 proxyId)\r
{\r
if (m_moveCount == m_moveCapacity)\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
enum\r
{\r
- e_nullProxy = -1\r
+ e_nullProxy = -1,\r
};\r
\r
b2BroadPhase();\r
/// call UpdatePairs to finalized the proxy pairs (for your time step).\r
void MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement);\r
\r
- /// Call to trigger a re-processing of it's pairs on the next call to UpdatePairs.\r
- void TouchProxy(int32 proxyId);\r
-\r
/// Get the fat AABB for a proxy.\r
const b2AABB& GetFatAABB(int32 proxyId) const;\r
\r
template <typename T>\r
void RayCast(T* callback, const b2RayCastInput& input) const;\r
\r
- /// Get the height of the embedded tree.\r
- int32 GetTreeHeight() const;\r
-\r
- /// Get the balance of the embedded tree.\r
- int32 GetTreeBalance() const;\r
-\r
- /// Get the quality metric of the embedded tree.\r
- float32 GetTreeQuality() const;\r
+ /// Compute the height of the embedded tree.\r
+ int32 ComputeHeight() const;\r
\r
private:\r
\r
return m_proxyCount;\r
}\r
\r
-inline int32 b2BroadPhase::GetTreeHeight() const\r
-{\r
- return m_tree.GetHeight();\r
-}\r
-\r
-inline int32 b2BroadPhase::GetTreeBalance() const\r
-{\r
- return m_tree.GetMaxBalance();\r
-}\r
-\r
-inline float32 b2BroadPhase::GetTreeQuality() const\r
+inline int32 b2BroadPhase::ComputeHeight() const\r
{\r
- return m_tree.GetAreaRatio();\r
+ return m_tree.ComputeHeight();\r
}\r
\r
template <typename T>\r
}\r
\r
// Try to keep the tree balanced.\r
- //m_tree.Rebalance(4);\r
+ m_tree.Rebalance(4);\r
}\r
\r
template <typename T>\r
/*\r
-* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2007-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
+++ /dev/null
-/*\r
-* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Collision/b2Collision.h>\r
-#include <Box2D/Collision/Shapes/b2CircleShape.h>\r
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>\r
-#include <Box2D/Collision/Shapes/b2PolygonShape.h>\r
-\r
-enum b2EdgeType\r
-{\r
- b2_isolated,\r
- b2_concave,\r
- b2_flat,\r
- b2_convex\r
-};\r
-\r
-// Compute contact points for edge versus circle.\r
-// This accounts for edge connectivity.\r
-void b2CollideEdgeAndCircle(b2Manifold* manifold,\r
- const b2EdgeShape* edgeA, const b2Transform& xfA,\r
- const b2CircleShape* circleB, const b2Transform& xfB)\r
-{\r
- manifold->pointCount = 0;\r
-\r
- // Compute circle in frame of edge\r
- b2Vec2 Q = b2MulT(xfA, b2Mul(xfB, circleB->m_p));\r
-\r
- b2Vec2 A = edgeA->m_vertex1, B = edgeA->m_vertex2;\r
- b2Vec2 e = B - A;\r
-\r
- // Barycentric coordinates\r
- float32 u = b2Dot(e, B - Q);\r
- float32 v = b2Dot(e, Q - A);\r
-\r
- float32 radius = edgeA->m_radius + circleB->m_radius;\r
-\r
- b2ContactFeature cf;\r
- cf.indexB = 0;\r
- cf.typeB = b2ContactFeature::e_vertex;\r
-\r
- // Region A\r
- if (v <= 0.0f)\r
- {\r
- b2Vec2 P = A;\r
- b2Vec2 d = Q - P;\r
- float32 dd = b2Dot(d, d);\r
- if (dd > radius * radius)\r
- {\r
- return;\r
- }\r
-\r
- // Is there an edge connected to A?\r
- if (edgeA->m_hasVertex0)\r
- {\r
- b2Vec2 A1 = edgeA->m_vertex0;\r
- b2Vec2 B1 = A;\r
- b2Vec2 e1 = B1 - A1;\r
- float32 u1 = b2Dot(e1, B1 - Q);\r
-\r
- // Is the circle in Region AB of the previous edge?\r
- if (u1 > 0.0f)\r
- {\r
- return;\r
- }\r
- }\r
-\r
- cf.indexA = 0;\r
- cf.typeA = b2ContactFeature::e_vertex;\r
- manifold->pointCount = 1;\r
- manifold->type = b2Manifold::e_circles;\r
- manifold->localNormal.SetZero();\r
- manifold->localPoint = P;\r
- manifold->points[0].id.key = 0;\r
- manifold->points[0].id.cf = cf;\r
- manifold->points[0].localPoint = circleB->m_p;\r
- return;\r
- }\r
- \r
- // Region B\r
- if (u <= 0.0f)\r
- {\r
- b2Vec2 P = B;\r
- b2Vec2 d = Q - P;\r
- float32 dd = b2Dot(d, d);\r
- if (dd > radius * radius)\r
- {\r
- return;\r
- }\r
-\r
- // Is there an edge connected to B?\r
- if (edgeA->m_hasVertex3)\r
- {\r
- b2Vec2 B2 = edgeA->m_vertex3;\r
- b2Vec2 A2 = B;\r
- b2Vec2 e2 = B2 - A2;\r
- float32 v2 = b2Dot(e2, Q - A2);\r
-\r
- // Is the circle in Region AB of the next edge?\r
- if (v2 > 0.0f)\r
- {\r
- return;\r
- }\r
- }\r
-\r
- cf.indexA = 1;\r
- cf.typeA = b2ContactFeature::e_vertex;\r
- manifold->pointCount = 1;\r
- manifold->type = b2Manifold::e_circles;\r
- manifold->localNormal.SetZero();\r
- manifold->localPoint = P;\r
- manifold->points[0].id.key = 0;\r
- manifold->points[0].id.cf = cf;\r
- manifold->points[0].localPoint = circleB->m_p;\r
- return;\r
- }\r
-\r
- // Region AB\r
- float32 den = b2Dot(e, e);\r
- b2Assert(den > 0.0f);\r
- b2Vec2 P = (1.0f / den) * (u * A + v * B);\r
- b2Vec2 d = Q - P;\r
- float32 dd = b2Dot(d, d);\r
- if (dd > radius * radius)\r
- {\r
- return;\r
- }\r
-\r
- b2Vec2 n(-e.y, e.x);\r
- if (b2Dot(n, Q - A) < 0.0f)\r
- {\r
- n.Set(-n.x, -n.y);\r
- }\r
- n.Normalize();\r
-\r
- cf.indexA = 0;\r
- cf.typeA = b2ContactFeature::e_face;\r
- manifold->pointCount = 1;\r
- manifold->type = b2Manifold::e_faceA;\r
- manifold->localNormal = n;\r
- manifold->localPoint = A;\r
- manifold->points[0].id.key = 0;\r
- manifold->points[0].id.cf = cf;\r
- manifold->points[0].localPoint = circleB->m_p;\r
-}\r
-\r
-struct b2EPAxis\r
-{\r
- enum Type\r
- {\r
- e_unknown,\r
- e_edgeA,\r
- e_edgeB\r
- };\r
-\r
- Type type;\r
- int32 index;\r
- float32 separation;\r
-};\r
-\r
-// Edge shape plus more stuff.\r
-struct b2FatEdge\r
-{\r
- b2Vec2 v0, v1, v2, v3;\r
- b2Vec2 normal;\r
- bool hasVertex0, hasVertex3;\r
-};\r
-\r
-// This lets us treate and edge shape and a polygon in the same\r
-// way in the SAT collider.\r
-struct b2EPProxy\r
-{\r
- b2Vec2 vertices[b2_maxPolygonVertices];\r
- b2Vec2 normals[b2_maxPolygonVertices];\r
- b2Vec2 centroid;\r
- int32 count;\r
-};\r
-\r
-// This class collides and edge and a polygon, taking into account edge adjacency.\r
-struct b2EPCollider\r
-{\r
- b2EPCollider(const b2EdgeShape* edgeA, const b2Transform& xfA,\r
- const b2PolygonShape* polygonB_in, const b2Transform& xfB);\r
-\r
- void Collide(b2Manifold* manifold);\r
-\r
- void ComputeAdjacency();\r
- b2EPAxis ComputeEdgeSeparation();\r
- b2EPAxis ComputePolygonSeparation();\r
- void FindIncidentEdge(b2ClipVertex c[2], const b2EPProxy* proxy1, int32 edge1, const b2EPProxy* proxy2);\r
-\r
- b2FatEdge m_edgeA;\r
-\r
- b2EPProxy m_proxyA, m_proxyB;\r
-\r
- b2Transform m_xf;\r
- b2Vec2 m_normal0, m_normal2;\r
- b2Vec2 m_limit11, m_limit12;\r
- b2Vec2 m_limit21, m_limit22;\r
- float32 m_radius;\r
-};\r
-\r
-b2EPCollider::b2EPCollider(const b2EdgeShape* edgeA, const b2Transform& xfA,\r
- const b2PolygonShape* polygonB, const b2Transform& xfB)\r
-{\r
- m_xf = b2MulT(xfA, xfB);\r
-\r
- // Edge geometry\r
- m_edgeA.v0 = edgeA->m_vertex0;\r
- m_edgeA.v1 = edgeA->m_vertex1;\r
- m_edgeA.v2 = edgeA->m_vertex2;\r
- m_edgeA.v3 = edgeA->m_vertex3;\r
- b2Vec2 e = m_edgeA.v2 - m_edgeA.v1;\r
-\r
- // Normal points outwards in CCW order.\r
- m_edgeA.normal.Set(e.y, -e.x);\r
- m_edgeA.normal.Normalize();\r
- m_edgeA.hasVertex0 = edgeA->m_hasVertex0;\r
- m_edgeA.hasVertex3 = edgeA->m_hasVertex3;\r
-\r
- // Proxy for edge\r
- m_proxyA.vertices[0] = m_edgeA.v1;\r
- m_proxyA.vertices[1] = m_edgeA.v2;\r
- m_proxyA.normals[0] = m_edgeA.normal;\r
- m_proxyA.normals[1] = -m_edgeA.normal;\r
- m_proxyA.centroid = 0.5f * (m_edgeA.v1 + m_edgeA.v2);\r
- m_proxyA.count = 2;\r
-\r
- // Proxy for polygon\r
- m_proxyB.count = polygonB->m_vertexCount;\r
- m_proxyB.centroid = b2Mul(m_xf, polygonB->m_centroid);\r
- for (int32 i = 0; i < polygonB->m_vertexCount; ++i)\r
- {\r
- m_proxyB.vertices[i] = b2Mul(m_xf, polygonB->m_vertices[i]);\r
- m_proxyB.normals[i] = b2Mul(m_xf.R, polygonB->m_normals[i]);\r
- }\r
-\r
- m_radius = 2.0f * b2_polygonRadius;\r
-\r
- m_limit11.SetZero();\r
- m_limit12.SetZero();\r
- m_limit21.SetZero();\r
- m_limit22.SetZero();\r
-}\r
-\r
-// Collide an edge and polygon. This uses the SAT and clipping to produce up to 2 contact points.\r
-// Edge adjacency is handle to produce locally valid contact points and normals. This is intended\r
-// to allow the polygon to slide smoothly over an edge chain.\r
-//\r
-// Algorithm\r
-// 1. Classify front-side or back-side collision with edge.\r
-// 2. Compute separation\r
-// 3. Process adjacent edges\r
-// 4. Classify adjacent edge as convex, flat, null, or concave\r
-// 5. Skip null or concave edges. Concave edges get a separate manifold.\r
-// 6. If the edge is flat, compute contact points as normal. Discard boundary points.\r
-// 7. If the edge is convex, compute it's separation.\r
-// 8. Use the minimum separation of up to three edges. If the minimum separation\r
-// is not the primary edge, return.\r
-// 9. If the minimum separation is the primary edge, compute the contact points and return.\r
-void b2EPCollider::Collide(b2Manifold* manifold)\r
-{\r
- manifold->pointCount = 0;\r
-\r
- ComputeAdjacency();\r
-\r
- b2EPAxis edgeAxis = ComputeEdgeSeparation();\r
-\r
- // If no valid normal can be found than this edge should not collide.\r
- // This can happen on the middle edge of a 3-edge zig-zag chain.\r
- if (edgeAxis.type == b2EPAxis::e_unknown)\r
- {\r
- return;\r
- }\r
-\r
- if (edgeAxis.separation > m_radius)\r
- {\r
- return;\r
- }\r
-\r
- b2EPAxis polygonAxis = ComputePolygonSeparation();\r
- if (polygonAxis.type != b2EPAxis::e_unknown && polygonAxis.separation > m_radius)\r
- {\r
- return;\r
- }\r
-\r
- // Use hysteresis for jitter reduction.\r
- const float32 k_relativeTol = 0.98f;\r
- const float32 k_absoluteTol = 0.001f;\r
-\r
- b2EPAxis primaryAxis;\r
- if (polygonAxis.type == b2EPAxis::e_unknown)\r
- {\r
- primaryAxis = edgeAxis;\r
- }\r
- else if (polygonAxis.separation > k_relativeTol * edgeAxis.separation + k_absoluteTol)\r
- {\r
- primaryAxis = polygonAxis;\r
- }\r
- else\r
- {\r
- primaryAxis = edgeAxis;\r
- }\r
-\r
- b2EPProxy* proxy1;\r
- b2EPProxy* proxy2;\r
- b2ClipVertex incidentEdge[2];\r
- if (primaryAxis.type == b2EPAxis::e_edgeA)\r
- {\r
- proxy1 = &m_proxyA;\r
- proxy2 = &m_proxyB;\r
- manifold->type = b2Manifold::e_faceA;\r
- }\r
- else\r
- {\r
- proxy1 = &m_proxyB;\r
- proxy2 = &m_proxyA;\r
- manifold->type = b2Manifold::e_faceB;\r
- }\r
-\r
- int32 edge1 = primaryAxis.index;\r
-\r
- FindIncidentEdge(incidentEdge, proxy1, primaryAxis.index, proxy2);\r
- int32 count1 = proxy1->count;\r
- const b2Vec2* vertices1 = proxy1->vertices;\r
-\r
- int32 iv1 = edge1;\r
- int32 iv2 = edge1 + 1 < count1 ? edge1 + 1 : 0;\r
-\r
- b2Vec2 v11 = vertices1[iv1];\r
- b2Vec2 v12 = vertices1[iv2];\r
-\r
- b2Vec2 tangent = v12 - v11;\r
- tangent.Normalize();\r
- \r
- b2Vec2 normal = b2Cross(tangent, 1.0f);\r
- b2Vec2 planePoint = 0.5f * (v11 + v12);\r
-\r
- // Face offset.\r
- float32 frontOffset = b2Dot(normal, v11);\r
-\r
- // Side offsets, extended by polytope skin thickness.\r
- float32 sideOffset1 = -b2Dot(tangent, v11) + m_radius;\r
- float32 sideOffset2 = b2Dot(tangent, v12) + m_radius;\r
-\r
- // Clip incident edge against extruded edge1 side edges.\r
- b2ClipVertex clipPoints1[2];\r
- b2ClipVertex clipPoints2[2];\r
- int np;\r
-\r
- // Clip to box side 1\r
- np = b2ClipSegmentToLine(clipPoints1, incidentEdge, -tangent, sideOffset1, iv1);\r
-\r
- if (np < b2_maxManifoldPoints)\r
- {\r
- return;\r
- }\r
-\r
- // Clip to negative box side 1\r
- np = b2ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2, iv2);\r
-\r
- if (np < b2_maxManifoldPoints)\r
- {\r
- return;\r
- }\r
-\r
- // Now clipPoints2 contains the clipped points.\r
- if (primaryAxis.type == b2EPAxis::e_edgeA)\r
- {\r
- manifold->localNormal = normal;\r
- manifold->localPoint = planePoint;\r
- }\r
- else\r
- {\r
- manifold->localNormal = b2MulT(m_xf.R, normal);\r
- manifold->localPoint = b2MulT(m_xf, planePoint);\r
- }\r
-\r
- int32 pointCount = 0;\r
- for (int32 i = 0; i < b2_maxManifoldPoints; ++i)\r
- {\r
- float32 separation;\r
- \r
- separation = b2Dot(normal, clipPoints2[i].v) - frontOffset;\r
-\r
- if (separation <= m_radius)\r
- {\r
- b2ManifoldPoint* cp = manifold->points + pointCount;\r
-\r
- if (primaryAxis.type == b2EPAxis::e_edgeA)\r
- {\r
- cp->localPoint = b2MulT(m_xf, clipPoints2[i].v);\r
- cp->id = clipPoints2[i].id;\r
- }\r
- else\r
- {\r
- cp->localPoint = clipPoints2[i].v;\r
- cp->id.cf.typeA = clipPoints2[i].id.cf.typeB;\r
- cp->id.cf.typeB = clipPoints2[i].id.cf.typeA;\r
- cp->id.cf.indexA = clipPoints2[i].id.cf.indexB;\r
- cp->id.cf.indexB = clipPoints2[i].id.cf.indexA;\r
- }\r
-\r
- ++pointCount;\r
- }\r
- }\r
-\r
- manifold->pointCount = pointCount;\r
-}\r
-\r
-// Compute allowable normal ranges based on adjacency.\r
-// A normal n is allowable iff:\r
-// cross(n, n1) >= 0.0f && cross(n2, n) >= 0.0f\r
-// n points from A to B (edge to polygon)\r
-void b2EPCollider::ComputeAdjacency()\r
-{\r
- b2Vec2 v0 = m_edgeA.v0;\r
- b2Vec2 v1 = m_edgeA.v1;\r
- b2Vec2 v2 = m_edgeA.v2;\r
- b2Vec2 v3 = m_edgeA.v3;\r
-\r
- // Determine allowable the normal regions based on adjacency.\r
- // Note: it may be possible that no normal is admissable.\r
- b2Vec2 centerB = m_proxyB.centroid;\r
- if (m_edgeA.hasVertex0)\r
- {\r
- b2Vec2 e0 = v1 - v0;\r
- b2Vec2 e1 = v2 - v1;\r
- b2Vec2 n0(e0.y, -e0.x);\r
- b2Vec2 n1(e1.y, -e1.x);\r
- n0.Normalize();\r
- n1.Normalize();\r
-\r
- bool convex = b2Cross(n0, n1) >= 0.0f;\r
- bool front0 = b2Dot(n0, centerB - v0) >= 0.0f;\r
- bool front1 = b2Dot(n1, centerB - v1) >= 0.0f;\r
-\r
- if (convex)\r
- {\r
- if (front0 || front1)\r
- {\r
- m_limit11 = n1;\r
- m_limit12 = n0;\r
- }\r
- else\r
- {\r
- m_limit11 = -n1;\r
- m_limit12 = -n0;\r
- }\r
- }\r
- else\r
- {\r
- if (front0 && front1)\r
- {\r
- m_limit11 = n0;\r
- m_limit12 = n1;\r
- }\r
- else\r
- {\r
- m_limit11 = -n0;\r
- m_limit12 = -n1;\r
- }\r
- }\r
- }\r
- else\r
- {\r
- m_limit11.SetZero();\r
- m_limit12.SetZero();\r
- }\r
-\r
- if (m_edgeA.hasVertex3)\r
- {\r
- b2Vec2 e1 = v2 - v1;\r
- b2Vec2 e2 = v3 - v2;\r
- b2Vec2 n1(e1.y, -e1.x);\r
- b2Vec2 n2(e2.y, -e2.x);\r
- n1.Normalize();\r
- n2.Normalize();\r
-\r
- bool convex = b2Cross(n1, n2) >= 0.0f;\r
- bool front1 = b2Dot(n1, centerB - v1) >= 0.0f;\r
- bool front2 = b2Dot(n2, centerB - v2) >= 0.0f;\r
-\r
- if (convex)\r
- {\r
- if (front1 || front2)\r
- {\r
- m_limit21 = n2;\r
- m_limit22 = n1;\r
- }\r
- else\r
- {\r
- m_limit21 = -n2;\r
- m_limit22 = -n1;\r
- }\r
- }\r
- else\r
- {\r
- if (front1 && front2)\r
- {\r
- m_limit21 = n1;\r
- m_limit22 = n2;\r
- }\r
- else\r
- {\r
- m_limit21 = -n1;\r
- m_limit22 = -n2;\r
- }\r
- }\r
- }\r
- else\r
- {\r
- m_limit21.SetZero();\r
- m_limit22.SetZero();\r
- }\r
-}\r
-\r
-b2EPAxis b2EPCollider::ComputeEdgeSeparation()\r
-{\r
- // EdgeA separation\r
- b2EPAxis bestAxis;\r
- bestAxis.type = b2EPAxis::e_unknown;\r
- bestAxis.index = -1;\r
- bestAxis.separation = -FLT_MAX;\r
- b2Vec2 normals[2] = {m_edgeA.normal, -m_edgeA.normal};\r
- \r
- for (int32 i = 0; i < 2; ++i)\r
- {\r
- b2Vec2 n = normals[i];\r
-\r
- // Adjacency\r
- bool valid1 = b2Cross(n, m_limit11) >= -b2_angularSlop && b2Cross(m_limit12, n) >= -b2_angularSlop;\r
- bool valid2 = b2Cross(n, m_limit21) >= -b2_angularSlop && b2Cross(m_limit22, n) >= -b2_angularSlop;\r
-\r
- if (valid1 == false || valid2 == false)\r
- {\r
- continue;\r
- }\r
- \r
- b2EPAxis axis;\r
- axis.type = b2EPAxis::e_edgeA;\r
- axis.index = i;\r
- axis.separation = FLT_MAX;\r
-\r
- for (int32 j = 0; j < m_proxyB.count; ++j)\r
- {\r
- float32 s = b2Dot(n, m_proxyB.vertices[j] - m_edgeA.v1);\r
- if (s < axis.separation)\r
- {\r
- axis.separation = s;\r
- }\r
- }\r
-\r
- if (axis.separation > m_radius)\r
- {\r
- return axis;\r
- }\r
-\r
- if (axis.separation > bestAxis.separation)\r
- {\r
- bestAxis = axis;\r
- }\r
- }\r
-\r
- return bestAxis;\r
-}\r
-\r
-b2EPAxis b2EPCollider::ComputePolygonSeparation()\r
-{\r
- b2EPAxis axis;\r
- axis.type = b2EPAxis::e_unknown;\r
- axis.index = -1;\r
- axis.separation = -FLT_MAX;\r
- for (int32 i = 0; i < m_proxyB.count; ++i)\r
- {\r
- b2Vec2 n = -m_proxyB.normals[i];\r
-\r
- // Adjacency\r
- bool valid1 = b2Cross(n, m_limit11) >= -b2_angularSlop && b2Cross(m_limit12, n) >= -b2_angularSlop;\r
- bool valid2 = b2Cross(n, m_limit21) >= -b2_angularSlop && b2Cross(m_limit22, n) >= -b2_angularSlop;\r
-\r
- if (valid1 == false && valid2 == false)\r
- {\r
- continue;\r
- }\r
-\r
- float32 s1 = b2Dot(n, m_proxyB.vertices[i] - m_edgeA.v1);\r
- float32 s2 = b2Dot(n, m_proxyB.vertices[i] - m_edgeA.v2);\r
- float32 s = b2Min(s1, s2);\r
-\r
- if (s > m_radius)\r
- {\r
- axis.type = b2EPAxis::e_edgeB;\r
- axis.index = i;\r
- axis.separation = s;\r
- }\r
-\r
- if (s > axis.separation)\r
- {\r
- axis.type = b2EPAxis::e_edgeB;\r
- axis.index = i;\r
- axis.separation = s;\r
- }\r
- }\r
-\r
- return axis;\r
-}\r
-\r
-void b2EPCollider::FindIncidentEdge(b2ClipVertex c[2], const b2EPProxy* proxy1, int32 edge1, const b2EPProxy* proxy2)\r
-{\r
- int32 count1 = proxy1->count;\r
- const b2Vec2* normals1 = proxy1->normals;\r
-\r
- int32 count2 = proxy2->count;\r
- const b2Vec2* vertices2 = proxy2->vertices;\r
- const b2Vec2* normals2 = proxy2->normals;\r
-\r
- b2Assert(0 <= edge1 && edge1 < count1);\r
-\r
- // Get the normal of the reference edge in proxy2's frame.\r
- b2Vec2 normal1 = normals1[edge1];\r
-\r
- // Find the incident edge on proxy2.\r
- int32 index = 0;\r
- float32 minDot = b2_maxFloat;\r
- for (int32 i = 0; i < count2; ++i)\r
- {\r
- float32 dot = b2Dot(normal1, normals2[i]);\r
- if (dot < minDot)\r
- {\r
- minDot = dot;\r
- index = i;\r
- }\r
- }\r
-\r
- // Build the clip vertices for the incident edge.\r
- int32 i1 = index;\r
- int32 i2 = i1 + 1 < count2 ? i1 + 1 : 0;\r
-\r
- c[0].v = vertices2[i1];\r
- c[0].id.cf.indexA = (uint8)edge1;\r
- c[0].id.cf.indexB = (uint8)i1;\r
- c[0].id.cf.typeA = b2ContactFeature::e_face;\r
- c[0].id.cf.typeB = b2ContactFeature::e_vertex;\r
-\r
- c[1].v = vertices2[i2];\r
- c[1].id.cf.indexA = (uint8)edge1;\r
- c[1].id.cf.indexB = (uint8)i2;\r
- c[1].id.cf.typeA = b2ContactFeature::e_face;\r
- c[1].id.cf.typeB = b2ContactFeature::e_vertex;\r
-}\r
-\r
-void b2CollideEdgeAndPolygon( b2Manifold* manifold,\r
- const b2EdgeShape* edgeA, const b2Transform& xfA,\r
- const b2PolygonShape* polygonB, const b2Transform& xfB)\r
-{\r
- b2EPCollider collider(edgeA, xfA, polygonB, xfB);\r
- collider.Collide(manifold);\r
-}\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
int32 i2 = i1 + 1 < count2 ? i1 + 1 : 0;\r
\r
c[0].v = b2Mul(xf2, vertices2[i1]);\r
- c[0].id.cf.indexA = (uint8)edge1;\r
- c[0].id.cf.indexB = (uint8)i1;\r
- c[0].id.cf.typeA = b2ContactFeature::e_face;\r
- c[0].id.cf.typeB = b2ContactFeature::e_vertex;\r
+ c[0].id.features.referenceEdge = (uint8)edge1;\r
+ c[0].id.features.incidentEdge = (uint8)i1;\r
+ c[0].id.features.incidentVertex = 0;\r
\r
c[1].v = b2Mul(xf2, vertices2[i2]);\r
- c[1].id.cf.indexA = (uint8)edge1;\r
- c[1].id.cf.indexB = (uint8)i2;\r
- c[1].id.cf.typeA = b2ContactFeature::e_face;\r
- c[1].id.cf.typeB = b2ContactFeature::e_vertex;\r
+ c[1].id.features.referenceEdge = (uint8)edge1;\r
+ c[1].id.features.incidentEdge = (uint8)i2;\r
+ c[1].id.features.incidentVertex = 1;\r
}\r
\r
// Find edge normal of max separation on A - return if separating axis is found\r
int32 count1 = poly1->m_vertexCount;\r
const b2Vec2* vertices1 = poly1->m_vertices;\r
\r
- int32 iv1 = edge1;\r
- int32 iv2 = edge1 + 1 < count1 ? edge1 + 1 : 0;\r
-\r
- b2Vec2 v11 = vertices1[iv1];\r
- b2Vec2 v12 = vertices1[iv2];\r
+ b2Vec2 v11 = vertices1[edge1];\r
+ b2Vec2 v12 = edge1 + 1 < count1 ? vertices1[edge1+1] : vertices1[0];\r
\r
b2Vec2 localTangent = v12 - v11;\r
localTangent.Normalize();\r
int np;\r
\r
// Clip to box side 1\r
- np = b2ClipSegmentToLine(clipPoints1, incidentEdge, -tangent, sideOffset1, iv1);\r
+ np = b2ClipSegmentToLine(clipPoints1, incidentEdge, -tangent, sideOffset1);\r
\r
if (np < 2)\r
return;\r
\r
// Clip to negative box side 1\r
- np = b2ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2, iv2);\r
+ np = b2ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2);\r
\r
if (np < 2)\r
{\r
b2ManifoldPoint* cp = manifold->points + pointCount;\r
cp->localPoint = b2MulT(xf2, clipPoints2[i].v);\r
cp->id = clipPoints2[i].id;\r
- if (flip)\r
- {\r
- // Swap features\r
- b2ContactFeature cf = cp->id.cf;\r
- cp->id.cf.indexA = cf.indexB;\r
- cp->id.cf.indexB = cf.indexA;\r
- cp->id.cf.typeA = cf.typeB;\r
- cp->id.cf.typeB = cf.typeA;\r
- }\r
+ cp->id.features.flip = flip;\r
++pointCount;\r
}\r
}\r
/*\r
-* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2007-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
// Sutherland-Hodgman clipping.\r
int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2],\r
- const b2Vec2& normal, float32 offset, int32 vertexIndexA)\r
+ const b2Vec2& normal, float32 offset)\r
{\r
// Start with no output points\r
int32 numOut = 0;\r
// Find intersection point of edge and plane\r
float32 interp = distance0 / (distance0 - distance1);\r
vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v);\r
-\r
- // VertexA is hitting edgeB.\r
- vOut[numOut].id.cf.indexA = vertexIndexA;\r
- vOut[numOut].id.cf.indexB = vIn[0].id.cf.indexB;\r
- vOut[numOut].id.cf.typeA = b2ContactFeature::e_vertex;\r
- vOut[numOut].id.cf.typeB = b2ContactFeature::e_face;\r
+ if (distance0 > 0.0f)\r
+ {\r
+ vOut[numOut].id = vIn[0].id;\r
+ }\r
+ else\r
+ {\r
+ vOut[numOut].id = vIn[1].id;\r
+ }\r
++numOut;\r
}\r
\r
return numOut;\r
}\r
\r
-bool b2TestOverlap( const b2Shape* shapeA, int32 indexA,\r
- const b2Shape* shapeB, int32 indexB,\r
- const b2Transform& xfA, const b2Transform& xfB)\r
+bool b2TestOverlap(const b2Shape* shapeA, const b2Shape* shapeB,\r
+ const b2Transform& xfA, const b2Transform& xfB)\r
{\r
b2DistanceInput input;\r
- input.proxyA.Set(shapeA, indexA);\r
- input.proxyB.Set(shapeB, indexB);\r
+ input.proxyA.Set(shapeA);\r
+ input.proxyB.Set(shapeB);\r
input.transformA = xfA;\r
input.transformB = xfB;\r
input.useRadii = true;\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
class b2Shape;\r
class b2CircleShape;\r
-class b2EdgeShape;\r
class b2PolygonShape;\r
\r
const uint8 b2_nullFeature = UCHAR_MAX;\r
\r
-/// The features that intersect to form the contact point\r
-/// This must be 4 bytes or less.\r
-struct b2ContactFeature\r
-{\r
- enum Type\r
- {\r
- e_vertex = 0,\r
- e_face = 1\r
- };\r
-\r
- uint8 indexA; ///< Feature index on shapeA\r
- uint8 indexB; ///< Feature index on shapeB\r
- uint8 typeA; ///< The feature type on shapeA\r
- uint8 typeB; ///< The feature type on shapeB\r
-};\r
-\r
/// Contact ids to facilitate warm starting.\r
union b2ContactID\r
{\r
- b2ContactFeature cf;\r
+ /// The features that intersect to form the contact point\r
+ struct Features\r
+ {\r
+ uint8 referenceEdge; ///< The edge that defines the outward contact normal.\r
+ uint8 incidentEdge; ///< The edge most anti-parallel to the reference edge.\r
+ uint8 incidentVertex; ///< The vertex (0 or 1) on the incident edge that was clipped.\r
+ uint8 flip; ///< A value of 1 indicates that the reference edge is on shape2.\r
+ } features;\r
uint32 key; ///< Used to quickly compare contact ids.\r
};\r
\r
return 0.5f * (upperBound - lowerBound);\r
}\r
\r
- /// Get the perimeter length\r
- float32 GetPerimeter() const\r
- {\r
- float32 wx = upperBound.x - lowerBound.x;\r
- float32 wy = upperBound.y - lowerBound.y;\r
- return 2.0f * (wx + wy);\r
- }\r
-\r
- /// Combine an AABB into this one.\r
- void Combine(const b2AABB& aabb)\r
- {\r
- lowerBound = b2Min(lowerBound, aabb.lowerBound);\r
- upperBound = b2Max(upperBound, aabb.upperBound);\r
- }\r
-\r
/// Combine two AABBs into this one.\r
void Combine(const b2AABB& aabb1, const b2AABB& aabb2)\r
{\r
\r
/// Compute the collision manifold between two circles.\r
void b2CollideCircles(b2Manifold* manifold,\r
- const b2CircleShape* circleA, const b2Transform& xfA,\r
- const b2CircleShape* circleB, const b2Transform& xfB);\r
+ const b2CircleShape* circle1, const b2Transform& xf1,\r
+ const b2CircleShape* circle2, const b2Transform& xf2);\r
\r
/// Compute the collision manifold between a polygon and a circle.\r
void b2CollidePolygonAndCircle(b2Manifold* manifold,\r
- const b2PolygonShape* polygonA, const b2Transform& xfA,\r
- const b2CircleShape* circleB, const b2Transform& xfB);\r
+ const b2PolygonShape* polygon, const b2Transform& xf1,\r
+ const b2CircleShape* circle, const b2Transform& xf2);\r
\r
/// Compute the collision manifold between two polygons.\r
void b2CollidePolygons(b2Manifold* manifold,\r
- const b2PolygonShape* polygonA, const b2Transform& xfA,\r
- const b2PolygonShape* polygonB, const b2Transform& xfB);\r
-\r
-/// Compute the collision manifold between an edge and a circle.\r
-void b2CollideEdgeAndCircle(b2Manifold* manifold,\r
- const b2EdgeShape* polygonA, const b2Transform& xfA,\r
- const b2CircleShape* circleB, const b2Transform& xfB);\r
-\r
-/// Compute the collision manifold between an edge and a circle.\r
-void b2CollideEdgeAndPolygon(b2Manifold* manifold,\r
- const b2EdgeShape* edgeA, const b2Transform& xfA,\r
- const b2PolygonShape* circleB, const b2Transform& xfB);\r
+ const b2PolygonShape* polygon1, const b2Transform& xf1,\r
+ const b2PolygonShape* polygon2, const b2Transform& xf2);\r
\r
/// Clipping for contact manifolds.\r
int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2],\r
- const b2Vec2& normal, float32 offset, int32 vertexIndexA);\r
+ const b2Vec2& normal, float32 offset);\r
\r
/// Determine if two generic shapes overlap.\r
-bool b2TestOverlap( const b2Shape* shapeA, int32 indexA,\r
- const b2Shape* shapeB, int32 indexB,\r
- const b2Transform& xfA, const b2Transform& xfB);\r
+bool b2TestOverlap(const b2Shape* shapeA, const b2Shape* shapeB,\r
+ const b2Transform& xfA, const b2Transform& xfB);\r
\r
// ---------------- Inline Functions ------------------------------------------\r
\r
/*\r
-* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2007-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
#include <Box2D/Collision/b2Distance.h>\r
#include <Box2D/Collision/Shapes/b2CircleShape.h>\r
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>\r
-#include <Box2D/Collision/Shapes/b2LoopShape.h>\r
#include <Box2D/Collision/Shapes/b2PolygonShape.h>\r
\r
// GJK using Voronoi regions (Christer Ericson) and Barycentric coordinates.\r
int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;\r
\r
-void b2DistanceProxy::Set(const b2Shape* shape, int32 index)\r
+void b2DistanceProxy::Set(const b2Shape* shape)\r
{\r
switch (shape->GetType())\r
{\r
}\r
break;\r
\r
- case b2Shape::e_loop:\r
- {\r
- const b2LoopShape* loop = (b2LoopShape*)shape;\r
- b2Assert(0 <= index && index < loop->GetCount());\r
-\r
- m_buffer[0] = loop->GetVertex(index);\r
- if (index + 1 < loop->GetCount())\r
- {\r
- m_buffer[1] = loop->GetVertex(index + 1);\r
- }\r
- else\r
- {\r
- m_buffer[1] = loop->GetVertex(0);\r
- }\r
-\r
- m_vertices = m_buffer;\r
- m_count = 2;\r
- m_radius = loop->m_radius;\r
- }\r
- break;\r
-\r
- case b2Shape::e_edge:\r
- {\r
- const b2EdgeShape* edge = (b2EdgeShape*)shape;\r
- m_vertices = &edge->m_vertex1;\r
- m_count = 2;\r
- m_radius = edge->m_radius;\r
- }\r
- break;\r
-\r
default:\r
b2Assert(false);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#define B2_DISTANCE_H\r
\r
#include <Box2D/Common/b2Math.h>\r
+#include <climits>\r
\r
class b2Shape;\r
\r
\r
/// Initialize the proxy using the given shape. The shape\r
/// must remain in scope while the proxy is in use.\r
- void Set(const b2Shape* shape, int32 index);\r
+ void Set(const b2Shape* shape);\r
\r
/// Get the supporting vertex index in the given direction.\r
int32 GetSupport(const b2Vec2& d) const;\r
/// Get a vertex by index. Used by b2Distance.\r
const b2Vec2& GetVertex(int32 index) const;\r
\r
- b2Vec2 m_buffer[2];\r
const b2Vec2* m_vertices;\r
int32 m_count;\r
float32 m_radius;\r
/*\r
-* Copyright (c) 2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#include <Box2D/Collision/b2DynamicTree.h>\r
#include <cstring>\r
#include <cfloat>\r
-using namespace std;\r
-\r
-\r
-#if B2_USE_DYNAMIC_TREE\r
\r
b2DynamicTree::b2DynamicTree()\r
{\r
\r
m_nodeCapacity = 16;\r
m_nodeCount = 0;\r
- m_nodes = (b2TreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2TreeNode));\r
- memset(m_nodes, 0, m_nodeCapacity * sizeof(b2TreeNode));\r
+ m_nodes = (b2DynamicTreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2DynamicTreeNode));\r
+ memset(m_nodes, 0, m_nodeCapacity * sizeof(b2DynamicTreeNode));\r
\r
// Build a linked list for the free list.\r
for (int32 i = 0; i < m_nodeCapacity - 1; ++i)\r
{\r
m_nodes[i].next = i + 1;\r
- m_nodes[i].height = -1;\r
}\r
m_nodes[m_nodeCapacity-1].next = b2_nullNode;\r
- m_nodes[m_nodeCapacity-1].height = -1;\r
m_freeList = 0;\r
\r
m_path = 0;\r
b2Assert(m_nodeCount == m_nodeCapacity);\r
\r
// The free list is empty. Rebuild a bigger pool.\r
- b2TreeNode* oldNodes = m_nodes;\r
+ b2DynamicTreeNode* oldNodes = m_nodes;\r
m_nodeCapacity *= 2;\r
- m_nodes = (b2TreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2TreeNode));\r
- memcpy(m_nodes, oldNodes, m_nodeCount * sizeof(b2TreeNode));\r
+ m_nodes = (b2DynamicTreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2DynamicTreeNode));\r
+ memcpy(m_nodes, oldNodes, m_nodeCount * sizeof(b2DynamicTreeNode));\r
b2Free(oldNodes);\r
\r
// Build a linked list for the free list. The parent\r
for (int32 i = m_nodeCount; i < m_nodeCapacity - 1; ++i)\r
{\r
m_nodes[i].next = i + 1;\r
- m_nodes[i].height = -1;\r
}\r
m_nodes[m_nodeCapacity-1].next = b2_nullNode;\r
- m_nodes[m_nodeCapacity-1].height = -1;\r
m_freeList = m_nodeCount;\r
}\r
\r
m_nodes[nodeId].parent = b2_nullNode;\r
m_nodes[nodeId].child1 = b2_nullNode;\r
m_nodes[nodeId].child2 = b2_nullNode;\r
- m_nodes[nodeId].height = 0;\r
- m_nodes[nodeId].userData = NULL;\r
++m_nodeCount;\r
return nodeId;\r
}\r
b2Assert(0 <= nodeId && nodeId < m_nodeCapacity);\r
b2Assert(0 < m_nodeCount);\r
m_nodes[nodeId].next = m_freeList;\r
- m_nodes[nodeId].height = -1;\r
m_freeList = nodeId;\r
--m_nodeCount;\r
}\r
m_nodes[proxyId].aabb.lowerBound = aabb.lowerBound - r;\r
m_nodes[proxyId].aabb.upperBound = aabb.upperBound + r;\r
m_nodes[proxyId].userData = userData;\r
- m_nodes[proxyId].height = 0;\r
\r
InsertLeaf(proxyId);\r
\r
+ // Rebalance if necessary.\r
+ int32 iterationCount = m_nodeCount >> 4;\r
+ int32 tryCount = 0;\r
+ int32 height = ComputeHeight();\r
+ while (height > 64 && tryCount < 10)\r
+ {\r
+ Rebalance(iterationCount);\r
+ height = ComputeHeight();\r
+ ++tryCount;\r
+ }\r
+\r
return proxyId;\r
}\r
\r
return;\r
}\r
\r
- // Find the best sibling for this node\r
- b2AABB leafAABB = m_nodes[leaf].aabb;\r
- int32 index = m_root;\r
- while (m_nodes[index].IsLeaf() == false)\r
+ // Find the best sibling for this node.\r
+ b2Vec2 center = m_nodes[leaf].aabb.GetCenter();\r
+ int32 sibling = m_root;\r
+ if (m_nodes[sibling].IsLeaf() == false)\r
{\r
- int32 child1 = m_nodes[index].child1;\r
- int32 child2 = m_nodes[index].child2;\r
-\r
- float32 area = m_nodes[index].aabb.GetPerimeter();\r
+ do \r
+ {\r
+ int32 child1 = m_nodes[sibling].child1;\r
+ int32 child2 = m_nodes[sibling].child2;\r
\r
- b2AABB combinedAABB;\r
- combinedAABB.Combine(m_nodes[index].aabb, leafAABB);\r
- float32 combinedArea = combinedAABB.GetPerimeter();\r
+ b2Vec2 delta1 = b2Abs(m_nodes[child1].aabb.GetCenter() - center);\r
+ b2Vec2 delta2 = b2Abs(m_nodes[child2].aabb.GetCenter() - center);\r
\r
- // Cost of creating a new parent for this node and the new leaf\r
- float32 cost = 2.0f * combinedArea;\r
+ float32 norm1 = delta1.x + delta1.y;\r
+ float32 norm2 = delta2.x + delta2.y;\r
\r
- // Minimum cost of pushing the leaf further down the tree\r
- float32 inheritanceCost = 2.0f * (combinedArea - area);\r
+ if (norm1 < norm2)\r
+ {\r
+ sibling = child1;\r
+ }\r
+ else\r
+ {\r
+ sibling = child2;\r
+ }\r
\r
- // Cost of descending into child1\r
- float32 cost1;\r
- if (m_nodes[child1].IsLeaf())\r
- {\r
- b2AABB aabb;\r
- aabb.Combine(leafAABB, m_nodes[child1].aabb);\r
- cost1 = aabb.GetPerimeter() + inheritanceCost;\r
- }\r
- else\r
- {\r
- b2AABB aabb;\r
- aabb.Combine(leafAABB, m_nodes[child1].aabb);\r
- float32 oldArea = m_nodes[child1].aabb.GetPerimeter();\r
- float32 newArea = aabb.GetPerimeter();\r
- cost1 = (newArea - oldArea) + inheritanceCost;\r
- }\r
-\r
- // Cost of descending into child2\r
- float32 cost2;\r
- if (m_nodes[child2].IsLeaf())\r
- {\r
- b2AABB aabb;\r
- aabb.Combine(leafAABB, m_nodes[child2].aabb);\r
- cost2 = aabb.GetPerimeter() + inheritanceCost;\r
- }\r
- else\r
- {\r
- b2AABB aabb;\r
- aabb.Combine(leafAABB, m_nodes[child2].aabb);\r
- float32 oldArea = m_nodes[child2].aabb.GetPerimeter();\r
- float32 newArea = aabb.GetPerimeter();\r
- cost2 = newArea - oldArea + inheritanceCost;\r
}\r
+ while(m_nodes[sibling].IsLeaf() == false);\r
+ }\r
\r
- // Descend according to the minimum cost.\r
- if (cost < cost1 && cost < cost2)\r
- {\r
- break;\r
- }\r
+ // Create a parent for the siblings.\r
+ int32 node1 = m_nodes[sibling].parent;\r
+ int32 node2 = AllocateNode();\r
+ m_nodes[node2].parent = node1;\r
+ m_nodes[node2].userData = NULL;\r
+ m_nodes[node2].aabb.Combine(m_nodes[leaf].aabb, m_nodes[sibling].aabb);\r
\r
- // Descend\r
- if (cost1 < cost2)\r
+ if (node1 != b2_nullNode)\r
+ {\r
+ if (m_nodes[m_nodes[sibling].parent].child1 == sibling)\r
{\r
- index = child1;\r
+ m_nodes[node1].child1 = node2;\r
}\r
else\r
{\r
- index = child2;\r
+ m_nodes[node1].child2 = node2;\r
}\r
- }\r
\r
- int32 sibling = index;\r
+ m_nodes[node2].child1 = sibling;\r
+ m_nodes[node2].child2 = leaf;\r
+ m_nodes[sibling].parent = node2;\r
+ m_nodes[leaf].parent = node2;\r
\r
- // Create a new parent.\r
- int32 oldParent = m_nodes[sibling].parent;\r
- int32 newParent = AllocateNode();\r
- m_nodes[newParent].parent = oldParent;\r
- m_nodes[newParent].userData = NULL;\r
- m_nodes[newParent].aabb.Combine(leafAABB, m_nodes[sibling].aabb);\r
- m_nodes[newParent].height = m_nodes[sibling].height + 1;\r
-\r
- if (oldParent != b2_nullNode)\r
- {\r
- // The sibling was not the root.\r
- if (m_nodes[oldParent].child1 == sibling)\r
- {\r
- m_nodes[oldParent].child1 = newParent;\r
- }\r
- else\r
+ do \r
{\r
- m_nodes[oldParent].child2 = newParent;\r
- }\r
+ if (m_nodes[node1].aabb.Contains(m_nodes[node2].aabb))\r
+ {\r
+ break;\r
+ }\r
\r
- m_nodes[newParent].child1 = sibling;\r
- m_nodes[newParent].child2 = leaf;\r
- m_nodes[sibling].parent = newParent;\r
- m_nodes[leaf].parent = newParent;\r
+ m_nodes[node1].aabb.Combine(m_nodes[m_nodes[node1].child1].aabb, m_nodes[m_nodes[node1].child2].aabb);\r
+ node2 = node1;\r
+ node1 = m_nodes[node1].parent;\r
+ }\r
+ while(node1 != b2_nullNode);\r
}\r
else\r
{\r
- // The sibling was the root.\r
- m_nodes[newParent].child1 = sibling;\r
- m_nodes[newParent].child2 = leaf;\r
- m_nodes[sibling].parent = newParent;\r
- m_nodes[leaf].parent = newParent;\r
- m_root = newParent;\r
+ m_nodes[node2].child1 = sibling;\r
+ m_nodes[node2].child2 = leaf;\r
+ m_nodes[sibling].parent = node2;\r
+ m_nodes[leaf].parent = node2;\r
+ m_root = node2;\r
}\r
-\r
- // Walk back up the tree fixing heights and AABBs\r
- index = m_nodes[leaf].parent;\r
- while (index != b2_nullNode)\r
- {\r
- index = Balance(index);\r
-\r
- int32 child1 = m_nodes[index].child1;\r
- int32 child2 = m_nodes[index].child2;\r
-\r
- b2Assert(child1 != b2_nullNode);\r
- b2Assert(child2 != b2_nullNode);\r
-\r
- m_nodes[index].height = 1 + b2Max(m_nodes[child1].height, m_nodes[child2].height);\r
- m_nodes[index].aabb.Combine(m_nodes[child1].aabb, m_nodes[child2].aabb);\r
-\r
- index = m_nodes[index].parent;\r
- }\r
-\r
- //Validate();\r
}\r
\r
void b2DynamicTree::RemoveLeaf(int32 leaf)\r
return;\r
}\r
\r
- int32 parent = m_nodes[leaf].parent;\r
- int32 grandParent = m_nodes[parent].parent;\r
+ int32 node2 = m_nodes[leaf].parent;\r
+ int32 node1 = m_nodes[node2].parent;\r
int32 sibling;\r
- if (m_nodes[parent].child1 == leaf)\r
+ if (m_nodes[node2].child1 == leaf)\r
{\r
- sibling = m_nodes[parent].child2;\r
+ sibling = m_nodes[node2].child2;\r
}\r
else\r
{\r
- sibling = m_nodes[parent].child1;\r
+ sibling = m_nodes[node2].child1;\r
}\r
\r
- if (grandParent != b2_nullNode)\r
+ if (node1 != b2_nullNode)\r
{\r
- // Destroy parent and connect sibling to grandParent.\r
- if (m_nodes[grandParent].child1 == parent)\r
+ // Destroy node2 and connect node1 to sibling.\r
+ if (m_nodes[node1].child1 == node2)\r
{\r
- m_nodes[grandParent].child1 = sibling;\r
+ m_nodes[node1].child1 = sibling;\r
}\r
else\r
{\r
- m_nodes[grandParent].child2 = sibling;\r
+ m_nodes[node1].child2 = sibling;\r
}\r
- m_nodes[sibling].parent = grandParent;\r
- FreeNode(parent);\r
+ m_nodes[sibling].parent = node1;\r
+ FreeNode(node2);\r
\r
// Adjust ancestor bounds.\r
- int32 index = grandParent;\r
- while (index != b2_nullNode)\r
+ while (node1 != b2_nullNode)\r
{\r
- index = Balance(index);\r
+ b2AABB oldAABB = m_nodes[node1].aabb;\r
+ m_nodes[node1].aabb.Combine(m_nodes[m_nodes[node1].child1].aabb, m_nodes[m_nodes[node1].child2].aabb);\r
\r
- int32 child1 = m_nodes[index].child1;\r
- int32 child2 = m_nodes[index].child2;\r
-\r
- m_nodes[index].aabb.Combine(m_nodes[child1].aabb, m_nodes[child2].aabb);\r
- m_nodes[index].height = 1 + b2Max(m_nodes[child1].height, m_nodes[child2].height);\r
+ if (oldAABB.Contains(m_nodes[node1].aabb))\r
+ {\r
+ break;\r
+ }\r
\r
- index = m_nodes[index].parent;\r
+ node1 = m_nodes[node1].parent;\r
}\r
}\r
else\r
{\r
m_root = sibling;\r
m_nodes[sibling].parent = b2_nullNode;\r
- FreeNode(parent);\r
- }\r
-\r
- //Validate();\r
-}\r
-\r
-// Perform a left or right rotation if node A is imbalanced.\r
-// Returns the new root index.\r
-int32 b2DynamicTree::Balance(int32 iA)\r
-{\r
- b2Assert(iA != b2_nullNode);\r
-\r
- b2TreeNode* A = m_nodes + iA;\r
- if (A->IsLeaf() || A->height < 2)\r
- {\r
- return iA;\r
- }\r
-\r
- int32 iB = A->child1;\r
- int32 iC = A->child2;\r
- b2Assert(0 <= iB && iB < m_nodeCapacity);\r
- b2Assert(0 <= iC && iC < m_nodeCapacity);\r
-\r
- b2TreeNode* B = m_nodes + iB;\r
- b2TreeNode* C = m_nodes + iC;\r
-\r
- int32 balance = C->height - B->height;\r
-\r
- // Rotate C up\r
- if (balance > 1)\r
- {\r
- int32 iF = C->child1;\r
- int32 iG = C->child2;\r
- b2TreeNode* F = m_nodes + iF;\r
- b2TreeNode* G = m_nodes + iG;\r
- b2Assert(0 <= iF && iF < m_nodeCapacity);\r
- b2Assert(0 <= iG && iG < m_nodeCapacity);\r
-\r
- // Swap A and C\r
- C->child1 = iA;\r
- C->parent = A->parent;\r
- A->parent = iC;\r
-\r
- // A's old parent should point to C\r
- if (C->parent != b2_nullNode)\r
- {\r
- if (m_nodes[C->parent].child1 == iA)\r
- {\r
- m_nodes[C->parent].child1 = iC;\r
- }\r
- else\r
- {\r
- b2Assert(m_nodes[C->parent].child2 == iA);\r
- m_nodes[C->parent].child2 = iC;\r
- }\r
- }\r
- else\r
- {\r
- m_root = iC;\r
- }\r
-\r
- // Rotate\r
- if (F->height > G->height)\r
- {\r
- C->child2 = iF;\r
- A->child2 = iG;\r
- G->parent = iA;\r
- A->aabb.Combine(B->aabb, G->aabb);\r
- C->aabb.Combine(A->aabb, F->aabb);\r
-\r
- A->height = 1 + b2Max(B->height, G->height);\r
- C->height = 1 + b2Max(A->height, F->height);\r
- }\r
- else\r
- {\r
- C->child2 = iG;\r
- A->child2 = iF;\r
- F->parent = iA;\r
- A->aabb.Combine(B->aabb, F->aabb);\r
- C->aabb.Combine(A->aabb, G->aabb);\r
-\r
- A->height = 1 + b2Max(B->height, F->height);\r
- C->height = 1 + b2Max(A->height, G->height);\r
- }\r
-\r
- return iC;\r
+ FreeNode(node2);\r
}\r
- \r
- // Rotate B up\r
- if (balance < -1)\r
- {\r
- int32 iD = B->child1;\r
- int32 iE = B->child2;\r
- b2TreeNode* D = m_nodes + iD;\r
- b2TreeNode* E = m_nodes + iE;\r
- b2Assert(0 <= iD && iD < m_nodeCapacity);\r
- b2Assert(0 <= iE && iE < m_nodeCapacity);\r
-\r
- // Swap A and B\r
- B->child1 = iA;\r
- B->parent = A->parent;\r
- A->parent = iB;\r
-\r
- // A's old parent should point to B\r
- if (B->parent != b2_nullNode)\r
- {\r
- if (m_nodes[B->parent].child1 == iA)\r
- {\r
- m_nodes[B->parent].child1 = iB;\r
- }\r
- else\r
- {\r
- b2Assert(m_nodes[B->parent].child2 == iA);\r
- m_nodes[B->parent].child2 = iB;\r
- }\r
- }\r
- else\r
- {\r
- m_root = iB;\r
- }\r
-\r
- // Rotate\r
- if (D->height > E->height)\r
- {\r
- B->child2 = iD;\r
- A->child1 = iE;\r
- E->parent = iA;\r
- A->aabb.Combine(C->aabb, E->aabb);\r
- B->aabb.Combine(A->aabb, D->aabb);\r
-\r
- A->height = 1 + b2Max(C->height, E->height);\r
- B->height = 1 + b2Max(A->height, D->height);\r
- }\r
- else\r
- {\r
- B->child2 = iE;\r
- A->child1 = iD;\r
- D->parent = iA;\r
- A->aabb.Combine(C->aabb, D->aabb);\r
- B->aabb.Combine(A->aabb, E->aabb);\r
-\r
- A->height = 1 + b2Max(C->height, D->height);\r
- B->height = 1 + b2Max(A->height, E->height);\r
- }\r
-\r
- return iB;\r
- }\r
-\r
- return iA;\r
}\r
\r
-int32 b2DynamicTree::GetHeight() const\r
+void b2DynamicTree::Rebalance(int32 iterations)\r
{\r
if (m_root == b2_nullNode)\r
{\r
- return 0;\r
+ return;\r
}\r
\r
- return m_nodes[m_root].height;\r
-}\r
-\r
-//\r
-float32 b2DynamicTree::GetAreaRatio() const\r
-{\r
- if (m_root == b2_nullNode)\r
+ for (int32 i = 0; i < iterations; ++i)\r
{\r
- return 0.0f;\r
- }\r
+ int32 node = m_root;\r
\r
- const b2TreeNode* root = m_nodes + m_root;\r
- float32 rootArea = root->aabb.GetPerimeter();\r
-\r
- float32 totalArea = 0.0f;\r
- for (int32 i = 0; i < m_nodeCapacity; ++i)\r
- {\r
- const b2TreeNode* node = m_nodes + i;\r
- if (node->height < 0)\r
+ uint32 bit = 0;\r
+ while (m_nodes[node].IsLeaf() == false)\r
{\r
- // Free node in pool\r
- continue;\r
+ int32* children = &m_nodes[node].child1;\r
+ node = children[(m_path >> bit) & 1];\r
+ bit = (bit + 1) & (8* sizeof(uint32) - 1);\r
}\r
+ ++m_path;\r
\r
- totalArea += node->aabb.GetPerimeter();\r
+ RemoveLeaf(node);\r
+ InsertLeaf(node);\r
}\r
-\r
- return totalArea / rootArea;\r
}\r
\r
// Compute the height of a sub-tree.\r
int32 b2DynamicTree::ComputeHeight(int32 nodeId) const\r
{\r
- b2Assert(0 <= nodeId && nodeId < m_nodeCapacity);\r
- b2TreeNode* node = m_nodes + nodeId;\r
-\r
- if (node->IsLeaf())\r
+ if (nodeId == b2_nullNode)\r
{\r
return 0;\r
}\r
\r
+ b2Assert(0 <= nodeId && nodeId < m_nodeCapacity);\r
+ b2DynamicTreeNode* node = m_nodes + nodeId;\r
int32 height1 = ComputeHeight(node->child1);\r
int32 height2 = ComputeHeight(node->child2);\r
return 1 + b2Max(height1, height2);\r
\r
int32 b2DynamicTree::ComputeHeight() const\r
{\r
- int32 height = ComputeHeight(m_root);\r
- return height;\r
-}\r
-\r
-void b2DynamicTree::ValidateStructure(int32 index) const\r
-{\r
- if (index == b2_nullNode)\r
- {\r
- return;\r
- }\r
-\r
- if (index == m_root)\r
- {\r
- b2Assert(m_nodes[index].parent == b2_nullNode);\r
- }\r
-\r
- const b2TreeNode* node = m_nodes + index;\r
-\r
- int32 child1 = node->child1;\r
- int32 child2 = node->child2;\r
-\r
- if (node->IsLeaf())\r
- {\r
- b2Assert(child1 == b2_nullNode);\r
- b2Assert(child2 == b2_nullNode);\r
- b2Assert(node->height == 0);\r
- return;\r
- }\r
-\r
- b2Assert(0 <= child1 && child1 < m_nodeCapacity);\r
- b2Assert(0 <= child2 && child2 < m_nodeCapacity);\r
-\r
- b2Assert(m_nodes[child1].parent == index);\r
- b2Assert(m_nodes[child2].parent == index);\r
-\r
- ValidateStructure(child1);\r
- ValidateStructure(child2);\r
-}\r
-\r
-void b2DynamicTree::ValidateMetrics(int32 index) const\r
-{\r
- if (index == b2_nullNode)\r
- {\r
- return;\r
- }\r
-\r
- const b2TreeNode* node = m_nodes + index;\r
-\r
- int32 child1 = node->child1;\r
- int32 child2 = node->child2;\r
-\r
- if (node->IsLeaf())\r
- {\r
- b2Assert(child1 == b2_nullNode);\r
- b2Assert(child2 == b2_nullNode);\r
- b2Assert(node->height == 0);\r
- return;\r
- }\r
-\r
- b2Assert(0 <= child1 && child1 < m_nodeCapacity);\r
- b2Assert(0 <= child2 && child2 < m_nodeCapacity);\r
-\r
- int32 height1 = m_nodes[child1].height;\r
- int32 height2 = m_nodes[child2].height;\r
- int32 height = 1 + b2Max(height1, height2);\r
- b2Assert(node->height == height);\r
-\r
- b2AABB aabb;\r
- aabb.Combine(m_nodes[child1].aabb, m_nodes[child2].aabb);\r
-\r
- b2Assert(aabb.lowerBound == node->aabb.lowerBound);\r
- b2Assert(aabb.upperBound == node->aabb.upperBound);\r
-\r
- ValidateMetrics(child1);\r
- ValidateMetrics(child2);\r
-}\r
-\r
-void b2DynamicTree::Validate() const\r
-{\r
- ValidateStructure(m_root);\r
- ValidateMetrics(m_root);\r
-\r
- int32 freeCount = 0;\r
- int32 freeIndex = m_freeList;\r
- while (freeIndex != b2_nullNode)\r
- {\r
- b2Assert(0 <= freeIndex && freeIndex < m_nodeCapacity);\r
- freeIndex = m_nodes[freeIndex].next;\r
- ++freeCount;\r
- }\r
-\r
- b2Assert(GetHeight() == ComputeHeight());\r
-\r
- b2Assert(m_nodeCount + freeCount == m_nodeCapacity);\r
-}\r
-\r
-int32 b2DynamicTree::GetMaxBalance() const\r
-{\r
- int32 maxBalance = 0;\r
- for (int32 i = 0; i < m_nodeCapacity; ++i)\r
- {\r
- const b2TreeNode* node = m_nodes + i;\r
- if (node->height <= 1)\r
- {\r
- continue;\r
- }\r
-\r
- b2Assert(node->IsLeaf() == false);\r
-\r
- int32 child1 = node->child1;\r
- int32 child2 = node->child2;\r
- int32 balance = b2Abs(m_nodes[child2].height - m_nodes[child1].height);\r
- maxBalance = b2Max(maxBalance, balance);\r
- }\r
-\r
- return maxBalance;\r
-}\r
-\r
-void b2DynamicTree::RebuildBottomUp()\r
-{\r
- int32* nodes = (int32*)b2Alloc(m_nodeCount * sizeof(int32));\r
- int32 count = 0;\r
-\r
- // Build array of leaves. Free the rest.\r
- for (int32 i = 0; i < m_nodeCapacity; ++i)\r
- {\r
- if (m_nodes[i].height < 0)\r
- {\r
- // free node in pool\r
- continue;\r
- }\r
-\r
- if (m_nodes[i].IsLeaf())\r
- {\r
- m_nodes[i].parent = b2_nullNode;\r
- nodes[count] = i;\r
- ++count;\r
- }\r
- else\r
- {\r
- FreeNode(i);\r
- }\r
- }\r
-\r
- while (count > 1)\r
- {\r
- float32 minCost = b2_maxFloat;\r
- int32 iMin = -1, jMin = -1;\r
- for (int32 i = 0; i < count; ++i)\r
- {\r
- b2AABB aabbi = m_nodes[nodes[i]].aabb;\r
-\r
- for (int32 j = i + 1; j < count; ++j)\r
- {\r
- b2AABB aabbj = m_nodes[nodes[j]].aabb;\r
- b2AABB b;\r
- b.Combine(aabbi, aabbj);\r
- float32 cost = b.GetPerimeter();\r
- if (cost < minCost)\r
- {\r
- iMin = i;\r
- jMin = j;\r
- minCost = cost;\r
- }\r
- }\r
- }\r
-\r
- int32 index1 = nodes[iMin];\r
- int32 index2 = nodes[jMin];\r
- b2TreeNode* child1 = m_nodes + index1;\r
- b2TreeNode* child2 = m_nodes + index2;\r
-\r
- int32 parentIndex = AllocateNode();\r
- b2TreeNode* parent = m_nodes + parentIndex;\r
- parent->child1 = index1;\r
- parent->child2 = index2;\r
- parent->height = 1 + b2Max(child1->height, child2->height);\r
- parent->aabb.Combine(child1->aabb, child2->aabb);\r
- parent->parent = b2_nullNode;\r
-\r
- child1->parent = parentIndex;\r
- child2->parent = parentIndex;\r
-\r
- nodes[jMin] = nodes[count-1];\r
- nodes[iMin] = parentIndex;\r
- --count;\r
- }\r
-\r
- m_root = nodes[0];\r
- b2Free(nodes);\r
-\r
- Validate();\r
-}\r
-\r
-#elif B2_USE_BRUTE_FORCE\r
-\r
-b2DynamicTree::b2DynamicTree()\r
-{\r
- m_proxyCapacity = 128;\r
- m_proxyCount = 0;\r
-\r
- m_proxyMap = (int32*)b2Alloc(m_proxyCapacity * sizeof(int32));\r
- m_proxies = (b2Proxy*)b2Alloc(m_proxyCapacity * sizeof(b2Proxy));\r
-\r
- // Build the free list\r
- m_freeId = 0;\r
- int32 last = m_proxyCapacity - 1;\r
- for (int32 i = m_freeId; i < last; ++i)\r
- {\r
- m_proxyMap[i] = i + 1;\r
- }\r
-\r
- m_proxyMap[last] = b2_nullNode;\r
-}\r
-\r
-b2DynamicTree::~b2DynamicTree()\r
-{\r
- b2Free(m_proxyMap);\r
- b2Free(m_proxies);\r
-}\r
-\r
-int32 b2DynamicTree::CreateProxy(const b2AABB& aabb, void* userData)\r
-{\r
- if (m_proxyCount == m_proxyCapacity)\r
- {\r
- m_proxyCapacity *= 2;\r
- int32* proxyMap = (int32*)b2Alloc(m_proxyCapacity * sizeof(int32));\r
- b2Proxy* proxies = (b2Proxy*)b2Alloc(m_proxyCapacity * sizeof(b2Proxy));\r
-\r
- memcpy(proxyMap, m_proxyMap, m_proxyCount * sizeof(int32));\r
- memcpy(proxies, m_proxies, m_proxyCount * sizeof(b2Proxy));\r
-\r
- b2Free(m_proxyMap);\r
- b2Free(m_proxies);\r
- m_proxyMap = proxyMap;\r
- m_proxies = proxies;\r
- proxyMap = NULL;\r
- proxies = NULL;\r
-\r
- m_freeId = m_proxyCount;\r
- int32 last = m_proxyCapacity - 1;\r
- for (int32 i = m_freeId; i < last; ++i)\r
- {\r
- m_proxyMap[i] = i + 1;\r
- }\r
-\r
- m_proxyMap[last] = b2_nullNode;\r
- }\r
-\r
- b2Assert(0 <= m_freeId && m_freeId < m_proxyCapacity);\r
- int32 id = m_freeId;\r
- m_freeId = m_proxyMap[id];\r
- int32 index = m_proxyCount;\r
-\r
- m_proxies[index].aabb = aabb;\r
- m_proxies[index].userData = userData;\r
- m_proxies[index].id = id;\r
- m_proxyMap[id] = index;\r
- ++m_proxyCount;\r
-\r
- return id;\r
-}\r
-\r
-void b2DynamicTree::DestroyProxy(int32 proxyId)\r
-{\r
- b2Assert(0 < m_proxyCount && 0 <= proxyId && proxyId < m_proxyCapacity);\r
- int32 index = m_proxyMap[proxyId];\r
-\r
- // Add to free list\r
- m_proxyMap[proxyId] = m_freeId;\r
- m_freeId = proxyId;\r
-\r
- // Keep proxy array contiguous\r
- if (index < m_proxyCount - 1)\r
- {\r
- m_proxies[index] = m_proxies[m_proxyCount-1];\r
- int32 id = m_proxies[index].id;\r
- m_proxyMap[id] = index;\r
- }\r
-\r
- --m_proxyCount;\r
-\r
- Validate();\r
+ return ComputeHeight(m_root);\r
}\r
-\r
-bool b2DynamicTree::MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement)\r
-{\r
- b2Assert(0 < m_proxyCount && 0 <= proxyId && proxyId < m_proxyCapacity);\r
- B2_NOT_USED(displacement);\r
-\r
- int32 index = m_proxyMap[proxyId];\r
-\r
- if (m_proxies[index].aabb.Contains(aabb))\r
- {\r
- return false;\r
- }\r
-\r
- // Extend AABB.\r
- b2AABB b = aabb;\r
- b2Vec2 r(b2_aabbExtension, b2_aabbExtension);\r
- b.lowerBound = b.lowerBound - r;\r
- b.upperBound = b.upperBound + r;\r
-\r
- // Predict AABB displacement.\r
- b2Vec2 d = b2_aabbMultiplier * displacement;\r
-\r
- if (d.x < 0.0f)\r
- {\r
- b.lowerBound.x += d.x;\r
- }\r
- else\r
- {\r
- b.upperBound.x += d.x;\r
- }\r
-\r
- if (d.y < 0.0f)\r
- {\r
- b.lowerBound.y += d.y;\r
- }\r
- else\r
- {\r
- b.upperBound.y += d.y;\r
- }\r
-\r
- m_proxies[index].aabb = b;\r
-\r
- return true;\r
-}\r
-\r
-void b2DynamicTree::Validate() const\r
-{\r
- b2Assert(m_proxyCount > 0 || m_freeId == b2_nullNode);\r
- b2Assert(m_freeId == b2_nullNode || m_freeId < m_proxyCapacity);\r
-\r
- int32 id = m_freeId;\r
- int32 freeCount = 0;\r
- while (id != b2_nullNode)\r
- {\r
- ++freeCount;\r
- b2Assert(freeCount <= m_proxyCapacity);\r
- id = m_proxyMap[id];\r
- }\r
-\r
- b2Assert(freeCount + m_proxyCount == m_proxyCapacity);\r
-\r
- b2Assert(m_proxyCount <= m_proxyCapacity);\r
-\r
- for (int32 i = 0; i < m_proxyCount; ++i)\r
- {\r
- int32 id = m_proxies[i].id;\r
-\r
- b2Assert(m_proxyMap[id] == i);\r
- }\r
-}\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#define B2_DYNAMIC_TREE_H\r
\r
#include <Box2D/Collision/b2Collision.h>\r
-#include <Box2D/Common/b2GrowableStack.h>\r
\r
-#define b2_nullNode (-1)\r
-\r
-#define B2_USE_DYNAMIC_TREE 1\r
-#define B2_USE_BRUTE_FORCE 0\r
+/// A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt.\r
\r
-#if B2_USE_DYNAMIC_TREE\r
+#define b2_nullNode (-1)\r
\r
/// A node in the dynamic tree. The client does not interact with this directly.\r
-struct b2TreeNode\r
+struct b2DynamicTreeNode\r
{\r
bool IsLeaf() const\r
{\r
return child1 == b2_nullNode;\r
}\r
\r
- /// Enlarged AABB\r
+ /// This is the fattened AABB.\r
b2AABB aabb;\r
\r
+ //int32 userData;\r
void* userData;\r
\r
union\r
\r
int32 child1;\r
int32 child2;\r
-\r
- // leaf = 0, free node = -1\r
- int32 height;\r
};\r
\r
-/// A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt.\r
/// A dynamic tree arranges data in a binary tree to accelerate\r
/// queries such as volume queries and ray casts. Leafs are proxies\r
/// with an AABB. In the tree we expand the proxy AABB by b2_fatAABBFactor\r
class b2DynamicTree\r
{\r
public:\r
+\r
/// Constructing the tree initializes the node pool.\r
b2DynamicTree();\r
\r
/// @return true if the proxy was re-inserted.\r
bool MoveProxy(int32 proxyId, const b2AABB& aabb1, const b2Vec2& displacement);\r
\r
+ /// Perform some iterations to re-balance the tree.\r
+ void Rebalance(int32 iterations);\r
+\r
/// Get proxy user data.\r
/// @return the proxy user data or 0 if the id is invalid.\r
void* GetUserData(int32 proxyId) const;\r
/// Get the fat AABB for a proxy.\r
const b2AABB& GetFatAABB(int32 proxyId) const;\r
\r
+ /// Compute the height of the tree.\r
+ int32 ComputeHeight() const;\r
+\r
/// Query an AABB for overlapping proxies. The callback class\r
/// is called for each proxy that overlaps the supplied AABB.\r
template <typename T>\r
template <typename T>\r
void RayCast(T* callback, const b2RayCastInput& input) const;\r
\r
- /// Validate this tree. For testing.\r
- void Validate() const;\r
-\r
- /// Compute the height of the binary tree in O(N) time. Should not be\r
- /// called often.\r
- int32 GetHeight() const;\r
-\r
- /// Get the maximum balance of an node in the tree. The balance is the difference\r
- /// in height of the two children of a node.\r
- int32 GetMaxBalance() const;\r
-\r
- /// Get the ratio of the sum of the node areas to the root area.\r
- float32 GetAreaRatio() const;\r
-\r
- /// Build an optimal tree. Very expensive. For testing.\r
- void RebuildBottomUp();\r
-\r
private:\r
\r
int32 AllocateNode();\r
void InsertLeaf(int32 node);\r
void RemoveLeaf(int32 node);\r
\r
- int32 Balance(int32 index);\r
-\r
- int32 ComputeHeight() const;\r
int32 ComputeHeight(int32 nodeId) const;\r
\r
- void ValidateStructure(int32 index) const;\r
- void ValidateMetrics(int32 index) const;\r
-\r
int32 m_root;\r
\r
- b2TreeNode* m_nodes;\r
+ b2DynamicTreeNode* m_nodes;\r
int32 m_nodeCount;\r
int32 m_nodeCapacity;\r
\r
int32 m_freeList;\r
\r
- /// This is used to incrementally traverse the tree for re-balancing.\r
+ /// This is used incrementally traverse the tree for re-balancing.\r
uint32 m_path;\r
\r
int32 m_insertionCount;\r
template <typename T>\r
inline void b2DynamicTree::Query(T* callback, const b2AABB& aabb) const\r
{\r
- b2GrowableStack<int32, 256> stack;\r
- stack.Push(m_root);\r
+ const int32 k_stackSize = 128;\r
+ int32 stack[k_stackSize];\r
+\r
+ int32 count = 0;\r
+ stack[count++] = m_root;\r
\r
- while (stack.GetCount() > 0)\r
+ while (count > 0)\r
{\r
- int32 nodeId = stack.Pop();\r
+ int32 nodeId = stack[--count];\r
if (nodeId == b2_nullNode)\r
{\r
continue;\r
}\r
\r
- const b2TreeNode* node = m_nodes + nodeId;\r
+ const b2DynamicTreeNode* node = m_nodes + nodeId;\r
\r
if (b2TestOverlap(node->aabb, aabb))\r
{\r
}\r
else\r
{\r
- stack.Push(node->child1);\r
- stack.Push(node->child2);\r
+ if (count < k_stackSize)\r
+ {\r
+ stack[count++] = node->child1;\r
+ }\r
+\r
+ if (count < k_stackSize)\r
+ {\r
+ stack[count++] = node->child2;\r
+ }\r
}\r
}\r
}\r
segmentAABB.upperBound = b2Max(p1, t);\r
}\r
\r
- b2GrowableStack<int32, 256> stack;\r
- stack.Push(m_root);\r
+ const int32 k_stackSize = 128;\r
+ int32 stack[k_stackSize];\r
\r
- while (stack.GetCount() > 0)\r
+ int32 count = 0;\r
+ stack[count++] = m_root;\r
+\r
+ while (count > 0)\r
{\r
- int32 nodeId = stack.Pop();\r
+ int32 nodeId = stack[--count];\r
if (nodeId == b2_nullNode)\r
{\r
continue;\r
}\r
\r
- const b2TreeNode* node = m_nodes + nodeId;\r
+ const b2DynamicTreeNode* node = m_nodes + nodeId;\r
\r
if (b2TestOverlap(node->aabb, segmentAABB) == false)\r
{\r
}\r
else\r
{\r
- stack.Push(node->child1);\r
- stack.Push(node->child2);\r
- }\r
- }\r
-}\r
-\r
-#elif B2_USE_BRUTE_FORCE 0\r
-\r
-struct b2Proxy\r
-{\r
- /// This is the fattened AABB.\r
- b2AABB aabb;\r
- void* userData;\r
- int32 id;\r
-};\r
-\r
-/// This implementation is not a tree at all. It is just a cache friendly array of AABBs.\r
-class b2DynamicTree\r
-{\r
-public:\r
-\r
- /// Constructing the tree initializes the node pool.\r
- b2DynamicTree();\r
-\r
- /// Destroy the tree, freeing the node pool.\r
- ~b2DynamicTree();\r
-\r
- /// Create a proxy. Provide a tight fitting AABB and a userData pointer.\r
- int32 CreateProxy(const b2AABB& aabb, void* userData);\r
-\r
- /// Destroy a proxy. This asserts if the id is invalid.\r
- void DestroyProxy(int32 proxyId);\r
-\r
- /// Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB,\r
- /// then the proxy is removed from the tree and re-inserted. Otherwise\r
- /// the function returns immediately.\r
- /// @return true if the proxy was re-inserted.\r
- bool MoveProxy(int32 proxyId, const b2AABB& aabb1, const b2Vec2& displacement);\r
-\r
- /// Perform some iterations to re-balance the tree.\r
- void Rebalance(int32 iterations)\r
- {\r
- B2_NOT_USED(iterations);\r
- }\r
-\r
- /// Get proxy user data.\r
- /// @return the proxy user data or 0 if the id is invalid.\r
- void* GetUserData(int32 proxyId) const;\r
-\r
- /// Get the fat AABB for a proxy.\r
- const b2AABB& GetFatAABB(int32 proxyId) const;\r
-\r
- /// Compute the height of the binary tree in O(N) time. Should not be\r
- /// called often.\r
- int32 ComputeHeight() const\r
- {\r
- return 0;\r
- }\r
-\r
- /// Query an AABB for overlapping proxies. The callback class\r
- /// is called for each proxy that overlaps the supplied AABB.\r
- template <typename T>\r
- void Query(T* callback, const b2AABB& aabb) const;\r
-\r
- /// Ray-cast against the proxies in the tree. This relies on the callback\r
- /// to perform a exact ray-cast in the case were the proxy contains a shape.\r
- /// The callback also performs the any collision filtering. This has performance\r
- /// roughly equal to k * log(n), where k is the number of collisions and n is the\r
- /// number of proxies in the tree.\r
- /// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).\r
- /// @param callback a callback class that is called for each proxy that is hit by the ray.\r
- template <typename T>\r
- void RayCast(T* callback, const b2RayCastInput& input) const;\r
-\r
- void Validate() const;\r
-\r
-private:\r
-\r
- // Map of ids to proxies indices. This may have holes (which contain a free list).\r
- int32* m_proxyMap;\r
-\r
- // Contiguous array of proxies\r
- b2Proxy* m_proxies;\r
-\r
- int32 m_proxyCount;\r
- int32 m_proxyCapacity;\r
-\r
- int32 m_freeId;\r
-};\r
-\r
-inline void* b2DynamicTree::GetUserData(int32 proxyId) const\r
-{\r
- b2Assert(0 <= proxyId && proxyId < m_proxyCapacity);\r
- int32 index = m_proxyMap[proxyId];\r
- return m_proxies[index].userData;\r
-}\r
-\r
-inline const b2AABB& b2DynamicTree::GetFatAABB(int32 proxyId) const\r
-{\r
- b2Assert(0 <= proxyId && proxyId < m_proxyCapacity);\r
- int32 index = m_proxyMap[proxyId];\r
- return m_proxies[index].aabb;\r
-}\r
-\r
-template <typename T>\r
-inline void b2DynamicTree::Query(T* callback, const b2AABB& aabb) const\r
-{\r
- for (int32 i = 0; i < m_proxyCount; ++i)\r
- {\r
- if (b2TestOverlap(m_proxies[i].aabb, aabb))\r
- {\r
- bool proceed = callback->QueryCallback(m_proxies[i].id);\r
- if (proceed == false)\r
+ if (count < k_stackSize)\r
{\r
- return;\r
+ stack[count++] = node->child1;\r
}\r
- }\r
- }\r
-}\r
-\r
-template <typename T>\r
-inline void b2DynamicTree::RayCast(T* callback, const b2RayCastInput& input) const\r
-{\r
- b2Vec2 p1 = input.p1;\r
- b2Vec2 p2 = input.p2;\r
- b2Vec2 r = p2 - p1;\r
- b2Assert(r.LengthSquared() > 0.0f);\r
- r.Normalize();\r
\r
- // v is perpendicular to the segment.\r
- b2Vec2 v = b2Cross(1.0f, r);\r
- b2Vec2 abs_v = b2Abs(v);\r
-\r
- // Separating axis for segment (Gino, p80).\r
- // |dot(v, p1 - c)| > dot(|v|, h)\r
-\r
- float32 maxFraction = input.maxFraction;\r
-\r
- // Build a bounding box for the segment.\r
- b2AABB segmentAABB;\r
- {\r
- b2Vec2 t = p1 + maxFraction * (p2 - p1);\r
- segmentAABB.lowerBound = b2Min(p1, t);\r
- segmentAABB.upperBound = b2Max(p1, t);\r
- }\r
-\r
- for (int32 i = 0; i < m_proxyCount; ++i)\r
- {\r
- const b2Proxy* proxy = m_proxies + i;\r
- b2AABB proxyAABB = proxy->aabb;\r
-\r
- if (b2TestOverlap(proxyAABB, segmentAABB) == false)\r
- {\r
- continue;\r
- }\r
-\r
- // Separating axis for segment (Gino, p80).\r
- // |dot(v, p1 - c)| > dot(|v|, h)\r
- b2Vec2 c = proxyAABB.GetCenter();\r
- b2Vec2 h = proxyAABB.GetExtents();\r
- float32 separation = b2Abs(b2Dot(v, p1 - c)) - b2Dot(abs_v, h);\r
- if (separation > 0.0f)\r
- {\r
- continue;\r
- }\r
-\r
- b2RayCastInput subInput;\r
- subInput.p1 = input.p1;\r
- subInput.p2 = input.p2;\r
- subInput.maxFraction = maxFraction;\r
-\r
- float32 value = callback->RayCastCallback(subInput, proxy->id);\r
-\r
- if (value == 0.0f)\r
- {\r
- // The client has terminated the ray cast.\r
- return;\r
- }\r
-\r
- if (value > 0.0f)\r
- {\r
- // Update segment bounding box.\r
- maxFraction = value;\r
- b2Vec2 t = p1 + maxFraction * (p2 - p1);\r
- segmentAABB.lowerBound = b2Min(p1, t);\r
- segmentAABB.upperBound = b2Max(p1, t);\r
+ if (count < k_stackSize)\r
+ {\r
+ stack[count++] = node->child2;\r
+ }\r
}\r
}\r
}\r
\r
#endif\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2007-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#include <Box2D/Collision/Shapes/b2PolygonShape.h>\r
\r
#include <cstdio>\r
-using namespace std;\r
\r
int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters;\r
int32 b2_toiRootIters, b2_toiMaxRootIters;\r
\r
+int32 b2_toiMaxOptIters;\r
+\r
struct b2SeparationFunction\r
{\r
enum Type\r
\r
float32 Initialize(const b2SimplexCache* cache,\r
const b2DistanceProxy* proxyA, const b2Sweep& sweepA,\r
- const b2DistanceProxy* proxyB, const b2Sweep& sweepB,\r
- float32 t1)\r
+ const b2DistanceProxy* proxyB, const b2Sweep& sweepB)\r
{\r
m_proxyA = proxyA;\r
m_proxyB = proxyB;\r
m_sweepB = sweepB;\r
\r
b2Transform xfA, xfB;\r
- m_sweepA.GetTransform(&xfA, t1);\r
- m_sweepB.GetTransform(&xfB, t1);\r
+ m_sweepA.GetTransform(&xfA, 0.0f);\r
+ m_sweepB.GetTransform(&xfB, 0.0f);\r
\r
if (count == 1)\r
{\r
\r
// Initialize the separating axis.\r
b2SeparationFunction fcn;\r
- fcn.Initialize(&cache, proxyA, sweepA, proxyB, sweepB, t1);\r
+ fcn.Initialize(&cache, proxyA, sweepA, proxyB, sweepB);\r
#if 0\r
// Dump the curve seen by the root finder\r
{\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
#include <Box2D/Common/b2Math.h>\r
#include <Box2D/Collision/b2Distance.h>\r
+#include <climits>\r
\r
/// Input parameters for b2TimeOfImpact\r
struct b2TOIInput\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#include <climits>\r
#include <cstring>\r
#include <memory>\r
-using namespace std;\r
\r
int32 b2BlockAllocator::s_blockSizes[b2_blockSizes] = \r
{\r
if (size == 0)\r
return NULL;\r
\r
- b2Assert(0 < size);\r
-\r
- if (size > b2_maxBlockSize)\r
- {\r
- return b2Alloc(size);\r
- }\r
+ b2Assert(0 < size && size <= b2_maxBlockSize);\r
\r
int32 index = s_blockSizeLookup[size];\r
b2Assert(0 <= index && index < b2_blockSizes);\r
return;\r
}\r
\r
- b2Assert(0 < size);\r
-\r
- if (size > b2_maxBlockSize)\r
- {\r
- b2Free(p);\r
- return;\r
- }\r
+ b2Assert(0 < size && size <= b2_maxBlockSize);\r
\r
int32 index = s_blockSizeLookup[size];\r
b2Assert(0 <= index && index < b2_blockSizes);\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
#include <Box2D/Common/b2Settings.h>\r
\r
-const int32 b2_chunkSize = 16 * 1024;\r
+const int32 b2_chunkSize = 4096;\r
const int32 b2_maxBlockSize = 640;\r
const int32 b2_blockSizes = 14;\r
const int32 b2_chunkArrayIncrement = 128;\r
struct b2Block;\r
struct b2Chunk;\r
\r
-/// This is a small object allocator used for allocating small\r
-/// objects that persist for more than one time step.\r
-/// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp\r
+// This is a small object allocator used for allocating small\r
+// objects that persist for more than one time step.\r
+// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp\r
class b2BlockAllocator\r
{\r
public:\r
b2BlockAllocator();\r
~b2BlockAllocator();\r
\r
- /// Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize.\r
void* Allocate(int32 size);\r
-\r
- /// Free memory. This will use b2Free if the size is larger than b2_maxBlockSize.\r
void Free(void* p, int32 size);\r
\r
void Clear();\r
+++ /dev/null
-/*\r
-* Copyright (c) 2011 Erin Catto http://box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Common/b2Draw.h>\r
-\r
-b2Draw::b2Draw()\r
-{\r
- m_drawFlags = 0;\r
-}\r
-\r
-void b2Draw::SetFlags(uint32 flags)\r
-{\r
- m_drawFlags = flags;\r
-}\r
-\r
-uint32 b2Draw::GetFlags() const\r
-{\r
- return m_drawFlags;\r
-}\r
-\r
-void b2Draw::AppendFlags(uint32 flags)\r
-{\r
- m_drawFlags |= flags;\r
-}\r
-\r
-void b2Draw::ClearFlags(uint32 flags)\r
-{\r
- m_drawFlags &= ~flags;\r
-}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2011 Erin Catto http://box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Common/b2Math.h>\r
-\r
-/// Color for debug drawing. Each value has the range [0,1].\r
-struct b2Color\r
-{\r
- b2Color() {}\r
- b2Color(float32 r, float32 g, float32 b) : r(r), g(g), b(b) {}\r
- void Set(float32 ri, float32 gi, float32 bi) { r = ri; g = gi; b = bi; }\r
- float32 r, g, b;\r
-};\r
-\r
-/// Implement and register this class with a b2World to provide debug drawing of physics\r
-/// entities in your game.\r
-class b2Draw\r
-{\r
-public:\r
- b2Draw();\r
-\r
- virtual ~b2Draw() {}\r
-\r
- enum\r
- {\r
- e_shapeBit = 0x0001, ///< draw shapes\r
- e_jointBit = 0x0002, ///< draw joint connections\r
- e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes\r
- e_pairBit = 0x0008, ///< draw broad-phase pairs\r
- e_centerOfMassBit = 0x0010 ///< draw center of mass frame\r
- };\r
-\r
- /// Set the drawing flags.\r
- void SetFlags(uint32 flags);\r
-\r
- /// Get the drawing flags.\r
- uint32 GetFlags() const;\r
- \r
- /// Append flags to the current flags.\r
- void AppendFlags(uint32 flags);\r
-\r
- /// Clear flags from the current flags.\r
- void ClearFlags(uint32 flags);\r
-\r
- /// Draw a closed polygon provided in CCW order.\r
- virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;\r
-\r
- /// Draw a solid closed polygon provided in CCW order.\r
- virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;\r
-\r
- /// Draw a circle.\r
- virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) = 0;\r
- \r
- /// Draw a solid circle.\r
- virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) = 0;\r
- \r
- /// Draw a line segment.\r
- virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0;\r
-\r
- /// Draw a transform. Choose your own length scale.\r
- /// @param xf a transform.\r
- virtual void DrawTransform(const b2Transform& xf) = 0;\r
-\r
-protected:\r
- uint32 m_drawFlags;\r
-};\r
+++ /dev/null
-/*\r
-* Copyright (c) 2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef B2_GROWABLE_STACK_H\r
-#define B2_GROWABLE_STACK_H\r
-#include <Box2D/Common/b2Settings.h>\r
-#include <cstring>\r
-\r
-/// This is a growable LIFO stack with an initial capacity of N.\r
-/// If the stack size exceeds the initial capacity, the heap is used\r
-/// to increase the size of the stack.\r
-template <typename T, int32 N>\r
-class b2GrowableStack\r
-{\r
-public:\r
- b2GrowableStack()\r
- {\r
- m_stack = m_array;\r
- m_count = 0;\r
- m_capacity = N;\r
- }\r
-\r
- ~b2GrowableStack()\r
- {\r
- if (m_stack != m_array)\r
- {\r
- b2Free(m_stack);\r
- m_stack = NULL;\r
- }\r
- }\r
-\r
- void Push(const T& element)\r
- {\r
- if (m_count == m_capacity)\r
- {\r
- T* old = m_stack;\r
- m_capacity *= 2;\r
- m_stack = (T*)b2Alloc(m_capacity * sizeof(T));\r
- std::memcpy(m_stack, old, m_count * sizeof(T));\r
- if (old != m_array)\r
- {\r
- b2Free(old);\r
- }\r
- }\r
-\r
- m_stack[m_count] = element;\r
- ++m_count;\r
- }\r
-\r
- T Pop()\r
- {\r
- b2Assert(m_count > 0);\r
- --m_count;\r
- return m_stack[m_count];\r
- }\r
-\r
- int32 GetCount()\r
- {\r
- return m_count;\r
- }\r
-\r
-private:\r
- T* m_stack;\r
- T m_array[N];\r
- int32 m_count;\r
- int32 m_capacity;\r
-};\r
-\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2007-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
return x;\r
}\r
\r
-#define b2Sqrt(x) std::sqrt(x)\r
-#define b2Atan2(y, x) std::atan2(y, x)\r
+#define b2Sqrt(x) sqrtf(x)\r
+#define b2Atan2(y, x) atan2f(y, x)\r
+\r
+inline float32 b2Abs(float32 a)\r
+{\r
+ return a > 0.0f ? a : -a;\r
+}\r
\r
/// A 2D column vector.\r
struct b2Vec2\r
return b2IsValid(x) && b2IsValid(y);\r
}\r
\r
- /// Get the skew vector such that dot(skew_vec, other) == cross(vec, other)\r
- b2Vec2 Skew() const\r
- {\r
- return b2Vec2(-y, x);\r
- }\r
-\r
float32 x, y;\r
};\r
\r
struct b2Sweep\r
{\r
/// Get the interpolated transform at a specific time.\r
- /// @param beta is a factor in [0,1], where 0 indicates alpha0.\r
- void GetTransform(b2Transform* xf, float32 beta) const;\r
+ /// @param alpha is a factor in [0,1], where 0 indicates t0.\r
+ void GetTransform(b2Transform* xf, float32 alpha) const;\r
\r
/// Advance the sweep forward, yielding a new initial state.\r
- /// @param alpha the new initial time.\r
- void Advance(float32 alpha);\r
+ /// @param t the new initial time.\r
+ void Advance(float32 t);\r
\r
/// Normalize the angles.\r
void Normalize();\r
b2Vec2 localCenter; ///< local center of mass position\r
b2Vec2 c0, c; ///< center world positions\r
float32 a0, a; ///< world angles\r
-\r
- /// Fraction of the current time step in the range [0,1]\r
- /// c0 and a0 are the positions at alpha0.\r
- float32 alpha0;\r
};\r
\r
\r
return b2MulT(T.R, v - T.position);\r
}\r
\r
-// v2 = A.R' * (B.R * v1 + B.p - A.p) = (A.R' * B.R) * v1 + (B.p - A.p)\r
-inline b2Transform b2MulT(const b2Transform& A, const b2Transform& B)\r
-{\r
- b2Transform C;\r
- C.R = b2MulT(A.R, B.R);\r
- C.position = B.position - A.position;\r
- return C;\r
-}\r
-\r
-template <typename T>\r
-inline T b2Abs(T a)\r
-{\r
- return a > T(0) ? a : -a;\r
-}\r
-\r
inline b2Vec2 b2Abs(const b2Vec2& a)\r
{\r
return b2Vec2(b2Abs(a.x), b2Abs(a.y));\r
return result;\r
}\r
\r
-inline void b2Sweep::GetTransform(b2Transform* xf, float32 beta) const\r
+inline void b2Sweep::GetTransform(b2Transform* xf, float32 alpha) const\r
{\r
- xf->position = (1.0f - beta) * c0 + beta * c;\r
- float32 angle = (1.0f - beta) * a0 + beta * a;\r
+ xf->position = (1.0f - alpha) * c0 + alpha * c;\r
+ float32 angle = (1.0f - alpha) * a0 + alpha * a;\r
xf->R.Set(angle);\r
\r
// Shift to origin\r
xf->position -= b2Mul(xf->R, localCenter);\r
}\r
\r
-inline void b2Sweep::Advance(float32 alpha)\r
+inline void b2Sweep::Advance(float32 t)\r
{\r
- b2Assert(alpha0 < 1.0f);\r
- float32 beta = (alpha - alpha0) / (1.0f - alpha0);\r
- c0 = (1.0f - beta) * c0 + beta * c;\r
- a0 = (1.0f - beta) * a0 + beta * a;\r
- alpha0 = alpha;\r
+ c0 = (1.0f - t) * c0 + t * c;\r
+ a0 = (1.0f - t) * a0 + t * a;\r
}\r
\r
/// Normalize an angle in radians to be between -pi and pi\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#include <Box2D/Common/b2Settings.h>\r
#include <cstdlib>\r
\r
-b2Version b2_version = {2, 2, 0};\r
+b2Version b2_version = {2, 1, 2};\r
\r
// Memory allocators. Modify these to use your own allocator.\r
void* b2Alloc(int32 size)\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
typedef unsigned short uint16;\r
typedef unsigned int uint32;\r
typedef float float32;\r
-typedef double float64;\r
\r
#define b2_maxFloat FLT_MAX\r
#define b2_epsilon FLT_EPSILON\r
/// The maximum number of contact points between two convex shapes.\r
#define b2_maxManifoldPoints 2\r
\r
-/// The maximum number of vertices on a convex polygon. You cannot increase\r
-/// this too much because b2BlockAllocator has a maximum object size.\r
+/// The maximum number of vertices on a convex polygon.\r
#define b2_maxPolygonVertices 8\r
\r
/// This is used to fatten AABBs in the dynamic tree. This allows proxies\r
/// Making it larger may create artifacts for vertex collision.\r
#define b2_polygonRadius (2.0f * b2_linearSlop)\r
\r
-/// Maximum number of sub-steps per contact in continuous physics simulation.\r
-#define b2_maxSubSteps 8\r
-\r
\r
// Dynamics\r
\r
/// to overshoot.\r
#define b2_contactBaumgarte 0.2f\r
\r
-\r
// Sleep\r
\r
/// The time that a body must be still before it will go to sleep.\r
/// Current version.\r
extern b2Version b2_version;\r
\r
+/// Friction mixing law. Feel free to customize this.\r
+inline float32 b2MixFriction(float32 friction1, float32 friction2)\r
+{\r
+ return sqrtf(friction1 * friction2);\r
+}\r
+\r
+/// Restitution mixing law. Feel free to customize this.\r
+inline float32 b2MixRestitution(float32 restitution1, float32 restitution2)\r
+{\r
+ return restitution1 > restitution2 ? restitution1 : restitution2;\r
+}\r
+\r
#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
+++ /dev/null
-/*\r
-* Copyright (c) 2011 Erin Catto http://box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Common/b2Timer.h>\r
-\r
-float64 b2Timer::s_invFrequency = 0.0f;\r
-\r
-#if defined(WIN32)\r
-\r
-#include <Windows.h>\r
-\r
-b2Timer::b2Timer()\r
-{\r
- LARGE_INTEGER largeInteger;\r
-\r
- if (s_invFrequency == 0.0f)\r
- {\r
- QueryPerformanceFrequency(&largeInteger);\r
- s_invFrequency = float64(largeInteger.QuadPart);\r
- if (s_invFrequency > 0.0f)\r
- {\r
- s_invFrequency = 1000.0f / s_invFrequency;\r
- }\r
- }\r
-\r
- QueryPerformanceCounter(&largeInteger);\r
- m_start = float64(largeInteger.QuadPart);\r
-}\r
-\r
-void b2Timer::Reset()\r
-{\r
- LARGE_INTEGER largeInteger;\r
- QueryPerformanceCounter(&largeInteger);\r
- m_start = float64(largeInteger.QuadPart);\r
-}\r
-\r
-float32 b2Timer::GetMilliseconds() const\r
-{\r
- LARGE_INTEGER largeInteger;\r
- QueryPerformanceCounter(&largeInteger);\r
- float64 count = float64(largeInteger.QuadPart);\r
- float32 ms = float32(s_invFrequency * (count - m_start));\r
- return ms;\r
-}\r
-\r
-#else\r
-\r
-b2Timer::b2Timer()\r
-{\r
-}\r
-\r
-void b2Timer::Reset()\r
-{\r
-}\r
-\r
-float32 b2Timer::GetMilliseconds() const\r
-{\r
- return 0.0f;\r
-}\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#include <Box2D/Collision/b2TimeOfImpact.h>\r
\r
#include <new>\r
-using namespace std;\r
\r
-b2Contact* b2CircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator)\r
+b2Contact* b2CircleContact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator)\r
{\r
void* mem = allocator->Allocate(sizeof(b2CircleContact));\r
return new (mem) b2CircleContact(fixtureA, fixtureB);\r
}\r
\r
b2CircleContact::b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB)\r
- : b2Contact(fixtureA, 0, fixtureB, 0)\r
+ : b2Contact(fixtureA, fixtureB)\r
{\r
b2Assert(m_fixtureA->GetType() == b2Shape::e_circle);\r
b2Assert(m_fixtureB->GetType() == b2Shape::e_circle);\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
class b2CircleContact : public b2Contact\r
{\r
public:\r
- static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,\r
- b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);\r
+ static b2Contact* Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator);\r
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);\r
\r
b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB);\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#include <Box2D/Dynamics/Contacts/b2CircleContact.h>\r
#include <Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h>\r
#include <Box2D/Dynamics/Contacts/b2PolygonContact.h>\r
-#include <Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h>\r
-#include <Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h>\r
-#include <Box2D/Dynamics/Contacts/b2LoopAndCircleContact.h>\r
-#include <Box2D/Dynamics/Contacts/b2LoopAndPolygonContact.h>\r
#include <Box2D/Dynamics/Contacts/b2ContactSolver.h>\r
\r
#include <Box2D/Collision/b2Collision.h>\r
AddType(b2CircleContact::Create, b2CircleContact::Destroy, b2Shape::e_circle, b2Shape::e_circle);\r
AddType(b2PolygonAndCircleContact::Create, b2PolygonAndCircleContact::Destroy, b2Shape::e_polygon, b2Shape::e_circle);\r
AddType(b2PolygonContact::Create, b2PolygonContact::Destroy, b2Shape::e_polygon, b2Shape::e_polygon);\r
- AddType(b2EdgeAndCircleContact::Create, b2EdgeAndCircleContact::Destroy, b2Shape::e_edge, b2Shape::e_circle);\r
- AddType(b2EdgeAndPolygonContact::Create, b2EdgeAndPolygonContact::Destroy, b2Shape::e_edge, b2Shape::e_polygon);\r
- AddType(b2LoopAndCircleContact::Create, b2LoopAndCircleContact::Destroy, b2Shape::e_loop, b2Shape::e_circle);\r
- AddType(b2LoopAndPolygonContact::Create, b2LoopAndPolygonContact::Destroy, b2Shape::e_loop, b2Shape::e_polygon);\r
}\r
\r
void b2Contact::AddType(b2ContactCreateFcn* createFcn, b2ContactDestroyFcn* destoryFcn,\r
}\r
}\r
\r
-b2Contact* b2Contact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator)\r
+b2Contact* b2Contact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator)\r
{\r
if (s_initialized == false)\r
{\r
{\r
if (s_registers[type1][type2].primary)\r
{\r
- return createFcn(fixtureA, indexA, fixtureB, indexB, allocator);\r
+ return createFcn(fixtureA, fixtureB, allocator);\r
}\r
else\r
{\r
- return createFcn(fixtureB, indexB, fixtureA, indexA, allocator);\r
+ return createFcn(fixtureB, fixtureA, allocator);\r
}\r
}\r
else\r
destroyFcn(contact, allocator);\r
}\r
\r
-b2Contact::b2Contact(b2Fixture* fA, int32 indexA, b2Fixture* fB, int32 indexB)\r
+b2Contact::b2Contact(b2Fixture* fA, b2Fixture* fB)\r
{\r
m_flags = e_enabledFlag;\r
\r
m_fixtureA = fA;\r
m_fixtureB = fB;\r
\r
- m_indexA = indexA;\r
- m_indexB = indexB;\r
-\r
m_manifold.pointCount = 0;\r
\r
m_prev = NULL;\r
m_nodeB.other = NULL;\r
\r
m_toiCount = 0;\r
-\r
- m_friction = b2MixFriction(m_fixtureA->m_friction, m_fixtureB->m_friction);\r
- m_restitution = b2MixRestitution(m_fixtureA->m_restitution, m_fixtureB->m_restitution);\r
}\r
\r
// Update the contact manifold and touching status.\r
{\r
const b2Shape* shapeA = m_fixtureA->GetShape();\r
const b2Shape* shapeB = m_fixtureB->GetShape();\r
- touching = b2TestOverlap(shapeA, m_indexA, shapeB, m_indexB, xfA, xfB);\r
+ touching = b2TestOverlap(shapeA, shapeB, xfA, xfB);\r
\r
// Sensors don't generate manifolds.\r
m_manifold.pointCount = 0;\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#include <Box2D/Common/b2Math.h>\r
#include <Box2D/Collision/b2Collision.h>\r
#include <Box2D/Collision/Shapes/b2Shape.h>\r
+#include <Box2D/Dynamics/Contacts/b2Contact.h>\r
#include <Box2D/Dynamics/b2Fixture.h>\r
\r
class b2Body;\r
class b2StackAllocator;\r
class b2ContactListener;\r
\r
-/// Friction mixing law. The idea is to allow either fixture to drive the restitution to zero.\r
-/// For example, anything slides on ice.\r
-inline float32 b2MixFriction(float32 friction1, float32 friction2)\r
-{\r
- return std::sqrt(friction1 * friction2);\r
-}\r
-\r
-/// Restitution mixing law. The idea is allow for anything to bounce off an inelastic surface.\r
-/// For example, a superball bounces on anything.\r
-inline float32 b2MixRestitution(float32 restitution1, float32 restitution2)\r
-{\r
- return restitution1 > restitution2 ? restitution1 : restitution2;\r
-}\r
-\r
-typedef b2Contact* b2ContactCreateFcn( b2Fixture* fixtureA, int32 indexA,\r
- b2Fixture* fixtureB, int32 indexB,\r
- b2BlockAllocator* allocator);\r
+typedef b2Contact* b2ContactCreateFcn(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator);\r
typedef void b2ContactDestroyFcn(b2Contact* contact, b2BlockAllocator* allocator);\r
\r
struct b2ContactRegister\r
b2Contact* GetNext();\r
const b2Contact* GetNext() const;\r
\r
- /// Get fixture A in this contact.\r
+ /// Get the first fixture in this contact.\r
b2Fixture* GetFixtureA();\r
const b2Fixture* GetFixtureA() const;\r
\r
- /// Get the child primitive index for fixture A.\r
- int32 GetChildIndexA() const;\r
-\r
- /// Get fixture B in this contact.\r
+ /// Get the second fixture in this contact.\r
b2Fixture* GetFixtureB();\r
const b2Fixture* GetFixtureB() const;\r
\r
- /// Get the child primitive index for fixture B.\r
- int32 GetChildIndexB() const;\r
-\r
- /// Override the default friction mixture. You can call this in b2ContactListener::PreSolve.\r
- /// This value persists until set or reset.\r
- void SetFriction(float32 friction);\r
-\r
- /// Get the friction.\r
- float32 GetFriction() const;\r
-\r
- /// Reset the friction mixture to the default value.\r
- void ResetFriction();\r
-\r
- /// Override the default restitution mixture. You can call this in b2ContactListener::PreSolve.\r
- /// The value persists until you set or reset.\r
- void SetRestitution(float32 restitution);\r
-\r
- /// Get the restitution.\r
- float32 GetRestitution() const;\r
-\r
- /// Reset the restitution to the default value.\r
- void ResetRestitution();\r
-\r
/// Evaluate this contact with your own manifold and transforms.\r
virtual void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) = 0;\r
\r
// This bullet contact had a TOI event\r
e_bulletHitFlag = 0x0010,\r
\r
- // This contact has a valid TOI in m_toi\r
- e_toiFlag = 0x0020\r
};\r
\r
/// Flag this contact for filtering. Filtering will occur the next time step.\r
static void AddType(b2ContactCreateFcn* createFcn, b2ContactDestroyFcn* destroyFcn,\r
b2Shape::Type typeA, b2Shape::Type typeB);\r
static void InitializeRegisters();\r
- static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);\r
+ static b2Contact* Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator);\r
static void Destroy(b2Contact* contact, b2Shape::Type typeA, b2Shape::Type typeB, b2BlockAllocator* allocator);\r
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);\r
\r
b2Contact() : m_fixtureA(NULL), m_fixtureB(NULL) {}\r
- b2Contact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB);\r
+ b2Contact(b2Fixture* fixtureA, b2Fixture* fixtureB);\r
virtual ~b2Contact() {}\r
\r
void Update(b2ContactListener* listener);\r
b2Fixture* m_fixtureA;\r
b2Fixture* m_fixtureB;\r
\r
- int32 m_indexA;\r
- int32 m_indexB;\r
-\r
b2Manifold m_manifold;\r
\r
int32 m_toiCount;\r
- float32 m_toi;\r
-\r
- float32 m_friction;\r
- float32 m_restitution;\r
+// float32 m_toi;\r
};\r
\r
inline b2Manifold* b2Contact::GetManifold()\r
return m_fixtureB;\r
}\r
\r
-inline int32 b2Contact::GetChildIndexA() const\r
-{\r
- return m_indexA;\r
-}\r
-\r
inline const b2Fixture* b2Contact::GetFixtureB() const\r
{\r
return m_fixtureB;\r
}\r
\r
-inline int32 b2Contact::GetChildIndexB() const\r
-{\r
- return m_indexB;\r
-}\r
-\r
inline void b2Contact::FlagForFiltering()\r
{\r
m_flags |= e_filterFlag;\r
}\r
\r
-inline void b2Contact::SetFriction(float32 friction)\r
-{\r
- m_friction = friction;\r
-}\r
-\r
-inline float32 b2Contact::GetFriction() const\r
-{\r
- return m_friction;\r
-}\r
-\r
-inline void b2Contact::ResetFriction()\r
-{\r
- m_friction = b2MixFriction(m_fixtureA->m_friction, m_fixtureB->m_friction);\r
-}\r
-\r
-inline void b2Contact::SetRestitution(float32 restitution)\r
-{\r
- m_restitution = restitution;\r
-}\r
-\r
-inline float32 b2Contact::GetRestitution() const\r
-{\r
- return m_restitution;\r
-}\r
-\r
-inline void b2Contact::ResetRestitution()\r
-{\r
- m_restitution = b2MixRestitution(m_fixtureA->m_restitution, m_fixtureB->m_restitution);\r
-}\r
-\r
#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
*/\r
\r
#include <Box2D/Dynamics/Contacts/b2ContactSolver.h>\r
-\r
-\r
#include <Box2D/Dynamics/Contacts/b2Contact.h>\r
#include <Box2D/Dynamics/b2Body.h>\r
#include <Box2D/Dynamics/b2Fixture.h>\r
\r
#define B2_DEBUG_SOLVER 0\r
\r
-b2ContactSolver::b2ContactSolver(b2ContactSolverDef* def)\r
+b2ContactSolver::b2ContactSolver(b2Contact** contacts, int32 contactCount,\r
+ b2StackAllocator* allocator, float32 impulseRatio)\r
{\r
- m_allocator = def->allocator;\r
+ m_allocator = allocator;\r
\r
- m_count = def->count;\r
- m_constraints = (b2ContactConstraint*)m_allocator->Allocate(m_count * sizeof(b2ContactConstraint));\r
+ m_constraintCount = contactCount;\r
+ m_constraints = (b2ContactConstraint*)m_allocator->Allocate(m_constraintCount * sizeof(b2ContactConstraint));\r
\r
- // Initialize position independent portions of the constraints.\r
- for (int32 i = 0; i < m_count; ++i)\r
+ for (int32 i = 0; i < m_constraintCount; ++i)\r
{\r
- b2Contact* contact = def->contacts[i];\r
+ b2Contact* contact = contacts[i];\r
\r
b2Fixture* fixtureA = contact->m_fixtureA;\r
b2Fixture* fixtureB = contact->m_fixtureB;\r
b2Body* bodyB = fixtureB->GetBody();\r
b2Manifold* manifold = contact->GetManifold();\r
\r
+ float32 friction = b2MixFriction(fixtureA->GetFriction(), fixtureB->GetFriction());\r
+ float32 restitution = b2MixRestitution(fixtureA->GetRestitution(), fixtureB->GetRestitution());\r
+\r
+ b2Vec2 vA = bodyA->m_linearVelocity;\r
+ b2Vec2 vB = bodyB->m_linearVelocity;\r
+ float32 wA = bodyA->m_angularVelocity;\r
+ float32 wB = bodyB->m_angularVelocity;\r
+\r
b2Assert(manifold->pointCount > 0);\r
\r
+ b2WorldManifold worldManifold;\r
+ worldManifold.Initialize(manifold, bodyA->m_xf, radiusA, bodyB->m_xf, radiusB);\r
+\r
b2ContactConstraint* cc = m_constraints + i;\r
- cc->friction = contact->m_friction;\r
- cc->restitution = contact->m_restitution;\r
cc->bodyA = bodyA;\r
cc->bodyB = bodyB;\r
cc->manifold = manifold;\r
- cc->normal.SetZero();\r
+ cc->normal = worldManifold.normal;\r
cc->pointCount = manifold->pointCount;\r
+ cc->friction = friction;\r
\r
cc->localNormal = manifold->localNormal;\r
cc->localPoint = manifold->localPoint;\r
- cc->radiusA = radiusA;\r
- cc->radiusB = radiusB;\r
+ cc->radius = radiusA + radiusB;\r
cc->type = manifold->type;\r
\r
for (int32 j = 0; j < cc->pointCount; ++j)\r
b2ManifoldPoint* cp = manifold->points + j;\r
b2ContactConstraintPoint* ccp = cc->points + j;\r
\r
- if (def->warmStarting)\r
- {\r
- ccp->normalImpulse = def->impulseRatio * cp->normalImpulse;\r
- ccp->tangentImpulse = def->impulseRatio * cp->tangentImpulse;\r
- }\r
- else\r
- {\r
- ccp->normalImpulse = 0.0f;\r
- ccp->tangentImpulse = 0.0f;\r
- }\r
+ ccp->normalImpulse = impulseRatio * cp->normalImpulse;\r
+ ccp->tangentImpulse = impulseRatio * cp->tangentImpulse;\r
\r
ccp->localPoint = cp->localPoint;\r
- ccp->rA.SetZero();\r
- ccp->rB.SetZero();\r
- ccp->normalMass = 0.0f;\r
- ccp->tangentMass = 0.0f;\r
- ccp->velocityBias = 0.0f;\r
- }\r
-\r
- cc->K.SetZero();\r
- cc->normalMass.SetZero();\r
- }\r
-}\r
-\r
-b2ContactSolver::~b2ContactSolver()\r
-{\r
- m_allocator->Free(m_constraints);\r
-}\r
-\r
-// Initialize position dependent portions of the velocity constraints.\r
-void b2ContactSolver::InitializeVelocityConstraints()\r
-{\r
- for (int32 i = 0; i < m_count; ++i)\r
- {\r
- b2ContactConstraint* cc = m_constraints + i;\r
-\r
- float32 radiusA = cc->radiusA;\r
- float32 radiusB = cc->radiusB;\r
- b2Body* bodyA = cc->bodyA;\r
- b2Body* bodyB = cc->bodyB;\r
- b2Manifold* manifold = cc->manifold;\r
-\r
- b2Vec2 vA = bodyA->m_linearVelocity;\r
- b2Vec2 vB = bodyB->m_linearVelocity;\r
- float32 wA = bodyA->m_angularVelocity;\r
- float32 wB = bodyB->m_angularVelocity;\r
-\r
- b2Assert(manifold->pointCount > 0);\r
-\r
- b2WorldManifold worldManifold;\r
- worldManifold.Initialize(manifold, bodyA->m_xf, radiusA, bodyB->m_xf, radiusB);\r
-\r
- cc->normal = worldManifold.normal;\r
-\r
- for (int32 j = 0; j < cc->pointCount; ++j)\r
- {\r
- b2ContactConstraintPoint* ccp = cc->points + j;\r
\r
ccp->rA = worldManifold.points[j] - bodyA->m_sweep.c;\r
ccp->rB = worldManifold.points[j] - bodyB->m_sweep.c;\r
float32 vRel = b2Dot(cc->normal, vB + b2Cross(wB, ccp->rB) - vA - b2Cross(wA, ccp->rA));\r
if (vRel < -b2_velocityThreshold)\r
{\r
- ccp->velocityBias = -cc->restitution * vRel;\r
+ ccp->velocityBias = -restitution * vRel;\r
}\r
}\r
\r
{\r
b2ContactConstraintPoint* ccp1 = cc->points + 0;\r
b2ContactConstraintPoint* ccp2 = cc->points + 1;\r
-\r
+ \r
float32 invMassA = bodyA->m_invMass;\r
float32 invIA = bodyA->m_invI;\r
float32 invMassB = bodyB->m_invMass;\r
float32 k12 = invMassA + invMassB + invIA * rn1A * rn2A + invIB * rn1B * rn2B;\r
\r
// Ensure a reasonable condition number.\r
- const float32 k_maxConditionNumber = 1000.0f;\r
+ const float32 k_maxConditionNumber = 100.0f;\r
if (k11 * k11 < k_maxConditionNumber * (k11 * k22 - k12 * k12))\r
{\r
// K is safe to invert.\r
}\r
}\r
\r
+b2ContactSolver::~b2ContactSolver()\r
+{\r
+ m_allocator->Free(m_constraints);\r
+}\r
+\r
void b2ContactSolver::WarmStart()\r
{\r
// Warm start.\r
- for (int32 i = 0; i < m_count; ++i)\r
+ for (int32 i = 0; i < m_constraintCount; ++i)\r
{\r
b2ContactConstraint* c = m_constraints + i;\r
\r
\r
void b2ContactSolver::SolveVelocityConstraints()\r
{\r
- for (int32 i = 0; i < m_count; ++i)\r
+ for (int32 i = 0; i < m_constraintCount; ++i)\r
{\r
b2ContactConstraint* c = m_constraints + i;\r
b2Body* bodyA = c->bodyA;\r
\r
void b2ContactSolver::StoreImpulses()\r
{\r
- for (int32 i = 0; i < m_count; ++i)\r
+ for (int32 i = 0; i < m_constraintCount; ++i)\r
{\r
b2ContactConstraint* c = m_constraints + i;\r
b2Manifold* m = c->manifold;\r
}\r
\r
point = 0.5f * (pointA + pointB);\r
- separation = b2Dot(pointB - pointA, normal) - cc->radiusA - cc->radiusB;\r
+ separation = b2Dot(pointB - pointA, normal) - cc->radius;\r
}\r
break;\r
\r
b2Vec2 planePoint = cc->bodyA->GetWorldPoint(cc->localPoint);\r
\r
b2Vec2 clipPoint = cc->bodyB->GetWorldPoint(cc->points[index].localPoint);\r
- separation = b2Dot(clipPoint - planePoint, normal) - cc->radiusA - cc->radiusB;\r
+ separation = b2Dot(clipPoint - planePoint, normal) - cc->radius;\r
point = clipPoint;\r
}\r
break;\r
b2Vec2 planePoint = cc->bodyB->GetWorldPoint(cc->localPoint);\r
\r
b2Vec2 clipPoint = cc->bodyA->GetWorldPoint(cc->points[index].localPoint);\r
- separation = b2Dot(clipPoint - planePoint, normal) - cc->radiusA - cc->radiusB;\r
+ separation = b2Dot(clipPoint - planePoint, normal) - cc->radius;\r
point = clipPoint;\r
\r
// Ensure normal points from A to B\r
{\r
float32 minSeparation = 0.0f;\r
\r
- for (int32 i = 0; i < m_count; ++i)\r
+ for (int32 i = 0; i < m_constraintCount; ++i)\r
{\r
b2ContactConstraint* c = m_constraints + i;\r
b2Body* bodyA = c->bodyA;\r
// push the separation above -b2_linearSlop.\r
return minSeparation >= -1.5f * b2_linearSlop;\r
}\r
-\r
-// Sequential position solver for position constraints.\r
-bool b2ContactSolver::SolveTOIPositionConstraints(float32 baumgarte, const b2Body* toiBodyA, const b2Body* toiBodyB)\r
-{\r
- float32 minSeparation = 0.0f;\r
-\r
- for (int32 i = 0; i < m_count; ++i)\r
- {\r
- b2ContactConstraint* c = m_constraints + i;\r
- b2Body* bodyA = c->bodyA;\r
- b2Body* bodyB = c->bodyB;\r
-\r
- float32 massA = 0.0f;\r
- if (bodyA == toiBodyA || bodyA == toiBodyB)\r
- {\r
- massA = bodyA->m_mass;\r
- }\r
-\r
- float32 massB = 0.0f;\r
- if (bodyB == toiBodyA || bodyB == toiBodyB)\r
- {\r
- massB = bodyB->m_mass;\r
- }\r
-\r
- float32 invMassA = bodyA->m_mass * bodyA->m_invMass;\r
- float32 invIA = bodyA->m_mass * bodyA->m_invI;\r
- float32 invMassB = bodyB->m_mass * bodyB->m_invMass;\r
- float32 invIB = bodyB->m_mass * bodyB->m_invI;\r
-\r
- // Solve normal constraints\r
- for (int32 j = 0; j < c->pointCount; ++j)\r
- {\r
- b2PositionSolverManifold psm;\r
- psm.Initialize(c, j);\r
- b2Vec2 normal = psm.normal;\r
-\r
- b2Vec2 point = psm.point;\r
- float32 separation = psm.separation;\r
-\r
- b2Vec2 rA = point - bodyA->m_sweep.c;\r
- b2Vec2 rB = point - bodyB->m_sweep.c;\r
-\r
- // Track max constraint error.\r
- minSeparation = b2Min(minSeparation, separation);\r
-\r
- // Prevent large corrections and allow slop.\r
- float32 C = b2Clamp(baumgarte * (separation + b2_linearSlop), -b2_maxLinearCorrection, 0.0f);\r
-\r
- // Compute the effective mass.\r
- float32 rnA = b2Cross(rA, normal);\r
- float32 rnB = b2Cross(rB, normal);\r
- float32 K = invMassA + invMassB + invIA * rnA * rnA + invIB * rnB * rnB;\r
-\r
- // Compute normal impulse\r
- float32 impulse = K > 0.0f ? - C / K : 0.0f;\r
-\r
- b2Vec2 P = impulse * normal;\r
-\r
- bodyA->m_sweep.c -= invMassA * P;\r
- bodyA->m_sweep.a -= invIA * b2Cross(rA, P);\r
- bodyA->SynchronizeTransform();\r
-\r
- bodyB->m_sweep.c += invMassB * P;\r
- bodyB->m_sweep.a += invIB * b2Cross(rB, P);\r
- bodyB->SynchronizeTransform();\r
- }\r
- }\r
-\r
- // We can't expect minSpeparation >= -b2_linearSlop because we don't\r
- // push the separation above -b2_linearSlop.\r
- return minSeparation >= -1.5f * b2_linearSlop;\r
-}\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2Body* bodyA;\r
b2Body* bodyB;\r
b2Manifold::Type type;\r
- float32 radiusA, radiusB;\r
+ float32 radius;\r
float32 friction;\r
- float32 restitution;\r
int32 pointCount;\r
b2Manifold* manifold;\r
};\r
\r
-struct b2ContactSolverDef\r
-{\r
- b2Contact** contacts;\r
- int32 count;\r
- b2StackAllocator* allocator;\r
- float32 impulseRatio;\r
- bool warmStarting;\r
-};\r
-\r
class b2ContactSolver\r
{\r
public:\r
- b2ContactSolver(b2ContactSolverDef* def);\r
- ~b2ContactSolver();\r
+ b2ContactSolver(b2Contact** contacts, int32 contactCount,\r
+ b2StackAllocator* allocator, float32 impulseRatio);\r
\r
- void InitializeVelocityConstraints();\r
+ ~b2ContactSolver();\r
\r
void WarmStart();\r
void SolveVelocityConstraints();\r
void StoreImpulses();\r
\r
bool SolvePositionConstraints(float32 baumgarte);\r
- bool SolveTOIPositionConstraints(float32 baumgarte, const b2Body* toiBodyA, const b2Body* toiBodyB);\r
\r
b2StackAllocator* m_allocator;\r
b2ContactConstraint* m_constraints;\r
- int m_count;\r
+ int m_constraintCount;\r
};\r
\r
#endif\r
-\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h>\r
-#include <Box2D/Common/b2BlockAllocator.h>\r
-#include <Box2D/Dynamics/b2Fixture.h>\r
-\r
-#include <new>\r
-using namespace std;\r
-\r
-b2Contact* b2EdgeAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator)\r
-{\r
- void* mem = allocator->Allocate(sizeof(b2EdgeAndCircleContact));\r
- return new (mem) b2EdgeAndCircleContact(fixtureA, fixtureB);\r
-}\r
-\r
-void b2EdgeAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)\r
-{\r
- ((b2EdgeAndCircleContact*)contact)->~b2EdgeAndCircleContact();\r
- allocator->Free(contact, sizeof(b2EdgeAndCircleContact));\r
-}\r
-\r
-b2EdgeAndCircleContact::b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB)\r
-: b2Contact(fixtureA, 0, fixtureB, 0)\r
-{\r
- b2Assert(m_fixtureA->GetType() == b2Shape::e_edge);\r
- b2Assert(m_fixtureB->GetType() == b2Shape::e_circle);\r
-}\r
-\r
-void b2EdgeAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)\r
-{\r
- b2CollideEdgeAndCircle( manifold,\r
- (b2EdgeShape*)m_fixtureA->GetShape(), xfA,\r
- (b2CircleShape*)m_fixtureB->GetShape(), xfB);\r
-}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef B2_EDGE_AND_CIRCLE_CONTACT_H\r
-#define B2_EDGE_AND_CIRCLE_CONTACT_H\r
-\r
-#include <Box2D/Dynamics/Contacts/b2Contact.h>\r
-\r
-class b2BlockAllocator;\r
-\r
-class b2EdgeAndCircleContact : public b2Contact\r
-{\r
-public:\r
- static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,\r
- b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);\r
- static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);\r
-\r
- b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB);\r
- ~b2EdgeAndCircleContact() {}\r
-\r
- void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);\r
-};\r
-\r
-#endif\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h>\r
-#include <Box2D/Common/b2BlockAllocator.h>\r
-#include <Box2D/Dynamics/b2Fixture.h>\r
-\r
-#include <new>\r
-using namespace std;\r
-\r
-b2Contact* b2EdgeAndPolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator)\r
-{\r
- void* mem = allocator->Allocate(sizeof(b2EdgeAndPolygonContact));\r
- return new (mem) b2EdgeAndPolygonContact(fixtureA, fixtureB);\r
-}\r
-\r
-void b2EdgeAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)\r
-{\r
- ((b2EdgeAndPolygonContact*)contact)->~b2EdgeAndPolygonContact();\r
- allocator->Free(contact, sizeof(b2EdgeAndPolygonContact));\r
-}\r
-\r
-b2EdgeAndPolygonContact::b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB)\r
-: b2Contact(fixtureA, 0, fixtureB, 0)\r
-{\r
- b2Assert(m_fixtureA->GetType() == b2Shape::e_edge);\r
- b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon);\r
-}\r
-\r
-void b2EdgeAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)\r
-{\r
- b2CollideEdgeAndPolygon( manifold,\r
- (b2EdgeShape*)m_fixtureA->GetShape(), xfA,\r
- (b2PolygonShape*)m_fixtureB->GetShape(), xfB);\r
-}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef B2_EDGE_AND_POLYGON_CONTACT_H\r
-#define B2_EDGE_AND_POLYGON_CONTACT_H\r
-\r
-#include <Box2D/Dynamics/Contacts/b2Contact.h>\r
-\r
-class b2BlockAllocator;\r
-\r
-class b2EdgeAndPolygonContact : public b2Contact\r
-{\r
-public:\r
- static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,\r
- b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);\r
- static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);\r
-\r
- b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB);\r
- ~b2EdgeAndPolygonContact() {}\r
-\r
- void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);\r
-};\r
-\r
-#endif\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Dynamics/Contacts/b2LoopAndCircleContact.h>\r
-#include <Box2D/Common/b2BlockAllocator.h>\r
-#include <Box2D/Dynamics/b2Fixture.h>\r
-#include <Box2D/Collision/Shapes/b2LoopShape.h>\r
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>\r
-\r
-#include <new>\r
-using namespace std;\r
-\r
-b2Contact* b2LoopAndCircleContact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator)\r
-{\r
- void* mem = allocator->Allocate(sizeof(b2LoopAndCircleContact));\r
- return new (mem) b2LoopAndCircleContact(fixtureA, indexA, fixtureB, indexB);\r
-}\r
-\r
-void b2LoopAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)\r
-{\r
- ((b2LoopAndCircleContact*)contact)->~b2LoopAndCircleContact();\r
- allocator->Free(contact, sizeof(b2LoopAndCircleContact));\r
-}\r
-\r
-b2LoopAndCircleContact::b2LoopAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB)\r
-: b2Contact(fixtureA, indexA, fixtureB, indexB)\r
-{\r
- b2Assert(m_fixtureA->GetType() == b2Shape::e_loop);\r
- b2Assert(m_fixtureB->GetType() == b2Shape::e_circle);\r
-}\r
-\r
-void b2LoopAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)\r
-{\r
- b2LoopShape* loop = (b2LoopShape*)m_fixtureA->GetShape();\r
- b2EdgeShape edge;\r
- loop->GetChildEdge(&edge, m_indexA);\r
- b2CollideEdgeAndCircle( manifold, &edge, xfA,\r
- (b2CircleShape*)m_fixtureB->GetShape(), xfB);\r
-}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef B2_LOOP_AND_CIRCLE_CONTACT_H\r
-#define B2_LOOP_AND_CIRCLE_CONTACT_H\r
-\r
-#include <Box2D/Dynamics/Contacts/b2Contact.h>\r
-\r
-class b2BlockAllocator;\r
-\r
-class b2LoopAndCircleContact : public b2Contact\r
-{\r
-public:\r
- static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,\r
- b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);\r
- static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);\r
-\r
- b2LoopAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB);\r
- ~b2LoopAndCircleContact() {}\r
-\r
- void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);\r
-};\r
-\r
-#endif\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Dynamics/Contacts/b2LoopAndPolygonContact.h>\r
-#include <Box2D/Common/b2BlockAllocator.h>\r
-#include <Box2D/Dynamics/b2Fixture.h>\r
-#include <Box2D/Collision/Shapes/b2LoopShape.h>\r
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>\r
-\r
-#include <new>\r
-using namespace std;\r
-\r
-b2Contact* b2LoopAndPolygonContact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator)\r
-{\r
- void* mem = allocator->Allocate(sizeof(b2LoopAndPolygonContact));\r
- return new (mem) b2LoopAndPolygonContact(fixtureA, indexA, fixtureB, indexB);\r
-}\r
-\r
-void b2LoopAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator)\r
-{\r
- ((b2LoopAndPolygonContact*)contact)->~b2LoopAndPolygonContact();\r
- allocator->Free(contact, sizeof(b2LoopAndPolygonContact));\r
-}\r
-\r
-b2LoopAndPolygonContact::b2LoopAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB)\r
-: b2Contact(fixtureA, indexA, fixtureB, indexB)\r
-{\r
- b2Assert(m_fixtureA->GetType() == b2Shape::e_loop);\r
- b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon);\r
-}\r
-\r
-void b2LoopAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB)\r
-{\r
- b2LoopShape* loop = (b2LoopShape*)m_fixtureA->GetShape();\r
- b2EdgeShape edge;\r
- loop->GetChildEdge(&edge, m_indexA);\r
- b2CollideEdgeAndPolygon( manifold, &edge, xfA,\r
- (b2PolygonShape*)m_fixtureB->GetShape(), xfB);\r
-}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef B2_LOOP_AND_POLYGON_CONTACT_H\r
-#define B2_LOOP_AND_POLYGON_CONTACT_H\r
-\r
-#include <Box2D/Dynamics/Contacts/b2Contact.h>\r
-\r
-class b2BlockAllocator;\r
-\r
-class b2LoopAndPolygonContact : public b2Contact\r
-{\r
-public:\r
- static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,\r
- b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);\r
- static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);\r
-\r
- b2LoopAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB);\r
- ~b2LoopAndPolygonContact() {}\r
-\r
- void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB);\r
-};\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
#include <Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h>\r
#include <Box2D/Common/b2BlockAllocator.h>\r
+#include <Box2D/Collision/b2TimeOfImpact.h>\r
+#include <Box2D/Dynamics/b2Body.h>\r
#include <Box2D/Dynamics/b2Fixture.h>\r
+#include <Box2D/Dynamics/b2WorldCallbacks.h>\r
\r
#include <new>\r
-using namespace std;\r
\r
-b2Contact* b2PolygonAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator)\r
+b2Contact* b2PolygonAndCircleContact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator)\r
{\r
void* mem = allocator->Allocate(sizeof(b2PolygonAndCircleContact));\r
return new (mem) b2PolygonAndCircleContact(fixtureA, fixtureB);\r
}\r
\r
b2PolygonAndCircleContact::b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB)\r
-: b2Contact(fixtureA, 0, fixtureB, 0)\r
+: b2Contact(fixtureA, fixtureB)\r
{\r
b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon);\r
b2Assert(m_fixtureB->GetType() == b2Shape::e_circle);\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
class b2PolygonAndCircleContact : public b2Contact\r
{\r
public:\r
- static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);\r
+ static b2Contact* Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator);\r
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);\r
\r
b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB);\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#include <Box2D/Dynamics/b2WorldCallbacks.h>\r
\r
#include <new>\r
-using namespace std;\r
\r
-b2Contact* b2PolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator)\r
+b2Contact* b2PolygonContact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator)\r
{\r
void* mem = allocator->Allocate(sizeof(b2PolygonContact));\r
return new (mem) b2PolygonContact(fixtureA, fixtureB);\r
}\r
\r
b2PolygonContact::b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB)\r
- : b2Contact(fixtureA, 0, fixtureB, 0)\r
+ : b2Contact(fixtureA, fixtureB)\r
{\r
b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon);\r
b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon);\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
class b2PolygonContact : public b2Contact\r
{\r
public:\r
- static b2Contact* Create( b2Fixture* fixtureA, int32 indexA,\r
- b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator);\r
+ static b2Contact* Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator);\r
static void Destroy(b2Contact* contact, b2BlockAllocator* allocator);\r
\r
b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB);\r
--- /dev/null
+/*\r
+* Copyright (c) 2006-2010 Erin Catto http://www.gphysics.com\r
+*\r
+* This software is provided 'as-is', without any express or implied\r
+* warranty. In no event will the authors be held liable for any damages\r
+* arising from the use of this software.\r
+* Permission is granted to anyone to use this software for any purpose,\r
+* including commercial applications, and to alter it and redistribute it\r
+* freely, subject to the following restrictions:\r
+* 1. The origin of this software must not be misrepresented; you must not\r
+* claim that you wrote the original software. If you use this software\r
+* in a product, an acknowledgment in the product documentation would be\r
+* appreciated but is not required.\r
+* 2. Altered source versions must be plainly marked as such, and must not be\r
+* misrepresented as being the original software.\r
+* 3. This notice may not be removed or altered from any source distribution.\r
+*/\r
+\r
+#include <Box2D/Dynamics/Contacts/b2TOISolver.h>\r
+#include <Box2D/Dynamics/Contacts/b2Contact.h>\r
+#include <Box2D/Dynamics/b2Body.h>\r
+#include <Box2D/Dynamics/b2Fixture.h>\r
+#include <Box2D/Common/b2StackAllocator.h>\r
+\r
+struct b2TOIConstraint\r
+{\r
+ b2Vec2 localPoints[b2_maxManifoldPoints];\r
+ b2Vec2 localNormal;\r
+ b2Vec2 localPoint;\r
+ b2Manifold::Type type;\r
+ float32 radius;\r
+ int32 pointCount;\r
+ b2Body* bodyA;\r
+ b2Body* bodyB;\r
+};\r
+\r
+b2TOISolver::b2TOISolver(b2StackAllocator* allocator)\r
+{\r
+ m_allocator = allocator;\r
+ m_constraints = NULL;\r
+ m_count = NULL;\r
+ m_toiBody = NULL;\r
+}\r
+\r
+b2TOISolver::~b2TOISolver()\r
+{\r
+ Clear();\r
+}\r
+\r
+void b2TOISolver::Clear()\r
+{\r
+ if (m_allocator && m_constraints)\r
+ {\r
+ m_allocator->Free(m_constraints);\r
+ m_constraints = NULL;\r
+ }\r
+}\r
+\r
+void b2TOISolver::Initialize(b2Contact** contacts, int32 count, b2Body* toiBody)\r
+{\r
+ Clear();\r
+\r
+ m_count = count;\r
+ m_toiBody = toiBody;\r
+\r
+ m_constraints = (b2TOIConstraint*) m_allocator->Allocate(m_count * sizeof(b2TOIConstraint));\r
+\r
+ for (int32 i = 0; i < m_count; ++i)\r
+ {\r
+ b2Contact* contact = contacts[i];\r
+\r
+ b2Fixture* fixtureA = contact->GetFixtureA();\r
+ b2Fixture* fixtureB = contact->GetFixtureB();\r
+ b2Shape* shapeA = fixtureA->GetShape();\r
+ b2Shape* shapeB = fixtureB->GetShape();\r
+ float32 radiusA = shapeA->m_radius;\r
+ float32 radiusB = shapeB->m_radius;\r
+ b2Body* bodyA = fixtureA->GetBody();\r
+ b2Body* bodyB = fixtureB->GetBody();\r
+ b2Manifold* manifold = contact->GetManifold();\r
+\r
+ b2Assert(manifold->pointCount > 0);\r
+\r
+ b2TOIConstraint* constraint = m_constraints + i;\r
+ constraint->bodyA = bodyA;\r
+ constraint->bodyB = bodyB;\r
+ constraint->localNormal = manifold->localNormal;\r
+ constraint->localPoint = manifold->localPoint;\r
+ constraint->type = manifold->type;\r
+ constraint->pointCount = manifold->pointCount;\r
+ constraint->radius = radiusA + radiusB;\r
+\r
+ for (int32 j = 0; j < constraint->pointCount; ++j)\r
+ {\r
+ b2ManifoldPoint* cp = manifold->points + j;\r
+ constraint->localPoints[j] = cp->localPoint;\r
+ }\r
+ }\r
+}\r
+\r
+struct b2TOISolverManifold\r
+{\r
+ void Initialize(b2TOIConstraint* cc, int32 index)\r
+ {\r
+ b2Assert(cc->pointCount > 0);\r
+\r
+ switch (cc->type)\r
+ {\r
+ case b2Manifold::e_circles:\r
+ {\r
+ b2Vec2 pointA = cc->bodyA->GetWorldPoint(cc->localPoint);\r
+ b2Vec2 pointB = cc->bodyB->GetWorldPoint(cc->localPoints[0]);\r
+ if (b2DistanceSquared(pointA, pointB) > b2_epsilon * b2_epsilon)\r
+ {\r
+ normal = pointB - pointA;\r
+ normal.Normalize();\r
+ }\r
+ else\r
+ {\r
+ normal.Set(1.0f, 0.0f);\r
+ }\r
+\r
+ point = 0.5f * (pointA + pointB);\r
+ separation = b2Dot(pointB - pointA, normal) - cc->radius;\r
+ }\r
+ break;\r
+\r
+ case b2Manifold::e_faceA:\r
+ {\r
+ normal = cc->bodyA->GetWorldVector(cc->localNormal);\r
+ b2Vec2 planePoint = cc->bodyA->GetWorldPoint(cc->localPoint);\r
+\r
+ b2Vec2 clipPoint = cc->bodyB->GetWorldPoint(cc->localPoints[index]);\r
+ separation = b2Dot(clipPoint - planePoint, normal) - cc->radius;\r
+ point = clipPoint;\r
+ }\r
+ break;\r
+\r
+ case b2Manifold::e_faceB:\r
+ {\r
+ normal = cc->bodyB->GetWorldVector(cc->localNormal);\r
+ b2Vec2 planePoint = cc->bodyB->GetWorldPoint(cc->localPoint);\r
+\r
+ b2Vec2 clipPoint = cc->bodyA->GetWorldPoint(cc->localPoints[index]);\r
+ separation = b2Dot(clipPoint - planePoint, normal) - cc->radius;\r
+ point = clipPoint;\r
+\r
+ // Ensure normal points from A to B\r
+ normal = -normal;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+\r
+ b2Vec2 normal;\r
+ b2Vec2 point;\r
+ float32 separation;\r
+};\r
+\r
+// Push out the toi body to provide clearance for further simulation.\r
+bool b2TOISolver::Solve(float32 baumgarte)\r
+{\r
+ float32 minSeparation = 0.0f;\r
+\r
+ for (int32 i = 0; i < m_count; ++i)\r
+ {\r
+ b2TOIConstraint* c = m_constraints + i;\r
+ b2Body* bodyA = c->bodyA;\r
+ b2Body* bodyB = c->bodyB;\r
+\r
+ float32 massA = bodyA->m_mass;\r
+ float32 massB = bodyB->m_mass;\r
+\r
+ // Only the TOI body should move.\r
+ if (bodyA == m_toiBody)\r
+ {\r
+ massB = 0.0f;\r
+ }\r
+ else\r
+ {\r
+ massA = 0.0f;\r
+ }\r
+\r
+ float32 invMassA = massA * bodyA->m_invMass;\r
+ float32 invIA = massA * bodyA->m_invI;\r
+ float32 invMassB = massB * bodyB->m_invMass;\r
+ float32 invIB = massB * bodyB->m_invI;\r
+\r
+ // Solve normal constraints\r
+ for (int32 j = 0; j < c->pointCount; ++j)\r
+ {\r
+ b2TOISolverManifold psm;\r
+ psm.Initialize(c, j);\r
+ b2Vec2 normal = psm.normal;\r
+\r
+ b2Vec2 point = psm.point;\r
+ float32 separation = psm.separation;\r
+\r
+ b2Vec2 rA = point - bodyA->m_sweep.c;\r
+ b2Vec2 rB = point - bodyB->m_sweep.c;\r
+\r
+ // Track max constraint error.\r
+ minSeparation = b2Min(minSeparation, separation);\r
+\r
+ // Prevent large corrections and allow slop.\r
+ float32 C = b2Clamp(baumgarte * (separation + b2_linearSlop), -b2_maxLinearCorrection, 0.0f);\r
+\r
+ // Compute the effective mass.\r
+ float32 rnA = b2Cross(rA, normal);\r
+ float32 rnB = b2Cross(rB, normal);\r
+ float32 K = invMassA + invMassB + invIA * rnA * rnA + invIB * rnB * rnB;\r
+\r
+ // Compute normal impulse\r
+ float32 impulse = K > 0.0f ? - C / K : 0.0f;\r
+\r
+ b2Vec2 P = impulse * normal;\r
+\r
+ bodyA->m_sweep.c -= invMassA * P;\r
+ bodyA->m_sweep.a -= invIA * b2Cross(rA, P);\r
+ bodyA->SynchronizeTransform();\r
+\r
+ bodyB->m_sweep.c += invMassB * P;\r
+ bodyB->m_sweep.a += invIB * b2Cross(rB, P);\r
+ bodyB->SynchronizeTransform();\r
+ }\r
+ }\r
+\r
+ // We can't expect minSpeparation >= -b2_linearSlop because we don't\r
+ // push the separation above -b2_linearSlop.\r
+ return minSeparation >= -1.5f * b2_linearSlop;\r
+}\r
/*\r
-* Copyright (c) 2011 Erin Catto http://box2d.org\r
+* Copyright (c) 2006-2010 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
* 3. This notice may not be removed or altered from any source distribution.\r
*/\r
\r
-#include <Box2D/Common/b2Settings.h>\r
+#ifndef B2_TOI_SOLVER_H\r
+#define B2_TOI_SOLVER_H\r
\r
-/// Timer for profiling. This has platform specific code and may\r
-/// not work on every platform.\r
-class b2Timer\r
+#include <Box2D/Common/b2Math.h>\r
+\r
+class b2Contact;\r
+class b2Body;\r
+struct b2TOIConstraint;\r
+class b2StackAllocator;\r
+\r
+/// This is a pure position solver for a single movable body in contact with\r
+/// multiple non-moving bodies.\r
+class b2TOISolver\r
{\r
public:\r
+ b2TOISolver(b2StackAllocator* allocator);\r
+ ~b2TOISolver();\r
\r
- /// Constructor\r
- b2Timer();\r
+ void Initialize(b2Contact** contacts, int32 contactCount, b2Body* toiBody);\r
+ void Clear();\r
\r
- /// Reset the timer.\r
- void Reset();\r
-\r
- /// Get the time since construction or the last reset.\r
- float32 GetMilliseconds() const;\r
+ // Perform one solver iteration. Returns true if converged.\r
+ bool Solve(float32 baumgarte);\r
\r
private:\r
\r
- float64 m_start;\r
- static float64 s_invFrequency;\r
+ b2TOIConstraint* m_constraints;\r
+ int32 m_count;\r
+ b2Body* m_toiBody;\r
+ b2StackAllocator* m_allocator;\r
};\r
+\r
+#endif\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
length = d.Length();\r
}\r
\r
+\r
b2DistanceJoint::b2DistanceJoint(const b2DistanceJointDef* def)\r
: b2Joint(def)\r
{\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2Vec2 GetAnchorA() const;\r
b2Vec2 GetAnchorB() const;\r
\r
- /// Get the reaction force given the inverse time step.\r
- /// Unit is N.\r
b2Vec2 GetReactionForce(float32 inv_dt) const;\r
-\r
- /// Get the reaction torque given the inverse time step.\r
- /// Unit is N*m. This is always zero for a distance joint.\r
float32 GetReactionTorque(float32 inv_dt) const;\r
\r
/// Set/get the natural length.\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
#include <Box2D/Dynamics/Joints/b2Joint.h>\r
#include <Box2D/Dynamics/Joints/b2DistanceJoint.h>\r
-#include <Box2D/Dynamics/Joints/b2WheelJoint.h>\r
+#include <Box2D/Dynamics/Joints/b2LineJoint.h>\r
#include <Box2D/Dynamics/Joints/b2MouseJoint.h>\r
#include <Box2D/Dynamics/Joints/b2RevoluteJoint.h>\r
#include <Box2D/Dynamics/Joints/b2PrismaticJoint.h>\r
#include <Box2D/Dynamics/Joints/b2GearJoint.h>\r
#include <Box2D/Dynamics/Joints/b2WeldJoint.h>\r
#include <Box2D/Dynamics/Joints/b2FrictionJoint.h>\r
-#include <Box2D/Dynamics/Joints/b2RopeJoint.h>\r
#include <Box2D/Dynamics/b2Body.h>\r
#include <Box2D/Dynamics/b2World.h>\r
#include <Box2D/Common/b2BlockAllocator.h>\r
}\r
break;\r
\r
- case e_wheelJoint:\r
+ case e_lineJoint:\r
{\r
- void* mem = allocator->Allocate(sizeof(b2WheelJoint));\r
- joint = new (mem) b2WheelJoint((b2WheelJointDef*)def);\r
+ void* mem = allocator->Allocate(sizeof(b2LineJoint));\r
+ joint = new (mem) b2LineJoint((b2LineJointDef*)def);\r
}\r
break;\r
\r
}\r
break;\r
\r
- case e_ropeJoint:\r
- {\r
- void* mem = allocator->Allocate(sizeof(b2RopeJoint));\r
- joint = new (mem) b2RopeJoint((b2RopeJointDef*)def);\r
- }\r
- break;\r
-\r
default:\r
b2Assert(false);\r
break;\r
allocator->Free(joint, sizeof(b2GearJoint));\r
break;\r
\r
- case e_wheelJoint:\r
- allocator->Free(joint, sizeof(b2WheelJoint));\r
+ case e_lineJoint:\r
+ allocator->Free(joint, sizeof(b2LineJoint));\r
break;\r
\r
case e_weldJoint:\r
allocator->Free(joint, sizeof(b2FrictionJoint));\r
break;\r
\r
- case e_ropeJoint:\r
- allocator->Free(joint, sizeof(b2RopeJoint));\r
- break;\r
-\r
default:\r
b2Assert(false);\r
break;\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
e_pulleyJoint,\r
e_mouseJoint,\r
e_gearJoint,\r
- e_wheelJoint,\r
+ e_lineJoint,\r
e_weldJoint,\r
e_frictionJoint,\r
- e_ropeJoint\r
};\r
\r
enum b2LimitState\r
\r
/// Get the next joint the world joint list.\r
b2Joint* GetNext();\r
- const b2Joint* GetNext() const;\r
\r
/// Get the user data pointer.\r
void* GetUserData() const;\r
/// Short-cut function to determine if either body is inactive.\r
bool IsActive() const;\r
\r
- /// Get collide connected.\r
- /// Note: modifying the collide connect flag won't work correctly because\r
- /// the flag is only checked when fixture AABBs begin to overlap.\r
- bool GetCollideConnected() const;\r
-\r
protected:\r
friend class b2World;\r
friend class b2Body;\r
void* m_userData;\r
\r
// Cache here per time step to reduce cache misses.\r
- // TODO_ERIN nuke\r
b2Vec2 m_localCenterA, m_localCenterB;\r
float32 m_invMassA, m_invIA;\r
float32 m_invMassB, m_invIB;\r
return m_next;\r
}\r
\r
-inline const b2Joint* b2Joint::GetNext() const\r
-{\r
- return m_next;\r
-}\r
-\r
inline void* b2Joint::GetUserData() const\r
{\r
return m_userData;\r
m_userData = data;\r
}\r
\r
-inline bool b2Joint::GetCollideConnected() const\r
-{\r
- return m_collideConnected;\r
-}\r
-\r
#endif\r
--- /dev/null
+/*\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
+*\r
+* This software is provided 'as-is', without any express or implied\r
+* warranty. In no event will the authors be held liable for any damages\r
+* arising from the use of this software.\r
+* Permission is granted to anyone to use this software for any purpose,\r
+* including commercial applications, and to alter it and redistribute it\r
+* freely, subject to the following restrictions:\r
+* 1. The origin of this software must not be misrepresented; you must not\r
+* claim that you wrote the original software. If you use this software\r
+* in a product, an acknowledgment in the product documentation would be\r
+* appreciated but is not required.\r
+* 2. Altered source versions must be plainly marked as such, and must not be\r
+* misrepresented as being the original software.\r
+* 3. This notice may not be removed or altered from any source distribution.\r
+*/\r
+\r
+#include <Box2D/Dynamics/Joints/b2LineJoint.h>\r
+#include <Box2D/Dynamics/b2Body.h>\r
+#include <Box2D/Dynamics/b2TimeStep.h>\r
+\r
+// Linear constraint (point-to-line)\r
+// d = p2 - p1 = x2 + r2 - x1 - r1\r
+// C = dot(perp, d)\r
+// Cdot = dot(d, cross(w1, perp)) + dot(perp, v2 + cross(w2, r2) - v1 - cross(w1, r1))\r
+// = -dot(perp, v1) - dot(cross(d + r1, perp), w1) + dot(perp, v2) + dot(cross(r2, perp), v2)\r
+// J = [-perp, -cross(d + r1, perp), perp, cross(r2,perp)]\r
+//\r
+// K = J * invM * JT\r
+//\r
+// J = [-a -s1 a s2]\r
+// a = perp\r
+// s1 = cross(d + r1, a) = cross(p2 - x1, a)\r
+// s2 = cross(r2, a) = cross(p2 - x2, a)\r
+\r
+\r
+// Motor/Limit linear constraint\r
+// C = dot(ax1, d)\r
+// Cdot = = -dot(ax1, v1) - dot(cross(d + r1, ax1), w1) + dot(ax1, v2) + dot(cross(r2, ax1), v2)\r
+// J = [-ax1 -cross(d+r1,ax1) ax1 cross(r2,ax1)]\r
+\r
+// Block Solver\r
+// We develop a block solver that includes the joint limit. This makes the limit stiff (inelastic) even\r
+// when the mass has poor distribution (leading to large torques about the joint anchor points).\r
+//\r
+// The Jacobian has 3 rows:\r
+// J = [-uT -s1 uT s2] // linear\r
+// [-vT -a1 vT a2] // limit\r
+//\r
+// u = perp\r
+// v = axis\r
+// s1 = cross(d + r1, u), s2 = cross(r2, u)\r
+// a1 = cross(d + r1, v), a2 = cross(r2, v)\r
+\r
+// M * (v2 - v1) = JT * df\r
+// J * v2 = bias\r
+//\r
+// v2 = v1 + invM * JT * df\r
+// J * (v1 + invM * JT * df) = bias\r
+// K * df = bias - J * v1 = -Cdot\r
+// K = J * invM * JT\r
+// Cdot = J * v1 - bias\r
+//\r
+// Now solve for f2.\r
+// df = f2 - f1\r
+// K * (f2 - f1) = -Cdot\r
+// f2 = invK * (-Cdot) + f1\r
+//\r
+// Clamp accumulated limit impulse.\r
+// lower: f2(2) = max(f2(2), 0)\r
+// upper: f2(2) = min(f2(2), 0)\r
+//\r
+// Solve for correct f2(1)\r
+// K(1,1) * f2(1) = -Cdot(1) - K(1,2) * f2(2) + K(1,1:2) * f1\r
+// = -Cdot(1) - K(1,2) * f2(2) + K(1,1) * f1(1) + K(1,2) * f1(2)\r
+// K(1,1) * f2(1) = -Cdot(1) - K(1,2) * (f2(2) - f1(2)) + K(1,1) * f1(1)\r
+// f2(1) = invK(1,1) * (-Cdot(1) - K(1,2) * (f2(2) - f1(2))) + f1(1)\r
+//\r
+// Now compute impulse to be applied:\r
+// df = f2 - f1\r
+\r
+void b2LineJointDef::Initialize(b2Body* b1, b2Body* b2, const b2Vec2& anchor, const b2Vec2& axis)\r
+{\r
+ bodyA = b1;\r
+ bodyB = b2;\r
+ localAnchorA = bodyA->GetLocalPoint(anchor);\r
+ localAnchorB = bodyB->GetLocalPoint(anchor);\r
+ localAxisA = bodyA->GetLocalVector(axis);\r
+}\r
+\r
+b2LineJoint::b2LineJoint(const b2LineJointDef* def)\r
+: b2Joint(def)\r
+{\r
+ m_localAnchor1 = def->localAnchorA;\r
+ m_localAnchor2 = def->localAnchorB;\r
+ m_localXAxis1 = def->localAxisA;\r
+ m_localYAxis1 = b2Cross(1.0f, m_localXAxis1);\r
+\r
+ m_impulse.SetZero();\r
+ m_motorMass = 0.0;\r
+ m_motorImpulse = 0.0f;\r
+\r
+ m_lowerTranslation = def->lowerTranslation;\r
+ m_upperTranslation = def->upperTranslation;\r
+ m_maxMotorForce = def->maxMotorForce;\r
+ m_motorSpeed = def->motorSpeed;\r
+ m_enableLimit = def->enableLimit;\r
+ m_enableMotor = def->enableMotor;\r
+ m_limitState = e_inactiveLimit;\r
+\r
+ m_axis.SetZero();\r
+ m_perp.SetZero();\r
+}\r
+\r
+void b2LineJoint::InitVelocityConstraints(const b2TimeStep& step)\r
+{\r
+ b2Body* b1 = m_bodyA;\r
+ b2Body* b2 = m_bodyB;\r
+\r
+ m_localCenterA = b1->GetLocalCenter();\r
+ m_localCenterB = b2->GetLocalCenter();\r
+\r
+ b2Transform xf1 = b1->GetTransform();\r
+ b2Transform xf2 = b2->GetTransform();\r
+\r
+ // Compute the effective masses.\r
+ b2Vec2 r1 = b2Mul(xf1.R, m_localAnchor1 - m_localCenterA);\r
+ b2Vec2 r2 = b2Mul(xf2.R, m_localAnchor2 - m_localCenterB);\r
+ b2Vec2 d = b2->m_sweep.c + r2 - b1->m_sweep.c - r1;\r
+\r
+ m_invMassA = b1->m_invMass;\r
+ m_invIA = b1->m_invI;\r
+ m_invMassB = b2->m_invMass;\r
+ m_invIB = b2->m_invI;\r
+\r
+ // Compute motor Jacobian and effective mass.\r
+ {\r
+ m_axis = b2Mul(xf1.R, m_localXAxis1);\r
+ m_a1 = b2Cross(d + r1, m_axis);\r
+ m_a2 = b2Cross(r2, m_axis);\r
+\r
+ m_motorMass = m_invMassA + m_invMassB + m_invIA * m_a1 * m_a1 + m_invIB * m_a2 * m_a2;\r
+ if (m_motorMass > b2_epsilon)\r
+ {\r
+ m_motorMass = 1.0f / m_motorMass;\r
+ }\r
+ else\r
+ {\r
+ m_motorMass = 0.0f;\r
+ }\r
+ }\r
+\r
+ // Prismatic constraint.\r
+ {\r
+ m_perp = b2Mul(xf1.R, m_localYAxis1);\r
+\r
+ m_s1 = b2Cross(d + r1, m_perp);\r
+ m_s2 = b2Cross(r2, m_perp);\r
+\r
+ float32 m1 = m_invMassA, m2 = m_invMassB;\r
+ float32 i1 = m_invIA, i2 = m_invIB;\r
+\r
+ float32 k11 = m1 + m2 + i1 * m_s1 * m_s1 + i2 * m_s2 * m_s2;\r
+ float32 k12 = i1 * m_s1 * m_a1 + i2 * m_s2 * m_a2;\r
+ float32 k22 = m1 + m2 + i1 * m_a1 * m_a1 + i2 * m_a2 * m_a2;\r
+\r
+ m_K.col1.Set(k11, k12);\r
+ m_K.col2.Set(k12, k22);\r
+ }\r
+\r
+ // Compute motor and limit terms.\r
+ if (m_enableLimit)\r
+ {\r
+ float32 jointTranslation = b2Dot(m_axis, d);\r
+ if (b2Abs(m_upperTranslation - m_lowerTranslation) < 2.0f * b2_linearSlop)\r
+ {\r
+ m_limitState = e_equalLimits;\r
+ }\r
+ else if (jointTranslation <= m_lowerTranslation)\r
+ {\r
+ if (m_limitState != e_atLowerLimit)\r
+ {\r
+ m_limitState = e_atLowerLimit;\r
+ m_impulse.y = 0.0f;\r
+ }\r
+ }\r
+ else if (jointTranslation >= m_upperTranslation)\r
+ {\r
+ if (m_limitState != e_atUpperLimit)\r
+ {\r
+ m_limitState = e_atUpperLimit;\r
+ m_impulse.y = 0.0f;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ m_limitState = e_inactiveLimit;\r
+ m_impulse.y = 0.0f;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ m_limitState = e_inactiveLimit;\r
+ }\r
+\r
+ if (m_enableMotor == false)\r
+ {\r
+ m_motorImpulse = 0.0f;\r
+ }\r
+\r
+ if (step.warmStarting)\r
+ {\r
+ // Account for variable time step.\r
+ m_impulse *= step.dtRatio;\r
+ m_motorImpulse *= step.dtRatio;\r
+\r
+ b2Vec2 P = m_impulse.x * m_perp + (m_motorImpulse + m_impulse.y) * m_axis;\r
+ float32 L1 = m_impulse.x * m_s1 + (m_motorImpulse + m_impulse.y) * m_a1;\r
+ float32 L2 = m_impulse.x * m_s2 + (m_motorImpulse + m_impulse.y) * m_a2;\r
+\r
+ b1->m_linearVelocity -= m_invMassA * P;\r
+ b1->m_angularVelocity -= m_invIA * L1;\r
+\r
+ b2->m_linearVelocity += m_invMassB * P;\r
+ b2->m_angularVelocity += m_invIB * L2;\r
+ }\r
+ else\r
+ {\r
+ m_impulse.SetZero();\r
+ m_motorImpulse = 0.0f;\r
+ }\r
+}\r
+\r
+void b2LineJoint::SolveVelocityConstraints(const b2TimeStep& step)\r
+{\r
+ b2Body* b1 = m_bodyA;\r
+ b2Body* b2 = m_bodyB;\r
+\r
+ b2Vec2 v1 = b1->m_linearVelocity;\r
+ float32 w1 = b1->m_angularVelocity;\r
+ b2Vec2 v2 = b2->m_linearVelocity;\r
+ float32 w2 = b2->m_angularVelocity;\r
+\r
+ // Solve linear motor constraint.\r
+ if (m_enableMotor && m_limitState != e_equalLimits)\r
+ {\r
+ float32 Cdot = b2Dot(m_axis, v2 - v1) + m_a2 * w2 - m_a1 * w1;\r
+ float32 impulse = m_motorMass * (m_motorSpeed - Cdot);\r
+ float32 oldImpulse = m_motorImpulse;\r
+ float32 maxImpulse = step.dt * m_maxMotorForce;\r
+ m_motorImpulse = b2Clamp(m_motorImpulse + impulse, -maxImpulse, maxImpulse);\r
+ impulse = m_motorImpulse - oldImpulse;\r
+\r
+ b2Vec2 P = impulse * m_axis;\r
+ float32 L1 = impulse * m_a1;\r
+ float32 L2 = impulse * m_a2;\r
+\r
+ v1 -= m_invMassA * P;\r
+ w1 -= m_invIA * L1;\r
+\r
+ v2 += m_invMassB * P;\r
+ w2 += m_invIB * L2;\r
+ }\r
+\r
+ float32 Cdot1 = b2Dot(m_perp, v2 - v1) + m_s2 * w2 - m_s1 * w1;\r
+\r
+ if (m_enableLimit && m_limitState != e_inactiveLimit)\r
+ {\r
+ // Solve prismatic and limit constraint in block form.\r
+ float32 Cdot2 = b2Dot(m_axis, v2 - v1) + m_a2 * w2 - m_a1 * w1;\r
+ b2Vec2 Cdot(Cdot1, Cdot2);\r
+\r
+ b2Vec2 f1 = m_impulse;\r
+ b2Vec2 df = m_K.Solve(-Cdot);\r
+ m_impulse += df;\r
+\r
+ if (m_limitState == e_atLowerLimit)\r
+ {\r
+ m_impulse.y = b2Max(m_impulse.y, 0.0f);\r
+ }\r
+ else if (m_limitState == e_atUpperLimit)\r
+ {\r
+ m_impulse.y = b2Min(m_impulse.y, 0.0f);\r
+ }\r
+\r
+ // f2(1) = invK(1,1) * (-Cdot(1) - K(1,2) * (f2(2) - f1(2))) + f1(1)\r
+ float32 b = -Cdot1 - (m_impulse.y - f1.y) * m_K.col2.x;\r
+ float32 f2r;\r
+ if (m_K.col1.x != 0.0f)\r
+ {\r
+ f2r = b / m_K.col1.x + f1.x;\r
+ }\r
+ else\r
+ {\r
+ f2r = f1.x; \r
+ }\r
+\r
+ m_impulse.x = f2r;\r
+\r
+ df = m_impulse - f1;\r
+\r
+ b2Vec2 P = df.x * m_perp + df.y * m_axis;\r
+ float32 L1 = df.x * m_s1 + df.y * m_a1;\r
+ float32 L2 = df.x * m_s2 + df.y * m_a2;\r
+\r
+ v1 -= m_invMassA * P;\r
+ w1 -= m_invIA * L1;\r
+\r
+ v2 += m_invMassB * P;\r
+ w2 += m_invIB * L2;\r
+ }\r
+ else\r
+ {\r
+ // Limit is inactive, just solve the prismatic constraint in block form.\r
+ float32 df;\r
+ if (m_K.col1.x != 0.0f)\r
+ {\r
+ df = - Cdot1 / m_K.col1.x;\r
+ }\r
+ else\r
+ {\r
+ df = 0.0f;\r
+ }\r
+ m_impulse.x += df;\r
+\r
+ b2Vec2 P = df * m_perp;\r
+ float32 L1 = df * m_s1;\r
+ float32 L2 = df * m_s2;\r
+\r
+ v1 -= m_invMassA * P;\r
+ w1 -= m_invIA * L1;\r
+\r
+ v2 += m_invMassB * P;\r
+ w2 += m_invIB * L2;\r
+ }\r
+\r
+ b1->m_linearVelocity = v1;\r
+ b1->m_angularVelocity = w1;\r
+ b2->m_linearVelocity = v2;\r
+ b2->m_angularVelocity = w2;\r
+}\r
+\r
+bool b2LineJoint::SolvePositionConstraints(float32 baumgarte)\r
+{\r
+ B2_NOT_USED(baumgarte);\r
+\r
+ b2Body* b1 = m_bodyA;\r
+ b2Body* b2 = m_bodyB;\r
+\r
+ b2Vec2 c1 = b1->m_sweep.c;\r
+ float32 a1 = b1->m_sweep.a;\r
+\r
+ b2Vec2 c2 = b2->m_sweep.c;\r
+ float32 a2 = b2->m_sweep.a;\r
+\r
+ // Solve linear limit constraint.\r
+ float32 linearError = 0.0f, angularError = 0.0f;\r
+ bool active = false;\r
+ float32 C2 = 0.0f;\r
+\r
+ b2Mat22 R1(a1), R2(a2);\r
+\r
+ b2Vec2 r1 = b2Mul(R1, m_localAnchor1 - m_localCenterA);\r
+ b2Vec2 r2 = b2Mul(R2, m_localAnchor2 - m_localCenterB);\r
+ b2Vec2 d = c2 + r2 - c1 - r1;\r
+\r
+ if (m_enableLimit)\r
+ {\r
+ m_axis = b2Mul(R1, m_localXAxis1);\r
+\r
+ m_a1 = b2Cross(d + r1, m_axis);\r
+ m_a2 = b2Cross(r2, m_axis);\r
+\r
+ float32 translation = b2Dot(m_axis, d);\r
+ if (b2Abs(m_upperTranslation - m_lowerTranslation) < 2.0f * b2_linearSlop)\r
+ {\r
+ // Prevent large angular corrections\r
+ C2 = b2Clamp(translation, -b2_maxLinearCorrection, b2_maxLinearCorrection);\r
+ linearError = b2Abs(translation);\r
+ active = true;\r
+ }\r
+ else if (translation <= m_lowerTranslation)\r
+ {\r
+ // Prevent large linear corrections and allow some slop.\r
+ C2 = b2Clamp(translation - m_lowerTranslation + b2_linearSlop, -b2_maxLinearCorrection, 0.0f);\r
+ linearError = m_lowerTranslation - translation;\r
+ active = true;\r
+ }\r
+ else if (translation >= m_upperTranslation)\r
+ {\r
+ // Prevent large linear corrections and allow some slop.\r
+ C2 = b2Clamp(translation - m_upperTranslation - b2_linearSlop, 0.0f, b2_maxLinearCorrection);\r
+ linearError = translation - m_upperTranslation;\r
+ active = true;\r
+ }\r
+ }\r
+\r
+ m_perp = b2Mul(R1, m_localYAxis1);\r
+\r
+ m_s1 = b2Cross(d + r1, m_perp);\r
+ m_s2 = b2Cross(r2, m_perp);\r
+\r
+ b2Vec2 impulse;\r
+ float32 C1;\r
+ C1 = b2Dot(m_perp, d);\r
+\r
+ linearError = b2Max(linearError, b2Abs(C1));\r
+ angularError = 0.0f;\r
+\r
+ if (active)\r
+ {\r
+ float32 m1 = m_invMassA, m2 = m_invMassB;\r
+ float32 i1 = m_invIA, i2 = m_invIB;\r
+\r
+ float32 k11 = m1 + m2 + i1 * m_s1 * m_s1 + i2 * m_s2 * m_s2;\r
+ float32 k12 = i1 * m_s1 * m_a1 + i2 * m_s2 * m_a2;\r
+ float32 k22 = m1 + m2 + i1 * m_a1 * m_a1 + i2 * m_a2 * m_a2;\r
+\r
+ m_K.col1.Set(k11, k12);\r
+ m_K.col2.Set(k12, k22);\r
+\r
+ b2Vec2 C;\r
+ C.x = C1;\r
+ C.y = C2;\r
+\r
+ impulse = m_K.Solve(-C);\r
+ }\r
+ else\r
+ {\r
+ float32 m1 = m_invMassA, m2 = m_invMassB;\r
+ float32 i1 = m_invIA, i2 = m_invIB;\r
+\r
+ float32 k11 = m1 + m2 + i1 * m_s1 * m_s1 + i2 * m_s2 * m_s2;\r
+\r
+ float32 impulse1;\r
+ if (k11 != 0.0f)\r
+ {\r
+ impulse1 = - C1 / k11;\r
+ }\r
+ else\r
+ {\r
+ impulse1 = 0.0f;\r
+ }\r
+\r
+ impulse.x = impulse1;\r
+ impulse.y = 0.0f;\r
+ }\r
+\r
+ b2Vec2 P = impulse.x * m_perp + impulse.y * m_axis;\r
+ float32 L1 = impulse.x * m_s1 + impulse.y * m_a1;\r
+ float32 L2 = impulse.x * m_s2 + impulse.y * m_a2;\r
+\r
+ c1 -= m_invMassA * P;\r
+ a1 -= m_invIA * L1;\r
+ c2 += m_invMassB * P;\r
+ a2 += m_invIB * L2;\r
+\r
+ // TODO_ERIN remove need for this.\r
+ b1->m_sweep.c = c1;\r
+ b1->m_sweep.a = a1;\r
+ b2->m_sweep.c = c2;\r
+ b2->m_sweep.a = a2;\r
+ b1->SynchronizeTransform();\r
+ b2->SynchronizeTransform();\r
+\r
+ return linearError <= b2_linearSlop && angularError <= b2_angularSlop;\r
+}\r
+\r
+b2Vec2 b2LineJoint::GetAnchorA() const\r
+{\r
+ return m_bodyA->GetWorldPoint(m_localAnchor1);\r
+}\r
+\r
+b2Vec2 b2LineJoint::GetAnchorB() const\r
+{\r
+ return m_bodyB->GetWorldPoint(m_localAnchor2);\r
+}\r
+\r
+b2Vec2 b2LineJoint::GetReactionForce(float32 inv_dt) const\r
+{\r
+ return inv_dt * (m_impulse.x * m_perp + (m_motorImpulse + m_impulse.y) * m_axis);\r
+}\r
+\r
+float32 b2LineJoint::GetReactionTorque(float32 inv_dt) const\r
+{\r
+ B2_NOT_USED(inv_dt);\r
+ return 0.0f;\r
+}\r
+\r
+float32 b2LineJoint::GetJointTranslation() const\r
+{\r
+ b2Body* b1 = m_bodyA;\r
+ b2Body* b2 = m_bodyB;\r
+\r
+ b2Vec2 p1 = b1->GetWorldPoint(m_localAnchor1);\r
+ b2Vec2 p2 = b2->GetWorldPoint(m_localAnchor2);\r
+ b2Vec2 d = p2 - p1;\r
+ b2Vec2 axis = b1->GetWorldVector(m_localXAxis1);\r
+\r
+ float32 translation = b2Dot(d, axis);\r
+ return translation;\r
+}\r
+\r
+float32 b2LineJoint::GetJointSpeed() const\r
+{\r
+ b2Body* b1 = m_bodyA;\r
+ b2Body* b2 = m_bodyB;\r
+\r
+ b2Vec2 r1 = b2Mul(b1->GetTransform().R, m_localAnchor1 - b1->GetLocalCenter());\r
+ b2Vec2 r2 = b2Mul(b2->GetTransform().R, m_localAnchor2 - b2->GetLocalCenter());\r
+ b2Vec2 p1 = b1->m_sweep.c + r1;\r
+ b2Vec2 p2 = b2->m_sweep.c + r2;\r
+ b2Vec2 d = p2 - p1;\r
+ b2Vec2 axis = b1->GetWorldVector(m_localXAxis1);\r
+\r
+ b2Vec2 v1 = b1->m_linearVelocity;\r
+ b2Vec2 v2 = b2->m_linearVelocity;\r
+ float32 w1 = b1->m_angularVelocity;\r
+ float32 w2 = b2->m_angularVelocity;\r
+\r
+ float32 speed = b2Dot(d, b2Cross(w1, axis)) + b2Dot(axis, v2 + b2Cross(w2, r2) - v1 - b2Cross(w1, r1));\r
+ return speed;\r
+}\r
+\r
+bool b2LineJoint::IsLimitEnabled() const\r
+{\r
+ return m_enableLimit;\r
+}\r
+\r
+void b2LineJoint::EnableLimit(bool flag)\r
+{\r
+ m_bodyA->SetAwake(true);\r
+ m_bodyB->SetAwake(true);\r
+ m_enableLimit = flag;\r
+}\r
+\r
+float32 b2LineJoint::GetLowerLimit() const\r
+{\r
+ return m_lowerTranslation;\r
+}\r
+\r
+float32 b2LineJoint::GetUpperLimit() const\r
+{\r
+ return m_upperTranslation;\r
+}\r
+\r
+void b2LineJoint::SetLimits(float32 lower, float32 upper)\r
+{\r
+ b2Assert(lower <= upper);\r
+ m_bodyA->SetAwake(true);\r
+ m_bodyB->SetAwake(true);\r
+ m_lowerTranslation = lower;\r
+ m_upperTranslation = upper;\r
+}\r
+\r
+bool b2LineJoint::IsMotorEnabled() const\r
+{\r
+ return m_enableMotor;\r
+}\r
+\r
+void b2LineJoint::EnableMotor(bool flag)\r
+{\r
+ m_bodyA->SetAwake(true);\r
+ m_bodyB->SetAwake(true);\r
+ m_enableMotor = flag;\r
+}\r
+\r
+void b2LineJoint::SetMotorSpeed(float32 speed)\r
+{\r
+ m_bodyA->SetAwake(true);\r
+ m_bodyB->SetAwake(true);\r
+ m_motorSpeed = speed;\r
+}\r
+\r
+void b2LineJoint::SetMaxMotorForce(float32 force)\r
+{\r
+ m_bodyA->SetAwake(true);\r
+ m_bodyB->SetAwake(true);\r
+ m_maxMotorForce = force;\r
+}\r
+\r
+float32 b2LineJoint::GetMotorForce() const\r
+{\r
+ return m_motorImpulse;\r
+}\r
+\r
+\r
+\r
+\r
+\r
/*\r
-* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
* 3. This notice may not be removed or altered from any source distribution.\r
*/\r
\r
-#ifndef B2_WHEEL_JOINT_H\r
-#define B2_WHEEL_JOINT_H\r
+#ifndef B2_LINE_JOINT_H\r
+#define B2_LINE_JOINT_H\r
\r
#include <Box2D/Dynamics/Joints/b2Joint.h>\r
\r
-/// Wheel joint definition. This requires defining a line of\r
+/// Line joint definition. This requires defining a line of\r
/// motion using an axis and an anchor point. The definition uses local\r
/// anchor points and a local axis so that the initial configuration\r
/// can violate the constraint slightly. The joint translation is zero\r
/// when the local anchor points coincide in world space. Using local\r
/// anchors and a local axis helps when saving and loading a game.\r
-struct b2WheelJointDef : public b2JointDef\r
+struct b2LineJointDef : public b2JointDef\r
{\r
- b2WheelJointDef()\r
+ b2LineJointDef()\r
{\r
- type = e_wheelJoint;\r
+ type = e_lineJoint;\r
localAnchorA.SetZero();\r
localAnchorB.SetZero();\r
localAxisA.Set(1.0f, 0.0f);\r
+ enableLimit = false;\r
+ lowerTranslation = 0.0f;\r
+ upperTranslation = 0.0f;\r
enableMotor = false;\r
- maxMotorTorque = 0.0f;\r
+ maxMotorForce = 0.0f;\r
motorSpeed = 0.0f;\r
- frequencyHz = 2.0f;\r
- dampingRatio = 0.7f;\r
}\r
\r
/// Initialize the bodies, anchors, axis, and reference angle using the world\r
/// The local translation axis in body1.\r
b2Vec2 localAxisA;\r
\r
+ /// Enable/disable the joint limit.\r
+ bool enableLimit;\r
+\r
+ /// The lower translation limit, usually in meters.\r
+ float32 lowerTranslation;\r
+\r
+ /// The upper translation limit, usually in meters.\r
+ float32 upperTranslation;\r
+\r
/// Enable/disable the joint motor.\r
bool enableMotor;\r
\r
/// The maximum motor torque, usually in N-m.\r
- float32 maxMotorTorque;\r
+ float32 maxMotorForce;\r
\r
/// The desired motor speed in radians per second.\r
float32 motorSpeed;\r
-\r
- /// Suspension frequency, zero indicates no suspension\r
- float32 frequencyHz;\r
-\r
- /// Suspension damping ratio, one indicates critical damping\r
- float32 dampingRatio;\r
};\r
\r
-/// A wheel joint. This joint provides two degrees of freedom: translation\r
+/// A line joint. This joint provides two degrees of freedom: translation\r
/// along an axis fixed in body1 and rotation in the plane. You can use a\r
/// joint limit to restrict the range of motion and a joint motor to drive\r
-/// the rotation or to model rotational friction.\r
-/// This joint is designed for vehicle suspensions.\r
-class b2WheelJoint : public b2Joint\r
+/// the motion or to model joint friction.\r
+class b2LineJoint : public b2Joint\r
{\r
public:\r
b2Vec2 GetAnchorA() const;\r
/// Get the current joint translation speed, usually in meters per second.\r
float32 GetJointSpeed() const;\r
\r
+ /// Is the joint limit enabled?\r
+ bool IsLimitEnabled() const;\r
+\r
+ /// Enable/disable the joint limit.\r
+ void EnableLimit(bool flag);\r
+\r
+ /// Get the lower joint limit, usually in meters.\r
+ float32 GetLowerLimit() const;\r
+\r
+ /// Get the upper joint limit, usually in meters.\r
+ float32 GetUpperLimit() const;\r
+\r
+ /// Set the joint limits, usually in meters.\r
+ void SetLimits(float32 lower, float32 upper);\r
+\r
/// Is the joint motor enabled?\r
bool IsMotorEnabled() const;\r
\r
/// Enable/disable the joint motor.\r
void EnableMotor(bool flag);\r
\r
- /// Set the motor speed, usually in radians per second.\r
+ /// Set the motor speed, usually in meters per second.\r
void SetMotorSpeed(float32 speed);\r
\r
- /// Get the motor speed, usually in radians per second.\r
+ /// Get the motor speed, usually in meters per second.\r
float32 GetMotorSpeed() const;\r
\r
- /// Set/Get the maximum motor force, usually in N-m.\r
- void SetMaxMotorTorque(float32 torque);\r
- float32 GetMaxMotorTorque() const;\r
-\r
- /// Get the current motor torque given the inverse time step, usually in N-m.\r
- float32 GetMotorTorque(float32 inv_dt) const;\r
+ /// Set/Get the maximum motor force, usually in N.\r
+ void SetMaxMotorForce(float32 force);\r
+ float32 GetMaxMotorForce() const;\r
\r
- /// Set/Get the spring frequency in hertz. Setting the frequency to zero disables the spring.\r
- void SetSpringFrequencyHz(float32 hz);\r
- float32 GetSpringFrequencyHz() const;\r
-\r
- /// Set/Get the spring damping ratio\r
- void SetSpringDampingRatio(float32 ratio);\r
- float32 GetSpringDampingRatio() const;\r
+ /// Get the current motor force, usually in N.\r
+ float32 GetMotorForce() const;\r
\r
protected:\r
\r
friend class b2Joint;\r
- b2WheelJoint(const b2WheelJointDef* def);\r
+ b2LineJoint(const b2LineJointDef* def);\r
\r
void InitVelocityConstraints(const b2TimeStep& step);\r
void SolveVelocityConstraints(const b2TimeStep& step);\r
bool SolvePositionConstraints(float32 baumgarte);\r
\r
- b2Vec2 m_localAnchorA;\r
- b2Vec2 m_localAnchorB;\r
- b2Vec2 m_localXAxisA;\r
- b2Vec2 m_localYAxisA;\r
+ b2Vec2 m_localAnchor1;\r
+ b2Vec2 m_localAnchor2;\r
+ b2Vec2 m_localXAxis1;\r
+ b2Vec2 m_localYAxis1;\r
+\r
+ b2Vec2 m_axis, m_perp;\r
+ float32 m_s1, m_s2;\r
+ float32 m_a1, m_a2;\r
\r
- b2Vec2 m_ax, m_ay;\r
- float32 m_sAx, m_sBx;\r
- float32 m_sAy, m_sBy;\r
+ b2Mat22 m_K;\r
+ b2Vec2 m_impulse;\r
\r
- float32 m_mass;\r
- float32 m_impulse;\r
- float32 m_motorMass;\r
+ float32 m_motorMass; // effective mass for motor/limit translational constraint.\r
float32 m_motorImpulse;\r
- float32 m_springMass;\r
- float32 m_springImpulse;\r
\r
- float32 m_maxMotorTorque;\r
+ float32 m_lowerTranslation;\r
+ float32 m_upperTranslation;\r
+ float32 m_maxMotorForce;\r
float32 m_motorSpeed;\r
- float32 m_frequencyHz;\r
- float32 m_dampingRatio;\r
- float32 m_bias;\r
- float32 m_gamma;\r
\r
+ bool m_enableLimit;\r
bool m_enableMotor;\r
+ b2LimitState m_limitState;\r
};\r
\r
-inline float32 b2WheelJoint::GetMotorSpeed() const\r
+inline float32 b2LineJoint::GetMotorSpeed() const\r
{\r
return m_motorSpeed;\r
}\r
\r
-inline float32 b2WheelJoint::GetMaxMotorTorque() const\r
-{\r
- return m_maxMotorTorque;\r
-}\r
-\r
-inline void b2WheelJoint::SetSpringFrequencyHz(float32 hz)\r
-{\r
- m_frequencyHz = hz;\r
-}\r
-\r
-inline float32 b2WheelJoint::GetSpringFrequencyHz() const\r
-{\r
- return m_frequencyHz;\r
-}\r
-\r
-inline void b2WheelJoint::SetSpringDampingRatio(float32 ratio)\r
-{\r
- m_dampingRatio = ratio;\r
-}\r
-\r
-inline float32 b2WheelJoint::GetSpringDampingRatio() const\r
-{\r
- return m_dampingRatio;\r
-}\r
-\r
#endif\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
m_a2 = b2Cross(r2, m_axis);\r
\r
m_motorMass = m_invMassA + m_invMassB + m_invIA * m_a1 * m_a1 + m_invIB * m_a2 * m_a2;\r
- if (m_motorMass > 0.0f)\r
+ if (m_motorMass > b2_epsilon)\r
{\r
m_motorMass = 1.0f / m_motorMass;\r
}\r
float32 k12 = i1 * m_s1 + i2 * m_s2;\r
float32 k13 = i1 * m_s1 * m_a1 + i2 * m_s2 * m_a2;\r
float32 k22 = i1 + i2;\r
- if (k22 == 0.0f)\r
- {\r
- k22 = 1.0f;\r
- }\r
float32 k23 = i1 * m_a1 + i2 * m_a2;\r
float32 k33 = m1 + m2 + i1 * m_a1 * m_a1 + i2 * m_a2 * m_a2;\r
\r
float32 k12 = i1 * m_s1 + i2 * m_s2;\r
float32 k13 = i1 * m_s1 * m_a1 + i2 * m_s2 * m_a2;\r
float32 k22 = i1 + i2;\r
- if (k22 == 0.0f)\r
- {\r
- k22 = 1.0f;\r
- }\r
float32 k23 = i1 * m_a1 + i2 * m_a2;\r
float32 k33 = m1 + m2 + i1 * m_a1 * m_a1 + i2 * m_a2 * m_a2;\r
\r
float32 k11 = m1 + m2 + i1 * m_s1 * m_s1 + i2 * m_s2 * m_s2;\r
float32 k12 = i1 * m_s1 + i2 * m_s2;\r
float32 k22 = i1 + i2;\r
- if (k22 == 0.0f)\r
- {\r
- k22 = 1.0f;\r
- }\r
\r
m_K.col1.Set(k11, k12, 0.0f);\r
m_K.col2.Set(k12, k22, 0.0f);\r
\r
void b2PrismaticJoint::EnableLimit(bool flag)\r
{\r
- if (flag != m_enableLimit)\r
- {\r
- m_bodyA->SetAwake(true);\r
- m_bodyB->SetAwake(true);\r
- m_enableLimit = flag;\r
- m_impulse.z = 0.0f;\r
- }\r
+ m_bodyA->SetAwake(true);\r
+ m_bodyB->SetAwake(true);\r
+ m_enableLimit = flag;\r
}\r
\r
float32 b2PrismaticJoint::GetLowerLimit() const\r
void b2PrismaticJoint::SetLimits(float32 lower, float32 upper)\r
{\r
b2Assert(lower <= upper);\r
- if (lower != m_lowerTranslation || upper != m_upperTranslation)\r
- {\r
- m_bodyA->SetAwake(true);\r
- m_bodyB->SetAwake(true);\r
- m_lowerTranslation = lower;\r
- m_upperTranslation = upper;\r
- m_impulse.z = 0.0f;\r
- }\r
+ m_bodyA->SetAwake(true);\r
+ m_bodyB->SetAwake(true);\r
+ m_lowerTranslation = lower;\r
+ m_upperTranslation = upper;\r
}\r
\r
bool b2PrismaticJoint::IsMotorEnabled() const\r
m_maxMotorForce = force;\r
}\r
\r
-float32 b2PrismaticJoint::GetMotorForce(float32 inv_dt) const\r
+float32 b2PrismaticJoint::GetMotorForce() const\r
{\r
- return inv_dt * m_motorImpulse;\r
+ return m_motorImpulse;\r
}\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/// Set the maximum motor force, usually in N.\r
void SetMaxMotorForce(float32 force);\r
\r
- /// Get the current motor force given the inverse time step, usually in N.\r
- float32 GetMotorForce(float32 inv_dt) const;\r
+ /// Get the current motor force, usually in N.\r
+ float32 GetMotorForce() const;\r
\r
protected:\r
friend class b2Joint;\r
/*\r
-* Copyright (c) 2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
// length1 = norm(p1 - s1)\r
// length2 = norm(p2 - s2)\r
// C0 = (length1 + ratio * length2)_initial\r
-// C = C0 - (length1 + ratio * length2)\r
+// C = C0 - (length1 + ratio * length2) >= 0\r
// u1 = (p1 - s1) / norm(p1 - s1)\r
// u2 = (p2 - s2) / norm(p2 - s2)\r
// Cdot = -dot(u1, v1 + cross(w1, r1)) - ratio * dot(u2, v2 + cross(w2, r2))\r
// J = -[u1 cross(r1, u1) ratio * u2 ratio * cross(r2, u2)]\r
// K = J * invM * JT\r
// = invMass1 + invI1 * cross(r1, u1)^2 + ratio^2 * (invMass2 + invI2 * cross(r2, u2)^2)\r
+//\r
+// Limit:\r
+// C = maxLength - length\r
+// u = (p - s) / norm(p - s)\r
+// Cdot = -dot(u, v + cross(w, r))\r
+// K = invMass + invI * cross(r, u)^2\r
+// 0 <= impulse\r
\r
void b2PulleyJointDef::Initialize(b2Body* b1, b2Body* b2,\r
const b2Vec2& ga1, const b2Vec2& ga2,\r
ratio = r;\r
b2Assert(ratio > b2_epsilon);\r
float32 C = lengthA + ratio * lengthB;\r
+ maxLengthA = C - ratio * b2_minPulleyLength;\r
+ maxLengthB = (C - b2_minPulleyLength) / ratio;\r
}\r
\r
b2PulleyJoint::b2PulleyJoint(const b2PulleyJointDef* def)\r
\r
m_constant = def->lengthA + m_ratio * def->lengthB;\r
\r
+ m_maxLength1 = b2Min(def->maxLengthA, m_constant - m_ratio * b2_minPulleyLength);\r
+ m_maxLength2 = b2Min(def->maxLengthB, (m_constant - b2_minPulleyLength) / m_ratio);\r
+\r
m_impulse = 0.0f;\r
+ m_limitImpulse1 = 0.0f;\r
+ m_limitImpulse2 = 0.0f;\r
}\r
\r
void b2PulleyJoint::InitVelocityConstraints(const b2TimeStep& step)\r
float32 length1 = m_u1.Length();\r
float32 length2 = m_u2.Length();\r
\r
- if (length1 > 10.0f * b2_linearSlop)\r
+ if (length1 > b2_linearSlop)\r
{\r
m_u1 *= 1.0f / length1;\r
}\r
m_u1.SetZero();\r
}\r
\r
- if (length2 > 10.0f * b2_linearSlop)\r
+ if (length2 > b2_linearSlop)\r
{\r
m_u2 *= 1.0f / length2;\r
}\r
m_u2.SetZero();\r
}\r
\r
- // Compute effective mass.\r
- float32 cr1u1 = b2Cross(r1, m_u1);\r
- float32 cr2u2 = b2Cross(r2, m_u2);\r
-\r
- float32 m1 = b1->m_invMass + b1->m_invI * cr1u1 * cr1u1;\r
- float32 m2 = b2->m_invMass + b2->m_invI * cr2u2 * cr2u2;\r
+ float32 C = m_constant - length1 - m_ratio * length2;\r
+ if (C > 0.0f)\r
+ {\r
+ m_state = e_inactiveLimit;\r
+ m_impulse = 0.0f;\r
+ }\r
+ else\r
+ {\r
+ m_state = e_atUpperLimit;\r
+ }\r
\r
- m_pulleyMass = m1 + m_ratio * m_ratio * m2;\r
+ if (length1 < m_maxLength1)\r
+ {\r
+ m_limitState1 = e_inactiveLimit;\r
+ m_limitImpulse1 = 0.0f;\r
+ }\r
+ else\r
+ {\r
+ m_limitState1 = e_atUpperLimit;\r
+ }\r
\r
- if (m_pulleyMass > 0.0f)\r
+ if (length2 < m_maxLength2)\r
{\r
- m_pulleyMass = 1.0f / m_pulleyMass;\r
+ m_limitState2 = e_inactiveLimit;\r
+ m_limitImpulse2 = 0.0f;\r
}\r
+ else\r
+ {\r
+ m_limitState2 = e_atUpperLimit;\r
+ }\r
+\r
+ // Compute effective mass.\r
+ float32 cr1u1 = b2Cross(r1, m_u1);\r
+ float32 cr2u2 = b2Cross(r2, m_u2);\r
+\r
+ m_limitMass1 = b1->m_invMass + b1->m_invI * cr1u1 * cr1u1;\r
+ m_limitMass2 = b2->m_invMass + b2->m_invI * cr2u2 * cr2u2;\r
+ m_pulleyMass = m_limitMass1 + m_ratio * m_ratio * m_limitMass2;\r
+ b2Assert(m_limitMass1 > b2_epsilon);\r
+ b2Assert(m_limitMass2 > b2_epsilon);\r
+ b2Assert(m_pulleyMass > b2_epsilon);\r
+ m_limitMass1 = 1.0f / m_limitMass1;\r
+ m_limitMass2 = 1.0f / m_limitMass2;\r
+ m_pulleyMass = 1.0f / m_pulleyMass;\r
\r
if (step.warmStarting)\r
{\r
// Scale impulses to support variable time steps.\r
m_impulse *= step.dtRatio;\r
+ m_limitImpulse1 *= step.dtRatio;\r
+ m_limitImpulse2 *= step.dtRatio;\r
\r
// Warm starting.\r
- b2Vec2 P1 = -(m_impulse) * m_u1;\r
- b2Vec2 P2 = (-m_ratio * m_impulse) * m_u2;\r
+ b2Vec2 P1 = -(m_impulse + m_limitImpulse1) * m_u1;\r
+ b2Vec2 P2 = (-m_ratio * m_impulse - m_limitImpulse2) * m_u2;\r
b1->m_linearVelocity += b1->m_invMass * P1;\r
b1->m_angularVelocity += b1->m_invI * b2Cross(r1, P1);\r
b2->m_linearVelocity += b2->m_invMass * P2;\r
else\r
{\r
m_impulse = 0.0f;\r
+ m_limitImpulse1 = 0.0f;\r
+ m_limitImpulse2 = 0.0f;\r
}\r
}\r
\r
b2Vec2 r1 = b2Mul(b1->GetTransform().R, m_localAnchor1 - b1->GetLocalCenter());\r
b2Vec2 r2 = b2Mul(b2->GetTransform().R, m_localAnchor2 - b2->GetLocalCenter());\r
\r
+ if (m_state == e_atUpperLimit)\r
{\r
b2Vec2 v1 = b1->m_linearVelocity + b2Cross(b1->m_angularVelocity, r1);\r
b2Vec2 v2 = b2->m_linearVelocity + b2Cross(b2->m_angularVelocity, r2);\r
\r
float32 Cdot = -b2Dot(m_u1, v1) - m_ratio * b2Dot(m_u2, v2);\r
float32 impulse = m_pulleyMass * (-Cdot);\r
- m_impulse += impulse;\r
+ float32 oldImpulse = m_impulse;\r
+ m_impulse = b2Max(0.0f, m_impulse + impulse);\r
+ impulse = m_impulse - oldImpulse;\r
\r
b2Vec2 P1 = -impulse * m_u1;\r
b2Vec2 P2 = -m_ratio * impulse * m_u2;\r
b2->m_linearVelocity += b2->m_invMass * P2;\r
b2->m_angularVelocity += b2->m_invI * b2Cross(r2, P2);\r
}\r
+\r
+ if (m_limitState1 == e_atUpperLimit)\r
+ {\r
+ b2Vec2 v1 = b1->m_linearVelocity + b2Cross(b1->m_angularVelocity, r1);\r
+\r
+ float32 Cdot = -b2Dot(m_u1, v1);\r
+ float32 impulse = -m_limitMass1 * Cdot;\r
+ float32 oldImpulse = m_limitImpulse1;\r
+ m_limitImpulse1 = b2Max(0.0f, m_limitImpulse1 + impulse);\r
+ impulse = m_limitImpulse1 - oldImpulse;\r
+\r
+ b2Vec2 P1 = -impulse * m_u1;\r
+ b1->m_linearVelocity += b1->m_invMass * P1;\r
+ b1->m_angularVelocity += b1->m_invI * b2Cross(r1, P1);\r
+ }\r
+\r
+ if (m_limitState2 == e_atUpperLimit)\r
+ {\r
+ b2Vec2 v2 = b2->m_linearVelocity + b2Cross(b2->m_angularVelocity, r2);\r
+\r
+ float32 Cdot = -b2Dot(m_u2, v2);\r
+ float32 impulse = -m_limitMass2 * Cdot;\r
+ float32 oldImpulse = m_limitImpulse2;\r
+ m_limitImpulse2 = b2Max(0.0f, m_limitImpulse2 + impulse);\r
+ impulse = m_limitImpulse2 - oldImpulse;\r
+\r
+ b2Vec2 P2 = -impulse * m_u2;\r
+ b2->m_linearVelocity += b2->m_invMass * P2;\r
+ b2->m_angularVelocity += b2->m_invI * b2Cross(r2, P2);\r
+ }\r
}\r
\r
bool b2PulleyJoint::SolvePositionConstraints(float32 baumgarte)\r
b2Vec2 s1 = m_groundAnchor1;\r
b2Vec2 s2 = m_groundAnchor2;\r
\r
- b2Vec2 r1 = b2Mul(b1->m_xf.R, m_localAnchor1 - b1->GetLocalCenter());\r
- b2Vec2 r2 = b2Mul(b2->m_xf.R, m_localAnchor2 - b2->GetLocalCenter());\r
+ float32 linearError = 0.0f;\r
\r
- b2Vec2 p1 = b1->m_sweep.c + r1;\r
- b2Vec2 p2 = b2->m_sweep.c + r2;\r
+ if (m_state == e_atUpperLimit)\r
+ {\r
+ b2Vec2 r1 = b2Mul(b1->GetTransform().R, m_localAnchor1 - b1->GetLocalCenter());\r
+ b2Vec2 r2 = b2Mul(b2->GetTransform().R, m_localAnchor2 - b2->GetLocalCenter());\r
+\r
+ b2Vec2 p1 = b1->m_sweep.c + r1;\r
+ b2Vec2 p2 = b2->m_sweep.c + r2;\r
+\r
+ // Get the pulley axes.\r
+ m_u1 = p1 - s1;\r
+ m_u2 = p2 - s2;\r
+\r
+ float32 length1 = m_u1.Length();\r
+ float32 length2 = m_u2.Length();\r
+\r
+ if (length1 > b2_linearSlop)\r
+ {\r
+ m_u1 *= 1.0f / length1;\r
+ }\r
+ else\r
+ {\r
+ m_u1.SetZero();\r
+ }\r
+\r
+ if (length2 > b2_linearSlop)\r
+ {\r
+ m_u2 *= 1.0f / length2;\r
+ }\r
+ else\r
+ {\r
+ m_u2.SetZero();\r
+ }\r
+\r
+ float32 C = m_constant - length1 - m_ratio * length2;\r
+ linearError = b2Max(linearError, -C);\r
+\r
+ C = b2Clamp(C + b2_linearSlop, -b2_maxLinearCorrection, 0.0f);\r
+ float32 impulse = -m_pulleyMass * C;\r
\r
- // Get the pulley axes.\r
- b2Vec2 u1 = p1 - s1;\r
- b2Vec2 u2 = p2 - s2;\r
+ b2Vec2 P1 = -impulse * m_u1;\r
+ b2Vec2 P2 = -m_ratio * impulse * m_u2;\r
\r
- float32 length1 = u1.Length();\r
- float32 length2 = u2.Length();\r
+ b1->m_sweep.c += b1->m_invMass * P1;\r
+ b1->m_sweep.a += b1->m_invI * b2Cross(r1, P1);\r
+ b2->m_sweep.c += b2->m_invMass * P2;\r
+ b2->m_sweep.a += b2->m_invI * b2Cross(r2, P2);\r
\r
- if (length1 > 10.0f * b2_linearSlop)\r
- {\r
- u1 *= 1.0f / length1;\r
- }\r
- else\r
- {\r
- u1.SetZero();\r
+ b1->SynchronizeTransform();\r
+ b2->SynchronizeTransform();\r
}\r
\r
- if (length2 > 10.0f * b2_linearSlop)\r
- {\r
- u2 *= 1.0f / length2;\r
- }\r
- else\r
+ if (m_limitState1 == e_atUpperLimit)\r
{\r
- u2.SetZero();\r
- }\r
-\r
- // Compute effective mass.\r
- float32 cr1u1 = b2Cross(r1, u1);\r
- float32 cr2u2 = b2Cross(r2, u2);\r
+ b2Vec2 r1 = b2Mul(b1->GetTransform().R, m_localAnchor1 - b1->GetLocalCenter());\r
+ b2Vec2 p1 = b1->m_sweep.c + r1;\r
+\r
+ m_u1 = p1 - s1;\r
+ float32 length1 = m_u1.Length();\r
+\r
+ if (length1 > b2_linearSlop)\r
+ {\r
+ m_u1 *= 1.0f / length1;\r
+ }\r
+ else\r
+ {\r
+ m_u1.SetZero();\r
+ }\r
+\r
+ float32 C = m_maxLength1 - length1;\r
+ linearError = b2Max(linearError, -C);\r
+ C = b2Clamp(C + b2_linearSlop, -b2_maxLinearCorrection, 0.0f);\r
+ float32 impulse = -m_limitMass1 * C;\r
\r
- float32 m1 = b1->m_invMass + b1->m_invI * cr1u1 * cr1u1;\r
- float32 m2 = b2->m_invMass + b2->m_invI * cr2u2 * cr2u2;\r
+ b2Vec2 P1 = -impulse * m_u1;\r
+ b1->m_sweep.c += b1->m_invMass * P1;\r
+ b1->m_sweep.a += b1->m_invI * b2Cross(r1, P1);\r
\r
- float32 mass = m1 + m_ratio * m_ratio * m2;\r
+ b1->SynchronizeTransform();\r
+ }\r
\r
- if (mass > 0.0f)\r
+ if (m_limitState2 == e_atUpperLimit)\r
{\r
- mass = 1.0f / mass;\r
+ b2Vec2 r2 = b2Mul(b2->GetTransform().R, m_localAnchor2 - b2->GetLocalCenter());\r
+ b2Vec2 p2 = b2->m_sweep.c + r2;\r
+\r
+ m_u2 = p2 - s2;\r
+ float32 length2 = m_u2.Length();\r
+\r
+ if (length2 > b2_linearSlop)\r
+ {\r
+ m_u2 *= 1.0f / length2;\r
+ }\r
+ else\r
+ {\r
+ m_u2.SetZero();\r
+ }\r
+\r
+ float32 C = m_maxLength2 - length2;\r
+ linearError = b2Max(linearError, -C);\r
+ C = b2Clamp(C + b2_linearSlop, -b2_maxLinearCorrection, 0.0f);\r
+ float32 impulse = -m_limitMass2 * C;\r
+\r
+ b2Vec2 P2 = -impulse * m_u2;\r
+ b2->m_sweep.c += b2->m_invMass * P2;\r
+ b2->m_sweep.a += b2->m_invI * b2Cross(r2, P2);\r
+\r
+ b2->SynchronizeTransform();\r
}\r
\r
- float32 C = m_constant - length1 - m_ratio * length2;\r
- float32 linearError = b2Abs(C);\r
-\r
- float32 impulse = -mass * C;\r
-\r
- b2Vec2 P1 = -impulse * u1;\r
- b2Vec2 P2 = -m_ratio * impulse * u2;\r
-\r
- b1->m_sweep.c += b1->m_invMass * P1;\r
- b1->m_sweep.a += b1->m_invI * b2Cross(r1, P1);\r
- b2->m_sweep.c += b2->m_invMass * P2;\r
- b2->m_sweep.a += b2->m_invI * b2Cross(r2, P2);\r
-\r
- b1->SynchronizeTransform();\r
- b2->SynchronizeTransform();\r
-\r
return linearError < b2_linearSlop;\r
}\r
\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
const float32 b2_minPulleyLength = 2.0f;\r
\r
/// Pulley joint definition. This requires two ground anchors,\r
-/// two dynamic body anchor points, and a pulley ratio.\r
+/// two dynamic body anchor points, max lengths for each side,\r
+/// and a pulley ratio.\r
struct b2PulleyJointDef : public b2JointDef\r
{\r
b2PulleyJointDef()\r
localAnchorA.Set(-1.0f, 0.0f);\r
localAnchorB.Set(1.0f, 0.0f);\r
lengthA = 0.0f;\r
+ maxLengthA = 0.0f;\r
lengthB = 0.0f;\r
+ maxLengthB = 0.0f;\r
ratio = 1.0f;\r
collideConnected = true;\r
}\r
/// The a reference length for the segment attached to bodyA.\r
float32 lengthA;\r
\r
+ /// The maximum length of the segment attached to bodyA.\r
+ float32 maxLengthA;\r
+\r
/// The a reference length for the segment attached to bodyB.\r
float32 lengthB;\r
\r
+ /// The maximum length of the segment attached to bodyB.\r
+ float32 maxLengthB;\r
+\r
/// The pulley ratio, used to simulate a block-and-tackle.\r
float32 ratio;\r
};\r
/// The pulley supports a ratio such that:\r
/// length1 + ratio * length2 <= constant\r
/// Yes, the force transmitted is scaled by the ratio.\r
-/// Warning: the pulley joint can get a bit squirrelly by itself. They often\r
-/// work better when combined with prismatic joints. You should also cover the\r
-/// the anchor points with static shapes to prevent one side from going to\r
-/// zero length.\r
+/// The pulley also enforces a maximum length limit on both sides. This is\r
+/// useful to prevent one side of the pulley hitting the top.\r
class b2PulleyJoint : public b2Joint\r
{\r
public:\r
float32 m_constant;\r
float32 m_ratio;\r
\r
+ float32 m_maxLength1;\r
+ float32 m_maxLength2;\r
+\r
// Effective masses\r
float32 m_pulleyMass;\r
+ float32 m_limitMass1;\r
+ float32 m_limitMass2;\r
\r
// Impulses for accumulation/warm starting.\r
float32 m_impulse;\r
+ float32 m_limitImpulse1;\r
+ float32 m_limitImpulse2;\r
+\r
+ b2LimitState m_state;\r
+ b2LimitState m_limitState1;\r
+ b2LimitState m_limitState2;\r
};\r
\r
#endif\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
float32 newImpulse = m_impulse.z + impulse.z;\r
if (newImpulse < 0.0f)\r
{\r
- b2Vec2 rhs = -Cdot1 + m_impulse.z * b2Vec2(m_mass.col3.x, m_mass.col3.y);\r
- b2Vec2 reduced = m_mass.Solve22(rhs);\r
+ b2Vec2 reduced = m_mass.Solve22(-Cdot1);\r
impulse.x = reduced.x;\r
impulse.y = reduced.y;\r
impulse.z = -m_impulse.z;\r
m_impulse.y += reduced.y;\r
m_impulse.z = 0.0f;\r
}\r
- else\r
- {\r
- m_impulse += impulse;\r
- }\r
}\r
else if (m_limitState == e_atUpperLimit)\r
{\r
float32 newImpulse = m_impulse.z + impulse.z;\r
if (newImpulse > 0.0f)\r
{\r
- b2Vec2 rhs = -Cdot1 + m_impulse.z * b2Vec2(m_mass.col3.x, m_mass.col3.y);\r
- b2Vec2 reduced = m_mass.Solve22(rhs);\r
+ b2Vec2 reduced = m_mass.Solve22(-Cdot1);\r
impulse.x = reduced.x;\r
impulse.y = reduced.y;\r
impulse.z = -m_impulse.z;\r
m_impulse.y += reduced.y;\r
m_impulse.z = 0.0f;\r
}\r
- else\r
- {\r
- m_impulse += impulse;\r
- }\r
}\r
\r
b2Vec2 P(impulse.x, impulse.y);\r
m_enableMotor = flag;\r
}\r
\r
-float32 b2RevoluteJoint::GetMotorTorque(float32 inv_dt) const\r
+float32 b2RevoluteJoint::GetMotorTorque() const\r
{\r
- return inv_dt * m_motorImpulse;\r
+ return m_motorImpulse;\r
}\r
\r
void b2RevoluteJoint::SetMotorSpeed(float32 speed)\r
\r
void b2RevoluteJoint::EnableLimit(bool flag)\r
{\r
- if (flag != m_enableLimit)\r
- {\r
- m_bodyA->SetAwake(true);\r
- m_bodyB->SetAwake(true);\r
- m_enableLimit = flag;\r
- m_impulse.z = 0.0f;\r
- }\r
+ m_bodyA->SetAwake(true);\r
+ m_bodyB->SetAwake(true);\r
+ m_enableLimit = flag;\r
}\r
\r
float32 b2RevoluteJoint::GetLowerLimit() const\r
void b2RevoluteJoint::SetLimits(float32 lower, float32 upper)\r
{\r
b2Assert(lower <= upper);\r
- \r
- if (lower != m_lowerAngle || upper != m_upperAngle)\r
- {\r
- m_bodyA->SetAwake(true);\r
- m_bodyB->SetAwake(true);\r
- m_impulse.z = 0.0f;\r
- m_lowerAngle = lower;\r
- m_upperAngle = upper;\r
- }\r
+ m_bodyA->SetAwake(true);\r
+ m_bodyB->SetAwake(true);\r
+ m_lowerAngle = lower;\r
+ m_upperAngle = upper;\r
}\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2Vec2 GetAnchorA() const;\r
b2Vec2 GetAnchorB() const;\r
\r
+ b2Vec2 GetReactionForce(float32 inv_dt) const;\r
+ float32 GetReactionTorque(float32 inv_dt) const;\r
+\r
/// Get the current joint angle in radians.\r
float32 GetJointAngle() const;\r
\r
/// Set the maximum motor torque, usually in N-m.\r
void SetMaxMotorTorque(float32 torque);\r
\r
- /// Get the reaction force given the inverse time step.\r
- /// Unit is N.\r
- b2Vec2 GetReactionForce(float32 inv_dt) const;\r
-\r
- /// Get the reaction torque due to the joint limit given the inverse time step.\r
- /// Unit is N*m.\r
- float32 GetReactionTorque(float32 inv_dt) const;\r
-\r
- /// Get the current motor torque given the inverse time step.\r
- /// Unit is N*m.\r
- float32 GetMotorTorque(float32 inv_dt) const;\r
+ /// Get the current motor torque, usually in N-m.\r
+ float32 GetMotorTorque() const;\r
\r
protected:\r
\r
+++ /dev/null
-/*\r
-* Copyright (c) 2007-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Dynamics/Joints/b2RopeJoint.h>\r
-#include <Box2D/Dynamics/b2Body.h>\r
-#include <Box2D/Dynamics/b2TimeStep.h>\r
-\r
-\r
-// Limit:\r
-// C = norm(pB - pA) - L\r
-// u = (pB - pA) / norm(pB - pA)\r
-// Cdot = dot(u, vB + cross(wB, rB) - vA - cross(wA, rA))\r
-// J = [-u -cross(rA, u) u cross(rB, u)]\r
-// K = J * invM * JT\r
-// = invMassA + invIA * cross(rA, u)^2 + invMassB + invIB * cross(rB, u)^2\r
-\r
-b2RopeJoint::b2RopeJoint(const b2RopeJointDef* def)\r
-: b2Joint(def)\r
-{\r
- m_localAnchorA = def->localAnchorA;\r
- m_localAnchorB = def->localAnchorB;\r
-\r
- m_maxLength = def->maxLength;\r
-\r
- m_mass = 0.0f;\r
- m_impulse = 0.0f;\r
- m_state = e_inactiveLimit;\r
- m_length = 0.0f;\r
-}\r
-\r
-void b2RopeJoint::InitVelocityConstraints(const b2TimeStep& step)\r
-{\r
- b2Body* bA = m_bodyA;\r
- b2Body* bB = m_bodyB;\r
-\r
- m_rA = b2Mul(bA->GetTransform().R, m_localAnchorA - bA->GetLocalCenter());\r
- m_rB = b2Mul(bB->GetTransform().R, m_localAnchorB - bB->GetLocalCenter());\r
-\r
- // Rope axis\r
- m_u = bB->m_sweep.c + m_rB - bA->m_sweep.c - m_rA;\r
-\r
- m_length = m_u.Length();\r
-\r
- float32 C = m_length - m_maxLength;\r
- if (C > 0.0f)\r
- {\r
- m_state = e_atUpperLimit;\r
- }\r
- else\r
- {\r
- m_state = e_inactiveLimit;\r
- }\r
-\r
- if (m_length > b2_linearSlop)\r
- {\r
- m_u *= 1.0f / m_length;\r
- }\r
- else\r
- {\r
- m_u.SetZero();\r
- m_mass = 0.0f;\r
- m_impulse = 0.0f;\r
- return;\r
- }\r
-\r
- // Compute effective mass.\r
- float32 crA = b2Cross(m_rA, m_u);\r
- float32 crB = b2Cross(m_rB, m_u);\r
- float32 invMass = bA->m_invMass + bA->m_invI * crA * crA + bB->m_invMass + bB->m_invI * crB * crB;\r
-\r
- m_mass = invMass != 0.0f ? 1.0f / invMass : 0.0f;\r
-\r
- if (step.warmStarting)\r
- {\r
- // Scale the impulse to support a variable time step.\r
- m_impulse *= step.dtRatio;\r
-\r
- b2Vec2 P = m_impulse * m_u;\r
- bA->m_linearVelocity -= bA->m_invMass * P;\r
- bA->m_angularVelocity -= bA->m_invI * b2Cross(m_rA, P);\r
- bB->m_linearVelocity += bB->m_invMass * P;\r
- bB->m_angularVelocity += bB->m_invI * b2Cross(m_rB, P);\r
- }\r
- else\r
- {\r
- m_impulse = 0.0f;\r
- }\r
-}\r
-\r
-void b2RopeJoint::SolveVelocityConstraints(const b2TimeStep& step)\r
-{\r
- B2_NOT_USED(step);\r
-\r
- b2Body* bA = m_bodyA;\r
- b2Body* bB = m_bodyB;\r
-\r
- // Cdot = dot(u, v + cross(w, r))\r
- b2Vec2 vA = bA->m_linearVelocity + b2Cross(bA->m_angularVelocity, m_rA);\r
- b2Vec2 vB = bB->m_linearVelocity + b2Cross(bB->m_angularVelocity, m_rB);\r
- float32 C = m_length - m_maxLength;\r
- float32 Cdot = b2Dot(m_u, vB - vA);\r
-\r
- // Predictive constraint.\r
- if (C < 0.0f)\r
- {\r
- Cdot += step.inv_dt * C;\r
- }\r
-\r
- float32 impulse = -m_mass * Cdot;\r
- float32 oldImpulse = m_impulse;\r
- m_impulse = b2Min(0.0f, m_impulse + impulse);\r
- impulse = m_impulse - oldImpulse;\r
-\r
- b2Vec2 P = impulse * m_u;\r
- bA->m_linearVelocity -= bA->m_invMass * P;\r
- bA->m_angularVelocity -= bA->m_invI * b2Cross(m_rA, P);\r
- bB->m_linearVelocity += bB->m_invMass * P;\r
- bB->m_angularVelocity += bB->m_invI * b2Cross(m_rB, P);\r
-}\r
-\r
-bool b2RopeJoint::SolvePositionConstraints(float32 baumgarte)\r
-{\r
- B2_NOT_USED(baumgarte);\r
-\r
- b2Body* bA = m_bodyA;\r
- b2Body* bB = m_bodyB;\r
-\r
- b2Vec2 rA = b2Mul(bA->GetTransform().R, m_localAnchorA - bA->GetLocalCenter());\r
- b2Vec2 rB = b2Mul(bB->GetTransform().R, m_localAnchorB - bB->GetLocalCenter());\r
-\r
- b2Vec2 u = bB->m_sweep.c + rB - bA->m_sweep.c - rA;\r
-\r
- float32 length = u.Normalize();\r
- float32 C = length - m_maxLength;\r
-\r
- C = b2Clamp(C, 0.0f, b2_maxLinearCorrection);\r
-\r
- float32 impulse = -m_mass * C;\r
- b2Vec2 P = impulse * u;\r
-\r
- bA->m_sweep.c -= bA->m_invMass * P;\r
- bA->m_sweep.a -= bA->m_invI * b2Cross(rA, P);\r
- bB->m_sweep.c += bB->m_invMass * P;\r
- bB->m_sweep.a += bB->m_invI * b2Cross(rB, P);\r
-\r
- bA->SynchronizeTransform();\r
- bB->SynchronizeTransform();\r
-\r
- return length - m_maxLength < b2_linearSlop;\r
-}\r
-\r
-b2Vec2 b2RopeJoint::GetAnchorA() const\r
-{\r
- return m_bodyA->GetWorldPoint(m_localAnchorA);\r
-}\r
-\r
-b2Vec2 b2RopeJoint::GetAnchorB() const\r
-{\r
- return m_bodyB->GetWorldPoint(m_localAnchorB);\r
-}\r
-\r
-b2Vec2 b2RopeJoint::GetReactionForce(float32 inv_dt) const\r
-{\r
- b2Vec2 F = (inv_dt * m_impulse) * m_u;\r
- return F;\r
-}\r
-\r
-float32 b2RopeJoint::GetReactionTorque(float32 inv_dt) const\r
-{\r
- B2_NOT_USED(inv_dt);\r
- return 0.0f;\r
-}\r
-\r
-float32 b2RopeJoint::GetMaxLength() const\r
-{\r
- return m_maxLength;\r
-}\r
-\r
-b2LimitState b2RopeJoint::GetLimitState() const\r
-{\r
- return m_state;\r
-}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef B2_ROPE_JOINT_H\r
-#define B2_ROPE_JOINT_H\r
-\r
-#include <Box2D/Dynamics/Joints/b2Joint.h>\r
-\r
-/// Rope joint definition. This requires two body anchor points and\r
-/// a maximum lengths.\r
-/// Note: by default the connected objects will not collide.\r
-/// see collideConnected in b2JointDef.\r
-struct b2RopeJointDef : public b2JointDef\r
-{\r
- b2RopeJointDef()\r
- {\r
- type = e_ropeJoint;\r
- localAnchorA.Set(-1.0f, 0.0f);\r
- localAnchorB.Set(1.0f, 0.0f);\r
- maxLength = 0.0f;\r
- }\r
-\r
- /// The local anchor point relative to bodyA's origin.\r
- b2Vec2 localAnchorA;\r
-\r
- /// The local anchor point relative to bodyB's origin.\r
- b2Vec2 localAnchorB;\r
-\r
- /// The maximum length of the rope.\r
- /// Warning: this must be larger than b2_linearSlop or\r
- /// the joint will have no effect.\r
- float32 maxLength;\r
-};\r
-\r
-/// A rope joint enforces a maximum distance between two points\r
-/// on two bodies. It has no other effect.\r
-/// Warning: if you attempt to change the maximum length during\r
-/// the simulation you will get some non-physical behavior.\r
-/// A model that would allow you to dynamically modify the length\r
-/// would have some sponginess, so I chose not to implement it\r
-/// that way. See b2DistanceJoint if you want to dynamically\r
-/// control length.\r
-class b2RopeJoint : public b2Joint\r
-{\r
-public:\r
- b2Vec2 GetAnchorA() const;\r
- b2Vec2 GetAnchorB() const;\r
-\r
- b2Vec2 GetReactionForce(float32 inv_dt) const;\r
- float32 GetReactionTorque(float32 inv_dt) const;\r
-\r
- /// Get the maximum length of the rope.\r
- float32 GetMaxLength() const;\r
-\r
- b2LimitState GetLimitState() const;\r
-\r
-protected:\r
-\r
- friend class b2Joint;\r
- b2RopeJoint(const b2RopeJointDef* data);\r
-\r
- void InitVelocityConstraints(const b2TimeStep& step);\r
- void SolveVelocityConstraints(const b2TimeStep& step);\r
- bool SolvePositionConstraints(float32 baumgarte);\r
-\r
- b2Vec2 m_localAnchorA;\r
- b2Vec2 m_localAnchorB;\r
-\r
- float32 m_maxLength;\r
- float32 m_length;\r
-\r
- // Jacobian info\r
- b2Vec2 m_u, m_rA, m_rB;\r
-\r
- // Effective mass\r
- float32 m_mass;\r
-\r
- // Impulses for accumulation/warm starting.\r
- float32 m_impulse;\r
-\r
- b2LimitState m_state;\r
-};\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Dynamics/Joints/b2WheelJoint.h>\r
-#include <Box2D/Dynamics/b2Body.h>\r
-#include <Box2D/Dynamics/b2TimeStep.h>\r
-\r
-// Linear constraint (point-to-line)\r
-// d = pB - pA = xB + rB - xA - rA\r
-// C = dot(ay, d)\r
-// Cdot = dot(d, cross(wA, ay)) + dot(ay, vB + cross(wB, rB) - vA - cross(wA, rA))\r
-// = -dot(ay, vA) - dot(cross(d + rA, ay), wA) + dot(ay, vB) + dot(cross(rB, ay), vB)\r
-// J = [-ay, -cross(d + rA, ay), ay, cross(rB, ay)]\r
-\r
-// Spring linear constraint\r
-// C = dot(ax, d)\r
-// Cdot = = -dot(ax, vA) - dot(cross(d + rA, ax), wA) + dot(ax, vB) + dot(cross(rB, ax), vB)\r
-// J = [-ax -cross(d+rA, ax) ax cross(rB, ax)]\r
-\r
-// Motor rotational constraint\r
-// Cdot = wB - wA\r
-// J = [0 0 -1 0 0 1]\r
-\r
-void b2WheelJointDef::Initialize(b2Body* bA, b2Body* bB, const b2Vec2& anchor, const b2Vec2& axis)\r
-{\r
- bodyA = bA;\r
- bodyB = bB;\r
- localAnchorA = bodyA->GetLocalPoint(anchor);\r
- localAnchorB = bodyB->GetLocalPoint(anchor);\r
- localAxisA = bodyA->GetLocalVector(axis);\r
-}\r
-\r
-b2WheelJoint::b2WheelJoint(const b2WheelJointDef* def)\r
-: b2Joint(def)\r
-{\r
- m_localAnchorA = def->localAnchorA;\r
- m_localAnchorB = def->localAnchorB;\r
- m_localXAxisA = def->localAxisA;\r
- m_localYAxisA = b2Cross(1.0f, m_localXAxisA);\r
-\r
- m_mass = 0.0f;\r
- m_impulse = 0.0f;\r
- m_motorMass = 0.0;\r
- m_motorImpulse = 0.0f;\r
- m_springMass = 0.0f;\r
- m_springImpulse = 0.0f;\r
-\r
- m_maxMotorTorque = def->maxMotorTorque;\r
- m_motorSpeed = def->motorSpeed;\r
- m_enableMotor = def->enableMotor;\r
-\r
- m_frequencyHz = def->frequencyHz;\r
- m_dampingRatio = def->dampingRatio;\r
-\r
- m_bias = 0.0f;\r
- m_gamma = 0.0f;\r
-\r
- m_ax.SetZero();\r
- m_ay.SetZero();\r
-}\r
-\r
-void b2WheelJoint::InitVelocityConstraints(const b2TimeStep& step)\r
-{\r
- b2Body* bA = m_bodyA;\r
- b2Body* bB = m_bodyB;\r
-\r
- m_localCenterA = bA->GetLocalCenter();\r
- m_localCenterB = bB->GetLocalCenter();\r
-\r
- b2Transform xfA = bA->GetTransform();\r
- b2Transform xfB = bB->GetTransform();\r
-\r
- // Compute the effective masses.\r
- b2Vec2 rA = b2Mul(xfA.R, m_localAnchorA - m_localCenterA);\r
- b2Vec2 rB = b2Mul(xfB.R, m_localAnchorB - m_localCenterB);\r
- b2Vec2 d = bB->m_sweep.c + rB - bA->m_sweep.c - rA;\r
-\r
- m_invMassA = bA->m_invMass;\r
- m_invIA = bA->m_invI;\r
- m_invMassB = bB->m_invMass;\r
- m_invIB = bB->m_invI;\r
-\r
- // Point to line constraint\r
- {\r
- m_ay = b2Mul(xfA.R, m_localYAxisA);\r
- m_sAy = b2Cross(d + rA, m_ay);\r
- m_sBy = b2Cross(rB, m_ay);\r
-\r
- m_mass = m_invMassA + m_invMassB + m_invIA * m_sAy * m_sAy + m_invIB * m_sBy * m_sBy;\r
-\r
- if (m_mass > 0.0f)\r
- {\r
- m_mass = 1.0f / m_mass;\r
- }\r
- }\r
-\r
- // Spring constraint\r
- m_springMass = 0.0f;\r
- if (m_frequencyHz > 0.0f)\r
- {\r
- m_ax = b2Mul(xfA.R, m_localXAxisA);\r
- m_sAx = b2Cross(d + rA, m_ax);\r
- m_sBx = b2Cross(rB, m_ax);\r
-\r
- float32 invMass = m_invMassA + m_invMassB + m_invIA * m_sAx * m_sAx + m_invIB * m_sBx * m_sBx;\r
-\r
- if (invMass > 0.0f)\r
- {\r
- m_springMass = 1.0f / invMass;\r
-\r
- float32 C = b2Dot(d, m_ax);\r
-\r
- // Frequency\r
- float32 omega = 2.0f * b2_pi * m_frequencyHz;\r
-\r
- // Damping coefficient\r
- float32 d = 2.0f * m_springMass * m_dampingRatio * omega;\r
-\r
- // Spring stiffness\r
- float32 k = m_springMass * omega * omega;\r
-\r
- // magic formulas\r
- m_gamma = step.dt * (d + step.dt * k);\r
- if (m_gamma > 0.0f)\r
- {\r
- m_gamma = 1.0f / m_gamma;\r
- }\r
-\r
- m_bias = C * step.dt * k * m_gamma;\r
-\r
- m_springMass = invMass + m_gamma;\r
- if (m_springMass > 0.0f)\r
- {\r
- m_springMass = 1.0f / m_springMass;\r
- }\r
- }\r
- }\r
- else\r
- {\r
- m_springImpulse = 0.0f;\r
- m_springMass = 0.0f;\r
- }\r
-\r
- // Rotational motor\r
- if (m_enableMotor)\r
- {\r
- m_motorMass = m_invIA + m_invIB;\r
- if (m_motorMass > 0.0f)\r
- {\r
- m_motorMass = 1.0f / m_motorMass;\r
- }\r
- }\r
- else\r
- {\r
- m_motorMass = 0.0f;\r
- m_motorImpulse = 0.0f;\r
- }\r
-\r
- if (step.warmStarting)\r
- {\r
- // Account for variable time step.\r
- m_impulse *= step.dtRatio;\r
- m_springImpulse *= step.dtRatio;\r
- m_motorImpulse *= step.dtRatio;\r
-\r
- b2Vec2 P = m_impulse * m_ay + m_springImpulse * m_ax;\r
- float32 LA = m_impulse * m_sAy + m_springImpulse * m_sAx + m_motorImpulse;\r
- float32 LB = m_impulse * m_sBy + m_springImpulse * m_sBx + m_motorImpulse;\r
-\r
- bA->m_linearVelocity -= m_invMassA * P;\r
- bA->m_angularVelocity -= m_invIA * LA;\r
-\r
- bB->m_linearVelocity += m_invMassB * P;\r
- bB->m_angularVelocity += m_invIB * LB;\r
- }\r
- else\r
- {\r
- m_impulse = 0.0f;\r
- m_springImpulse = 0.0f;\r
- m_motorImpulse = 0.0f;\r
- }\r
-}\r
-\r
-void b2WheelJoint::SolveVelocityConstraints(const b2TimeStep& step)\r
-{\r
- b2Body* bA = m_bodyA;\r
- b2Body* bB = m_bodyB;\r
-\r
- b2Vec2 vA = bA->m_linearVelocity;\r
- float32 wA = bA->m_angularVelocity;\r
- b2Vec2 vB = bB->m_linearVelocity;\r
- float32 wB = bB->m_angularVelocity;\r
-\r
- // Solve spring constraint\r
- {\r
- float32 Cdot = b2Dot(m_ax, vB - vA) + m_sBx * wB - m_sAx * wA;\r
- float32 impulse = -m_springMass * (Cdot + m_bias + m_gamma * m_springImpulse);\r
- m_springImpulse += impulse;\r
-\r
- b2Vec2 P = impulse * m_ax;\r
- float32 LA = impulse * m_sAx;\r
- float32 LB = impulse * m_sBx;\r
-\r
- vA -= m_invMassA * P;\r
- wA -= m_invIA * LA;\r
-\r
- vB += m_invMassB * P;\r
- wB += m_invIB * LB;\r
- }\r
-\r
- // Solve rotational motor constraint\r
- {\r
- float32 Cdot = wB - wA - m_motorSpeed;\r
- float32 impulse = -m_motorMass * Cdot;\r
-\r
- float32 oldImpulse = m_motorImpulse;\r
- float32 maxImpulse = step.dt * m_maxMotorTorque;\r
- m_motorImpulse = b2Clamp(m_motorImpulse + impulse, -maxImpulse, maxImpulse);\r
- impulse = m_motorImpulse - oldImpulse;\r
-\r
- wA -= m_invIA * impulse;\r
- wB += m_invIB * impulse;\r
- }\r
-\r
- // Solve point to line constraint\r
- {\r
- float32 Cdot = b2Dot(m_ay, vB - vA) + m_sBy * wB - m_sAy * wA;\r
- float32 impulse = m_mass * (-Cdot);\r
- m_impulse += impulse;\r
-\r
- b2Vec2 P = impulse * m_ay;\r
- float32 LA = impulse * m_sAy;\r
- float32 LB = impulse * m_sBy;\r
-\r
- vA -= m_invMassA * P;\r
- wA -= m_invIA * LA;\r
-\r
- vB += m_invMassB * P;\r
- wB += m_invIB * LB;\r
- }\r
-\r
- bA->m_linearVelocity = vA;\r
- bA->m_angularVelocity = wA;\r
- bB->m_linearVelocity = vB;\r
- bB->m_angularVelocity = wB;\r
-}\r
-\r
-bool b2WheelJoint::SolvePositionConstraints(float32 baumgarte)\r
-{\r
- B2_NOT_USED(baumgarte);\r
-\r
- b2Body* bA = m_bodyA;\r
- b2Body* bB = m_bodyB;\r
-\r
- b2Vec2 xA = bA->m_sweep.c;\r
- float32 angleA = bA->m_sweep.a;\r
-\r
- b2Vec2 xB = bB->m_sweep.c;\r
- float32 angleB = bB->m_sweep.a;\r
-\r
- b2Mat22 RA(angleA), RB(angleB);\r
-\r
- b2Vec2 rA = b2Mul(RA, m_localAnchorA - m_localCenterA);\r
- b2Vec2 rB = b2Mul(RB, m_localAnchorB - m_localCenterB);\r
- b2Vec2 d = xB + rB - xA - rA;\r
-\r
- b2Vec2 ay = b2Mul(RA, m_localYAxisA);\r
-\r
- float32 sAy = b2Cross(d + rA, ay);\r
- float32 sBy = b2Cross(rB, ay);\r
-\r
- float32 C = b2Dot(d, ay);\r
-\r
- float32 k = m_invMassA + m_invMassB + m_invIA * m_sAy * m_sAy + m_invIB * m_sBy * m_sBy;\r
-\r
- float32 impulse;\r
- if (k != 0.0f)\r
- {\r
- impulse = - C / k;\r
- }\r
- else\r
- {\r
- impulse = 0.0f;\r
- }\r
-\r
- b2Vec2 P = impulse * ay;\r
- float32 LA = impulse * sAy;\r
- float32 LB = impulse * sBy;\r
-\r
- xA -= m_invMassA * P;\r
- angleA -= m_invIA * LA;\r
- xB += m_invMassB * P;\r
- angleB += m_invIB * LB;\r
-\r
- // TODO_ERIN remove need for this.\r
- bA->m_sweep.c = xA;\r
- bA->m_sweep.a = angleA;\r
- bB->m_sweep.c = xB;\r
- bB->m_sweep.a = angleB;\r
- bA->SynchronizeTransform();\r
- bB->SynchronizeTransform();\r
-\r
- return b2Abs(C) <= b2_linearSlop;\r
-}\r
-\r
-b2Vec2 b2WheelJoint::GetAnchorA() const\r
-{\r
- return m_bodyA->GetWorldPoint(m_localAnchorA);\r
-}\r
-\r
-b2Vec2 b2WheelJoint::GetAnchorB() const\r
-{\r
- return m_bodyB->GetWorldPoint(m_localAnchorB);\r
-}\r
-\r
-b2Vec2 b2WheelJoint::GetReactionForce(float32 inv_dt) const\r
-{\r
- return inv_dt * (m_impulse * m_ay + m_springImpulse * m_ax);\r
-}\r
-\r
-float32 b2WheelJoint::GetReactionTorque(float32 inv_dt) const\r
-{\r
- return inv_dt * m_motorImpulse;\r
-}\r
-\r
-float32 b2WheelJoint::GetJointTranslation() const\r
-{\r
- b2Body* bA = m_bodyA;\r
- b2Body* bB = m_bodyB;\r
-\r
- b2Vec2 pA = bA->GetWorldPoint(m_localAnchorA);\r
- b2Vec2 pB = bB->GetWorldPoint(m_localAnchorB);\r
- b2Vec2 d = pB - pA;\r
- b2Vec2 axis = bA->GetWorldVector(m_localXAxisA);\r
-\r
- float32 translation = b2Dot(d, axis);\r
- return translation;\r
-}\r
-\r
-float32 b2WheelJoint::GetJointSpeed() const\r
-{\r
- float32 wA = m_bodyA->m_angularVelocity;\r
- float32 wB = m_bodyB->m_angularVelocity;\r
- return wB - wA;\r
-}\r
-\r
-bool b2WheelJoint::IsMotorEnabled() const\r
-{\r
- return m_enableMotor;\r
-}\r
-\r
-void b2WheelJoint::EnableMotor(bool flag)\r
-{\r
- m_bodyA->SetAwake(true);\r
- m_bodyB->SetAwake(true);\r
- m_enableMotor = flag;\r
-}\r
-\r
-void b2WheelJoint::SetMotorSpeed(float32 speed)\r
-{\r
- m_bodyA->SetAwake(true);\r
- m_bodyB->SetAwake(true);\r
- m_motorSpeed = speed;\r
-}\r
-\r
-void b2WheelJoint::SetMaxMotorTorque(float32 torque)\r
-{\r
- m_bodyA->SetAwake(true);\r
- m_bodyB->SetAwake(true);\r
- m_maxMotorTorque = torque;\r
-}\r
-\r
-float32 b2WheelJoint::GetMotorTorque(float32 inv_dt) const\r
-{\r
- return inv_dt * m_motorImpulse;\r
-}\r
-\r
-\r
-\r
-\r
-\r
/*\r
-* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2Assert(bd->linearVelocity.IsValid());\r
b2Assert(b2IsValid(bd->angle));\r
b2Assert(b2IsValid(bd->angularVelocity));\r
+ b2Assert(b2IsValid(bd->inertiaScale) && bd->inertiaScale >= 0.0f);\r
b2Assert(b2IsValid(bd->angularDamping) && bd->angularDamping >= 0.0f);\r
b2Assert(b2IsValid(bd->linearDamping) && bd->linearDamping >= 0.0f);\r
\r
\r
m_linearDamping = bd->linearDamping;\r
m_angularDamping = bd->angularDamping;\r
- m_gravityScale = bd->gravityScale;\r
\r
m_force.SetZero();\r
m_torque = 0.0f;\r
m_torque = 0.0f;\r
\r
// Since the body type changed, we need to flag contacts for filtering.\r
- for (b2Fixture* f = m_fixtureList; f; f = f->m_next)\r
+ for (b2ContactEdge* ce = m_contactList; ce; ce = ce->next)\r
{\r
- f->Refilter();\r
+ ce->contact->FlagForFiltering();\r
}\r
}\r
\r
if (m_flags & e_activeFlag)\r
{\r
b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase;\r
- fixture->CreateProxies(broadPhase, m_xf);\r
+ fixture->CreateProxy(broadPhase, m_xf);\r
}\r
\r
fixture->m_next = m_fixtureList;\r
\r
if (m_flags & e_activeFlag)\r
{\r
+ b2Assert(fixture->m_proxyId != b2BroadPhase::e_nullProxy);\r
b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase;\r
- fixture->DestroyProxies(broadPhase);\r
+ fixture->DestroyProxy(broadPhase);\r
+ }\r
+ else\r
+ {\r
+ b2Assert(fixture->m_proxyId == b2BroadPhase::e_nullProxy);\r
}\r
\r
fixture->Destroy(allocator);\r
\r
void b2Body::SetActive(bool flag)\r
{\r
- b2Assert(m_world->IsLocked() == false);\r
-\r
if (flag == IsActive())\r
{\r
return;\r
b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase;\r
for (b2Fixture* f = m_fixtureList; f; f = f->m_next)\r
{\r
- f->CreateProxies(broadPhase, m_xf);\r
+ f->CreateProxy(broadPhase, m_xf);\r
}\r
\r
// Contacts are created the next time step.\r
b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase;\r
for (b2Fixture* f = m_fixtureList; f; f = f->m_next)\r
{\r
- f->DestroyProxies(broadPhase);\r
+ f->DestroyProxy(broadPhase);\r
}\r
\r
// Destroy the attached contacts.\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
{\r
b2_staticBody = 0,\r
b2_kinematicBody,\r
- b2_dynamicBody\r
-\r
- // TODO_ERIN\r
- //b2_bulletBody,\r
+ b2_dynamicBody,\r
};\r
\r
/// A body definition holds all the data needed to construct a rigid body.\r
bullet = false;\r
type = b2_staticBody;\r
active = true;\r
- gravityScale = 1.0f;\r
+ inertiaScale = 1.0f;\r
}\r
\r
/// The body type: static, kinematic, or dynamic.\r
/// Use this to store application specific body data.\r
void* userData;\r
\r
- /// Scale the gravity applied to this body.\r
- float32 gravityScale;\r
+ /// Experimental: scales the inertia tensor.\r
+ float32 inertiaScale;\r
};\r
\r
/// A rigid body. These are created via b2World::CreateBody.\r
/// Set the angular damping of the body.\r
void SetAngularDamping(float32 angularDamping);\r
\r
- /// Get the gravity scale of the body.\r
- float32 GetGravityScale() const;\r
-\r
- /// Set the angular damping of the body.\r
- void SetGravityScale(float32 scale);\r
-\r
/// Set the type of this body. This may alter the mass and velocity.\r
void SetType(b2BodyType type);\r
\r
friend class b2Island;\r
friend class b2ContactManager;\r
friend class b2ContactSolver;\r
+ friend class b2TOISolver;\r
\r
friend class b2DistanceJoint;\r
friend class b2GearJoint;\r
- friend class b2WheelJoint;\r
+ friend class b2LineJoint;\r
friend class b2MouseJoint;\r
friend class b2PrismaticJoint;\r
friend class b2PulleyJoint;\r
friend class b2RevoluteJoint;\r
friend class b2WeldJoint;\r
friend class b2FrictionJoint;\r
- friend class b2RopeJoint;\r
\r
// m_flags\r
enum\r
e_bulletFlag = 0x0008,\r
e_fixedRotationFlag = 0x0010,\r
e_activeFlag = 0x0020,\r
- e_toiFlag = 0x0040\r
+ e_toiFlag = 0x0040,\r
};\r
\r
b2Body(const b2BodyDef* bd, b2World* world);\r
\r
float32 m_linearDamping;\r
float32 m_angularDamping;\r
- float32 m_gravityScale;\r
\r
float32 m_sleepTime;\r
\r
m_angularDamping = angularDamping;\r
}\r
\r
-inline float32 b2Body::GetGravityScale() const\r
-{\r
- return m_gravityScale;\r
-}\r
-\r
-inline void b2Body::SetGravityScale(float32 scale)\r
-{\r
- m_gravityScale = scale;\r
-}\r
-\r
inline void b2Body::SetBullet(bool flag)\r
{\r
if (flag)\r
m_xf.position = m_sweep.c - b2Mul(m_xf.R, m_sweep.localCenter);\r
}\r
\r
-inline void b2Body::Advance(float32 alpha)\r
+inline void b2Body::Advance(float32 t)\r
{\r
// Advance to the new safe time.\r
- m_sweep.Advance(alpha);\r
+ m_sweep.Advance(t);\r
m_sweep.c = m_sweep.c0;\r
m_sweep.a = m_sweep.a0;\r
SynchronizeTransform();\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
{\r
b2Fixture* fixtureA = c->GetFixtureA();\r
b2Fixture* fixtureB = c->GetFixtureB();\r
- int32 indexA = c->GetChildIndexA();\r
- int32 indexB = c->GetChildIndexB();\r
b2Body* bodyA = fixtureA->GetBody();\r
b2Body* bodyB = fixtureB->GetBody();\r
\r
c->m_flags &= ~b2Contact::e_filterFlag;\r
}\r
\r
- int32 proxyIdA = fixtureA->m_proxies[indexA].proxyId;\r
- int32 proxyIdB = fixtureB->m_proxies[indexB].proxyId;\r
+ int32 proxyIdA = fixtureA->m_proxyId;\r
+ int32 proxyIdB = fixtureB->m_proxyId;\r
bool overlap = m_broadPhase.TestOverlap(proxyIdA, proxyIdB);\r
\r
// Here we destroy contacts that cease to overlap in the broad-phase.\r
\r
void b2ContactManager::AddPair(void* proxyUserDataA, void* proxyUserDataB)\r
{\r
- b2FixtureProxy* proxyA = (b2FixtureProxy*)proxyUserDataA;\r
- b2FixtureProxy* proxyB = (b2FixtureProxy*)proxyUserDataB;\r
-\r
- b2Fixture* fixtureA = proxyA->fixture;\r
- b2Fixture* fixtureB = proxyB->fixture;\r
-\r
- int32 indexA = proxyA->childIndex;\r
- int32 indexB = proxyB->childIndex;\r
+ b2Fixture* fixtureA = (b2Fixture*)proxyUserDataA;\r
+ b2Fixture* fixtureB = (b2Fixture*)proxyUserDataB;\r
\r
b2Body* bodyA = fixtureA->GetBody();\r
b2Body* bodyB = fixtureB->GetBody();\r
{\r
b2Fixture* fA = edge->contact->GetFixtureA();\r
b2Fixture* fB = edge->contact->GetFixtureB();\r
- int32 iA = edge->contact->GetChildIndexA();\r
- int32 iB = edge->contact->GetChildIndexB();\r
-\r
- if (fA == fixtureA && fB == fixtureB && iA == indexA && iB == indexB)\r
+ if (fA == fixtureA && fB == fixtureB)\r
{\r
// A contact already exists.\r
return;\r
}\r
\r
- if (fA == fixtureB && fB == fixtureA && iA == indexB && iB == indexA)\r
+ if (fA == fixtureB && fB == fixtureA)\r
{\r
// A contact already exists.\r
return;\r
}\r
\r
// Call the factory.\r
- b2Contact* c = b2Contact::Create(fixtureA, indexA, fixtureB, indexB, m_allocator);\r
+ b2Contact* c = b2Contact::Create(fixtureA, fixtureB, m_allocator);\r
\r
// Contact creation may swap fixtures.\r
fixtureA = c->GetFixtureA();\r
fixtureB = c->GetFixtureB();\r
- indexA = c->GetChildIndexA();\r
- indexB = c->GetChildIndexB();\r
bodyA = fixtureA->GetBody();\r
bodyB = fixtureB->GetBody();\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
#include <Box2D/Dynamics/b2Fixture.h>\r
#include <Box2D/Dynamics/Contacts/b2Contact.h>\r
-#include <Box2D/Dynamics/b2World.h>\r
#include <Box2D/Collision/Shapes/b2CircleShape.h>\r
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>\r
#include <Box2D/Collision/Shapes/b2PolygonShape.h>\r
-#include <Box2D/Collision/Shapes/b2LoopShape.h>\r
#include <Box2D/Collision/b2BroadPhase.h>\r
#include <Box2D/Collision/b2Collision.h>\r
#include <Box2D/Common/b2BlockAllocator.h>\r
\r
+\r
b2Fixture::b2Fixture()\r
{\r
m_userData = NULL;\r
m_body = NULL;\r
m_next = NULL;\r
- m_proxies = NULL;\r
- m_proxyCount = 0;\r
+ m_proxyId = b2BroadPhase::e_nullProxy;\r
m_shape = NULL;\r
m_density = 0.0f;\r
}\r
\r
+b2Fixture::~b2Fixture()\r
+{\r
+ b2Assert(m_shape == NULL);\r
+ b2Assert(m_proxyId == b2BroadPhase::e_nullProxy);\r
+}\r
+\r
void b2Fixture::Create(b2BlockAllocator* allocator, b2Body* body, const b2FixtureDef* def)\r
{\r
m_userData = def->userData;\r
\r
m_shape = def->shape->Clone(allocator);\r
\r
- // Reserve proxy space\r
- int32 childCount = m_shape->GetChildCount();\r
- m_proxies = (b2FixtureProxy*)allocator->Allocate(childCount * sizeof(b2FixtureProxy));\r
- for (int32 i = 0; i < childCount; ++i)\r
- {\r
- m_proxies[i].fixture = NULL;\r
- m_proxies[i].proxyId = b2BroadPhase::e_nullProxy;\r
- }\r
- m_proxyCount = 0;\r
-\r
m_density = def->density;\r
}\r
\r
void b2Fixture::Destroy(b2BlockAllocator* allocator)\r
{\r
- // The proxies must be destroyed before calling this.\r
- b2Assert(m_proxyCount == 0);\r
-\r
- // Free the proxy array.\r
- int32 childCount = m_shape->GetChildCount();\r
- allocator->Free(m_proxies, childCount * sizeof(b2FixtureProxy));\r
- m_proxies = NULL;\r
+ // The proxy must be destroyed before calling this.\r
+ b2Assert(m_proxyId == b2BroadPhase::e_nullProxy);\r
\r
// Free the child shape.\r
switch (m_shape->m_type)\r
}\r
break;\r
\r
- case b2Shape::e_edge:\r
- {\r
- b2EdgeShape* s = (b2EdgeShape*)m_shape;\r
- s->~b2EdgeShape();\r
- allocator->Free(s, sizeof(b2EdgeShape));\r
- }\r
- break;\r
-\r
case b2Shape::e_polygon:\r
{\r
b2PolygonShape* s = (b2PolygonShape*)m_shape;\r
}\r
break;\r
\r
- case b2Shape::e_loop:\r
- {\r
- b2LoopShape* s = (b2LoopShape*)m_shape;\r
- s->~b2LoopShape();\r
- allocator->Free(s, sizeof(b2LoopShape));\r
- }\r
- break;\r
-\r
default:\r
b2Assert(false);\r
break;\r
m_shape = NULL;\r
}\r
\r
-void b2Fixture::CreateProxies(b2BroadPhase* broadPhase, const b2Transform& xf)\r
+void b2Fixture::CreateProxy(b2BroadPhase* broadPhase, const b2Transform& xf)\r
{\r
- b2Assert(m_proxyCount == 0);\r
-\r
- // Create proxies in the broad-phase.\r
- m_proxyCount = m_shape->GetChildCount();\r
+ b2Assert(m_proxyId == b2BroadPhase::e_nullProxy);\r
\r
- for (int32 i = 0; i < m_proxyCount; ++i)\r
- {\r
- b2FixtureProxy* proxy = m_proxies + i;\r
- m_shape->ComputeAABB(&proxy->aabb, xf, i);\r
- proxy->proxyId = broadPhase->CreateProxy(proxy->aabb, proxy);\r
- proxy->fixture = this;\r
- proxy->childIndex = i;\r
- }\r
+ // Create proxy in the broad-phase.\r
+ m_shape->ComputeAABB(&m_aabb, xf);\r
+ m_proxyId = broadPhase->CreateProxy(m_aabb, this);\r
}\r
\r
-void b2Fixture::DestroyProxies(b2BroadPhase* broadPhase)\r
+void b2Fixture::DestroyProxy(b2BroadPhase* broadPhase)\r
{\r
- // Destroy proxies in the broad-phase.\r
- for (int32 i = 0; i < m_proxyCount; ++i)\r
+ if (m_proxyId == b2BroadPhase::e_nullProxy)\r
{\r
- b2FixtureProxy* proxy = m_proxies + i;\r
- broadPhase->DestroyProxy(proxy->proxyId);\r
- proxy->proxyId = b2BroadPhase::e_nullProxy;\r
+ return;\r
}\r
\r
- m_proxyCount = 0;\r
+ // Destroy proxy in the broad-phase.\r
+ broadPhase->DestroyProxy(m_proxyId);\r
+ m_proxyId = b2BroadPhase::e_nullProxy;\r
}\r
\r
void b2Fixture::Synchronize(b2BroadPhase* broadPhase, const b2Transform& transform1, const b2Transform& transform2)\r
{\r
- if (m_proxyCount == 0)\r
+ if (m_proxyId == b2BroadPhase::e_nullProxy)\r
{ \r
return;\r
}\r
\r
- for (int32 i = 0; i < m_proxyCount; ++i)\r
- {\r
- b2FixtureProxy* proxy = m_proxies + i;\r
-\r
- // Compute an AABB that covers the swept shape (may miss some rotation effect).\r
- b2AABB aabb1, aabb2;\r
- m_shape->ComputeAABB(&aabb1, transform1, proxy->childIndex);\r
- m_shape->ComputeAABB(&aabb2, transform2, proxy->childIndex);\r
+ // Compute an AABB that covers the swept shape (may miss some rotation effect).\r
+ b2AABB aabb1, aabb2;\r
+ m_shape->ComputeAABB(&aabb1, transform1);\r
+ m_shape->ComputeAABB(&aabb2, transform2);\r
\r
- proxy->aabb.Combine(aabb1, aabb2);\r
+ m_aabb.Combine(aabb1, aabb2);\r
\r
- b2Vec2 displacement = transform2.position - transform1.position;\r
+ b2Vec2 displacement = transform2.position - transform1.position;\r
\r
- broadPhase->MoveProxy(proxy->proxyId, proxy->aabb, displacement);\r
- }\r
+ broadPhase->MoveProxy(m_proxyId, m_aabb, displacement);\r
}\r
\r
void b2Fixture::SetFilterData(const b2Filter& filter)\r
{\r
m_filter = filter;\r
\r
- Refilter();\r
-}\r
-\r
-void b2Fixture::Refilter()\r
-{\r
if (m_body == NULL)\r
{\r
return;\r
\r
edge = edge->next;\r
}\r
-\r
- b2World* world = m_body->GetWorld();\r
-\r
- if (world == NULL)\r
- {\r
- return;\r
- }\r
-\r
- // Touch each proxy so that new pairs may be created\r
- b2BroadPhase* broadPhase = &world->m_contactManager.m_broadPhase;\r
- for (int32 i = 0; i < m_proxyCount; ++i)\r
- {\r
- broadPhase->TouchProxy(m_proxies[i].proxyId);\r
- }\r
}\r
\r
void b2Fixture::SetSensor(bool sensor)\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
class b2BlockAllocator;\r
class b2Body;\r
class b2BroadPhase;\r
-class b2Fixture;\r
\r
/// This holds contact filtering data.\r
struct b2Filter\r
isSensor = false;\r
}\r
\r
+ virtual ~b2FixtureDef() {}\r
+\r
/// The shape, this must be set. The shape will be cloned, so you\r
/// can create the shape on the stack.\r
const b2Shape* shape;\r
b2Filter filter;\r
};\r
\r
-/// This proxy is used internally to connect fixtures to the broad-phase.\r
-struct b2FixtureProxy\r
-{\r
- b2AABB aabb;\r
- b2Fixture* fixture;\r
- int32 childIndex;\r
- int32 proxyId;\r
-};\r
\r
/// A fixture is used to attach a shape to a body for collision detection. A fixture\r
/// inherits its transform from its parent. Fixtures hold additional non-geometric data\r
\r
/// Set the contact filtering data. This will not update contacts until the next time\r
/// step when either parent body is active and awake.\r
- /// This automatically calls Refilter.\r
void SetFilterData(const b2Filter& filter);\r
\r
/// Get the contact filtering data.\r
const b2Filter& GetFilterData() const;\r
\r
- /// Call this if you want to establish collision that was previously disabled by b2ContactFilter::ShouldCollide.\r
- void Refilter();\r
-\r
/// Get the parent body of this fixture. This is NULL if the fixture is not attached.\r
/// @return the parent body.\r
b2Body* GetBody();\r
void SetUserData(void* data);\r
\r
/// Test a point for containment in this fixture.\r
+ /// @param xf the shape world transform.\r
/// @param p a point in world coordinates.\r
bool TestPoint(const b2Vec2& p) const;\r
\r
/// Cast a ray against this shape.\r
/// @param output the ray-cast results.\r
/// @param input the ray-cast input parameters.\r
- bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const;\r
+ bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const;\r
\r
/// Get the mass data for this fixture. The mass data is based on the density and\r
/// the shape. The rotational inertia is about the shape's origin. This operation\r
/// Get the coefficient of friction.\r
float32 GetFriction() const;\r
\r
- /// Set the coefficient of friction. This will _not_ change the friction of\r
- /// existing contacts.\r
+ /// Set the coefficient of friction.\r
void SetFriction(float32 friction);\r
\r
/// Get the coefficient of restitution.\r
float32 GetRestitution() const;\r
\r
- /// Set the coefficient of restitution. This will _not_ change the restitution of\r
- /// existing contacts.\r
+ /// Set the coefficient of restitution.\r
void SetRestitution(float32 restitution);\r
\r
/// Get the fixture's AABB. This AABB may be enlarge and/or stale.\r
/// If you need a more accurate AABB, compute it using the shape and\r
/// the body transform.\r
- const b2AABB& GetAABB(int32 childIndex) const;\r
+ const b2AABB& GetAABB() const;\r
\r
protected:\r
\r
friend class b2ContactManager;\r
\r
b2Fixture();\r
+ ~b2Fixture();\r
\r
// We need separation create/destroy functions from the constructor/destructor because\r
// the destructor cannot access the allocator (no destructor arguments allowed by C++).\r
void Destroy(b2BlockAllocator* allocator);\r
\r
// These support body activation/deactivation.\r
- void CreateProxies(b2BroadPhase* broadPhase, const b2Transform& xf);\r
- void DestroyProxies(b2BroadPhase* broadPhase);\r
+ void CreateProxy(b2BroadPhase* broadPhase, const b2Transform& xf);\r
+ void DestroyProxy(b2BroadPhase* broadPhase);\r
\r
void Synchronize(b2BroadPhase* broadPhase, const b2Transform& xf1, const b2Transform& xf2);\r
\r
+ b2AABB m_aabb;\r
+\r
float32 m_density;\r
\r
b2Fixture* m_next;\r
float32 m_friction;\r
float32 m_restitution;\r
\r
- b2FixtureProxy* m_proxies;\r
- int32 m_proxyCount;\r
-\r
+ int32 m_proxyId;\r
b2Filter m_filter;\r
\r
bool m_isSensor;\r
return m_shape->TestPoint(m_body->GetTransform(), p);\r
}\r
\r
-inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const\r
+inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const\r
{\r
- return m_shape->RayCast(output, input, m_body->GetTransform(), childIndex);\r
+ return m_shape->RayCast(output, input, m_body->GetTransform());\r
}\r
\r
inline void b2Fixture::GetMassData(b2MassData* massData) const\r
m_shape->ComputeMass(massData, m_density);\r
}\r
\r
-inline const b2AABB& b2Fixture::GetAABB(int32 childIndex) const\r
+inline const b2AABB& b2Fixture::GetAABB() const\r
{\r
- b2Assert(0 <= childIndex && childIndex < m_proxyCount);\r
- return m_proxies[childIndex].aabb;\r
+ return m_aabb;\r
}\r
\r
#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
* 3. This notice may not be removed or altered from any source distribution.\r
*/\r
\r
-#include <Box2D/Collision/b2Distance.h>\r
#include <Box2D/Dynamics/b2Island.h>\r
#include <Box2D/Dynamics/b2Body.h>\r
#include <Box2D/Dynamics/b2Fixture.h>\r
}\r
\r
// Integrate velocities.\r
- b->m_linearVelocity += step.dt * (b->m_gravityScale * gravity + b->m_invMass * b->m_force);\r
+ b->m_linearVelocity += step.dt * (gravity + b->m_invMass * b->m_force);\r
b->m_angularVelocity += step.dt * b->m_invI * b->m_torque;\r
\r
// Apply damping.\r
}\r
\r
// Initialize velocity constraints.\r
- b2ContactSolverDef solverDef;\r
- solverDef.contacts = m_contacts;\r
- solverDef.count = m_contactCount;\r
- solverDef.allocator = m_allocator;\r
- solverDef.impulseRatio = step.dtRatio;\r
- solverDef.warmStarting = step.warmStarting;\r
-\r
- b2ContactSolver contactSolver(&solverDef);\r
-\r
- contactSolver.InitializeVelocityConstraints();\r
-\r
- if (step.warmStarting)\r
- {\r
- contactSolver.WarmStart();\r
- }\r
- \r
+ b2ContactSolver contactSolver(m_contacts, m_contactCount, m_allocator, step.dtRatio);\r
+ contactSolver.WarmStart();\r
for (int32 i = 0; i < m_jointCount; ++i)\r
{\r
m_joints[i]->InitVelocityConstraints(step);\r
}\r
}\r
\r
-void b2Island::SolveTOI(const b2TimeStep& subStep, const b2Body* bodyA, const b2Body* bodyB)\r
-{\r
- b2ContactSolverDef solverDef;\r
- solverDef.contacts = m_contacts;\r
- solverDef.count = m_contactCount;\r
- solverDef.allocator = m_allocator;\r
- solverDef.impulseRatio = subStep.dtRatio;\r
- solverDef.warmStarting = subStep.warmStarting;\r
- b2ContactSolver contactSolver(&solverDef);\r
-\r
- // Solve position constraints.\r
- const float32 k_toiBaumgarte = 0.75f;\r
- for (int32 i = 0; i < subStep.positionIterations; ++i)\r
- {\r
- bool contactsOkay = contactSolver.SolveTOIPositionConstraints(k_toiBaumgarte, bodyA, bodyB);\r
- if (contactsOkay)\r
- {\r
- break;\r
- }\r
-\r
- if (i == subStep.positionIterations - 1)\r
- {\r
- i += 0;\r
- }\r
- }\r
-\r
-#if 0\r
- // Is the new position really safe?\r
- for (int32 i = 0; i < m_contactCount; ++i)\r
- {\r
- b2Contact* c = m_contacts[i];\r
- b2Fixture* fA = c->GetFixtureA();\r
- b2Fixture* fB = c->GetFixtureB();\r
-\r
- b2Body* bA = fA->GetBody();\r
- b2Body* bB = fB->GetBody();\r
-\r
- int32 indexA = c->GetChildIndexA();\r
- int32 indexB = c->GetChildIndexB();\r
-\r
- b2DistanceInput input;\r
- input.proxyA.Set(fA->GetShape(), indexA);\r
- input.proxyB.Set(fB->GetShape(), indexB);\r
- input.transformA = bA->GetTransform();\r
- input.transformB = bB->GetTransform();\r
- input.useRadii = false;\r
-\r
- b2DistanceOutput output;\r
- b2SimplexCache cache;\r
- cache.count = 0;\r
- b2Distance(&output, &cache, &input);\r
-\r
- if (output.distance == 0 || cache.count == 3)\r
- {\r
- cache.count += 0;\r
- }\r
- }\r
-#endif\r
-\r
- // Leap of faith to new safe state.\r
- for (int32 i = 0; i < m_bodyCount; ++i)\r
- {\r
- m_bodies[i]->m_sweep.a0 = m_bodies[i]->m_sweep.a;\r
- m_bodies[i]->m_sweep.c0 = m_bodies[i]->m_sweep.c;\r
- }\r
-\r
- // No warm starting is needed for TOI events because warm\r
- // starting impulses were applied in the discrete solver.\r
- contactSolver.InitializeVelocityConstraints();\r
-\r
- // Solve velocity constraints.\r
- for (int32 i = 0; i < subStep.velocityIterations; ++i)\r
- {\r
- contactSolver.SolveVelocityConstraints();\r
- }\r
-\r
- // Don't store the TOI contact forces for warm starting\r
- // because they can be quite large.\r
-\r
- // Integrate positions.\r
- for (int32 i = 0; i < m_bodyCount; ++i)\r
- {\r
- b2Body* b = m_bodies[i];\r
-\r
- if (b->GetType() == b2_staticBody)\r
- {\r
- continue;\r
- }\r
-\r
- // Check for large velocities.\r
- b2Vec2 translation = subStep.dt * b->m_linearVelocity;\r
- if (b2Dot(translation, translation) > b2_maxTranslationSquared)\r
- {\r
- translation.Normalize();\r
- b->m_linearVelocity = (b2_maxTranslation * subStep.inv_dt) * translation;\r
- }\r
-\r
- float32 rotation = subStep.dt * b->m_angularVelocity;\r
- if (rotation * rotation > b2_maxRotationSquared)\r
- {\r
- if (rotation < 0.0)\r
- {\r
- b->m_angularVelocity = -subStep.inv_dt * b2_maxRotation;\r
- }\r
- else\r
- {\r
- b->m_angularVelocity = subStep.inv_dt * b2_maxRotation;\r
- }\r
- }\r
-\r
- // Integrate\r
- b->m_sweep.c += subStep.dt * b->m_linearVelocity;\r
- b->m_sweep.a += subStep.dt * b->m_angularVelocity;\r
-\r
- // Compute new transform\r
- b->SynchronizeTransform();\r
-\r
- // Note: shapes are synchronized later.\r
- }\r
-\r
- Report(contactSolver.m_constraints);\r
-}\r
-\r
void b2Island::Report(const b2ContactConstraint* constraints)\r
{\r
if (m_listener == NULL)\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
void Solve(const b2TimeStep& step, const b2Vec2& gravity, bool allowSleep);\r
\r
- void SolveTOI(const b2TimeStep& subStep, const b2Body* bodyA, const b2Body* bodyB);\r
-\r
void Add(b2Body* body)\r
{\r
b2Assert(m_bodyCount < m_bodyCapacity);\r
int32 m_bodyCapacity;\r
int32 m_contactCapacity;\r
int32 m_jointCapacity;\r
+\r
+ int32 m_positionIterationCount;\r
};\r
\r
#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
#include <Box2D/Common/b2Settings.h>\r
\r
-/// This is an internal structure.\r
-struct b2TimeStep\r
-{\r
- float32 dt; // time step\r
- float32 inv_dt; // inverse time step (0 if dt == 0).\r
- float32 dtRatio; // dt * inv_dt0\r
- int32 velocityIterations;\r
- int32 positionIterations;\r
- bool warmStarting;\r
-};\r
+/// This is an internal structure.
+struct b2TimeStep
+{
+ float32 dt; // time step
+ float32 inv_dt; // inverse time step (0 if dt == 0).
+ float32 dtRatio; // dt * inv_dt0
+ int32 velocityIterations;
+ int32 positionIterations;
+ bool warmStarting;
+};
\r
#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#include <Box2D/Dynamics/Joints/b2PulleyJoint.h>\r
#include <Box2D/Dynamics/Contacts/b2Contact.h>\r
#include <Box2D/Dynamics/Contacts/b2ContactSolver.h>\r
+#include <Box2D/Dynamics/Contacts/b2TOISolver.h>\r
#include <Box2D/Collision/b2Collision.h>\r
#include <Box2D/Collision/b2BroadPhase.h>\r
#include <Box2D/Collision/Shapes/b2CircleShape.h>\r
-#include <Box2D/Collision/Shapes/b2EdgeShape.h>\r
-#include <Box2D/Collision/Shapes/b2LoopShape.h>\r
#include <Box2D/Collision/Shapes/b2PolygonShape.h>\r
#include <Box2D/Collision/b2TimeOfImpact.h>\r
-#include <Box2D/Common/b2Draw.h>\r
-#include <Box2D/Common/b2Timer.h>\r
#include <new>\r
\r
b2World::b2World(const b2Vec2& gravity, bool doSleep)\r
\r
m_warmStarting = true;\r
m_continuousPhysics = true;\r
- m_subStepping = false;\r
-\r
- m_stepComplete = true;\r
\r
m_allowSleep = doSleep;\r
m_gravity = gravity;\r
m_inv_dt0 = 0.0f;\r
\r
m_contactManager.m_allocator = &m_blockAllocator;\r
-\r
- memset(&m_profile, 0, sizeof(b2Profile));\r
}\r
\r
b2World::~b2World()\r
{\r
- // Some shapes allocate using b2Alloc.\r
- b2Body* b = m_bodyList;\r
- while (b)\r
- {\r
- b2Body* bNext = b->m_next;\r
-\r
- b2Fixture* f = b->m_fixtureList;\r
- while (f)\r
- {\r
- b2Fixture* fNext = f->m_next;\r
- f->m_proxyCount = 0;\r
- f->Destroy(&m_blockAllocator);\r
- f = fNext;\r
- }\r
-\r
- b = bNext;\r
- }\r
}\r
\r
void b2World::SetDestructionListener(b2DestructionListener* listener)\r
m_contactManager.m_contactListener = listener;\r
}\r
\r
-void b2World::SetDebugDraw(b2Draw* debugDraw)\r
+void b2World::SetDebugDraw(b2DebugDraw* debugDraw)\r
{\r
m_debugDraw = debugDraw;\r
}\r
}\r
\r
DestroyJoint(je0->joint);\r
-\r
- b->m_jointList = je;\r
}\r
b->m_jointList = NULL;\r
\r
m_destructionListener->SayGoodbye(f0);\r
}\r
\r
- f0->DestroyProxies(&m_contactManager.m_broadPhase);\r
+ f0->DestroyProxy(&m_contactManager.m_broadPhase);\r
f0->Destroy(&m_blockAllocator);\r
f0->~b2Fixture();\r
m_blockAllocator.Free(f0, sizeof(b2Fixture));\r
-\r
- b->m_fixtureList = f;\r
- b->m_fixtureCount -= 1;\r
}\r
b->m_fixtureList = NULL;\r
b->m_fixtureCount = 0;\r
m_contactManager.FindNewContacts();\r
}\r
\r
-// Find TOI contacts and solve them.\r
-void b2World::SolveTOI(const b2TimeStep& step)\r
+// Advance a dynamic body to its first time of contact\r
+// and adjust the position to ensure clearance.\r
+void b2World::SolveTOI(b2Body* body)\r
{\r
- b2Island island(2 * b2_maxTOIContacts, b2_maxTOIContacts, 0, &m_stackAllocator, m_contactManager.m_contactListener);\r
-\r
- if (m_stepComplete)\r
+ // Find the minimum contact.\r
+ b2Contact* toiContact = NULL;\r
+ float32 toi = 1.0f;\r
+ b2Body* toiOther = NULL;\r
+ bool found;\r
+ int32 count;\r
+ int32 iter = 0;\r
+\r
+ bool bullet = body->IsBullet();\r
+\r
+ // Iterate until all contacts agree on the minimum TOI. We have\r
+ // to iterate because the TOI algorithm may skip some intermediate\r
+ // collisions when objects rotate through each other.\r
+ do\r
{\r
- for (b2Body* b = m_bodyList; b; b = b->m_next)\r
+ count = 0;\r
+ found = false;\r
+ for (b2ContactEdge* ce = body->m_contactList; ce; ce = ce->next)\r
{\r
- b->m_flags &= ~b2Body::e_islandFlag;\r
- b->m_sweep.alpha0 = 0.0f;\r
- }\r
-\r
- for (b2Contact* c = m_contactManager.m_contactList; c; c = c->m_next)\r
- {\r
- // Invalidate TOI\r
- c->m_flags &= ~(b2Contact::e_toiFlag | b2Contact::e_islandFlag);\r
- c->m_toiCount = 0;\r
- c->m_toi = 1.0f;\r
- }\r
- }\r
-\r
- // Find TOI events and solve them.\r
- for (;;)\r
- {\r
- // Find the first TOI.\r
- b2Contact* minContact = NULL;\r
- float32 minAlpha = 1.0f;\r
-\r
- for (b2Contact* c = m_contactManager.m_contactList; c; c = c->m_next)\r
- {\r
- // Is this contact disabled?\r
- if (c->IsEnabled() == false)\r
+ if (ce->contact == toiContact)\r
{\r
continue;\r
}\r
\r
- // Prevent excessive sub-stepping.\r
- if (c->m_toiCount > b2_maxSubSteps)\r
- {\r
- continue;\r
- }\r
+ b2Body* other = ce->other;\r
+ b2BodyType type = other->GetType();\r
\r
- float32 alpha = 1.0f;\r
- if (c->m_flags & b2Contact::e_toiFlag)\r
+ // Only bullets perform TOI with dynamic bodies.\r
+ if (bullet == true)\r
{\r
- // This contact has a valid cached TOI.\r
- alpha = c->m_toi;\r
- }\r
- else\r
- {\r
- b2Fixture* fA = c->GetFixtureA();\r
- b2Fixture* fB = c->GetFixtureB();\r
-\r
- // Is there a sensor?\r
- if (fA->IsSensor() || fB->IsSensor())\r
- {\r
- continue;\r
- }\r
-\r
- b2Body* bA = fA->GetBody();\r
- b2Body* bB = fB->GetBody();\r
-\r
- b2BodyType typeA = bA->GetType();\r
- b2BodyType typeB = bB->GetType();\r
- b2Assert(typeA == b2_dynamicBody || typeB == b2_dynamicBody);\r
-\r
- bool awakeA = bA->IsAwake() && typeA != b2_staticBody;\r
- bool awakeB = bB->IsAwake() && typeB != b2_staticBody;\r
-\r
- // Is at least one body awake?\r
- if (awakeA == false && awakeB == false)\r
+ // Bullets only perform TOI with bodies that have their TOI resolved.\r
+ if ((other->m_flags & b2Body::e_toiFlag) == 0)\r
{\r
continue;\r
}\r
\r
- bool collideA = bA->IsBullet() || typeA != b2_dynamicBody;\r
- bool collideB = bB->IsBullet() || typeB != b2_dynamicBody;\r
-\r
- // Are these two non-bullet dynamic bodies?\r
- if (collideA == false && collideB == false)\r
+ // No repeated hits on non-static bodies\r
+ if (type != b2_staticBody && (ce->contact->m_flags & b2Contact::e_bulletHitFlag) != 0)\r
{\r
- continue;\r
+ continue;\r
}\r
+ }\r
+ else if (type == b2_dynamicBody)\r
+ {\r
+ continue;\r
+ }\r
\r
- // Compute the TOI for this contact.\r
- // Put the sweeps onto the same time interval.\r
- float32 alpha0 = bA->m_sweep.alpha0;\r
-\r
- if (bA->m_sweep.alpha0 < bB->m_sweep.alpha0)\r
- {\r
- alpha0 = bB->m_sweep.alpha0;\r
- bA->m_sweep.Advance(alpha0);\r
- }\r
- else if (bB->m_sweep.alpha0 < bA->m_sweep.alpha0)\r
- {\r
- alpha0 = bA->m_sweep.alpha0;\r
- bB->m_sweep.Advance(alpha0);\r
- }\r
+ // Check for a disabled contact.\r
+ b2Contact* contact = ce->contact;\r
+ if (contact->IsEnabled() == false)\r
+ {\r
+ continue;\r
+ }\r
\r
- b2Assert(alpha0 < 1.0f);\r
+ // Prevent infinite looping.\r
+ if (contact->m_toiCount > 10)\r
+ {\r
+ continue;\r
+ }\r
\r
- int32 indexA = c->GetChildIndexA();\r
- int32 indexB = c->GetChildIndexB();\r
+ b2Fixture* fixtureA = contact->m_fixtureA;\r
+ b2Fixture* fixtureB = contact->m_fixtureB;\r
\r
- // Compute the time of impact in interval [0, minTOI]\r
- b2TOIInput input;\r
- input.proxyA.Set(fA->GetShape(), indexA);\r
- input.proxyB.Set(fB->GetShape(), indexB);\r
- input.sweepA = bA->m_sweep;\r
- input.sweepB = bB->m_sweep;\r
- input.tMax = 1.0f;\r
+ // Cull sensors.\r
+ if (fixtureA->IsSensor() || fixtureB->IsSensor())\r
+ {\r
+ continue;\r
+ }\r
\r
- b2TOIOutput output;\r
- b2TimeOfImpact(&output, &input);\r
+ b2Body* bodyA = fixtureA->m_body;\r
+ b2Body* bodyB = fixtureB->m_body;\r
\r
- // Beta is the fraction of the remaining portion of the .\r
- float32 beta = output.t;\r
- if (output.state == b2TOIOutput::e_touching)\r
- {\r
- alpha = b2Min(alpha0 + (1.0f - alpha0) * beta, 1.0f);\r
- }\r
- else\r
- {\r
- alpha = 1.0f;\r
- }\r
+ // Compute the time of impact in interval [0, minTOI]\r
+ b2TOIInput input;\r
+ input.proxyA.Set(fixtureA->GetShape());\r
+ input.proxyB.Set(fixtureB->GetShape());\r
+ input.sweepA = bodyA->m_sweep;\r
+ input.sweepB = bodyB->m_sweep;\r
+ input.tMax = toi;\r
\r
- c->m_toi = alpha;\r
- c->m_flags |= b2Contact::e_toiFlag;\r
- }\r
+ b2TOIOutput output;\r
+ b2TimeOfImpact(&output, &input);\r
\r
- if (alpha < minAlpha)\r
+ if (output.state == b2TOIOutput::e_touching && output.t < toi)\r
{\r
- // This is the minimum TOI found so far.\r
- minContact = c;\r
- minAlpha = alpha;\r
+ toiContact = contact;\r
+ toi = output.t;\r
+ toiOther = other;\r
+ found = true;\r
}\r
- }\r
\r
- if (minContact == NULL || 1.0f - 10.0f * b2_epsilon < minAlpha)\r
- {\r
- // No more TOI events. Done!\r
- m_stepComplete = true;\r
- break;\r
+ ++count;\r
}\r
\r
- // Advance the bodies to the TOI.\r
- b2Fixture* fA = minContact->GetFixtureA();\r
- b2Fixture* fB = minContact->GetFixtureB();\r
- b2Body* bA = fA->GetBody();\r
- b2Body* bB = fB->GetBody();\r
+ ++iter;\r
+ } while (found && count > 1 && iter < 50);\r
+\r
+ if (toiContact == NULL)\r
+ {\r
+ body->Advance(1.0f);\r
+ return;\r
+ }\r
\r
- b2Sweep backup1 = bA->m_sweep;\r
- b2Sweep backup2 = bB->m_sweep;\r
+ b2Sweep backup = body->m_sweep;\r
+ body->Advance(toi);\r
+ toiContact->Update(m_contactManager.m_contactListener);\r
+ if (toiContact->IsEnabled() == false)\r
+ {\r
+ // Contact disabled. Backup and recurse.\r
+ body->m_sweep = backup;\r
+ SolveTOI(body);\r
+ }\r
\r
- bA->Advance(minAlpha);\r
- bB->Advance(minAlpha);\r
+ ++toiContact->m_toiCount;\r
\r
- // The TOI contact likely has some new contact points.\r
- minContact->Update(m_contactManager.m_contactListener);\r
- minContact->m_flags &= ~b2Contact::e_toiFlag;\r
- ++minContact->m_toiCount;\r
+ // Update all the valid contacts on this body and build a contact island.\r
+ b2Contact* contacts[b2_maxTOIContacts];\r
+ count = 0;\r
+ for (b2ContactEdge* ce = body->m_contactList; ce && count < b2_maxTOIContacts; ce = ce->next)\r
+ {\r
+ b2Body* other = ce->other;\r
+ b2BodyType type = other->GetType();\r
\r
- // Is the contact solid?\r
- if (minContact->IsEnabled() == false || minContact->IsTouching() == false)\r
+ // Only perform correction with static bodies, so the\r
+ // body won't get pushed out of the world.\r
+ if (type == b2_dynamicBody)\r
{\r
- // Restore the sweeps.\r
- minContact->SetEnabled(false);\r
- bA->m_sweep = backup1;\r
- bB->m_sweep = backup2;\r
- bA->SynchronizeTransform();\r
- bB->SynchronizeTransform();\r
continue;\r
}\r
\r
- bA->SetAwake(true);\r
- bB->SetAwake(true);\r
-\r
- // Build the island\r
- island.Clear();\r
- island.Add(bA);\r
- island.Add(bB);\r
- island.Add(minContact);\r
+ // Check for a disabled contact.\r
+ b2Contact* contact = ce->contact;\r
+ if (contact->IsEnabled() == false)\r
+ {\r
+ continue;\r
+ }\r
\r
- bA->m_flags |= b2Body::e_islandFlag;\r
- bB->m_flags |= b2Body::e_islandFlag;\r
- minContact->m_flags |= b2Contact::e_islandFlag;\r
+ b2Fixture* fixtureA = contact->m_fixtureA;\r
+ b2Fixture* fixtureB = contact->m_fixtureB;\r
\r
- // Get contacts on bodyA and bodyB.\r
- b2Body* bodies[2] = {bA, bB};\r
- for (int32 i = 0; i < 2; ++i)\r
+ // Cull sensors.\r
+ if (fixtureA->IsSensor() || fixtureB->IsSensor())\r
{\r
- b2Body* body = bodies[i];\r
- if (body->m_type == b2_dynamicBody)\r
- {\r
- for (b2ContactEdge* ce = body->m_contactList; ce; ce = ce->next)\r
- {\r
- if (island.m_bodyCount == island.m_bodyCapacity)\r
- {\r
- break;\r
- }\r
+ continue;\r
+ }\r
\r
- if (island.m_contactCount == island.m_contactCapacity)\r
- {\r
- break;\r
- }\r
+ // The contact likely has some new contact points. The listener\r
+ // gives the user a chance to disable the contact.\r
+ if (contact != toiContact)\r
+ {\r
+ contact->Update(m_contactManager.m_contactListener);\r
+ }\r
\r
- b2Contact* contact = ce->contact;\r
+ // Did the user disable the contact?\r
+ if (contact->IsEnabled() == false)\r
+ {\r
+ // Skip this contact.\r
+ continue;\r
+ }\r
\r
- // Has this contact already been added to the island?\r
- if (contact->m_flags & b2Contact::e_islandFlag)\r
- {\r
- continue;\r
- }\r
+ if (contact->IsTouching() == false)\r
+ {\r
+ continue;\r
+ }\r
\r
- // Only add static, kinematic, or bullet bodies.\r
- b2Body* other = ce->other;\r
- if (other->m_type == b2_dynamicBody &&\r
- body->IsBullet() == false && other->IsBullet() == false)\r
- {\r
- continue;\r
- }\r
+ contacts[count] = contact;\r
+ ++count;\r
+ }\r
\r
- // Skip sensors.\r
- bool sensorA = contact->m_fixtureA->m_isSensor;\r
- bool sensorB = contact->m_fixtureB->m_isSensor;\r
- if (sensorA || sensorB)\r
- {\r
- continue;\r
- }\r
-\r
- // Tentatively advance the body to the TOI.\r
- b2Sweep backup = other->m_sweep;\r
- if ((other->m_flags & b2Body::e_islandFlag) == 0)\r
- {\r
- other->Advance(minAlpha);\r
- }\r
-\r
- // Update the contact points\r
- contact->Update(m_contactManager.m_contactListener);\r
-\r
- // Was the contact disabled by the user?\r
- if (contact->IsEnabled() == false)\r
- {\r
- other->m_sweep = backup;\r
- other->SynchronizeTransform();\r
- continue;\r
- }\r
+ // Reduce the TOI body's overlap with the contact island.\r
+ b2TOISolver solver(&m_stackAllocator);\r
+ solver.Initialize(contacts, count, body);\r
\r
- // Are there contact points?\r
- if (contact->IsTouching() == false)\r
- {\r
- other->m_sweep = backup;\r
- other->SynchronizeTransform();\r
- continue;\r
- }\r
+ const float32 k_toiBaumgarte = 0.75f;\r
+ bool solved = false;\r
+ for (int32 i = 0; i < 20; ++i)\r
+ {\r
+ bool contactsOkay = solver.Solve(k_toiBaumgarte);\r
+ if (contactsOkay)\r
+ {\r
+ solved = true;\r
+ break;\r
+ }\r
+ }\r
\r
- // Add the contact to the island\r
- contact->m_flags |= b2Contact::e_islandFlag;\r
- island.Add(contact);\r
+ if (toiOther->GetType() != b2_staticBody)\r
+ {\r
+ toiContact->m_flags |= b2Contact::e_bulletHitFlag;\r
+ }\r
+}\r
\r
- // Has the other body already been added to the island?\r
- if (other->m_flags & b2Body::e_islandFlag)\r
- {\r
- continue;\r
- }\r
- \r
- // Add the other body to the island.\r
- other->m_flags |= b2Body::e_islandFlag;\r
+// Sequentially solve TOIs for each body. We bring each\r
+// body to the time of contact and perform some position correction.\r
+// Time is not conserved.\r
+void b2World::SolveTOI()\r
+{\r
+ // Prepare all contacts.\r
+ for (b2Contact* c = m_contactManager.m_contactList; c; c = c->m_next)\r
+ {\r
+ // Enable the contact\r
+ c->m_flags |= b2Contact::e_enabledFlag;\r
\r
- if (other->m_type != b2_staticBody)\r
- {\r
- other->SetAwake(true);\r
- }\r
+ // Set the number of TOI events for this contact to zero.\r
+ c->m_toiCount = 0;\r
+ }\r
\r
- island.Add(other);\r
- }\r
- }\r
+ // Initialize the TOI flag.\r
+ for (b2Body* body = m_bodyList; body; body = body->m_next)\r
+ {\r
+ // Kinematic, and static bodies will not be affected by the TOI event.\r
+ // If a body was not in an island then it did not move.\r
+ if ((body->m_flags & b2Body::e_islandFlag) == 0 || body->GetType() == b2_kinematicBody || body->GetType() == b2_staticBody)\r
+ {\r
+ body->m_flags |= b2Body::e_toiFlag;\r
+ }\r
+ else\r
+ {\r
+ body->m_flags &= ~b2Body::e_toiFlag;\r
}\r
+ }\r
\r
- b2TimeStep subStep;\r
- subStep.dt = (1.0f - minAlpha) * step.dt;\r
- subStep.inv_dt = 1.0f / subStep.dt;\r
- subStep.dtRatio = 1.0f;\r
- subStep.positionIterations = 20;\r
- subStep.velocityIterations = step.velocityIterations;\r
- subStep.warmStarting = false;\r
- island.SolveTOI(subStep, bA, bB);\r
+ // Collide non-bullets.\r
+ for (b2Body* body = m_bodyList; body; body = body->m_next)\r
+ {\r
+ if (body->m_flags & b2Body::e_toiFlag)\r
+ {\r
+ continue;\r
+ }\r
\r
- // Reset island flags and synchronize broad-phase proxies.\r
- for (int32 i = 0; i < island.m_bodyCount; ++i)\r
+ if (body->IsBullet() == true)\r
{\r
- b2Body* body = island.m_bodies[i];\r
- body->m_flags &= ~b2Body::e_islandFlag;\r
+ continue;\r
+ }\r
\r
- if (body->m_type != b2_dynamicBody)\r
- {\r
- continue;\r
- }\r
+ SolveTOI(body);\r
\r
- body->SynchronizeFixtures();\r
+ body->m_flags |= b2Body::e_toiFlag;\r
+ }\r
\r
- // Invalidate all contact TOIs on this displaced body.\r
- for (b2ContactEdge* ce = body->m_contactList; ce; ce = ce->next)\r
- {\r
- ce->contact->m_flags &= ~(b2Contact::e_toiFlag | b2Contact::e_islandFlag);\r
- }\r
+ // Collide bullets.\r
+ for (b2Body* body = m_bodyList; body; body = body->m_next)\r
+ {\r
+ if (body->m_flags & b2Body::e_toiFlag)\r
+ {\r
+ continue;\r
}\r
\r
- // Commit fixture proxy movements to the broad-phase so that new contacts are created.\r
- // Also, some contacts can be destroyed.\r
- m_contactManager.FindNewContacts();\r
-\r
- if (m_subStepping)\r
+ if (body->IsBullet() == false)\r
{\r
- m_stepComplete = false;\r
- break;\r
+ continue;\r
}\r
+\r
+ SolveTOI(body);\r
+\r
+ body->m_flags |= b2Body::e_toiFlag;\r
}\r
}\r
\r
void b2World::Step(float32 dt, int32 velocityIterations, int32 positionIterations)\r
{\r
- b2Timer stepTimer;\r
-\r
// If new fixtures were added, we need to find the new contacts.\r
if (m_flags & e_newFixture)\r
{\r
step.dtRatio = m_inv_dt0 * dt;\r
\r
step.warmStarting = m_warmStarting;\r
- \r
+\r
// Update contacts. This is where some contacts are destroyed.\r
- {\r
- b2Timer timer;\r
- m_contactManager.Collide();\r
- m_profile.collide = timer.GetMilliseconds();\r
- }\r
+ m_contactManager.Collide();\r
\r
// Integrate velocities, solve velocity constraints, and integrate positions.\r
- if (m_stepComplete && step.dt > 0.0f)\r
+ if (step.dt > 0.0f)\r
{\r
- b2Timer timer;\r
Solve(step);\r
- m_profile.solve = timer.GetMilliseconds();\r
}\r
\r
// Handle TOI events.\r
if (m_continuousPhysics && step.dt > 0.0f)\r
{\r
- b2Timer timer;\r
- SolveTOI(step);\r
- m_profile.solveTOI = timer.GetMilliseconds();\r
+ SolveTOI();\r
}\r
\r
if (step.dt > 0.0f)\r
}\r
\r
m_flags &= ~e_locked;\r
-\r
- m_profile.step = stepTimer.GetMilliseconds();\r
}\r
\r
void b2World::ClearForces()\r
{\r
bool QueryCallback(int32 proxyId)\r
{\r
- b2FixtureProxy* proxy = (b2FixtureProxy*)broadPhase->GetUserData(proxyId);\r
- return callback->ReportFixture(proxy->fixture);\r
+ b2Fixture* fixture = (b2Fixture*)broadPhase->GetUserData(proxyId);\r
+ return callback->ReportFixture(fixture);\r
}\r
\r
const b2BroadPhase* broadPhase;\r
float32 RayCastCallback(const b2RayCastInput& input, int32 proxyId)\r
{\r
void* userData = broadPhase->GetUserData(proxyId);\r
- b2FixtureProxy* proxy = (b2FixtureProxy*)userData;\r
- b2Fixture* fixture = proxy->fixture;\r
- int32 index = proxy->childIndex;\r
+ b2Fixture* fixture = (b2Fixture*)userData;\r
b2RayCastOutput output;\r
- bool hit = fixture->RayCast(&output, input, index);\r
+ bool hit = fixture->RayCast(&output, input);\r
\r
if (hit)\r
{\r
}\r
break;\r
\r
- case b2Shape::e_edge:\r
- {\r
- b2EdgeShape* edge = (b2EdgeShape*)fixture->GetShape();\r
- b2Vec2 v1 = b2Mul(xf, edge->m_vertex1);\r
- b2Vec2 v2 = b2Mul(xf, edge->m_vertex2);\r
- m_debugDraw->DrawSegment(v1, v2, color);\r
- }\r
- break;\r
-\r
- case b2Shape::e_loop:\r
- {\r
- b2LoopShape* loop = (b2LoopShape*)fixture->GetShape();\r
- int32 count = loop->GetCount();\r
- const b2Vec2* vertices = loop->GetVertices();\r
-\r
- b2Vec2 v1 = b2Mul(xf, vertices[count - 1]);\r
- for (int32 i = 0; i < count; ++i)\r
- {\r
- b2Vec2 v2 = b2Mul(xf, vertices[i]);\r
- m_debugDraw->DrawSegment(v1, v2, color);\r
- m_debugDraw->DrawCircle(v1, 0.05f, color);\r
- v1 = v2;\r
- }\r
- }\r
- break;\r
-\r
case b2Shape::e_polygon:\r
{\r
b2PolygonShape* poly = (b2PolygonShape*)fixture->GetShape();\r
\r
uint32 flags = m_debugDraw->GetFlags();\r
\r
- if (flags & b2Draw::e_shapeBit)\r
+ if (flags & b2DebugDraw::e_shapeBit)\r
{\r
for (b2Body* b = m_bodyList; b; b = b->GetNext())\r
{\r
}\r
}\r
\r
- if (flags & b2Draw::e_jointBit)\r
+ if (flags & b2DebugDraw::e_jointBit)\r
{\r
for (b2Joint* j = m_jointList; j; j = j->GetNext())\r
{\r
}\r
}\r
\r
- if (flags & b2Draw::e_pairBit)\r
+ if (flags & b2DebugDraw::e_pairBit)\r
{\r
b2Color color(0.3f, 0.9f, 0.9f);\r
for (b2Contact* c = m_contactManager.m_contactList; c; c = c->GetNext())\r
{\r
- //b2Fixture* fixtureA = c->GetFixtureA();\r
- //b2Fixture* fixtureB = c->GetFixtureB();\r
+ b2Fixture* fixtureA = c->GetFixtureA();\r
+ b2Fixture* fixtureB = c->GetFixtureB();\r
\r
- //b2Vec2 cA = fixtureA->GetAABB().GetCenter();\r
- //b2Vec2 cB = fixtureB->GetAABB().GetCenter();\r
+ b2Vec2 cA = fixtureA->GetAABB().GetCenter();\r
+ b2Vec2 cB = fixtureB->GetAABB().GetCenter();\r
\r
- //m_debugDraw->DrawSegment(cA, cB, color);\r
+ m_debugDraw->DrawSegment(cA, cB, color);\r
}\r
}\r
\r
- if (flags & b2Draw::e_aabbBit)\r
+ if (flags & b2DebugDraw::e_aabbBit)\r
{\r
b2Color color(0.9f, 0.3f, 0.9f);\r
b2BroadPhase* bp = &m_contactManager.m_broadPhase;\r
\r
for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext())\r
{\r
- for (int32 i = 0; i < f->m_proxyCount; ++i)\r
- {\r
- b2FixtureProxy* proxy = f->m_proxies + i;\r
- b2AABB aabb = bp->GetFatAABB(proxy->proxyId);\r
- b2Vec2 vs[4];\r
- vs[0].Set(aabb.lowerBound.x, aabb.lowerBound.y);\r
- vs[1].Set(aabb.upperBound.x, aabb.lowerBound.y);\r
- vs[2].Set(aabb.upperBound.x, aabb.upperBound.y);\r
- vs[3].Set(aabb.lowerBound.x, aabb.upperBound.y);\r
-\r
- m_debugDraw->DrawPolygon(vs, 4, color);\r
- }\r
+ b2AABB aabb = bp->GetFatAABB(f->m_proxyId);\r
+ b2Vec2 vs[4];\r
+ vs[0].Set(aabb.lowerBound.x, aabb.lowerBound.y);\r
+ vs[1].Set(aabb.upperBound.x, aabb.lowerBound.y);\r
+ vs[2].Set(aabb.upperBound.x, aabb.upperBound.y);\r
+ vs[3].Set(aabb.lowerBound.x, aabb.upperBound.y);\r
+\r
+ m_debugDraw->DrawPolygon(vs, 4, color);\r
}\r
}\r
}\r
\r
- if (flags & b2Draw::e_centerOfMassBit)\r
+ if (flags & b2DebugDraw::e_centerOfMassBit)\r
{\r
for (b2Body* b = m_bodyList; b; b = b->GetNext())\r
{\r
{\r
return m_contactManager.m_broadPhase.GetProxyCount();\r
}\r
-\r
-int32 b2World::GetTreeHeight() const\r
-{\r
- return m_contactManager.m_broadPhase.GetTreeHeight();\r
-}\r
-\r
-int32 b2World::GetTreeBalance() const\r
-{\r
- return m_contactManager.m_broadPhase.GetTreeBalance();\r
-}\r
-\r
-float32 b2World::GetTreeQuality() const\r
-{\r
- return m_contactManager.m_broadPhase.GetTreeQuality();\r
-}\r
/*
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
struct b2AABB;
struct b2BodyDef;
-struct b2Color;
struct b2JointDef;
struct b2TimeStep;
class b2Body;
-class b2Draw;
class b2Fixture;
class b2Joint;
-/// Profiling data. Times are in milliseconds.
-struct b2Profile
-{
- float32 step;
- float32 collide;
- float32 solve;
- float32 solveTOI;
-};
-
/// The world class manages all physics entities, dynamic simulation,
/// and asynchronous queries. The world also contains efficient memory
/// management facilities.
/// Register a routine for debug drawing. The debug draw functions are called
/// inside with b2World::DrawDebugData method. The debug draw object is owned
/// by you and must remain in scope.
- void SetDebugDraw(b2Draw* debugDraw);
+ void SetDebugDraw(b2DebugDraw* debugDraw);
/// Create a rigid body given a definition. No reference to the definition
/// is retained.
int32 velocityIterations,
int32 positionIterations);
- /// Manually clear the force buffer on all bodies. By default, forces are cleared automatically
- /// after each call to Step. The default behavior is modified by calling SetAutoClearForces.
- /// The purpose of this function is to support sub-stepping. Sub-stepping is often used to maintain
- /// a fixed sized time step under a variable frame-rate.
- /// When you perform sub-stepping you will disable auto clearing of forces and instead call
- /// ClearForces after all sub-steps are complete in one pass of your game loop.
+ /// Call this after you are done with time steps to clear the forces. You normally
+ /// call this after each call to Step, unless you are performing sub-steps. By default,
+ /// forces will be automatically cleared, so you don't need to call this function.
/// @see SetAutoClearForces
void ClearForces();
/// the next body in the world list. A NULL body indicates the end of the list.
/// @return the head of the world body list.
b2Body* GetBodyList();
- const b2Body* GetBodyList() const;
/// Get the world joint list. With the returned joint, use b2Joint::GetNext to get
/// the next joint in the world list. A NULL joint indicates the end of the list.
/// @return the head of the world joint list.
b2Joint* GetJointList();
- const b2Joint* GetJointList() const;
/// Get the world contact list. With the returned contact, use b2Contact::GetNext to get
/// the next contact in the world list. A NULL contact indicates the end of the list.
/// @return the head of the world contact list.
/// @warning contacts are
b2Contact* GetContactList();
- const b2Contact* GetContactList() const;
/// Enable/disable warm starting. For testing.
void SetWarmStarting(bool flag) { m_warmStarting = flag; }
/// Enable/disable continuous physics. For testing.
void SetContinuousPhysics(bool flag) { m_continuousPhysics = flag; }
- /// Enable/disable single stepped continuous physics. For testing.
- void SetSubStepping(bool flag) { m_subStepping = flag; }
-
/// Get the number of broad-phase proxies.
int32 GetProxyCount() const;
/// Get the number of contacts (each may have 0 or more contact points).
int32 GetContactCount() const;
- /// Get the height of the dynamic tree.
- int32 GetTreeHeight() const;
-
- /// Get the balance of the dynamic tree.
- int32 GetTreeBalance() const;
-
- /// Get the quality metric of the dynamic tree. The smaller the better.
- /// The minimum is 1.
- float32 GetTreeQuality() const;
-
/// Change the global gravity vector.
void SetGravity(const b2Vec2& gravity);
/// Get the flag that controls automatic clearing of forces after each time step.
bool GetAutoClearForces() const;
- /// Get the contact manager for testing.
- const b2ContactManager& GetContactManager() const;
-
- /// Get the current profile.
- const b2Profile& GetProfile() const;
-
private:
// m_flags
{
e_newFixture = 0x0001,
e_locked = 0x0002,
- e_clearForces = 0x0004
+ e_clearForces = 0x0004,
};
friend class b2Body;
- friend class b2Fixture;
friend class b2ContactManager;
friend class b2Controller;
void Solve(const b2TimeStep& step);
- void SolveTOI(const b2TimeStep& step);
+ void SolveTOI();
+ void SolveTOI(b2Body* body);
void DrawJoint(b2Joint* joint);
void DrawShape(b2Fixture* shape, const b2Transform& xf, const b2Color& color);
b2Vec2 m_gravity;
bool m_allowSleep;
+ b2Body* m_groundBody;
+
b2DestructionListener* m_destructionListener;
- b2Draw* m_debugDraw;
+ b2DebugDraw* m_debugDraw;
// This is used to compute the time step ratio to
// support a variable time step.
float32 m_inv_dt0;
- // These are for debugging the solver.
+ // This is for debugging the solver.
bool m_warmStarting;
- bool m_continuousPhysics;
- bool m_subStepping;
-
- bool m_stepComplete;
- b2Profile m_profile;
+ // This is for debugging the solver.
+ bool m_continuousPhysics;
};
inline b2Body* b2World::GetBodyList()
return m_bodyList;
}
-inline const b2Body* b2World::GetBodyList() const
-{
- return m_bodyList;
-}
-
inline b2Joint* b2World::GetJointList()
{
return m_jointList;
}
-inline const b2Joint* b2World::GetJointList() const
-{
- return m_jointList;
-}
-
inline b2Contact* b2World::GetContactList()
{
return m_contactManager.m_contactList;
}
-inline const b2Contact* b2World::GetContactList() const
-{
- return m_contactManager.m_contactList;
-}
-
inline int32 b2World::GetBodyCount() const
{
return m_bodyCount;
return (m_flags & e_clearForces) == e_clearForces;
}
-inline const b2ContactManager& b2World::GetContactManager() const
-{
- return m_contactManager;
-}
-
-inline const b2Profile& b2World::GetProfile() const
-{
- return m_profile;
-}
-
#endif
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
bool collide = (filterA.maskBits & filterB.categoryBits) != 0 && (filterA.categoryBits & filterB.maskBits) != 0;\r
return collide;\r
}\r
+\r
+b2DebugDraw::b2DebugDraw()\r
+{\r
+ m_drawFlags = 0;\r
+}\r
+\r
+void b2DebugDraw::SetFlags(uint32 flags)\r
+{\r
+ m_drawFlags = flags;\r
+}\r
+\r
+uint32 b2DebugDraw::GetFlags() const\r
+{\r
+ return m_drawFlags;\r
+}\r
+\r
+void b2DebugDraw::AppendFlags(uint32 flags)\r
+{\r
+ m_drawFlags |= flags;\r
+}\r
+\r
+void b2DebugDraw::ClearFlags(uint32 flags)\r
+{\r
+ m_drawFlags &= ~flags;\r
+}\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
class b2Body;\r
class b2Joint;\r
class b2Contact;\r
+struct b2ContactPoint;\r
struct b2ContactResult;\r
struct b2Manifold;\r
\r
const b2Vec2& normal, float32 fraction) = 0;\r
};\r
\r
+/// Color for debug drawing. Each value has the range [0,1].\r
+struct b2Color\r
+{\r
+ b2Color() {}\r
+ b2Color(float32 r, float32 g, float32 b) : r(r), g(g), b(b) {}\r
+ void Set(float32 ri, float32 gi, float32 bi) { r = ri; g = gi; b = bi; }\r
+ float32 r, g, b;\r
+};\r
+\r
+/// Implement and register this class with a b2World to provide debug drawing of physics\r
+/// entities in your game.\r
+class b2DebugDraw\r
+{\r
+public:\r
+ b2DebugDraw();\r
+\r
+ virtual ~b2DebugDraw() {}\r
+\r
+ enum\r
+ {\r
+ e_shapeBit = 0x0001, ///< draw shapes\r
+ e_jointBit = 0x0002, ///< draw joint connections\r
+ e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes\r
+ e_pairBit = 0x0008, ///< draw broad-phase pairs\r
+ e_centerOfMassBit = 0x0010, ///< draw center of mass frame\r
+ };\r
+\r
+ /// Set the drawing flags.\r
+ void SetFlags(uint32 flags);\r
+\r
+ /// Get the drawing flags.\r
+ uint32 GetFlags() const;\r
+ \r
+ /// Append flags to the current flags.\r
+ void AppendFlags(uint32 flags);\r
+\r
+ /// Clear flags from the current flags.\r
+ void ClearFlags(uint32 flags);\r
+\r
+ /// Draw a closed polygon provided in CCW order.\r
+ virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;\r
+\r
+ /// Draw a solid closed polygon provided in CCW order.\r
+ virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0;\r
+\r
+ /// Draw a circle.\r
+ virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) = 0;\r
+ \r
+ /// Draw a solid circle.\r
+ virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) = 0;\r
+ \r
+ /// Draw a line segment.\r
+ virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0;\r
+\r
+ /// Draw a transform. Choose your own length scale.\r
+ /// @param xf a transform.\r
+ virtual void DrawTransform(const b2Transform& xf) = 0;\r
+\r
+protected:\r
+ uint32 m_drawFlags;\r
+};\r
+\r
#endif\r
+++ /dev/null
-/*\r
-* Copyright (c) 2011 Erin Catto http://box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#include <Box2D/Rope/b2Rope.h>\r
-#include <Box2D/Common/b2Draw.h>\r
-\r
-b2Rope::b2Rope()\r
-{\r
- m_count = 0;\r
- m_ps = NULL;\r
- m_p0s = NULL;\r
- m_vs = NULL;\r
- m_ims = NULL;\r
- m_Ls = NULL;\r
- m_as = NULL;\r
- m_gravity.SetZero();\r
- m_k2 = 1.0f;\r
- m_k3 = 0.1f;\r
-}\r
-\r
-b2Rope::~b2Rope()\r
-{\r
- b2Free(m_ps);\r
- b2Free(m_p0s);\r
- b2Free(m_vs);\r
- b2Free(m_ims);\r
- b2Free(m_Ls);\r
- b2Free(m_as);\r
-}\r
-\r
-void b2Rope::Initialize(const b2RopeDef* def)\r
-{\r
- b2Assert(def->count >= 3);\r
- m_count = def->count;\r
- m_ps = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));\r
- m_p0s = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));\r
- m_vs = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));\r
- m_ims = (float32*)b2Alloc(m_count * sizeof(float32));\r
-\r
- for (int32 i = 0; i < m_count; ++i)\r
- {\r
- m_ps[i] = def->vertices[i];\r
- m_p0s[i] = def->vertices[i];\r
- m_vs[i].SetZero();\r
-\r
- float32 m = def->masses[i];\r
- if (m > 0.0f)\r
- {\r
- m_ims[i] = 1.0f / m;\r
- }\r
- else\r
- {\r
- m_ims[i] = 0.0f;\r
- }\r
- }\r
-\r
- int32 count2 = m_count - 1;\r
- int32 count3 = m_count - 2;\r
- m_Ls = (float32*)b2Alloc(count2 * sizeof(float32));\r
- m_as = (float32*)b2Alloc(count3 * sizeof(float32));\r
-\r
- for (int32 i = 0; i < count2; ++i)\r
- {\r
- b2Vec2 p1 = m_ps[i];\r
- b2Vec2 p2 = m_ps[i+1];\r
- m_Ls[i] = b2Distance(p1, p2);\r
- }\r
-\r
- for (int32 i = 0; i < count3; ++i)\r
- {\r
- b2Vec2 p1 = m_ps[i];\r
- b2Vec2 p2 = m_ps[i + 1];\r
- b2Vec2 p3 = m_ps[i + 2];\r
-\r
- b2Vec2 d1 = p2 - p1;\r
- b2Vec2 d2 = p3 - p2;\r
-\r
- float32 a = b2Cross(d1, d2);\r
- float32 b = b2Dot(d1, d2);\r
-\r
- m_as[i] = b2Atan2(a, b);\r
- }\r
-\r
- m_gravity = def->gravity;\r
- m_damping = def->damping;\r
- m_k2 = def->k2;\r
- m_k3 = def->k3;\r
-}\r
-\r
-void b2Rope::Step(float32 h, int32 iterations)\r
-{\r
- if (h == 0.0)\r
- {\r
- return;\r
- }\r
-\r
- float32 d = expf(- h * m_damping);\r
-\r
- for (int32 i = 0; i < m_count; ++i)\r
- {\r
- m_p0s[i] = m_ps[i];\r
- if (m_ims[i] > 0.0f)\r
- {\r
- m_vs[i] += h * m_gravity;\r
- }\r
- m_vs[i] *= d;\r
- m_ps[i] += h * m_vs[i];\r
-\r
- }\r
-\r
- for (int32 i = 0; i < iterations; ++i)\r
- {\r
- SolveC2();\r
- SolveC3();\r
- SolveC2();\r
- }\r
-\r
- float32 inv_h = 1.0f / h;\r
- for (int32 i = 0; i < m_count; ++i)\r
- {\r
- m_vs[i] = inv_h * (m_ps[i] - m_p0s[i]);\r
- }\r
-}\r
-\r
-void b2Rope::SolveC2()\r
-{\r
- int32 count2 = m_count - 1;\r
-\r
- for (int32 i = 0; i < count2; ++i)\r
- {\r
- b2Vec2 p1 = m_ps[i];\r
- b2Vec2 p2 = m_ps[i + 1];\r
-\r
- b2Vec2 d = p2 - p1;\r
- float32 L = d.Normalize();\r
-\r
- float32 im1 = m_ims[i];\r
- float32 im2 = m_ims[i + 1];\r
-\r
- if (im1 + im2 == 0.0f)\r
- {\r
- continue;\r
- }\r
-\r
- float32 s1 = im1 / (im1 + im2);\r
- float32 s2 = im2 / (im1 + im2);\r
-\r
- p1 -= m_k2 * s1 * (m_Ls[i] - L) * d;\r
- p2 += m_k2 * s2 * (m_Ls[i] - L) * d;\r
-\r
- m_ps[i] = p1;\r
- m_ps[i + 1] = p2;\r
- }\r
-}\r
-\r
-void b2Rope::SetAngle(float32 angle)\r
-{\r
- int32 count3 = m_count - 2;\r
- for (int32 i = 0; i < count3; ++i)\r
- {\r
- m_as[i] = angle;\r
- }\r
-}\r
-\r
-void b2Rope::SolveC3()\r
-{\r
- int32 count3 = m_count - 2;\r
-\r
- for (int32 i = 0; i < count3; ++i)\r
- {\r
- b2Vec2 p1 = m_ps[i];\r
- b2Vec2 p2 = m_ps[i + 1];\r
- b2Vec2 p3 = m_ps[i + 2];\r
-\r
- float32 m1 = m_ims[i];\r
- float32 m2 = m_ims[i + 1];\r
- float32 m3 = m_ims[i + 2];\r
-\r
- b2Vec2 d1 = p2 - p1;\r
- b2Vec2 d2 = p3 - p2;\r
-\r
- float32 L1sqr = d1.LengthSquared();\r
- float32 L2sqr = d2.LengthSquared();\r
-\r
- if (L1sqr * L2sqr == 0.0f)\r
- {\r
- continue;\r
- }\r
-\r
- float32 a = b2Cross(d1, d2);\r
- float32 b = b2Dot(d1, d2);\r
-\r
- float32 angle = b2Atan2(a, b);\r
-\r
- b2Vec2 Jd1 = (-1.0f / L1sqr) * d1.Skew();\r
- b2Vec2 Jd2 = (1.0f / L2sqr) * d2.Skew();\r
-\r
- b2Vec2 J1 = -Jd1;\r
- b2Vec2 J2 = Jd1 - Jd2;\r
- b2Vec2 J3 = Jd2;\r
-\r
- float32 mass = m1 * b2Dot(J1, J1) + m2 * b2Dot(J2, J2) + m3 * b2Dot(J3, J3);\r
- if (mass == 0.0f)\r
- {\r
- continue;\r
- }\r
-\r
- mass = 1.0f / mass;\r
-\r
- float32 C = angle - m_as[i];\r
-\r
- while (C > b2_pi)\r
- {\r
- angle -= 2 * b2_pi;\r
- C = angle - m_as[i];\r
- }\r
-\r
- while (C < -b2_pi)\r
- {\r
- angle += 2.0f * b2_pi;\r
- C = angle - m_as[i];\r
- }\r
-\r
- float32 impulse = - m_k3 * mass * C;\r
-\r
- p1 += (m1 * impulse) * J1;\r
- p2 += (m2 * impulse) * J2;\r
- p3 += (m3 * impulse) * J3;\r
-\r
- m_ps[i] = p1;\r
- m_ps[i + 1] = p2;\r
- m_ps[i + 2] = p3;\r
- }\r
-}\r
-\r
-void b2Rope::Draw(b2Draw* draw) const\r
-{\r
- b2Color c(0.4f, 0.5f, 0.7f);\r
-\r
- for (int32 i = 0; i < m_count - 1; ++i)\r
- {\r
- draw->DrawSegment(m_ps[i], m_ps[i+1], c);\r
- }\r
-}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2011 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef B2_ROPE_H\r
-#define B2_ROPE_H\r
-\r
-#include <Box2D/Common/b2Math.h>\r
-\r
-class b2Draw;\r
-\r
-/// \r
-struct b2RopeDef\r
-{\r
- b2RopeDef()\r
- {\r
- vertices = NULL;\r
- count = 0;\r
- masses = NULL;\r
- gravity.SetZero();\r
- damping = 0.1f;\r
- k2 = 0.9f;\r
- k3 = 0.1f;\r
- }\r
-\r
- ///\r
- b2Vec2* vertices;\r
-\r
- ///\r
- int32 count;\r
-\r
- ///\r
- float32* masses;\r
-\r
- ///\r
- b2Vec2 gravity;\r
-\r
- ///\r
- float32 damping;\r
-\r
- /// Stretching stiffness\r
- float32 k2;\r
-\r
- /// Bending stiffness. Values above 0.5 can make the simulation blow up.\r
- float32 k3;\r
-};\r
-\r
-/// \r
-class b2Rope\r
-{\r
-public:\r
- b2Rope();\r
- ~b2Rope();\r
-\r
- ///\r
- void Initialize(const b2RopeDef* def);\r
-\r
- ///\r
- void Step(float32 timeStep, int32 iterations);\r
-\r
- ///\r
- int32 GetVertexCount() const\r
- {\r
- return m_count;\r
- }\r
-\r
- ///\r
- const b2Vec2* GetVertices() const\r
- {\r
- return m_ps;\r
- }\r
-\r
- ///\r
- void Draw(b2Draw* draw) const;\r
-\r
- ///\r
- void SetAngle(float32 angle);\r
-\r
-private:\r
-\r
- void SolveC2();\r
- void SolveC3();\r
-\r
- int32 m_count;\r
- b2Vec2* m_ps;\r
- b2Vec2* m_p0s;\r
- b2Vec2* m_vs;\r
-\r
- float32* m_ims;\r
-\r
- float32* m_Ls;\r
- float32* m_as;\r
-\r
- b2Vec2 m_gravity;\r
- float32 m_damping;\r
-\r
- float32 m_k2;\r
- float32 m_k3;\r
-};\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
bd.position.Set(0.0f, 20.0f);\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
+ b2PolygonShape shape;\r
\r
b2FixtureDef sd;\r
sd.shape = &shape;\r
sd.restitution = k_restitution;\r
\r
// Left vertical\r
- shape.Set(b2Vec2(-20.0f, -20.0f), b2Vec2(-20.0f, 20.0f));\r
+ shape.SetAsEdge(b2Vec2(-20.0f, -20.0f), b2Vec2(-20.0f, 20.0f));\r
ground->CreateFixture(&sd);\r
\r
// Right vertical\r
- shape.Set(b2Vec2(20.0f, -20.0f), b2Vec2(20.0f, 20.0f));\r
+ shape.SetAsEdge(b2Vec2(20.0f, -20.0f), b2Vec2(20.0f, 20.0f));\r
ground->CreateFixture(&sd);\r
\r
// Top horizontal\r
- shape.Set(b2Vec2(-20.0f, 20.0f), b2Vec2(20.0f, 20.0f));\r
+ shape.SetAsEdge(b2Vec2(-20.0f, 20.0f), b2Vec2(20.0f, 20.0f));\r
ground->CreateFixture(&sd);\r
\r
// Bottom horizontal\r
- shape.Set(b2Vec2(-20.0f, -20.0f), b2Vec2(20.0f, -20.0f));\r
+ shape.SetAsEdge(b2Vec2(-20.0f, -20.0f), b2Vec2(20.0f, -20.0f));\r
ground->CreateFixture(&sd);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f));\r
\r
b2FixtureDef fd;\r
fd.shape = &shape;\r
/*\r
-* Copyright (c) 2008-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2008-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
enum\r
{\r
- e_count = 30\r
+ e_count = 30,\r
};\r
\r
Bridge()\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef BULLET_TEST_H\r
-#define BULLET_TEST_H\r
-\r
-class BulletTest : public Test\r
-{\r
-public:\r
-\r
- BulletTest()\r
- {\r
- {\r
- b2BodyDef bd;\r
- bd.position.Set(0.0f, 0.0f);\r
- b2Body* body = m_world->CreateBody(&bd);\r
-\r
- b2EdgeShape edge;\r
-\r
- edge.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f));\r
- body->CreateFixture(&edge, 0.0f);\r
-\r
- b2PolygonShape shape;\r
- shape.SetAsBox(0.2f, 1.0f, b2Vec2(0.5f, 1.0f), 0.0f);\r
- body->CreateFixture(&shape, 0.0f);\r
- }\r
-\r
- {\r
- b2BodyDef bd;\r
- bd.type = b2_dynamicBody;\r
- bd.position.Set(0.0f, 4.0f);\r
-\r
- b2PolygonShape box;\r
- box.SetAsBox(2.0f, 0.1f);\r
-\r
- m_body = m_world->CreateBody(&bd);\r
- m_body->CreateFixture(&box, 1.0f);\r
-\r
- box.SetAsBox(0.25f, 0.25f);\r
-\r
- //m_x = RandomFloat(-1.0f, 1.0f);\r
- m_x = 0.20352793f;\r
- bd.position.Set(m_x, 10.0f);\r
- bd.bullet = true;\r
-\r
- m_bullet = m_world->CreateBody(&bd);\r
- m_bullet->CreateFixture(&box, 100.0f);\r
-\r
- m_bullet->SetLinearVelocity(b2Vec2(0.0f, -50.0f));\r
- }\r
- }\r
-\r
- void Launch()\r
- {\r
- m_body->SetTransform(b2Vec2(0.0f, 4.0f), 0.0f);\r
- m_body->SetLinearVelocity(b2Vec2_zero);\r
- m_body->SetAngularVelocity(0.0f);\r
-\r
- m_x = RandomFloat(-1.0f, 1.0f);\r
- m_bullet->SetTransform(b2Vec2(m_x, 10.0f), 0.0f);\r
- m_bullet->SetLinearVelocity(b2Vec2(0.0f, -50.0f));\r
- m_bullet->SetAngularVelocity(0.0f);\r
-\r
- extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;\r
- extern int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters;\r
- extern int32 b2_toiRootIters, b2_toiMaxRootIters;\r
-\r
- b2_gjkCalls = 0;\r
- b2_gjkIters = 0;\r
- b2_gjkMaxIters = 0;\r
-\r
- b2_toiCalls = 0;\r
- b2_toiIters = 0;\r
- b2_toiMaxIters = 0;\r
- b2_toiRootIters = 0;\r
- b2_toiMaxRootIters = 0;\r
- }\r
-\r
- void Step(Settings* settings)\r
- {\r
- Test::Step(settings);\r
-\r
- extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;\r
- extern int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters;\r
- extern int32 b2_toiRootIters, b2_toiMaxRootIters;\r
-\r
- if (b2_gjkCalls > 0)\r
- {\r
- m_debugDraw.DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",\r
- b2_gjkCalls, b2_gjkIters / float32(b2_gjkCalls), b2_gjkMaxIters);\r
- m_textLine += 15;\r
- }\r
-\r
- if (b2_toiCalls > 0)\r
- {\r
- m_debugDraw.DrawString(5, m_textLine, "toi calls = %d, ave toi iters = %3.1f, max toi iters = %d",\r
- b2_toiCalls, b2_toiIters / float32(b2_toiCalls), b2_toiMaxRootIters);\r
- m_textLine += 15;\r
-\r
- m_debugDraw.DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d",\r
- b2_toiRootIters / float32(b2_toiCalls), b2_toiMaxRootIters);\r
- m_textLine += 15;\r
- }\r
-\r
- if (m_stepCount % 60 == 0)\r
- {\r
- Launch();\r
- }\r
- }\r
-\r
- static Test* Create()\r
- {\r
- return new BulletTest;\r
- }\r
-\r
- b2Body* m_body;\r
- b2Body* m_bullet;\r
- float32 m_x;\r
-};\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
enum\r
{\r
- e_count = 8\r
+ e_count = 8,\r
};\r
\r
Cantilever()\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
b2BodyDef bd;\r
bd.type = b2_dynamicBody;\r
bd.position.Set(-14.5f + 1.0f * i, 15.0f);\r
+ bd.inertiaScale = 10.0f;\r
b2Body* body = m_world->CreateBody(&bd);\r
body->CreateFixture(&fd);\r
\r
b2BodyDef bd;\r
bd.type = b2_dynamicBody;\r
bd.position.Set(5.5f + 1.0f * i, 10.0f);\r
+ bd.inertiaScale = 10.0f;\r
b2Body* body = m_world->CreateBody(&bd);\r
body->CreateFixture(&fd);\r
\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef CAR_H\r
-#define CAR_H\r
-\r
-// This is a fun demo that shows off the wheel joint\r
-class Car : public Test\r
-{\r
-public:\r
- Car()\r
- { \r
- m_hz = 4.0f;\r
- m_zeta = 0.7f;\r
- m_speed = 50.0f;\r
-\r
- b2Body* ground = NULL;\r
- {\r
- b2BodyDef bd;\r
- ground = m_world->CreateBody(&bd);\r
-\r
- b2EdgeShape shape;\r
-\r
- b2FixtureDef fd;\r
- fd.shape = &shape;\r
- fd.density = 0.0f;\r
- fd.friction = 0.6f;\r
-\r
- shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f));\r
- ground->CreateFixture(&fd);\r
-\r
- float32 hs[10] = {0.25f, 1.0f, 4.0f, 0.0f, 0.0f, -1.0f, -2.0f, -2.0f, -1.25f, 0.0f};\r
-\r
- float32 x = 20.0f, y1 = 0.0f, dx = 5.0f;\r
-\r
- for (int32 i = 0; i < 10; ++i)\r
- {\r
- float32 y2 = hs[i];\r
- shape.Set(b2Vec2(x, y1), b2Vec2(x + dx, y2));\r
- ground->CreateFixture(&fd);\r
- y1 = y2;\r
- x += dx;\r
- }\r
-\r
- for (int32 i = 0; i < 10; ++i)\r
- {\r
- float32 y2 = hs[i];\r
- shape.Set(b2Vec2(x, y1), b2Vec2(x + dx, y2));\r
- ground->CreateFixture(&fd);\r
- y1 = y2;\r
- x += dx;\r
- }\r
-\r
- shape.Set(b2Vec2(x, 0.0f), b2Vec2(x + 40.0f, 0.0f));\r
- ground->CreateFixture(&fd);\r
-\r
- x += 80.0f;\r
- shape.Set(b2Vec2(x, 0.0f), b2Vec2(x + 40.0f, 0.0f));\r
- ground->CreateFixture(&fd);\r
-\r
- x += 40.0f;\r
- shape.Set(b2Vec2(x, 0.0f), b2Vec2(x + 10.0f, 5.0f));\r
- ground->CreateFixture(&fd);\r
-\r
- x += 20.0f;\r
- shape.Set(b2Vec2(x, 0.0f), b2Vec2(x + 40.0f, 0.0f));\r
- ground->CreateFixture(&fd);\r
-\r
- x += 40.0f;\r
- shape.Set(b2Vec2(x, 0.0f), b2Vec2(x, 20.0f));\r
- ground->CreateFixture(&fd);\r
- }\r
-\r
- // Teeter\r
- {\r
- b2BodyDef bd;\r
- bd.position.Set(140.0f, 1.0f);\r
- bd.type = b2_dynamicBody;\r
- b2Body* body = m_world->CreateBody(&bd);\r
-\r
- b2PolygonShape box;\r
- box.SetAsBox(10.0f, 0.25f);\r
- body->CreateFixture(&box, 1.0f);\r
-\r
- b2RevoluteJointDef jd;\r
- jd.Initialize(ground, body, body->GetPosition());\r
- jd.lowerAngle = -8.0f * b2_pi / 180.0f;\r
- jd.upperAngle = 8.0f * b2_pi / 180.0f;\r
- jd.enableLimit = true;\r
- m_world->CreateJoint(&jd);\r
-\r
- body->ApplyAngularImpulse(100.0f);\r
- }\r
-\r
- // Bridge\r
- {\r
- int32 N = 20;\r
- b2PolygonShape shape;\r
- shape.SetAsBox(1.0f, 0.125f);\r
-\r
- b2FixtureDef fd;\r
- fd.shape = &shape;\r
- fd.density = 1.0f;\r
- fd.friction = 0.6f;\r
-\r
- b2RevoluteJointDef jd;\r
-\r
- b2Body* prevBody = ground;\r
- for (int32 i = 0; i < N; ++i)\r
- {\r
- b2BodyDef bd;\r
- bd.type = b2_dynamicBody;\r
- bd.position.Set(161.0f + 2.0f * i, -0.125f);\r
- b2Body* body = m_world->CreateBody(&bd);\r
- body->CreateFixture(&fd);\r
-\r
- b2Vec2 anchor(160.0f + 2.0f * i, -0.125f);\r
- jd.Initialize(prevBody, body, anchor);\r
- m_world->CreateJoint(&jd);\r
-\r
- prevBody = body;\r
- }\r
-\r
- b2Vec2 anchor(160.0f + 2.0f * N, -0.125f);\r
- jd.Initialize(prevBody, ground, anchor);\r
- m_world->CreateJoint(&jd);\r
- }\r
-\r
- // Boxes\r
- {\r
- b2PolygonShape box;\r
- box.SetAsBox(0.5f, 0.5f);\r
-\r
- b2Body* body = NULL;\r
- b2BodyDef bd;\r
- bd.type = b2_dynamicBody;\r
-\r
- bd.position.Set(230.0f, 0.5f);\r
- body = m_world->CreateBody(&bd);\r
- body->CreateFixture(&box, 0.5f);\r
-\r
- bd.position.Set(230.0f, 1.5f);\r
- body = m_world->CreateBody(&bd);\r
- body->CreateFixture(&box, 0.5f);\r
-\r
- bd.position.Set(230.0f, 2.5f);\r
- body = m_world->CreateBody(&bd);\r
- body->CreateFixture(&box, 0.5f);\r
-\r
- bd.position.Set(230.0f, 3.5f);\r
- body = m_world->CreateBody(&bd);\r
- body->CreateFixture(&box, 0.5f);\r
-\r
- bd.position.Set(230.0f, 4.5f);\r
- body = m_world->CreateBody(&bd);\r
- body->CreateFixture(&box, 0.5f);\r
- }\r
-\r
- // Car\r
- {\r
- b2PolygonShape chassis;\r
- b2Vec2 vertices[8];\r
- vertices[0].Set(-1.5f, -0.5f);\r
- vertices[1].Set(1.5f, -0.5f);\r
- vertices[2].Set(1.5f, 0.0f);\r
- vertices[3].Set(0.0f, 0.9f);\r
- vertices[4].Set(-1.15f, 0.9f);\r
- vertices[5].Set(-1.5f, 0.2f);\r
- chassis.Set(vertices, 6);\r
-\r
- b2CircleShape circle;\r
- circle.m_radius = 0.4f;\r
-\r
- b2BodyDef bd;\r
- bd.type = b2_dynamicBody;\r
- bd.position.Set(0.0f, 1.0f);\r
- m_car = m_world->CreateBody(&bd);\r
- m_car->CreateFixture(&chassis, 1.0f);\r
-\r
- b2FixtureDef fd;\r
- fd.shape = &circle;\r
- fd.density = 1.0f;\r
- fd.friction = 0.9f;\r
-\r
- bd.position.Set(-1.0f, 0.35f);\r
- m_wheel1 = m_world->CreateBody(&bd);\r
- m_wheel1->CreateFixture(&fd);\r
-\r
- bd.position.Set(1.0f, 0.4f);\r
- m_wheel2 = m_world->CreateBody(&bd);\r
- m_wheel2->CreateFixture(&fd);\r
-\r
- b2WheelJointDef jd;\r
- b2Vec2 axis(0.0f, 1.0f);\r
-\r
- jd.Initialize(m_car, m_wheel1, m_wheel1->GetPosition(), axis);\r
- jd.motorSpeed = 0.0f;\r
- jd.maxMotorTorque = 20.0f;\r
- jd.enableMotor = true;\r
- jd.frequencyHz = m_hz;\r
- jd.dampingRatio = m_zeta;\r
- m_spring1 = (b2WheelJoint*)m_world->CreateJoint(&jd);\r
-\r
- jd.Initialize(m_car, m_wheel2, m_wheel2->GetPosition(), axis);\r
- jd.motorSpeed = 0.0f;\r
- jd.maxMotorTorque = 10.0f;\r
- jd.enableMotor = false;\r
- jd.frequencyHz = m_hz;\r
- jd.dampingRatio = m_zeta;\r
- m_spring2 = (b2WheelJoint*)m_world->CreateJoint(&jd);\r
- }\r
- }\r
-\r
- void Keyboard(unsigned char key)\r
- {\r
- switch (key)\r
- {\r
- case 'a':\r
- m_spring1->SetMotorSpeed(m_speed);\r
- break;\r
-\r
- case 's':\r
- m_spring1->SetMotorSpeed(0.0f);\r
- break;\r
-\r
- case 'd':\r
- m_spring1->SetMotorSpeed(-m_speed);\r
- break;\r
-\r
- case 'q':\r
- m_hz = b2Max(0.0f, m_hz - 1.0f);\r
- m_spring1->SetSpringFrequencyHz(m_hz);\r
- m_spring2->SetSpringFrequencyHz(m_hz);\r
- break;\r
-\r
- case 'e':\r
- m_hz += 1.0f;\r
- m_spring1->SetSpringFrequencyHz(m_hz);\r
- m_spring2->SetSpringFrequencyHz(m_hz);\r
- break;\r
- }\r
- }\r
-\r
- void Step(Settings* settings)\r
- {\r
- m_debugDraw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, hz down = q, hz up = e");\r
- m_textLine += 15;\r
- m_debugDraw.DrawString(5, m_textLine, "frequency = %g hz, damping ratio = %g", m_hz, m_zeta);\r
- m_textLine += 15;\r
-\r
- settings->viewCenter.x = m_car->GetPosition().x;\r
- Test::Step(settings);\r
- }\r
-\r
- static Test* Create()\r
- {\r
- return new Car;\r
- }\r
-\r
- b2Body* m_car;\r
- b2Body* m_wheel1;\r
- b2Body* m_wheel2;\r
-\r
- float32 m_hz;\r
- float32 m_zeta;\r
- float32 m_speed;\r
- b2WheelJoint* m_spring1;\r
- b2WheelJoint* m_spring2;\r
-};\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2010 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
- // Collinear edges with no adjacency information.\r
- // This shows the problematic case where a box shape can hit\r
- // an internal vertex.\r
+ // Collinear edges\r
{\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-8.0f, 1.0f), b2Vec2(-6.0f, 1.0f));\r
+ b2PolygonShape shape;\r
+ shape.m_radius = 0.0f;\r
+ shape.SetAsEdge(b2Vec2(-8.0f, 1.0f), b2Vec2(-6.0f, 1.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
- shape.Set(b2Vec2(-6.0f, 1.0f), b2Vec2(-4.0f, 1.0f));\r
+ shape.SetAsEdge(b2Vec2(-6.0f, 1.0f), b2Vec2(-4.0f, 1.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
- shape.Set(b2Vec2(-4.0f, 1.0f), b2Vec2(-2.0f, 1.0f));\r
+ shape.SetAsEdge(b2Vec2(-4.0f, 1.0f), b2Vec2(-2.0f, 1.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
- // Square tiles. This shows that adjacency shapes may\r
- // have non-smooth collision. There is no solution\r
- // to this problem.\r
+ // Square tiles\r
{\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
- // Square made from an edge loop. Collision should be smooth.\r
+ // Square made from edges notice how the edges are shrunk to account\r
+ // for the polygon radius. This makes it so the square character does\r
+ // not get snagged. However, ray casts can now go through the cracks.\r
{\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2Vec2 vs[4];\r
- vs[0].Set(-1.0f, 3.0f);\r
- vs[1].Set(1.0f, 3.0f);\r
- vs[2].Set(1.0f, 5.0f);\r
- vs[3].Set(-1.0f, 5.0f);\r
- b2LoopShape shape;\r
- shape.Create(vs, 4);\r
+ b2PolygonShape shape;\r
+ float32 d = 2.0f * b2_polygonRadius;\r
+ shape.SetAsEdge(b2Vec2(-1.0f + d, 3.0f), b2Vec2(1.0f - d, 3.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
- }\r
-\r
- // Edge loop. Collision should be smooth.\r
- {\r
- b2BodyDef bd;\r
- bd.position.Set(-10.0f, 4.0f);\r
- b2Body* ground = m_world->CreateBody(&bd);\r
-\r
- b2Vec2 vs[10];\r
- vs[0].Set(0.0f, 0.0f);\r
- vs[1].Set(6.0f, 0.0f);\r
- vs[2].Set(6.0f, 2.0f);\r
- vs[3].Set(4.0f, 1.0f);\r
- vs[4].Set(2.0f, 2.0f);\r
- vs[5].Set(0.0f, 2.0f);\r
- vs[6].Set(-2.0f, 2.0f);\r
- vs[7].Set(-4.0f, 3.0f);\r
- vs[8].Set(-6.0f, 2.0f);\r
- vs[9].Set(-6.0f, 0.0f);\r
- b2LoopShape shape;\r
- shape.Create(vs, 10);\r
+ shape.SetAsEdge(b2Vec2(1.0f, 3.0f + d), b2Vec2(1.0f, 5.0f - d));\r
+ ground->CreateFixture(&shape, 0.0f);\r
+ shape.SetAsEdge(b2Vec2(1.0f - d, 5.0f), b2Vec2(-1.0f + d, 5.0f));\r
+ ground->CreateFixture(&shape, 0.0f);\r
+ shape.SetAsEdge(b2Vec2(-1.0f, 5.0f - d), b2Vec2(-1.0f, 3.0f + d));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
- // Square character 1\r
+ // Square character\r
{\r
b2BodyDef bd;\r
- bd.position.Set(-3.0f, 8.0f);\r
+ bd.position.Set(-3.0f, 5.0f);\r
bd.type = b2_dynamicBody;\r
bd.fixedRotation = true;\r
bd.allowSleep = false;\r
body->CreateFixture(&fd);\r
}\r
\r
- // Square character 2\r
- {\r
- b2BodyDef bd;\r
- bd.position.Set(-5.0f, 5.0f);\r
- bd.type = b2_dynamicBody;\r
- bd.fixedRotation = true;\r
- bd.allowSleep = false;\r
-\r
- b2Body* body = m_world->CreateBody(&bd);\r
-\r
- b2PolygonShape shape;\r
- shape.SetAsBox(0.25f, 0.25f);\r
-\r
- b2FixtureDef fd;\r
- fd.shape = &shape;\r
- fd.density = 20.0f;\r
- body->CreateFixture(&fd);\r
- }\r
-\r
// Hexagon character\r
{\r
b2BodyDef bd;\r
- bd.position.Set(-5.0f, 8.0f);\r
+ bd.position.Set(-5.0f, 5.0f);\r
bd.type = b2_dynamicBody;\r
bd.fixedRotation = true;\r
bd.allowSleep = false;\r
void Step(Settings* settings)\r
{\r
Test::Step(settings);\r
- m_debugDraw.DrawString(5, m_textLine, "This tests various character collision shapes.");\r
- m_textLine += 15;\r
- m_debugDraw.DrawString(5, m_textLine, "Limitation: square and hexagon can snag on aligned boxes.");\r
- m_textLine += 15;\r
- m_debugDraw.DrawString(5, m_textLine, "Feature: loops have smooth collision inside and out.");\r
+ m_debugDraw.DrawString(5, m_textLine, "This tests various character collision shapes");\r
m_textLine += 15;\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
{\r
// Ground body\r
{\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
\r
b2FixtureDef sd;\r
sd.shape = &shape;\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
{\r
// Ground body\r
{\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-50.0f, 0.0f), b2Vec2(50.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-50.0f, 0.0f), b2Vec2(50.0f, 0.0f));\r
\r
b2FixtureDef sd;\r
sd.shape = &shape;;\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
bd.position.Set(0.0f, 0.0f);\r
b2Body* body = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(50.0f, 0.0f), b2Vec2(-50.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(50.0f, 0.0f), b2Vec2(-50.0f, 0.0f));\r
\r
body->CreateFixture(&shape, 0.0f);\r
}\r
/*\r
-* Copyright (c) 2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
+ b2PolygonShape shape;\r
\r
// Floor\r
- shape.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f));\r
+ shape.SetAsEdge(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
\r
// Left wall\r
- shape.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(-10.0f, 20.0f));\r
+ shape.SetAsEdge(b2Vec2(-10.0f, 0.0f), b2Vec2(-10.0f, 20.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
\r
// Right wall\r
- shape.Set(b2Vec2(10.0f, 0.0f), b2Vec2(10.0f, 20.0f));\r
+ shape.SetAsEdge(b2Vec2(10.0f, 0.0f), b2Vec2(10.0f, 20.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
\r
// Roof\r
- shape.Set(b2Vec2(-10.0f, 20.0f), b2Vec2(10.0f, 20.0f));\r
+ shape.SetAsEdge(b2Vec2(-10.0f, 20.0f), b2Vec2(10.0f, 20.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
bd.position.Set(0.0f, 0.0f);\r
b2Body* body = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape edge;\r
+ b2PolygonShape shape;\r
\r
- edge.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f));\r
- body->CreateFixture(&edge, 0.0f);\r
+ shape.SetAsEdge(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f));\r
+ body->CreateFixture(&shape, 0.0f);\r
\r
- b2PolygonShape shape;\r
shape.SetAsBox(0.2f, 1.0f, b2Vec2(0.5f, 1.0f), 0.0f);\r
body->CreateFixture(&shape, 0.0f);\r
}\r
m_body->CreateFixture(&shape, 1.0f);\r
\r
m_angularVelocity = RandomFloat(-50.0f, 50.0f);\r
- //m_angularVelocity = 46.661274f;\r
+ m_angularVelocity = 33.468121f;\r
m_body->SetLinearVelocity(b2Vec2(0.0f, -100.0f));\r
m_body->SetAngularVelocity(m_angularVelocity);\r
}\r
{\r
b2BodyDef bd;\r
bd.type = b2_dynamicBody;\r
- bd.position.Set(0.0f, 2.0f);\r
+ bd.position.Set(0.0f, 0.5f);\r
b2Body* body = m_world->CreateBody(&bd);\r
\r
b2CircleShape shape;\r
shape.m_radius = 0.5f;\r
body->CreateFixture(&shape, 1.0f);\r
\r
- bd.bullet = true;\r
+ //bd.bullet = true;\r
bd.position.Set(0.0f, 10.0f);\r
body = m_world->CreateBody(&bd);\r
body->CreateFixture(&shape, 1.0f);\r
\r
extern int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters;\r
extern int32 b2_toiRootIters, b2_toiMaxRootIters;\r
+ extern int32 b2_toiMaxOptIters;\r
\r
if (b2_toiCalls > 0)\r
{\r
m_debugDraw.DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d",\r
b2_toiRootIters / float32(b2_toiCalls), b2_toiMaxRootIters);\r
m_textLine += 15;\r
+\r
+ m_debugDraw.DrawString(5, m_textLine, "max toi opt iters = %d", b2_toiMaxOptIters);\r
+ m_textLine += 15;\r
}\r
\r
if (m_stepCount % 60 == 0)\r
{\r
- //Launch();\r
+ Launch();\r
}\r
}\r
\r
/*
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
Test::Step(settings);
b2DistanceInput input;
- input.proxyA.Set(&m_polygonA, 0);
- input.proxyB.Set(&m_polygonB, 0);
+ input.proxyA.Set(&m_polygonA);
+ input.proxyB.Set(&m_polygonB);
input.transformA = m_transformA;
input.transformB = m_transformB;
input.useRadii = true;
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
{\r
b2Body* b1;\r
{\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
\r
b2BodyDef bd;\r
b1 = m_world->CreateBody(&bd);\r
/*\r
-* Copyright (c) 2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
enum\r
{\r
- e_actorCount = 128\r
+ e_actorCount = 128,\r
};\r
\r
DynamicTreeTest()\r
m_debugDraw.DrawPoint(p, 6.0f, cr);\r
}\r
\r
- {\r
- int32 height = m_tree.GetHeight();\r
- m_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d", height);\r
- m_textLine += 15;\r
- }\r
-\r
++m_stepCount;\r
}\r
\r
/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2010 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
enum\r
{\r
- e_maxBodies = 256\r
+ e_maxBodies = 256,\r
};\r
\r
EdgeShapes()\r
float32 x2 = x1 + 0.5f;\r
float32 y2 = 2.0f * cosf(x2 / 10.0f * b2_pi);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(x1, y1), b2Vec2(x2, y2));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(x1, y1), b2Vec2(x2, y2));\r
ground->CreateFixture(&shape, 0.0f);\r
\r
x1 = x2;\r
\r
{\r
float32 w = 1.0f;\r
- float32 b = w / (2.0f + b2Sqrt(2.0f));\r
- float32 s = b2Sqrt(2.0f) * b;\r
+ float32 b = w / (2.0f + sqrtf(2.0f));\r
+ float32 s = sqrtf(2.0f) * b;\r
\r
b2Vec2 vertices[8];\r
vertices[0].Set(0.5f * s, 0.0f);\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef EDGE_TEST_H\r
-#define EDGE_TEST_H\r
-\r
-class EdgeTest : public Test\r
-{\r
-public:\r
-\r
- EdgeTest()\r
- {\r
- {\r
- b2BodyDef bd;\r
- b2Body* ground = m_world->CreateBody(&bd);\r
-\r
- b2Vec2 v1(-10.0f, 0.0f), v2(-7.0f, -2.0f), v3(-4.0f, 0.0f);\r
- b2Vec2 v4(0.0f, 0.0f), v5(4.0f, 0.0f), v6(7.0f, 2.0f), v7(10.0f, 0.0f);\r
-\r
- b2EdgeShape shape;\r
-\r
- shape.Set(v1, v2);\r
- shape.m_hasVertex3 = true;\r
- shape.m_vertex3 = v3;\r
- ground->CreateFixture(&shape, 0.0f);\r
-\r
- shape.Set(v2, v3);\r
- shape.m_hasVertex0 = true;\r
- shape.m_hasVertex3 = true;\r
- shape.m_vertex0 = v1;\r
- shape.m_vertex3 = v4;\r
- ground->CreateFixture(&shape, 0.0f);\r
-\r
- shape.Set(v3, v4);\r
- shape.m_hasVertex0 = true;\r
- shape.m_hasVertex3 = true;\r
- shape.m_vertex0 = v2;\r
- shape.m_vertex3 = v5;\r
- ground->CreateFixture(&shape, 0.0f);\r
-\r
- shape.Set(v4, v5);\r
- shape.m_hasVertex0 = true;\r
- shape.m_hasVertex3 = true;\r
- shape.m_vertex0 = v3;\r
- shape.m_vertex3 = v6;\r
- ground->CreateFixture(&shape, 0.0f);\r
-\r
- shape.Set(v5, v6);\r
- shape.m_hasVertex0 = true;\r
- shape.m_hasVertex3 = true;\r
- shape.m_vertex0 = v4;\r
- shape.m_vertex3 = v7;\r
- ground->CreateFixture(&shape, 0.0f);\r
-\r
- shape.Set(v6, v7);\r
- shape.m_hasVertex0 = true;\r
- shape.m_vertex0 = v5;\r
- ground->CreateFixture(&shape, 0.0f);\r
- }\r
-\r
- {\r
- b2BodyDef bd;\r
- bd.type = b2_dynamicBody;\r
- bd.position.Set(-0.5f, 0.6f);\r
- bd.allowSleep = false;\r
- b2Body* body = m_world->CreateBody(&bd);\r
-\r
- b2CircleShape shape;\r
- shape.m_radius = 0.5f;\r
-\r
- body->CreateFixture(&shape, 1.0f);\r
- }\r
-\r
- {\r
- b2BodyDef bd;\r
- bd.type = b2_dynamicBody;\r
- bd.position.Set(1.0f, 0.6f);\r
- bd.allowSleep = false;\r
- b2Body* body = m_world->CreateBody(&bd);\r
-\r
- b2PolygonShape shape;\r
- shape.SetAsBox(0.5f, 0.5f);\r
-\r
- body->CreateFixture(&shape, 1.0f);\r
- }\r
- }\r
-\r
- static Test* Create()\r
- {\r
- return new EdgeTest;\r
- }\r
-};\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2007-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(50.0f, 0.0f), b2Vec2(-50.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(50.0f, 0.0f), b2Vec2(-50.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2008-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2008-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
{\r
e_unknown,\r
e_above,\r
- e_below\r
+ e_below,\r
};\r
\r
OneSidedPlatform()\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
return;\r
}\r
\r
- if (fixtureB != m_platform && fixtureB != m_character)\r
+ if (fixtureB != m_character && fixtureB != m_character)\r
{\r
return;\r
}\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef PINBALL_H\r
-#define PINBALL_H\r
-\r
-/// This tests bullet collision and provides an example of a gameplay scenario.\r
-/// This also uses a loop shape.\r
-class Pinball : public Test\r
-{\r
-public:\r
- Pinball()\r
- {\r
- // Ground body\r
- b2Body* ground = NULL;\r
- {\r
- b2BodyDef bd;\r
- ground = m_world->CreateBody(&bd);\r
-\r
- b2Vec2 vs[5];\r
- vs[0].Set(0.0f, -2.0f);\r
- vs[1].Set(8.0f, 6.0f);\r
- vs[2].Set(8.0f, 20.0f);\r
- vs[3].Set(-8.0f, 20.0f);\r
- vs[4].Set(-8.0f, 6.0f);\r
-\r
- b2LoopShape loop;\r
- loop.Create(vs, 5);\r
- b2FixtureDef fd;\r
- fd.shape = &loop;\r
- fd.density = 0.0f;\r
- ground->CreateFixture(&fd);\r
- }\r
-\r
- // Flippers\r
- {\r
- b2Vec2 p1(-2.0f, 0.0f), p2(2.0f, 0.0f);\r
-\r
- b2BodyDef bd;\r
- bd.type = b2_dynamicBody;\r
-\r
- bd.position = p1;\r
- b2Body* leftFlipper = m_world->CreateBody(&bd);\r
-\r
- bd.position = p2;\r
- b2Body* rightFlipper = m_world->CreateBody(&bd);\r
-\r
- b2PolygonShape box;\r
- box.SetAsBox(1.75f, 0.1f);\r
-\r
- b2FixtureDef fd;\r
- fd.shape = &box;\r
- fd.density = 1.0f;\r
-\r
- leftFlipper->CreateFixture(&fd);\r
- rightFlipper->CreateFixture(&fd);\r
-\r
- b2RevoluteJointDef jd;\r
- jd.bodyA = ground;\r
- jd.localAnchorB.SetZero();\r
- jd.enableMotor = true;\r
- jd.maxMotorTorque = 1000.0f;\r
- jd.enableLimit = true;\r
-\r
- jd.motorSpeed = 0.0f;\r
- jd.localAnchorA = p1;\r
- jd.bodyB = leftFlipper;\r
- jd.lowerAngle = -30.0f * b2_pi / 180.0f;\r
- jd.upperAngle = 5.0f * b2_pi / 180.0f;\r
- m_leftJoint = (b2RevoluteJoint*)m_world->CreateJoint(&jd);\r
-\r
- jd.motorSpeed = 0.0f;\r
- jd.localAnchorA = p2;\r
- jd.bodyB = rightFlipper;\r
- jd.lowerAngle = -5.0f * b2_pi / 180.0f;\r
- jd.upperAngle = 30.0f * b2_pi / 180.0f;\r
- m_rightJoint = (b2RevoluteJoint*)m_world->CreateJoint(&jd);\r
- }\r
-\r
- // Circle character\r
- {\r
- b2BodyDef bd;\r
- bd.position.Set(1.0f, 15.0f);\r
- bd.type = b2_dynamicBody;\r
- bd.bullet = true;\r
-\r
- m_ball = m_world->CreateBody(&bd);\r
-\r
- b2CircleShape shape;\r
- shape.m_radius = 0.2f;\r
-\r
- b2FixtureDef fd;\r
- fd.shape = &shape;\r
- fd.density = 1.0f;\r
- m_ball->CreateFixture(&fd);\r
- }\r
-\r
- m_button = false;\r
- }\r
-\r
- void Step(Settings* settings)\r
- {\r
- if (m_button)\r
- {\r
- m_leftJoint->SetMotorSpeed(20.0f);\r
- m_rightJoint->SetMotorSpeed(-20.0f);\r
- }\r
- else\r
- {\r
- m_leftJoint->SetMotorSpeed(-10.0f);\r
- m_rightJoint->SetMotorSpeed(10.0f);\r
- }\r
-\r
- Test::Step(settings);\r
-\r
- m_debugDraw.DrawString(5, m_textLine, "Press 'a' to control the flippers");\r
- m_textLine += 15;\r
-\r
- }\r
-\r
- void Keyboard(unsigned char key)\r
- {\r
- switch (key)\r
- {\r
- case 'a':\r
- case 'A':\r
- m_button = true;\r
- break;\r
- }\r
- }\r
-\r
- void KeyboardUp(unsigned char key)\r
- {\r
- switch (key)\r
- {\r
- case 'a':\r
- case 'A':\r
- m_button = false;\r
- break;\r
- }\r
- }\r
-\r
- static Test* Create()\r
- {\r
- return new Pinball;\r
- }\r
-\r
- b2RevoluteJoint* m_leftJoint;\r
- b2RevoluteJoint* m_rightJoint;\r
- b2Body* m_ball;\r
- bool m_button;\r
-};\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
PolyCollision()\r
{\r
{\r
- m_polygonA.SetAsBox(0.2f, 0.4f);\r
+ m_polygonA.SetAsEdge(b2Vec2(20.0f, 0.0f), b2Vec2(20.0f, 20.0f));\r
m_transformA.Set(b2Vec2(0.0f, 0.0f), 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2Body* body = fixture->GetBody();\r
b2Shape* shape = fixture->GetShape();\r
\r
- bool overlap = b2TestOverlap(shape, 0, &m_circle, 0, body->GetTransform(), m_transform);\r
+ bool overlap = b2TestOverlap(shape, &m_circle, body->GetTransform(), m_transform);\r
\r
if (overlap)\r
{\r
\r
b2CircleShape m_circle;\r
b2Transform m_transform;\r
- b2Draw* m_debugDraw;\r
+ b2DebugDraw* m_debugDraw;\r
int32 m_count;\r
};\r
\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
\r
{\r
float32 w = 1.0f;\r
- float32 b = w / (2.0f + b2Sqrt(2.0f));\r
- float32 s = b2Sqrt(2.0f) * b;\r
+ float32 b = w / (2.0f + sqrtf(2.0f));\r
+ float32 s = sqrtf(2.0f) * b;\r
\r
b2Vec2 vertices[8];\r
vertices[0].Set(0.5f * s, 0.0f);\r
callback.m_debugDraw = &m_debugDraw;\r
\r
b2AABB aabb;\r
- callback.m_circle.ComputeAABB(&aabb, callback.m_transform, 0);\r
+ callback.m_circle.ComputeAABB(&aabb, callback.m_transform);\r
\r
m_world->QueryAABB(&callback, aabb);\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
Test::Step(settings);\r
m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (m) motors, (s) speed");\r
m_textLine += 15;\r
- float32 force = m_joint->GetMotorForce(settings->hz);\r
+ float32 force = m_joint->GetMotorForce();\r
m_debugDraw.DrawString(5, m_textLine, "Motor Force = %4.0f", (float) force);\r
m_textLine += 15;\r
}\r
/*\r
-* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2007-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
public:\r
Pulleys()\r
{\r
- float32 y = 16.0f;\r
- float32 L = 12.0f;\r
- float32 a = 1.0f;\r
- float32 b = 2.0f;\r
-\r
b2Body* ground = NULL;\r
{\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape edge;\r
- edge.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
- //ground->CreateFixture(&shape, 0.0f);\r
-\r
- b2CircleShape circle;\r
- circle.m_radius = 2.0f;\r
-\r
- circle.m_p.Set(-10.0f, y + b + L);\r
- ground->CreateFixture(&circle, 0.0f);\r
-\r
- circle.m_p.Set(10.0f, y + b + L);\r
- ground->CreateFixture(&circle, 0.0f);\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
{\r
+ float32 a = 2.0f;\r
+ float32 b = 4.0f;\r
+ float32 y = 16.0f;\r
+ float32 L = 12.0f;\r
\r
b2PolygonShape shape;\r
shape.SetAsBox(a, b);\r
b2BodyDef bd;\r
bd.type = b2_dynamicBody;\r
\r
- //bd.fixedRotation = true;\r
bd.position.Set(-10.0f, y);\r
b2Body* body1 = m_world->CreateBody(&bd);\r
body1->CreateFixture(&shape, 5.0f);\r
b2Vec2 anchor2(10.0f, y + b);\r
b2Vec2 groundAnchor1(-10.0f, y + b + L);\r
b2Vec2 groundAnchor2(10.0f, y + b + L);\r
- pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 1.5f);\r
+ pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 2.0f);\r
\r
m_joint1 = (b2PulleyJoint*)m_world->CreateJoint(&pulleyDef);\r
}\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
public:\r
enum\r
{\r
- e_count = 20\r
+ e_count = 20,\r
};\r
\r
Pyramid()\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
}\r
}\r
\r
- void Step(Settings* settings)\r
- {\r
- Test::Step(settings);\r
-\r
- //b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree;\r
-\r
- //if (m_stepCount == 400)\r
- //{\r
- // tree->RebuildBottomUp();\r
- //}\r
- }\r
+ //void Step(Settings* settings)\r
+ //{\r
+ // // We need higher accuracy for the pyramid.\r
+ // int32 velocityIterations = settings->velocityIterations;\r
+ // int32 positionIterations = settings->positionIterations;\r
+ // settings->velocityIterations = b2Max(8, velocityIterations);\r
+ // settings->positionIterations = b2Max(1, positionIterations);\r
+ // Test::Step(settings);\r
+ // settings->velocityIterations = velocityIterations;\r
+ // settings->positionIterations = positionIterations;\r
+ //}\r
\r
static Test* Create()\r
{\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
\r
enum\r
{\r
- e_maxBodies = 256\r
+ e_maxBodies = 256,\r
};\r
\r
enum Mode\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
\r
{\r
float32 w = 1.0f;\r
- float32 b = w / (2.0f + b2Sqrt(2.0f));\r
- float32 s = b2Sqrt(2.0f) * b;\r
+ float32 b = w / (2.0f + sqrtf(2.0f));\r
+ float32 s = sqrtf(2.0f) * b;\r
\r
b2Vec2 vertices[8];\r
vertices[0].Set(0.5f * s, 0.0f);\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
-\r
- b2FixtureDef fd;\r
- fd.shape = &shape;\r
- //fd.filter.categoryBits = 2;\r
-\r
- ground->CreateFixture(&fd);\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
{\r
\r
b2RevoluteJointDef rjd;\r
\r
- bd.position.Set(-10.0f, 20.0f);\r
+ bd.position.Set(0.0f, 20.0f);\r
b2Body* body = m_world->CreateBody(&bd);\r
body->CreateFixture(&shape, 5.0f);\r
\r
body->SetAngularVelocity(w);\r
body->SetLinearVelocity(b2Vec2(-8.0f * w, 0.0f));\r
\r
- rjd.Initialize(ground, body, b2Vec2(-10.0f, 12.0f));\r
+ rjd.Initialize(ground, body, b2Vec2(0.0f, 12.0f));\r
rjd.motorSpeed = 1.0f * b2_pi;\r
rjd.maxMotorTorque = 10000.0f;\r
rjd.enableMotor = false;\r
\r
m_joint = (b2RevoluteJoint*)m_world->CreateJoint(&rjd);\r
}\r
-\r
- {\r
- b2CircleShape circle_shape;\r
- circle_shape.m_radius = 3.0f;\r
-\r
- b2BodyDef circle_bd;\r
- circle_bd.type = b2_dynamicBody;\r
- circle_bd.position.Set(5.0f, 30.0f);\r
-\r
- b2FixtureDef fd;\r
- fd.density = 5.0f;\r
- fd.filter.maskBits = 1;\r
- fd.shape = &circle_shape;\r
-\r
- m_ball = m_world->CreateBody(&circle_bd);\r
- m_ball->CreateFixture(&fd);\r
-\r
- b2PolygonShape polygon_shape;\r
- polygon_shape.SetAsBox(10.0f, 0.2f, b2Vec2 (-10.0f, 0.0f), 0.0f);\r
-\r
- b2BodyDef polygon_bd;\r
- polygon_bd.position.Set(20.0f, 10.0f);\r
- polygon_bd.type = b2_dynamicBody;\r
- polygon_bd.bullet = true;\r
- b2Body* polygon_body = m_world->CreateBody(&polygon_bd);\r
- polygon_body->CreateFixture(&polygon_shape, 2.0f);\r
-\r
- b2RevoluteJointDef rjd;\r
- rjd.Initialize(ground, polygon_body, b2Vec2(20.0f, 10.0f));\r
- rjd.lowerAngle = -0.25f * b2_pi;\r
- rjd.upperAngle = 0.0f * b2_pi;\r
- rjd.enableLimit = true;\r
- m_world->CreateJoint(&rjd);\r
- }\r
-\r
- // Tests mass computation of a small object far from the origin\r
- {\r
- b2BodyDef bodyDef;\r
- bodyDef.type = b2_dynamicBody;\r
- b2Body* body = m_world->CreateBody(&bodyDef);\r
- \r
- b2PolygonShape polyShape; \r
- b2Vec2 verts[3];\r
- verts[0].Set( 17.63f, 36.31f );\r
- verts[1].Set( 17.52f, 36.69f );\r
- verts[2].Set( 17.19f, 36.36f );\r
- polyShape.Set(verts, 3);\r
- \r
- b2FixtureDef polyFixtureDef;\r
- polyFixtureDef.shape = &polyShape;\r
- polyFixtureDef.density = 1;\r
-\r
- body->CreateFixture(&polyFixtureDef); //assertion hits inside here\r
- }\r
-\r
}\r
\r
void Keyboard(unsigned char key)\r
switch (key)\r
{\r
case 'l':\r
- m_joint->EnableLimit(!m_joint->IsLimitEnabled());\r
+ m_joint->EnableLimit(m_joint->IsLimitEnabled());\r
break;\r
\r
- case 'm':\r
- m_joint->EnableMotor(!m_joint->IsMotorEnabled());\r
+ case 's':\r
+ m_joint->EnableMotor(false);\r
break;\r
}\r
}\r
void Step(Settings* settings)\r
{\r
Test::Step(settings);\r
- m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (m) motor");\r
+ m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (a) left, (s) off, (d) right");\r
m_textLine += 15;\r
-\r
- //if (m_stepCount == 360)\r
- //{\r
- // m_ball->SetTransform(b2Vec2(0.0f, 0.5f), 0.0f);\r
- //}\r
-\r
//float32 torque1 = m_joint1->GetMotorTorque();\r
//m_debugDraw.DrawString(5, m_textLine, "Motor Torque = %4.0f, %4.0f : Motor Force = %4.0f", (float) torque1, (float) torque2, (float) force3);\r
//m_textLine += 15;\r
return new Revolute;\r
}\r
\r
- b2Body* m_ball;\r
b2RevoluteJoint* m_joint;\r
};\r
\r
+++ /dev/null
-/*\r
-* Copyright (c) 2011 Erin Catto http://box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef ROPE_H\r
-#define ROPE_H\r
-\r
-///\r
-class Rope : public Test\r
-{\r
-public:\r
- Rope()\r
- {\r
- const int32 N = 40;\r
- b2Vec2 vertices[N];\r
- float32 masses[N];\r
-\r
- for (int32 i = 0; i < N; ++i)\r
- {\r
- vertices[i].Set(0.0f, 20.0f - 0.25f * i);\r
- masses[i] = 1.0f;\r
- }\r
- masses[0] = 0.0f;\r
- masses[1] = 0.0f;\r
-\r
- b2RopeDef def;\r
- def.vertices = vertices;\r
- def.count = N;\r
- def.gravity.Set(0.0f, -10.0f);\r
- def.masses = masses;\r
- def.damping = 0.1f;\r
- def.k2 = 1.0f;\r
- def.k3 = 0.5f;\r
-\r
- m_rope.Initialize(&def);\r
-\r
- m_angle = 0.0f;\r
- m_rope.SetAngle(m_angle);\r
- }\r
-\r
- void Keyboard(unsigned char key)\r
- {\r
- switch (key)\r
- {\r
- case 'q':\r
- m_angle = b2Max(-b2_pi, m_angle - 0.05f * b2_pi);\r
- m_rope.SetAngle(m_angle);\r
- break;\r
-\r
- case 'e':\r
- m_angle = b2Min(b2_pi, m_angle + 0.05f * b2_pi);\r
- m_rope.SetAngle(m_angle);\r
- break;\r
- }\r
- }\r
-\r
- void Step(Settings* settings)\r
- {\r
- float32 dt = settings->hz > 0.0f ? 1.0f / settings->hz : 0.0f;\r
-\r
- if (settings->pause == 1 && settings->singleStep == 0)\r
- {\r
- dt = 0.0f;\r
- }\r
-\r
- m_rope.Step(dt, 1);\r
-\r
- Test::Step(settings);\r
-\r
- m_rope.Draw(&m_debugDraw);\r
-\r
- m_debugDraw.DrawString(5, m_textLine, "Press (q,e) to adjust target angle");\r
- m_textLine += 15;\r
- m_debugDraw.DrawString(5, m_textLine, "Target angle = %g degrees", m_angle * 180.0f / b2_pi);\r
- m_textLine += 15;\r
- }\r
-\r
- static Test* Create()\r
- {\r
- return new Rope;\r
- }\r
-\r
- b2Rope m_rope;\r
- float32 m_angle;\r
-};\r
-\r
-#endif\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef ROPE_JOINT_H\r
-#define ROPE_JOINT_H\r
-\r
-/// This test shows how a rope joint can be used to stabilize a chain of\r
-/// bodies with a heavy payload. Notice that the rope joint just prevents\r
-/// excessive stretching and has no other effect.\r
-/// By disabling the rope joint you can see that the Box2D solver has trouble\r
-/// supporting heavy bodies with light bodies. Try playing around with the\r
-/// densities, time step, and iterations to see how they affect stability.\r
-/// This test also shows how to use contact filtering. Filtering is configured\r
-/// so that the payload does not collide with the chain.\r
-class RopeJoint : public Test\r
-{\r
-public:\r
- RopeJoint()\r
- {\r
- b2Body* ground = NULL;\r
- {\r
- b2BodyDef bd;\r
- ground = m_world->CreateBody(&bd);\r
-\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
- ground->CreateFixture(&shape, 0.0f);\r
- }\r
-\r
- {\r
- b2PolygonShape shape;\r
- shape.SetAsBox(0.5f, 0.125f);\r
-\r
- b2FixtureDef fd;\r
- fd.shape = &shape;\r
- fd.density = 20.0f;\r
- fd.friction = 0.2f;\r
- fd.filter.categoryBits = 0x0001;\r
- fd.filter.maskBits = 0xFFFF & ~0x0002;\r
-\r
- b2RevoluteJointDef jd;\r
- jd.collideConnected = false;\r
-\r
- const int32 N = 10;\r
- const float32 y = 15.0f;\r
- m_ropeDef.localAnchorA.Set(0.0f, y);\r
-\r
- b2Body* prevBody = ground;\r
- for (int32 i = 0; i < N; ++i)\r
- {\r
- b2BodyDef bd;\r
- bd.type = b2_dynamicBody;\r
- bd.position.Set(0.5f + 1.0f * i, y);\r
- if (i == N - 1)\r
- {\r
- shape.SetAsBox(1.5f, 1.5f);\r
- fd.density = 100.0f;\r
- fd.filter.categoryBits = 0x0002;\r
- bd.position.Set(1.0f * i, y);\r
- bd.angularDamping = 0.4f;\r
- }\r
-\r
- b2Body* body = m_world->CreateBody(&bd);\r
-\r
- body->CreateFixture(&fd);\r
-\r
- b2Vec2 anchor(float32(i), y);\r
- jd.Initialize(prevBody, body, anchor);\r
- m_world->CreateJoint(&jd);\r
-\r
- prevBody = body;\r
- }\r
-\r
- m_ropeDef.localAnchorB.SetZero();\r
-\r
- float32 extraLength = 0.01f;\r
- m_ropeDef.maxLength = N - 1.0f + extraLength;\r
- m_ropeDef.bodyB = prevBody;\r
- }\r
-\r
- {\r
- m_ropeDef.bodyA = ground;\r
- m_rope = m_world->CreateJoint(&m_ropeDef);\r
- }\r
- }\r
-\r
- void Keyboard(unsigned char key)\r
- {\r
- switch (key)\r
- {\r
- case 'j':\r
- if (m_rope)\r
- {\r
- m_world->DestroyJoint(m_rope);\r
- m_rope = NULL;\r
- }\r
- else\r
- {\r
- m_rope = m_world->CreateJoint(&m_ropeDef);\r
- }\r
- break;\r
- }\r
- }\r
-\r
- void Step(Settings* settings)\r
- {\r
- Test::Step(settings);\r
- m_debugDraw.DrawString(5, m_textLine, "Press (j) to toggle the rope joint.");\r
- m_textLine += 15;\r
- if (m_rope)\r
- {\r
- m_debugDraw.DrawString(5, m_textLine, "Rope ON");\r
- }\r
- else\r
- {\r
- m_debugDraw.DrawString(5, m_textLine, "Rope OFF");\r
- }\r
- m_textLine += 15;\r
- }\r
-\r
- static Test* Create()\r
- {\r
- return new RopeJoint;\r
- }\r
-\r
- b2RopeJointDef m_ropeDef;\r
- b2Joint* m_rope;\r
-};\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2008-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2008-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
{\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2008-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2008-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
\r
b2BodyDef bd;\r
bd.type = b2_dynamicBody;\r
- bd.fixedRotation = true;\r
bd.position.Set(0.0f, 17.0f);\r
b2Body* body = m_world->CreateBody(&bd);\r
body->CreateFixture(&shape, 2.0f);\r
Test::Step(settings);\r
m_debugDraw.DrawString(5, m_textLine, "Keys: (f) toggle friction, (m) toggle motor");\r
m_textLine += 15;\r
- float32 torque = m_joint1->GetMotorTorque(settings->hz);\r
+ float32 torque = m_joint1->GetMotorTorque();\r
m_debugDraw.DrawString(5, m_textLine, "Motor Torque = %5.0f", (float) torque);\r
m_textLine += 15;\r
}\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
\r
m_bodies[i]->CreateFixture(&shape, 1.0f);\r
\r
- m_bodies[i]->SetLinearVelocity(b2Vec2(0.0f, -50.0f));\r
+ //m_bodies[i]->SetLinearVelocity(b2Vec2(0.0f, -100.0f));\r
}\r
}\r
}\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-50.0f, 0.0f), b2Vec2(50.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-50.0f, 0.0f), b2Vec2(50.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
\r
- shape.Set(b2Vec2(-50.0f, 0.0f), b2Vec2(-50.0f, 10.0f));\r
+ shape.SetAsEdge(b2Vec2(-50.0f, 0.0f), b2Vec2(-50.0f, 10.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
\r
- shape.Set(b2Vec2(50.0f, 0.0f), b2Vec2(50.0f, 10.0f));\r
+ shape.SetAsEdge(b2Vec2(50.0f, 0.0f), b2Vec2(50.0f, 10.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
+++ /dev/null
-/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
-*\r
-* This software is provided 'as-is', without any express or implied\r
-* warranty. In no event will the authors be held liable for any damages\r
-* arising from the use of this software.\r
-* Permission is granted to anyone to use this software for any purpose,\r
-* including commercial applications, and to alter it and redistribute it\r
-* freely, subject to the following restrictions:\r
-* 1. The origin of this software must not be misrepresented; you must not\r
-* claim that you wrote the original software. If you use this software\r
-* in a product, an acknowledgment in the product documentation would be\r
-* appreciated but is not required.\r
-* 2. Altered source versions must be plainly marked as such, and must not be\r
-* misrepresented as being the original software.\r
-* 3. This notice may not be removed or altered from any source distribution.\r
-*/\r
-\r
-#ifndef TILES_H\r
-#define TILES_H\r
-\r
-/// This stress tests the dynamic tree broad-phase. This also shows that tile\r
-/// based collision is _not_ smooth due to Box2D not knowing about adjacency.\r
-class Tiles : public Test\r
-{\r
-public:\r
- enum\r
- {\r
- e_count = 20\r
- };\r
-\r
- Tiles()\r
- {\r
- m_fixtureCount = 0;\r
- b2Timer timer;\r
-\r
- {\r
- float32 a = 0.5f;\r
- b2BodyDef bd;\r
- bd.position.y = -a;\r
- b2Body* ground = m_world->CreateBody(&bd);\r
-\r
-#if 1\r
- int32 N = 200;\r
- int32 M = 10;\r
- b2Vec2 position;\r
- position.y = 0.0f;\r
- for (int32 j = 0; j < M; ++j)\r
- {\r
- position.x = -N * a;\r
- for (int32 i = 0; i < N; ++i)\r
- {\r
- b2PolygonShape shape;\r
- shape.SetAsBox(a, a, position, 0.0f);\r
- ground->CreateFixture(&shape, 0.0f);\r
- ++m_fixtureCount;\r
- position.x += 2.0f * a;\r
- }\r
- position.y -= 2.0f * a;\r
- }\r
-#else\r
- int32 N = 200;\r
- int32 M = 10;\r
- b2Vec2 position;\r
- position.x = -N * a;\r
- for (int32 i = 0; i < N; ++i)\r
- {\r
- position.y = 0.0f;\r
- for (int32 j = 0; j < M; ++j)\r
- {\r
- b2PolygonShape shape;\r
- shape.SetAsBox(a, a, position, 0.0f);\r
- ground->CreateFixture(&shape, 0.0f);\r
- position.y -= 2.0f * a;\r
- }\r
- position.x += 2.0f * a;\r
- }\r
-#endif\r
- }\r
-\r
- {\r
- float32 a = 0.5f;\r
- b2PolygonShape shape;\r
- shape.SetAsBox(a, a);\r
-\r
- b2Vec2 x(-7.0f, 0.75f);\r
- b2Vec2 y;\r
- b2Vec2 deltaX(0.5625f, 1.25f);\r
- b2Vec2 deltaY(1.125f, 0.0f);\r
-\r
- for (int32 i = 0; i < e_count; ++i)\r
- {\r
- y = x;\r
-\r
- for (int32 j = i; j < e_count; ++j)\r
- {\r
- b2BodyDef bd;\r
- bd.type = b2_dynamicBody;\r
- bd.position = y;\r
- b2Body* body = m_world->CreateBody(&bd);\r
- body->CreateFixture(&shape, 5.0f);\r
- ++m_fixtureCount;\r
- y += deltaY;\r
- }\r
-\r
- x += deltaX;\r
- }\r
- }\r
-\r
- m_createTime = timer.GetMilliseconds();\r
- }\r
-\r
- void Step(Settings* settings)\r
- {\r
- const b2ContactManager& cm = m_world->GetContactManager();\r
- int32 height = cm.m_broadPhase.GetTreeHeight();\r
- int32 leafCount = cm.m_broadPhase.GetProxyCount();\r
- int32 minimumNodeCount = 2 * leafCount - 1;\r
- float32 minimumHeight = ceilf(logf(float32(minimumNodeCount)) / logf(2.0f));\r
- m_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d, min = %d", height, int32(minimumHeight));\r
- m_textLine += 15;\r
-\r
- Test::Step(settings);\r
-\r
- m_debugDraw.DrawString(5, m_textLine, "create time = %6.2f ms, fixture count = %d",\r
- m_createTime, m_fixtureCount);\r
- m_textLine += 15;\r
-\r
- //b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree;\r
-\r
- //if (m_stepCount == 400)\r
- //{\r
- // tree->RebuildBottomUp();\r
- //}\r
- }\r
-\r
- static Test* Create()\r
- {\r
- return new Tiles;\r
- }\r
-\r
- int32 m_fixtureCount;\r
- float32 m_createTime;\r
-};\r
-\r
-#endif\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
//sweepB.a -= 300.0f * b2_pi;\r
\r
b2TOIInput input;\r
- input.proxyA.Set(&m_shapeA, 0);\r
- input.proxyB.Set(&m_shapeB, 0);\r
+ input.proxyA.Set(&m_shapeA);\r
+ input.proxyB.Set(&m_shapeB);\r
input.sweepA = sweepA;\r
input.sweepB = sweepB;\r
input.tMax = 1.0f;\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
#ifndef VARYING_RESTITUTION_H\r
#define VARYING_RESTITUTION_H\r
\r
-// Note: even with a restitution of 1.0, there is some energy change\r
-// due to position correction.\r
class VaryingRestitution : public Test\r
{\r
public:\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
b2Body* ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
\r
- shape.Set(b2Vec2(20.0f, 0.0f), b2Vec2(20.0f, 20.0f));\r
+ shape.SetAsEdge(b2Vec2(20.0f, 0.0f), b2Vec2(20.0f, 20.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
/*\r
-* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org\r
+* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com\r
*\r
* This software is provided 'as-is', without any express or implied\r
* warranty. In no event will the authors be held liable for any damages\r
b2BodyDef bd;\r
ground = m_world->CreateBody(&bd);\r
\r
- b2EdgeShape shape;\r
- shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
+ b2PolygonShape shape;\r
+ shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));\r
ground->CreateFixture(&shape, 0.0f);\r
}\r
\r
b2DistanceJointDef jd;\r
b2Vec2 p1, p2, d;\r
\r
- jd.frequencyHz = 2.0f;\r
- jd.dampingRatio = 0.0f;\r
+ jd.frequencyHz = 4.0f;\r
+ jd.dampingRatio = 0.5f;\r
\r
jd.bodyA = ground;\r
jd.bodyB = m_bodies[0];\r