From: dsc Date: Thu, 5 May 2011 06:46:43 +0000 (-0700) Subject: Rolls back update to Box2D SVN trunk. X-Git-Tag: box2d-testbed~8 X-Git-Url: http://git.lttlst.com:3516/?a=commitdiff_plain;h=7195dae657073b0f12205fb40b292b319a28593b;p=tanks-ios.git Rolls back update to Box2D SVN trunk. --- diff --git a/libs/box2d/box2d-ios.xcodeproj/project.pbxproj b/libs/box2d/box2d-ios.xcodeproj/project.pbxproj index edca52a..7a456a4 100644 --- a/libs/box2d/box2d-ios.xcodeproj/project.pbxproj +++ b/libs/box2d/box2d-ios.xcodeproj/project.pbxproj @@ -7,156 +7,156 @@ 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 = ""; }; - 4913307D1372616300DFB46D /* b2BroadPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2BroadPhase.cpp; sourceTree = ""; }; - 4913307E1372616300DFB46D /* b2BroadPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2BroadPhase.h; sourceTree = ""; }; - 4913307F1372616300DFB46D /* b2CollideCircle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CollideCircle.cpp; sourceTree = ""; }; - 491330801372616300DFB46D /* b2CollidePolygon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CollidePolygon.cpp; sourceTree = ""; }; - 491330811372616300DFB46D /* b2Collision.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Collision.cpp; sourceTree = ""; }; - 491330821372616300DFB46D /* b2Collision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Collision.h; sourceTree = ""; }; - 491330831372616300DFB46D /* b2Distance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Distance.cpp; sourceTree = ""; }; - 491330841372616300DFB46D /* b2Distance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Distance.h; sourceTree = ""; }; - 491330851372616300DFB46D /* b2DynamicTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2DynamicTree.cpp; sourceTree = ""; }; - 491330861372616300DFB46D /* b2DynamicTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2DynamicTree.h; sourceTree = ""; }; - 491330871372616300DFB46D /* b2TimeOfImpact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2TimeOfImpact.cpp; sourceTree = ""; }; - 491330881372616300DFB46D /* b2TimeOfImpact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TimeOfImpact.h; sourceTree = ""; }; - 4913308A1372616300DFB46D /* b2CircleShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CircleShape.cpp; sourceTree = ""; }; - 4913308B1372616300DFB46D /* b2CircleShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2CircleShape.h; sourceTree = ""; }; - 4913308C1372616300DFB46D /* b2PolygonShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonShape.cpp; sourceTree = ""; }; - 4913308D1372616300DFB46D /* b2PolygonShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonShape.h; sourceTree = ""; }; - 4913308E1372616300DFB46D /* b2Shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Shape.h; sourceTree = ""; }; - 491330901372616300DFB46D /* b2BlockAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2BlockAllocator.cpp; sourceTree = ""; }; - 491330911372616300DFB46D /* b2BlockAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2BlockAllocator.h; sourceTree = ""; }; - 491330921372616300DFB46D /* b2Math.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Math.cpp; sourceTree = ""; }; - 491330931372616300DFB46D /* b2Math.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Math.h; sourceTree = ""; }; - 491330941372616300DFB46D /* b2Settings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Settings.cpp; sourceTree = ""; }; - 491330951372616300DFB46D /* b2Settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Settings.h; sourceTree = ""; }; - 491330961372616300DFB46D /* b2StackAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2StackAllocator.cpp; sourceTree = ""; }; - 491330971372616300DFB46D /* b2StackAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2StackAllocator.h; sourceTree = ""; }; - 491330991372616300DFB46D /* b2Body.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Body.cpp; sourceTree = ""; }; - 4913309A1372616300DFB46D /* b2Body.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Body.h; sourceTree = ""; }; - 4913309B1372616300DFB46D /* b2ContactManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2ContactManager.cpp; sourceTree = ""; }; - 4913309C1372616300DFB46D /* b2ContactManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2ContactManager.h; sourceTree = ""; }; - 4913309D1372616300DFB46D /* b2Fixture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Fixture.cpp; sourceTree = ""; }; - 4913309E1372616300DFB46D /* b2Fixture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Fixture.h; sourceTree = ""; }; - 4913309F1372616300DFB46D /* b2Island.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Island.cpp; sourceTree = ""; }; - 491330A01372616300DFB46D /* b2Island.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Island.h; sourceTree = ""; }; - 491330A11372616300DFB46D /* b2TimeStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TimeStep.h; sourceTree = ""; }; - 491330A21372616300DFB46D /* b2World.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2World.cpp; sourceTree = ""; }; - 491330A31372616300DFB46D /* b2World.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2World.h; sourceTree = ""; }; - 491330A41372616300DFB46D /* b2WorldCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2WorldCallbacks.cpp; sourceTree = ""; }; - 491330A51372616300DFB46D /* b2WorldCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2WorldCallbacks.h; sourceTree = ""; }; - 491330A71372616300DFB46D /* b2CircleContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CircleContact.cpp; sourceTree = ""; }; - 491330A81372616300DFB46D /* b2CircleContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2CircleContact.h; sourceTree = ""; }; - 491330A91372616300DFB46D /* b2Contact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Contact.cpp; sourceTree = ""; }; - 491330AA1372616300DFB46D /* b2Contact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Contact.h; sourceTree = ""; }; - 491330AB1372616300DFB46D /* b2ContactSolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2ContactSolver.cpp; sourceTree = ""; }; - 491330AC1372616300DFB46D /* b2ContactSolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2ContactSolver.h; sourceTree = ""; }; - 491330AD1372616300DFB46D /* b2PolygonAndCircleContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonAndCircleContact.cpp; sourceTree = ""; }; - 491330AE1372616300DFB46D /* b2PolygonAndCircleContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonAndCircleContact.h; sourceTree = ""; }; - 491330AF1372616300DFB46D /* b2PolygonContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonContact.cpp; sourceTree = ""; }; - 491330B01372616300DFB46D /* b2PolygonContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonContact.h; sourceTree = ""; }; - 491330B11372616300DFB46D /* b2TOISolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2TOISolver.cpp; sourceTree = ""; }; - 491330B21372616300DFB46D /* b2TOISolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TOISolver.h; sourceTree = ""; }; - 491330B41372616300DFB46D /* b2DistanceJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2DistanceJoint.cpp; sourceTree = ""; }; - 491330B51372616300DFB46D /* b2DistanceJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2DistanceJoint.h; sourceTree = ""; }; - 491330B61372616300DFB46D /* b2FrictionJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2FrictionJoint.cpp; sourceTree = ""; }; - 491330B71372616300DFB46D /* b2FrictionJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2FrictionJoint.h; sourceTree = ""; }; - 491330B81372616300DFB46D /* b2GearJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2GearJoint.cpp; sourceTree = ""; }; - 491330B91372616300DFB46D /* b2GearJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2GearJoint.h; sourceTree = ""; }; - 491330BA1372616300DFB46D /* b2Joint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Joint.cpp; sourceTree = ""; }; - 491330BB1372616300DFB46D /* b2Joint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Joint.h; sourceTree = ""; }; - 491330BC1372616300DFB46D /* b2LineJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2LineJoint.cpp; sourceTree = ""; }; - 491330BD1372616300DFB46D /* b2LineJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2LineJoint.h; sourceTree = ""; }; - 491330BE1372616300DFB46D /* b2MouseJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MouseJoint.cpp; sourceTree = ""; }; - 491330BF1372616300DFB46D /* b2MouseJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MouseJoint.h; sourceTree = ""; }; - 491330C01372616300DFB46D /* b2PrismaticJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PrismaticJoint.cpp; sourceTree = ""; }; - 491330C11372616300DFB46D /* b2PrismaticJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PrismaticJoint.h; sourceTree = ""; }; - 491330C21372616300DFB46D /* b2PulleyJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PulleyJoint.cpp; sourceTree = ""; }; - 491330C31372616300DFB46D /* b2PulleyJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PulleyJoint.h; sourceTree = ""; }; - 491330C41372616300DFB46D /* b2RevoluteJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2RevoluteJoint.cpp; sourceTree = ""; }; - 491330C51372616300DFB46D /* b2RevoluteJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2RevoluteJoint.h; sourceTree = ""; }; - 491330C61372616300DFB46D /* b2WeldJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2WeldJoint.cpp; sourceTree = ""; }; - 491330C71372616300DFB46D /* b2WeldJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2WeldJoint.h; sourceTree = ""; }; 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 = ""; }; + 491333F713727CB100DFB46D /* b2BroadPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2BroadPhase.cpp; sourceTree = ""; }; + 491333F813727CB100DFB46D /* b2BroadPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2BroadPhase.h; sourceTree = ""; }; + 491333F913727CB100DFB46D /* b2CollideCircle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CollideCircle.cpp; sourceTree = ""; }; + 491333FA13727CB100DFB46D /* b2CollidePolygon.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CollidePolygon.cpp; sourceTree = ""; }; + 491333FB13727CB100DFB46D /* b2Collision.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Collision.cpp; sourceTree = ""; }; + 491333FC13727CB100DFB46D /* b2Collision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Collision.h; sourceTree = ""; }; + 491333FD13727CB100DFB46D /* b2Distance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Distance.cpp; sourceTree = ""; }; + 491333FE13727CB100DFB46D /* b2Distance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Distance.h; sourceTree = ""; }; + 491333FF13727CB100DFB46D /* b2DynamicTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2DynamicTree.cpp; sourceTree = ""; }; + 4913340013727CB100DFB46D /* b2DynamicTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2DynamicTree.h; sourceTree = ""; }; + 4913340113727CB100DFB46D /* b2TimeOfImpact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2TimeOfImpact.cpp; sourceTree = ""; }; + 4913340213727CB100DFB46D /* b2TimeOfImpact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TimeOfImpact.h; sourceTree = ""; }; + 4913340413727CB100DFB46D /* b2CircleShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CircleShape.cpp; sourceTree = ""; }; + 4913340513727CB100DFB46D /* b2CircleShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2CircleShape.h; sourceTree = ""; }; + 4913340613727CB100DFB46D /* b2PolygonShape.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonShape.cpp; sourceTree = ""; }; + 4913340713727CB100DFB46D /* b2PolygonShape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonShape.h; sourceTree = ""; }; + 4913340813727CB100DFB46D /* b2Shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Shape.h; sourceTree = ""; }; + 4913340A13727CB100DFB46D /* b2BlockAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2BlockAllocator.cpp; sourceTree = ""; }; + 4913340B13727CB100DFB46D /* b2BlockAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2BlockAllocator.h; sourceTree = ""; }; + 4913340C13727CB100DFB46D /* b2Math.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Math.cpp; sourceTree = ""; }; + 4913340D13727CB100DFB46D /* b2Math.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Math.h; sourceTree = ""; }; + 4913340E13727CB100DFB46D /* b2Settings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Settings.cpp; sourceTree = ""; }; + 4913340F13727CB100DFB46D /* b2Settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Settings.h; sourceTree = ""; }; + 4913341013727CB100DFB46D /* b2StackAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2StackAllocator.cpp; sourceTree = ""; }; + 4913341113727CB100DFB46D /* b2StackAllocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2StackAllocator.h; sourceTree = ""; }; + 4913341313727CB100DFB46D /* b2Body.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Body.cpp; sourceTree = ""; }; + 4913341413727CB100DFB46D /* b2Body.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Body.h; sourceTree = ""; }; + 4913341513727CB100DFB46D /* b2ContactManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2ContactManager.cpp; sourceTree = ""; }; + 4913341613727CB100DFB46D /* b2ContactManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2ContactManager.h; sourceTree = ""; }; + 4913341713727CB100DFB46D /* b2Fixture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Fixture.cpp; sourceTree = ""; }; + 4913341813727CB100DFB46D /* b2Fixture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Fixture.h; sourceTree = ""; }; + 4913341913727CB100DFB46D /* b2Island.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Island.cpp; sourceTree = ""; }; + 4913341A13727CB100DFB46D /* b2Island.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Island.h; sourceTree = ""; }; + 4913341B13727CB100DFB46D /* b2TimeStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TimeStep.h; sourceTree = ""; }; + 4913341C13727CB100DFB46D /* b2World.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2World.cpp; sourceTree = ""; }; + 4913341D13727CB100DFB46D /* b2World.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2World.h; sourceTree = ""; }; + 4913341E13727CB100DFB46D /* b2WorldCallbacks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2WorldCallbacks.cpp; sourceTree = ""; }; + 4913341F13727CB100DFB46D /* b2WorldCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2WorldCallbacks.h; sourceTree = ""; }; + 4913342113727CB100DFB46D /* b2CircleContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2CircleContact.cpp; sourceTree = ""; }; + 4913342213727CB100DFB46D /* b2CircleContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2CircleContact.h; sourceTree = ""; }; + 4913342313727CB100DFB46D /* b2Contact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Contact.cpp; sourceTree = ""; }; + 4913342413727CB100DFB46D /* b2Contact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Contact.h; sourceTree = ""; }; + 4913342513727CB100DFB46D /* b2ContactSolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2ContactSolver.cpp; sourceTree = ""; }; + 4913342613727CB100DFB46D /* b2ContactSolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2ContactSolver.h; sourceTree = ""; }; + 4913342713727CB100DFB46D /* b2PolygonAndCircleContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonAndCircleContact.cpp; sourceTree = ""; }; + 4913342813727CB100DFB46D /* b2PolygonAndCircleContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonAndCircleContact.h; sourceTree = ""; }; + 4913342913727CB100DFB46D /* b2PolygonContact.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PolygonContact.cpp; sourceTree = ""; }; + 4913342A13727CB100DFB46D /* b2PolygonContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PolygonContact.h; sourceTree = ""; }; + 4913342B13727CB100DFB46D /* b2TOISolver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2TOISolver.cpp; sourceTree = ""; }; + 4913342C13727CB100DFB46D /* b2TOISolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2TOISolver.h; sourceTree = ""; }; + 4913342E13727CB100DFB46D /* b2DistanceJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2DistanceJoint.cpp; sourceTree = ""; }; + 4913342F13727CB100DFB46D /* b2DistanceJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2DistanceJoint.h; sourceTree = ""; }; + 4913343013727CB100DFB46D /* b2FrictionJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2FrictionJoint.cpp; sourceTree = ""; }; + 4913343113727CB100DFB46D /* b2FrictionJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2FrictionJoint.h; sourceTree = ""; }; + 4913343213727CB100DFB46D /* b2GearJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2GearJoint.cpp; sourceTree = ""; }; + 4913343313727CB100DFB46D /* b2GearJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2GearJoint.h; sourceTree = ""; }; + 4913343413727CB100DFB46D /* b2Joint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2Joint.cpp; sourceTree = ""; }; + 4913343513727CB100DFB46D /* b2Joint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2Joint.h; sourceTree = ""; }; + 4913343613727CB100DFB46D /* b2LineJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2LineJoint.cpp; sourceTree = ""; }; + 4913343713727CB100DFB46D /* b2LineJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2LineJoint.h; sourceTree = ""; }; + 4913343813727CB100DFB46D /* b2MouseJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2MouseJoint.cpp; sourceTree = ""; }; + 4913343913727CB100DFB46D /* b2MouseJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MouseJoint.h; sourceTree = ""; }; + 4913343A13727CB100DFB46D /* b2PrismaticJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PrismaticJoint.cpp; sourceTree = ""; }; + 4913343B13727CB100DFB46D /* b2PrismaticJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PrismaticJoint.h; sourceTree = ""; }; + 4913343C13727CB100DFB46D /* b2PulleyJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2PulleyJoint.cpp; sourceTree = ""; }; + 4913343D13727CB100DFB46D /* b2PulleyJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2PulleyJoint.h; sourceTree = ""; }; + 4913343E13727CB100DFB46D /* b2RevoluteJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2RevoluteJoint.cpp; sourceTree = ""; }; + 4913343F13727CB100DFB46D /* b2RevoluteJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2RevoluteJoint.h; sourceTree = ""; }; + 4913344013727CB100DFB46D /* b2WeldJoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b2WeldJoint.cpp; sourceTree = ""; }; + 4913344113727CB100DFB46D /* b2WeldJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2WeldJoint.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -175,7 +175,7 @@ 491330541372610400DFB46D = { isa = PBXGroup; children = ( - 4913307A1372616300DFB46D /* Box2D */, + 491333F413727CB100DFB46D /* Box2D */, 491331291372630F00DFB46D /* Frameworks */, 491330601372610400DFB46D /* Products */, ); @@ -189,142 +189,142 @@ name = Products; sourceTree = ""; }; - 4913307A1372616300DFB46D /* Box2D */ = { + 491331291372630F00DFB46D /* Frameworks */ = { + isa = PBXGroup; + children = ( + 491331271372630700DFB46D /* UIKit.framework */, + 49133122137262F200DFB46D /* Foundation.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + 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 = ""; }; - 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 = ""; }; - 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 = ""; }; - 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 = ""; }; - 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 = ""; }; - 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 = ""; }; - 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 = ""; }; - 491331291372630F00DFB46D /* Frameworks */ = { - isa = PBXGroup; - children = ( - 491331271372630700DFB46D /* UIKit.framework */, - 49133122137262F200DFB46D /* Foundation.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -332,42 +332,42 @@ 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; }; @@ -418,41 +418,41 @@ 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; }; diff --git a/libs/box2d/box2d-iphone.xcodeproj/project.pbxproj b/libs/box2d/box2d-iphone.xcodeproj/project.pbxproj index 6e1af9d..65cf69b 100644 --- a/libs/box2d/box2d-iphone.xcodeproj/project.pbxproj +++ b/libs/box2d/box2d-iphone.xcodeproj/project.pbxproj @@ -21,9 +21,7 @@ 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 */; }; @@ -35,26 +33,20 @@ 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 */; }; @@ -109,9 +101,7 @@ 4913320E13726B1F00DFB46D /* BodyTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BodyTypes.h; sourceTree = ""; }; 4913320F13726B1F00DFB46D /* Breakable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Breakable.h; sourceTree = ""; }; 4913321013726B1F00DFB46D /* Bridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Bridge.h; sourceTree = ""; }; - 4913321113726B1F00DFB46D /* BulletTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BulletTest.h; sourceTree = ""; }; 4913321213726B1F00DFB46D /* Cantilever.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Cantilever.h; sourceTree = ""; }; - 4913321313726B1F00DFB46D /* Car.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Car.h; sourceTree = ""; }; 4913321413726B1F00DFB46D /* Chain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Chain.h; sourceTree = ""; }; 4913321513726B1F00DFB46D /* CharacterCollision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CharacterCollision.h; sourceTree = ""; }; 4913321613726B1F00DFB46D /* CollisionFiltering.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollisionFiltering.h; sourceTree = ""; }; @@ -123,26 +113,20 @@ 4913321C13726B1F00DFB46D /* Dominos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Dominos.h; sourceTree = ""; }; 4913321D13726B1F00DFB46D /* DynamicTreeTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicTreeTest.h; sourceTree = ""; }; 4913321E13726B1F00DFB46D /* EdgeShapes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EdgeShapes.h; sourceTree = ""; }; - 4913321F13726B1F00DFB46D /* EdgeTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EdgeTest.h; sourceTree = ""; }; 4913322013726B1F00DFB46D /* Gears.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Gears.h; sourceTree = ""; }; 4913322113726B1F00DFB46D /* LineJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LineJoint.h; sourceTree = ""; }; 4913322213726B1F00DFB46D /* OneSidedPlatform.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OneSidedPlatform.h; sourceTree = ""; }; - 4913322313726B1F00DFB46D /* Pinball.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pinball.h; sourceTree = ""; }; 4913322413726B1F00DFB46D /* PolyCollision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyCollision.h; sourceTree = ""; }; 4913322513726B1F00DFB46D /* PolyShapes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolyShapes.h; sourceTree = ""; }; 4913322613726B1F00DFB46D /* Prismatic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Prismatic.h; sourceTree = ""; }; 4913322713726B1F00DFB46D /* Pulleys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pulleys.h; sourceTree = ""; }; 4913322813726B1F00DFB46D /* Pyramid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pyramid.h; sourceTree = ""; }; 4913322913726B1F00DFB46D /* RayCast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RayCast.h; sourceTree = ""; }; - 4913322A13726B1F00DFB46D /* Revolute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Revolute.h; sourceTree = ""; }; - 4913322B13726B1F00DFB46D /* Rope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Rope.h; sourceTree = ""; }; - 4913322C13726B1F00DFB46D /* RopeJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RopeJoint.h; sourceTree = ""; }; 4913322D13726B1F00DFB46D /* SensorTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SensorTest.h; sourceTree = ""; }; 4913322E13726B1F00DFB46D /* ShapeEditing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShapeEditing.h; sourceTree = ""; }; 4913322F13726B1F00DFB46D /* SliderCrank.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SliderCrank.h; sourceTree = ""; }; 4913323013726B1F00DFB46D /* SphereStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SphereStack.h; sourceTree = ""; }; 4913323113726B1F00DFB46D /* TheoJansen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TheoJansen.h; sourceTree = ""; }; - 4913323213726B1F00DFB46D /* Tiles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tiles.h; sourceTree = ""; }; 4913323313726B1F00DFB46D /* TimeOfImpact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TimeOfImpact.h; sourceTree = ""; }; 4913323413726B1F00DFB46D /* VaryingFriction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VaryingFriction.h; sourceTree = ""; }; 4913323513726B1F00DFB46D /* VaryingRestitution.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VaryingRestitution.h; sourceTree = ""; }; @@ -259,9 +243,7 @@ 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 */, @@ -273,26 +255,20 @@ 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 */, @@ -321,9 +297,7 @@ 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 */, @@ -335,26 +309,20 @@ 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 */, diff --git a/libs/box2d/iPhone/Classes/Box2DView.mm b/libs/box2d/iPhone/Classes/Box2DView.mm index edbf9ef..11743b0 100644 --- a/libs/box2d/iPhone/Classes/Box2DView.mm +++ b/libs/box2d/iPhone/Classes/Box2DView.mm @@ -66,8 +66,6 @@ Settings settings; [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)]; [[UIAccelerometer sharedAccelerometer] setDelegate:self]; - - //[self setMultipleTouchEnabled:YES]; } @@ -248,9 +246,7 @@ Settings settings; //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; } diff --git a/libs/box2d/iPhone/Classes/GLES-Render.h b/libs/box2d/iPhone/Classes/GLES-Render.h index 8e02a74..2551666 100644 --- a/libs/box2d/iPhone/Classes/GLES-Render.h +++ b/libs/box2d/iPhone/Classes/GLES-Render.h @@ -32,7 +32,7 @@ struct b2AABB; // 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); diff --git a/libs/box2d/iPhone/Classes/TestEntriesViewController.mm b/libs/box2d/iPhone/Classes/TestEntriesViewController.mm index bb8e1ac..49eb94e 100644 --- a/libs/box2d/iPhone/Classes/TestEntriesViewController.mm +++ b/libs/box2d/iPhone/Classes/TestEntriesViewController.mm @@ -57,7 +57,7 @@ TestEntry* e = g_testEntries; e+=indexPath.row; - cell.textLabel.text = [NSString stringWithUTF8String:e->name]; + [cell setText:[NSString stringWithCString:e->name]]; return cell; } diff --git a/libs/box2d/iPhone/Classes/iPhoneTest.h b/libs/box2d/iPhone/Classes/iPhoneTest.h index c7c767a..dc82ed5 100644 --- a/libs/box2d/iPhone/Classes/iPhoneTest.h +++ b/libs/box2d/iPhone/Classes/iPhoneTest.h @@ -58,28 +58,25 @@ inline float32 RandomFloat(float32 lo, float32 hi) 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; @@ -95,7 +92,6 @@ struct Settings int32 drawStats; int32 enableWarmStarting; int32 enableContinuous; - int32 enableSubStepping; int32 pause; int32 singleStep; }; diff --git a/libs/box2d/iPhone/Classes/iPhoneTest.mm b/libs/box2d/iPhone/Classes/iPhoneTest.mm index faf08df..16cc5da 100644 --- a/libs/box2d/iPhone/Classes/iPhoneTest.mm +++ b/libs/box2d/iPhone/Classes/iPhoneTest.mm @@ -1,5 +1,5 @@ /* -* 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 * @@ -46,16 +46,16 @@ Test::Test() 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); } @@ -79,21 +79,21 @@ void Test::SetGravity( float x, float y) 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; @@ -112,36 +112,37 @@ void Test::DrawTitle(int x, int y, const char *string) } 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) { @@ -151,18 +152,18 @@ 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(); @@ -186,14 +187,14 @@ void Test::SpawnBomb(const b2Vec2& worldPt) 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; @@ -209,7 +210,7 @@ void Test::ShiftMouseDown(const b2Vec2& p) { return; } - + SpawnBomb(p); } @@ -251,7 +252,7 @@ void Test::LaunchBomb(const b2Vec2& position, const b2Vec2& velocity) m_world->DestroyBody(m_bomb); m_bomb = NULL; } - + b2BodyDef bd; bd.type = b2_dynamicBody; bd.position = position; @@ -261,11 +262,11 @@ void Test::LaunchBomb(const b2Vec2& position, const b2Vec2& velocity) 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); @@ -273,14 +274,14 @@ void Test::LaunchBomb(const b2Vec2& position, const b2Vec2& velocity) 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) @@ -291,94 +292,89 @@ void Test::Step(Settings* settings) { 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 @@ -389,12 +385,12 @@ void Test::Step(Settings* settings) // 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) { @@ -402,7 +398,7 @@ void Test::Step(Settings* settings) //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); diff --git a/libs/box2d/iPhone/Classes/iPhoneTestEntries.mm b/libs/box2d/iPhone/Classes/iPhoneTestEntries.mm index 18faaa0..02da5f5 100644 --- a/libs/box2d/iPhone/Classes/iPhoneTestEntries.mm +++ b/libs/box2d/iPhone/Classes/iPhoneTestEntries.mm @@ -1,111 +1,92 @@ -/* -* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org -* -* 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 -using namespace std; - -#include "ApplyForce.h" -#include "BodyTypes.h" -#include "Breakable.h" -#include "Bridge.h" -#include "BulletTest.h" -#include "Cantilever.h" -#include "Car.h" -#include "ContinuousTest.h" -#include "Chain.h" -#include "CharacterCollision.h" -#include "CollisionFiltering.h" -#include "CollisionProcessing.h" -#include "CompoundShapes.h" -#include "Confined.h" -#include "DistanceTest.h" -#include "Dominos.h" -#include "DynamicTreeTest.h" -#include "EdgeShapes.h" -#include "EdgeTest.h" -#include "Gears.h" -#include "OneSidedPlatform.h" -#include "Pinball.h" -#include "PolyCollision.h" -#include "PolyShapes.h" -#include "Prismatic.h" -#include "Pulleys.h" -#include "Pyramid.h" -#include "RayCast.h" -#include "Revolute.h" -#include "Rope.h" -#include "RopeJoint.h" -#include "SensorTest.h" -#include "ShapeEditing.h" -#include "SliderCrank.h" -#include "SphereStack.h" -#include "TheoJansen.h" -#include "Tiles.h" -#include "TimeOfImpact.h" -#include "VaryingFriction.h" -#include "VaryingRestitution.h" -#include "VerticalStack.h" -#include "Web.h" - -TestEntry g_testEntries[] = -{ - {"Pulleys", Pulleys::Create}, - {"SphereStack", SphereStack::Create}, - {"Tiles", Tiles::Create}, - {"Polygon Shapes", PolyShapes::Create}, - {"Rope", Rope::Create}, - {"Web", Web::Create}, - {"Car", Car::Create}, - {"Vertical Stack", VerticalStack::Create}, - {"RopeJoint", RopeJoint::Create}, - {"Character Collision", CharacterCollision::Create}, - {"Edge Test", EdgeTest::Create}, - {"One-Sided Platform", OneSidedPlatform::Create}, - {"Pinball", Pinball::Create}, - {"Bullet Test", BulletTest::Create}, - {"Continuous Test", ContinuousTest::Create}, - {"Time of Impact", TimeOfImpact::Create}, - {"Ray-Cast", RayCast::Create}, - {"Confined", Confined::Create}, - {"Pyramid", Pyramid::Create}, - {"Varying Restitution", VaryingRestitution::Create}, - {"Theo Jansen's Walker", TheoJansen::Create}, - {"Body Types", BodyTypes::Create}, - {"Prismatic", Prismatic::Create}, - {"Edge Shapes", EdgeShapes::Create}, - {"PolyCollision", PolyCollision::Create}, - {"Apply Force", ApplyForce::Create}, - {"Cantilever", Cantilever::Create}, - {"Bridge", Bridge::Create}, - {"Breakable", Breakable::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}, - {"Revolute", Revolute::Create}, - {"Sensor Test", SensorTest::Create}, - {"Shape Editing", ShapeEditing::Create}, - {"Slider Crank", SliderCrank::Create}, - {"Varying Friction", VaryingFriction::Create}, - {NULL, NULL} -}; +/* + * 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} + +}; diff --git a/libs/box2d/src/Box2D/Box2D.h b/libs/box2d/src/Box2D/Box2D.h index 0414477..dc5701f 100644 --- a/libs/box2d/src/Box2D/Box2D.h +++ b/libs/box2d/src/Box2D/Box2D.h @@ -1,5 +1,5 @@ /* -* 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 @@ -32,12 +32,8 @@ For discussion please visit http://box2d.org/forum // These include files constitute the main Box2D API #include -#include -#include #include -#include -#include #include #include @@ -56,14 +52,11 @@ For discussion please visit http://box2d.org/forum #include #include #include -#include +#include #include #include #include #include -#include #include -#include - #endif diff --git a/libs/box2d/src/Box2D/Collision/Shapes/b2CircleShape.cpp b/libs/box2d/src/Box2D/Collision/Shapes/b2CircleShape.cpp index 80dac85..a950b0b 100644 --- a/libs/box2d/src/Box2D/Collision/Shapes/b2CircleShape.cpp +++ b/libs/box2d/src/Box2D/Collision/Shapes/b2CircleShape.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -18,7 +18,6 @@ #include #include -using namespace std; b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const { @@ -28,11 +27,6 @@ b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const return clone; } -int32 b2CircleShape::GetChildCount() const -{ - return 1; -} - bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) const { b2Vec2 center = transform.position + b2Mul(transform.R, m_p); @@ -44,11 +38,8 @@ bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) con // From Section 3.1.2 // x = s + a * r // norm(x) = radius -bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, - const b2Transform& transform, int32 childIndex) const +bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& transform) const { - B2_NOT_USED(childIndex); - b2Vec2 position = transform.position + b2Mul(transform.R, m_p); b2Vec2 s = input.p1 - position; float32 b = b2Dot(s, s) - m_radius * m_radius; @@ -81,10 +72,8 @@ bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input return false; } -void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const +void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform) const { - B2_NOT_USED(childIndex); - b2Vec2 p = transform.position + b2Mul(transform.R, m_p); aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius); aabb->upperBound.Set(p.x + m_radius, p.y + m_radius); diff --git a/libs/box2d/src/Box2D/Collision/Shapes/b2CircleShape.h b/libs/box2d/src/Box2D/Collision/Shapes/b2CircleShape.h index 6c1fd54..bb31da8 100644 --- a/libs/box2d/src/Box2D/Collision/Shapes/b2CircleShape.h +++ b/libs/box2d/src/Box2D/Collision/Shapes/b2CircleShape.h @@ -1,5 +1,5 @@ /* -* 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 @@ -30,18 +30,14 @@ public: /// Implement b2Shape. b2Shape* Clone(b2BlockAllocator* allocator) const; - /// @see b2Shape::GetChildCount - int32 GetChildCount() const; - /// Implement b2Shape. bool TestPoint(const b2Transform& transform, const b2Vec2& p) const; /// Implement b2Shape. - bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, - const b2Transform& transform, int32 childIndex) const; + bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& transform) const; /// @see b2Shape::ComputeAABB - void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const; + void ComputeAABB(b2AABB* aabb, const b2Transform& transform) const; /// @see b2Shape::ComputeMass void ComputeMass(b2MassData* massData, float32 density) const; diff --git a/libs/box2d/src/Box2D/Collision/Shapes/b2EdgeShape.cpp b/libs/box2d/src/Box2D/Collision/Shapes/b2EdgeShape.cpp deleted file mode 100644 index 19ca893..0000000 --- a/libs/box2d/src/Box2D/Collision/Shapes/b2EdgeShape.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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 -#include -using namespace std; - -void b2EdgeShape::Set(const b2Vec2& v1, const b2Vec2& v2) -{ - m_vertex1 = v1; - m_vertex2 = v2; - m_hasVertex0 = false; - m_hasVertex3 = false; -} - -b2Shape* b2EdgeShape::Clone(b2BlockAllocator* allocator) const -{ - void* mem = allocator->Allocate(sizeof(b2EdgeShape)); - b2EdgeShape* clone = new (mem) b2EdgeShape; - *clone = *this; - return clone; -} - -int32 b2EdgeShape::GetChildCount() const -{ - return 1; -} - -bool b2EdgeShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const -{ - B2_NOT_USED(xf); - B2_NOT_USED(p); - return false; -} - -// p = p1 + t * d -// v = v1 + s * e -// p1 + t * d = v1 + s * e -// s * e - t * d = p1 - v1 -bool b2EdgeShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, - const b2Transform& xf, int32 childIndex) const -{ - B2_NOT_USED(childIndex); - - // Put the ray into the edge's frame of reference. - b2Vec2 p1 = b2MulT(xf.R, input.p1 - xf.position); - b2Vec2 p2 = b2MulT(xf.R, input.p2 - xf.position); - b2Vec2 d = p2 - p1; - - b2Vec2 v1 = m_vertex1; - b2Vec2 v2 = m_vertex2; - b2Vec2 e = v2 - v1; - b2Vec2 normal(e.y, -e.x); - normal.Normalize(); - - // q = p1 + t * d - // dot(normal, q - v1) = 0 - // dot(normal, p1 - v1) + t * dot(normal, d) = 0 - float32 numerator = b2Dot(normal, v1 - p1); - float32 denominator = b2Dot(normal, d); - - if (denominator == 0.0f) - { - return false; - } - - float32 t = numerator / denominator; - if (t < 0.0f || 1.0f < t) - { - return false; - } - - b2Vec2 q = p1 + t * d; - - // q = v1 + s * r - // s = dot(q - v1, r) / dot(r, r) - b2Vec2 r = v2 - v1; - float32 rr = b2Dot(r, r); - if (rr == 0.0f) - { - return false; - } - - float32 s = b2Dot(q - v1, r) / rr; - if (s < 0.0f || 1.0f < s) - { - return false; - } - - output->fraction = t; - if (numerator > 0.0f) - { - output->normal = -normal; - } - else - { - output->normal = normal; - } - return true; -} - -void b2EdgeShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const -{ - B2_NOT_USED(childIndex); - - b2Vec2 v1 = b2Mul(xf, m_vertex1); - b2Vec2 v2 = b2Mul(xf, m_vertex2); - - b2Vec2 lower = b2Min(v1, v2); - b2Vec2 upper = b2Max(v1, v2); - - b2Vec2 r(m_radius, m_radius); - aabb->lowerBound = lower - r; - aabb->upperBound = upper + r; -} - -void b2EdgeShape::ComputeMass(b2MassData* massData, float32 density) const -{ - B2_NOT_USED(density); - - massData->mass = 0.0f; - massData->center = 0.5f * (m_vertex1 + m_vertex2); - massData->I = 0.0f; -} diff --git a/libs/box2d/src/Box2D/Collision/Shapes/b2EdgeShape.h b/libs/box2d/src/Box2D/Collision/Shapes/b2EdgeShape.h deleted file mode 100644 index 780eb2c..0000000 --- a/libs/box2d/src/Box2D/Collision/Shapes/b2EdgeShape.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef B2_EDGE_SHAPE_H -#define B2_EDGE_SHAPE_H - -#include - -/// A line segment (edge) shape. These can be connected in chains or loops -/// to other edge shapes. The connectivity information is used to ensure -/// correct contact normals. -class b2EdgeShape : public b2Shape -{ -public: - b2EdgeShape(); - - /// Set this as an isolated edge. - void Set(const b2Vec2& v1, const b2Vec2& v2); - - /// Implement b2Shape. - b2Shape* Clone(b2BlockAllocator* allocator) const; - - /// @see b2Shape::GetChildCount - int32 GetChildCount() const; - - /// @see b2Shape::TestPoint - bool TestPoint(const b2Transform& transform, const b2Vec2& p) const; - - /// Implement b2Shape. - bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, - const b2Transform& transform, int32 childIndex) const; - - /// @see b2Shape::ComputeAABB - void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const; - - /// @see b2Shape::ComputeMass - void ComputeMass(b2MassData* massData, float32 density) const; - - /// These are the edge vertices - b2Vec2 m_vertex1, m_vertex2; - - /// Optional adjacent vertices. These are used for smooth collision. - b2Vec2 m_vertex0, m_vertex3; - bool m_hasVertex0, m_hasVertex3; -}; - -inline b2EdgeShape::b2EdgeShape() -{ - m_type = e_edge; - m_radius = b2_polygonRadius; - m_hasVertex0 = false; - m_hasVertex3 = false; -} - -#endif diff --git a/libs/box2d/src/Box2D/Collision/Shapes/b2LoopShape.cpp b/libs/box2d/src/Box2D/Collision/Shapes/b2LoopShape.cpp deleted file mode 100644 index 7f7a216..0000000 --- a/libs/box2d/src/Box2D/Collision/Shapes/b2LoopShape.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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 -#include -#include -#include -using namespace std; - -b2LoopShape::~b2LoopShape() -{ - b2Free(m_vertices); - m_vertices = NULL; - m_count = 0; -} - -void b2LoopShape::Create(const b2Vec2* vertices, int32 count) -{ - b2Assert(m_vertices == NULL && m_count == 0); - b2Assert(count >= 2); - m_count = count; - m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2)); - memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2)); -} - -b2Shape* b2LoopShape::Clone(b2BlockAllocator* allocator) const -{ - void* mem = allocator->Allocate(sizeof(b2LoopShape)); - b2LoopShape* clone = new (mem) b2LoopShape; - clone->Create(m_vertices, m_count); - return clone; -} - -int32 b2LoopShape::GetChildCount() const -{ - return m_count; -} - -void b2LoopShape::GetChildEdge(b2EdgeShape* edge, int32 index) const -{ - b2Assert(2 <= m_count); - b2Assert(0 <= index && index < m_count); - edge->m_type = b2Shape::e_edge; - edge->m_radius = m_radius; - edge->m_hasVertex0 = true; - edge->m_hasVertex3 = true; - - int32 i0 = index - 1 >= 0 ? index - 1 : m_count - 1; - int32 i1 = index; - int32 i2 = index + 1 < m_count ? index + 1 : 0; - int32 i3 = index + 2; - while (i3 >= m_count) - { - i3 -= m_count; - } - - edge->m_vertex0 = m_vertices[i0]; - edge->m_vertex1 = m_vertices[i1]; - edge->m_vertex2 = m_vertices[i2]; - edge->m_vertex3 = m_vertices[i3]; -} - -bool b2LoopShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const -{ - B2_NOT_USED(xf); - B2_NOT_USED(p); - return false; -} - -bool b2LoopShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, - const b2Transform& xf, int32 childIndex) const -{ - b2Assert(childIndex < m_count); - - b2EdgeShape edgeShape; - - int32 i1 = childIndex; - int32 i2 = childIndex + 1; - if (i2 == m_count) - { - i2 = 0; - } - - edgeShape.m_vertex1 = m_vertices[i1]; - edgeShape.m_vertex2 = m_vertices[i2]; - - return edgeShape.RayCast(output, input, xf, 0); -} - -void b2LoopShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const -{ - b2Assert(childIndex < m_count); - - int32 i1 = childIndex; - int32 i2 = childIndex + 1; - if (i2 == m_count) - { - i2 = 0; - } - - b2Vec2 v1 = b2Mul(xf, m_vertices[i1]); - b2Vec2 v2 = b2Mul(xf, m_vertices[i2]); - - aabb->lowerBound = b2Min(v1, v2); - aabb->upperBound = b2Max(v1, v2); -} - -void b2LoopShape::ComputeMass(b2MassData* massData, float32 density) const -{ - B2_NOT_USED(density); - - massData->mass = 0.0f; - massData->center.SetZero(); - massData->I = 0.0f; -} diff --git a/libs/box2d/src/Box2D/Collision/Shapes/b2LoopShape.h b/libs/box2d/src/Box2D/Collision/Shapes/b2LoopShape.h deleted file mode 100644 index 0dd7f1c..0000000 --- a/libs/box2d/src/Box2D/Collision/Shapes/b2LoopShape.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef B2_LOOP_SHAPE_H -#define B2_LOOP_SHAPE_H - -#include - -class b2EdgeShape; - -/// A loop shape is a free form sequence of line segments that form a circular list. -/// The loop may cross upon itself, but this is not recommended for smooth collision. -/// The loop has double sided collision, so you can use inside and outside collision. -/// Therefore, you may use any winding order. -/// Since there may be many vertices, they are allocated using b2Alloc. -class b2LoopShape : public b2Shape -{ -public: - b2LoopShape(); - - /// The destructor frees the vertices using b2Free. - ~b2LoopShape(); - - /// Create the loop shape, copy all vertices. - void Create(const b2Vec2* vertices, int32 count); - - /// Implement b2Shape. Vertices are cloned using b2Alloc. - b2Shape* Clone(b2BlockAllocator* allocator) const; - - /// @see b2Shape::GetChildCount - int32 GetChildCount() const; - - /// Get a child edge. - void GetChildEdge(b2EdgeShape* edge, int32 index) const; - - /// This always return false. - /// @see b2Shape::TestPoint - bool TestPoint(const b2Transform& transform, const b2Vec2& p) const; - - /// Implement b2Shape. - bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, - const b2Transform& transform, int32 childIndex) const; - - /// @see b2Shape::ComputeAABB - void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const; - - /// Chains have zero mass. - /// @see b2Shape::ComputeMass - void ComputeMass(b2MassData* massData, float32 density) const; - - /// Get the number of vertices. - int32 GetCount() const { return m_count; } - - /// Get the vertices (read-only). - const b2Vec2& GetVertex(int32 index) const - { - b2Assert(0 <= index && index < m_count); - return m_vertices[index]; - } - - /// Get the vertices (read-only). - const b2Vec2* GetVertices() const { return m_vertices; } - -protected: - - /// The vertices. Owned by this class. - b2Vec2* m_vertices; - - /// The vertex count. - int32 m_count; -}; - -inline b2LoopShape::b2LoopShape() -{ - m_type = e_loop; - m_radius = b2_polygonRadius; - m_vertices = NULL; - m_count = 0; -} - -#endif diff --git a/libs/box2d/src/Box2D/Collision/Shapes/b2PolygonShape.cpp b/libs/box2d/src/Box2D/Collision/Shapes/b2PolygonShape.cpp index a625aff..429e647 100644 --- a/libs/box2d/src/Box2D/Collision/Shapes/b2PolygonShape.cpp +++ b/libs/box2d/src/Box2D/Collision/Shapes/b2PolygonShape.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -66,18 +66,30 @@ void b2PolygonShape::SetAsBox(float32 hx, float32 hy, const b2Vec2& center, floa } } -int32 b2PolygonShape::GetChildCount() const +void b2PolygonShape::SetAsEdge(const b2Vec2& v1, const b2Vec2& v2) { - return 1; + m_vertexCount = 2; + m_vertices[0] = v1; + m_vertices[1] = v2; + m_centroid = 0.5f * (v1 + v2); + m_normals[0] = b2Cross(v2 - v1, 1.0f); + m_normals[0].Normalize(); + m_normals[1] = -m_normals[0]; } static b2Vec2 ComputeCentroid(const b2Vec2* vs, int32 count) { - b2Assert(count >= 3); + b2Assert(count >= 2); b2Vec2 c; c.Set(0.0f, 0.0f); float32 area = 0.0f; + if (count == 2) + { + c = 0.5f * (vs[0] + vs[1]); + return c; + } + // pRef is the reference point for forming triangles. // It's location doesn't change the result (except for rounding error). b2Vec2 pRef(0.0f, 0.0f); @@ -119,7 +131,7 @@ static b2Vec2 ComputeCentroid(const b2Vec2* vs, int32 count) void b2PolygonShape::Set(const b2Vec2* vertices, int32 count) { - b2Assert(3 <= count && count <= b2_maxPolygonVertices); + b2Assert(2 <= count && count <= b2_maxPolygonVertices); m_vertexCount = count; // Copy vertices. @@ -186,82 +198,131 @@ bool b2PolygonShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const return true; } -bool b2PolygonShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, - const b2Transform& xf, int32 childIndex) const +bool b2PolygonShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& xf) const { - B2_NOT_USED(childIndex); - // Put the ray into the polygon's frame of reference. b2Vec2 p1 = b2MulT(xf.R, input.p1 - xf.position); b2Vec2 p2 = b2MulT(xf.R, input.p2 - xf.position); b2Vec2 d = p2 - p1; - float32 lower = 0.0f, upper = input.maxFraction; - - int32 index = -1; - - for (int32 i = 0; i < m_vertexCount; ++i) + if (m_vertexCount == 2) { - // p = p1 + a * d - // dot(normal, p - v) = 0 - // dot(normal, p1 - v) + a * dot(normal, d) = 0 - float32 numerator = b2Dot(m_normals[i], m_vertices[i] - p1); - float32 denominator = b2Dot(m_normals[i], d); + b2Vec2 v1 = m_vertices[0]; + b2Vec2 v2 = m_vertices[1]; + b2Vec2 normal = m_normals[0]; + + // q = p1 + t * d + // dot(normal, q - v1) = 0 + // dot(normal, p1 - v1) + t * dot(normal, d) = 0 + float32 numerator = b2Dot(normal, v1 - p1); + float32 denominator = b2Dot(normal, d); if (denominator == 0.0f) - { - if (numerator < 0.0f) - { - return false; - } + { + return false; + } + + float32 t = numerator / denominator; + if (t < 0.0f || 1.0f < t) + { + return false; + } + + b2Vec2 q = p1 + t * d; + + // q = v1 + s * r + // s = dot(q - v1, r) / dot(r, r) + b2Vec2 r = v2 - v1; + float32 rr = b2Dot(r, r); + if (rr == 0.0f) + { + return false; + } + + float32 s = b2Dot(q - v1, r) / rr; + if (s < 0.0f || 1.0f < s) + { + return false; + } + + output->fraction = t; + if (numerator > 0.0f) + { + output->normal = -normal; } else { - // Note: we want this predicate without division: - // lower < numerator / denominator, where denominator < 0 - // Since denominator < 0, we have to flip the inequality: - // lower < numerator / denominator <==> denominator * lower > numerator. - if (denominator < 0.0f && numerator < lower * denominator) + output->normal = normal; + } + return true; + } + else + { + float32 lower = 0.0f, upper = input.maxFraction; + + int32 index = -1; + + for (int32 i = 0; i < m_vertexCount; ++i) + { + // p = p1 + a * d + // dot(normal, p - v) = 0 + // dot(normal, p1 - v) + a * dot(normal, d) = 0 + float32 numerator = b2Dot(m_normals[i], m_vertices[i] - p1); + float32 denominator = b2Dot(m_normals[i], d); + + if (denominator == 0.0f) + { + if (numerator < 0.0f) + { + return false; + } + } + else { - // Increase lower. - // The segment enters this half-space. - lower = numerator / denominator; - index = i; + // Note: we want this predicate without division: + // lower < numerator / denominator, where denominator < 0 + // Since denominator < 0, we have to flip the inequality: + // lower < numerator / denominator <==> denominator * lower > numerator. + if (denominator < 0.0f && numerator < lower * denominator) + { + // Increase lower. + // The segment enters this half-space. + lower = numerator / denominator; + index = i; + } + else if (denominator > 0.0f && numerator < upper * denominator) + { + // Decrease upper. + // The segment exits this half-space. + upper = numerator / denominator; + } } - else if (denominator > 0.0f && numerator < upper * denominator) + + // The use of epsilon here causes the assert on lower to trip + // in some cases. Apparently the use of epsilon was to make edge + // shapes work, but now those are handled separately. + //if (upper < lower - b2_epsilon) + if (upper < lower) { - // Decrease upper. - // The segment exits this half-space. - upper = numerator / denominator; + return false; } } - // The use of epsilon here causes the assert on lower to trip - // in some cases. Apparently the use of epsilon was to make edge - // shapes work, but now those are handled separately. - //if (upper < lower - b2_epsilon) - if (upper < lower) + b2Assert(0.0f <= lower && lower <= input.maxFraction); + + if (index >= 0) { - return false; + output->fraction = lower; + output->normal = b2Mul(xf.R, m_normals[index]); + return true; } } - b2Assert(0.0f <= lower && lower <= input.maxFraction); - - if (index >= 0) - { - output->fraction = lower; - output->normal = b2Mul(xf.R, m_normals[index]); - return true; - } - return false; } -void b2PolygonShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const +void b2PolygonShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf) const { - B2_NOT_USED(childIndex); - b2Vec2 lower = b2Mul(xf, m_vertices[0]); b2Vec2 upper = lower; @@ -303,30 +364,44 @@ void b2PolygonShape::ComputeMass(b2MassData* massData, float32 density) const // // The rest of the derivation is handled by computer algebra. - b2Assert(m_vertexCount >= 3); + b2Assert(m_vertexCount >= 2); + + // A line segment has zero mass. + if (m_vertexCount == 2) + { + massData->center = 0.5f * (m_vertices[0] + m_vertices[1]); + massData->mass = 0.0f; + massData->I = 0.0f; + return; + } b2Vec2 center; center.Set(0.0f, 0.0f); float32 area = 0.0f; float32 I = 0.0f; - // s is the reference point for forming triangles. + // pRef is the reference point for forming triangles. // It's location doesn't change the result (except for rounding error). - b2Vec2 s(0.0f, 0.0f); - + b2Vec2 pRef(0.0f, 0.0f); +#if 0 // This code would put the reference point inside the polygon. for (int32 i = 0; i < m_vertexCount; ++i) { - s += m_vertices[i]; + pRef += m_vertices[i]; } - s *= 1.0f / m_vertexCount; + pRef *= 1.0f / count; +#endif const float32 k_inv3 = 1.0f / 3.0f; for (int32 i = 0; i < m_vertexCount; ++i) { // Triangle vertices. - b2Vec2 e1 = m_vertices[i] - s; - b2Vec2 e2 = i + 1 < m_vertexCount ? m_vertices[i+1] - s : m_vertices[0] - s; + b2Vec2 p1 = pRef; + b2Vec2 p2 = m_vertices[i]; + b2Vec2 p3 = i + 1 < m_vertexCount ? m_vertices[i+1] : m_vertices[0]; + + b2Vec2 e1 = p2 - p1; + b2Vec2 e2 = p3 - p1; float32 D = b2Cross(e1, e2); @@ -334,15 +409,16 @@ void b2PolygonShape::ComputeMass(b2MassData* massData, float32 density) const area += triangleArea; // Area weighted centroid - center += triangleArea * k_inv3 * (e1 + e2); + center += triangleArea * k_inv3 * (p1 + p2 + p3); + float32 px = p1.x, py = p1.y; float32 ex1 = e1.x, ey1 = e1.y; float32 ex2 = e2.x, ey2 = e2.y; - float32 intx2 = ex1*ex1 + ex2*ex1 + ex2*ex2; - float32 inty2 = ey1*ey1 + ey2*ey1 + ey2*ey2; + float32 intx2 = k_inv3 * (0.25f * (ex1*ex1 + ex2*ex1 + ex2*ex2) + (px*ex1 + px*ex2)) + 0.5f*px*px; + float32 inty2 = k_inv3 * (0.25f * (ey1*ey1 + ey2*ey1 + ey2*ey2) + (py*ey1 + py*ey2)) + 0.5f*py*py; - I += (0.25f * k_inv3 * D) * (intx2 + inty2); + I += D * (intx2 + inty2); } // Total mass @@ -351,8 +427,8 @@ void b2PolygonShape::ComputeMass(b2MassData* massData, float32 density) const // Center of mass b2Assert(area > b2_epsilon); center *= 1.0f / area; - massData->center = center + s; + massData->center = center; // Inertia tensor relative to the local origin. - massData->I = density * I + massData->mass * b2Dot(s, s); + massData->I = density * I; } diff --git a/libs/box2d/src/Box2D/Collision/Shapes/b2PolygonShape.h b/libs/box2d/src/Box2D/Collision/Shapes/b2PolygonShape.h index fd11bd1..564d4b0 100644 --- a/libs/box2d/src/Box2D/Collision/Shapes/b2PolygonShape.h +++ b/libs/box2d/src/Box2D/Collision/Shapes/b2PolygonShape.h @@ -1,5 +1,5 @@ /* -* 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 @@ -23,8 +23,6 @@ /// A convex polygon. It is assumed that the interior of the polygon is to /// the left of each edge. -/// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices. -/// In most cases you should not need many vertices for a convex polygon. class b2PolygonShape : public b2Shape { public: @@ -33,12 +31,8 @@ public: /// Implement b2Shape. b2Shape* Clone(b2BlockAllocator* allocator) const; - /// @see b2Shape::GetChildCount - int32 GetChildCount() const; - /// Copy vertices. This assumes the vertices define a convex polygon. /// It is assumed that the exterior is the the right of each edge. - /// The count must be in the range [3, b2_maxPolygonVertices]. void Set(const b2Vec2* vertices, int32 vertexCount); /// Build vertices to represent an axis-aligned box. @@ -53,19 +47,27 @@ public: /// @param angle the rotation of the box in local coordinates. void SetAsBox(float32 hx, float32 hy, const b2Vec2& center, float32 angle); + /// Set this as a single edge. + void SetAsEdge(const b2Vec2& v1, const b2Vec2& v2); + /// @see b2Shape::TestPoint bool TestPoint(const b2Transform& transform, const b2Vec2& p) const; /// Implement b2Shape. - bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, - const b2Transform& transform, int32 childIndex) const; + bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& transform) const; /// @see b2Shape::ComputeAABB - void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const; + void ComputeAABB(b2AABB* aabb, const b2Transform& transform) const; /// @see b2Shape::ComputeMass void ComputeMass(b2MassData* massData, float32 density) const; + /// Get the supporting vertex index in the given direction. + int32 GetSupport(const b2Vec2& d) const; + + /// Get the supporting vertex in the given direction. + const b2Vec2& GetSupportVertex(const b2Vec2& d) const; + /// Get the vertex count. int32 GetVertexCount() const { return m_vertexCount; } @@ -86,6 +88,40 @@ inline b2PolygonShape::b2PolygonShape() m_centroid.SetZero(); } +inline int32 b2PolygonShape::GetSupport(const b2Vec2& d) const +{ + int32 bestIndex = 0; + float32 bestValue = b2Dot(m_vertices[0], d); + for (int32 i = 1; i < m_vertexCount; ++i) + { + float32 value = b2Dot(m_vertices[i], d); + if (value > bestValue) + { + bestIndex = i; + bestValue = value; + } + } + + return bestIndex; +} + +inline const b2Vec2& b2PolygonShape::GetSupportVertex(const b2Vec2& d) const +{ + int32 bestIndex = 0; + float32 bestValue = b2Dot(m_vertices[0], d); + for (int32 i = 1; i < m_vertexCount; ++i) + { + float32 value = b2Dot(m_vertices[i], d); + if (value > bestValue) + { + bestIndex = i; + bestValue = value; + } + } + + return m_vertices[bestIndex]; +} + inline const b2Vec2& b2PolygonShape::GetVertex(int32 index) const { b2Assert(0 <= index && index < m_vertexCount); diff --git a/libs/box2d/src/Box2D/Collision/Shapes/b2Shape.h b/libs/box2d/src/Box2D/Collision/Shapes/b2Shape.h index 34656dd..9082c0e 100644 --- a/libs/box2d/src/Box2D/Collision/Shapes/b2Shape.h +++ b/libs/box2d/src/Box2D/Collision/Shapes/b2Shape.h @@ -1,5 +1,5 @@ /* -* 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 @@ -38,7 +38,7 @@ struct b2MassData /// A shape is used for collision detection. You can create a shape however you like. /// Shapes used for simulation in b2World are created automatically when a b2Fixture -/// is created. Shapes may encapsulate a one or more child shapes. +/// is created. class b2Shape { public: @@ -47,10 +47,8 @@ public: { e_unknown= -1, e_circle = 0, - e_edge = 1, - e_polygon = 2, - e_loop = 3, - e_typeCount = 4 + e_polygon = 1, + e_typeCount = 2, }; b2Shape() { m_type = e_unknown; } @@ -63,27 +61,21 @@ public: /// @return the shape type. Type GetType() const; - /// Get the number of child primitives. - virtual int32 GetChildCount() const = 0; - /// Test a point for containment in this shape. This only works for convex shapes. /// @param xf the shape world transform. /// @param p a point in world coordinates. virtual bool TestPoint(const b2Transform& xf, const b2Vec2& p) const = 0; - /// Cast a ray against a child shape. + /// Cast a ray against this shape. /// @param output the ray-cast results. /// @param input the ray-cast input parameters. /// @param transform the transform to be applied to the shape. - /// @param childIndex the child shape index - virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, - const b2Transform& transform, int32 childIndex) const = 0; + virtual bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, const b2Transform& transform) const = 0; - /// Given a transform, compute the associated axis aligned bounding box for a child shape. + /// Given a transform, compute the associated axis aligned bounding box for this shape. /// @param aabb returns the axis aligned box. /// @param xf the world transform of the shape. - /// @param childIndex the child shape - virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const = 0; + virtual void ComputeAABB(b2AABB* aabb, const b2Transform& xf) const = 0; /// Compute the mass properties of this shape using its dimensions and density. /// The inertia tensor is computed about the local origin. diff --git a/libs/box2d/src/Box2D/Collision/b2BroadPhase.cpp b/libs/box2d/src/Box2D/Collision/b2BroadPhase.cpp index 2aa62f9..12c7967 100644 --- a/libs/box2d/src/Box2D/Collision/b2BroadPhase.cpp +++ b/libs/box2d/src/Box2D/Collision/b2BroadPhase.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -18,7 +18,6 @@ #include #include -using namespace std; b2BroadPhase::b2BroadPhase() { @@ -63,11 +62,6 @@ void b2BroadPhase::MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& di } } -void b2BroadPhase::TouchProxy(int32 proxyId) -{ - BufferMove(proxyId); -} - void b2BroadPhase::BufferMove(int32 proxyId) { if (m_moveCount == m_moveCapacity) diff --git a/libs/box2d/src/Box2D/Collision/b2BroadPhase.h b/libs/box2d/src/Box2D/Collision/b2BroadPhase.h index c7398c9..bff188e 100644 --- a/libs/box2d/src/Box2D/Collision/b2BroadPhase.h +++ b/libs/box2d/src/Box2D/Collision/b2BroadPhase.h @@ -1,5 +1,5 @@ /* -* 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 @@ -40,7 +40,7 @@ public: enum { - e_nullProxy = -1 + e_nullProxy = -1, }; b2BroadPhase(); @@ -57,9 +57,6 @@ public: /// call UpdatePairs to finalized the proxy pairs (for your time step). void MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement); - /// Call to trigger a re-processing of it's pairs on the next call to UpdatePairs. - void TouchProxy(int32 proxyId); - /// Get the fat AABB for a proxy. const b2AABB& GetFatAABB(int32 proxyId) const; @@ -91,14 +88,8 @@ public: template void RayCast(T* callback, const b2RayCastInput& input) const; - /// Get the height of the embedded tree. - int32 GetTreeHeight() const; - - /// Get the balance of the embedded tree. - int32 GetTreeBalance() const; - - /// Get the quality metric of the embedded tree. - float32 GetTreeQuality() const; + /// Compute the height of the embedded tree. + int32 ComputeHeight() const; private: @@ -162,19 +153,9 @@ inline int32 b2BroadPhase::GetProxyCount() const return m_proxyCount; } -inline int32 b2BroadPhase::GetTreeHeight() const -{ - return m_tree.GetHeight(); -} - -inline int32 b2BroadPhase::GetTreeBalance() const -{ - return m_tree.GetMaxBalance(); -} - -inline float32 b2BroadPhase::GetTreeQuality() const +inline int32 b2BroadPhase::ComputeHeight() const { - return m_tree.GetAreaRatio(); + return m_tree.ComputeHeight(); } template @@ -230,7 +211,7 @@ void b2BroadPhase::UpdatePairs(T* callback) } // Try to keep the tree balanced. - //m_tree.Rebalance(4); + m_tree.Rebalance(4); } template diff --git a/libs/box2d/src/Box2D/Collision/b2CollideCircle.cpp b/libs/box2d/src/Box2D/Collision/b2CollideCircle.cpp index 0ad58f0..6edf89d 100644 --- a/libs/box2d/src/Box2D/Collision/b2CollideCircle.cpp +++ b/libs/box2d/src/Box2D/Collision/b2CollideCircle.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2007-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 diff --git a/libs/box2d/src/Box2D/Collision/b2CollideEdge.cpp b/libs/box2d/src/Box2D/Collision/b2CollideEdge.cpp deleted file mode 100644 index e2ded85..0000000 --- a/libs/box2d/src/Box2D/Collision/b2CollideEdge.cpp +++ /dev/null @@ -1,673 +0,0 @@ -/* -* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org -* -* 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 -#include -#include -#include - -enum b2EdgeType -{ - b2_isolated, - b2_concave, - b2_flat, - b2_convex -}; - -// Compute contact points for edge versus circle. -// This accounts for edge connectivity. -void b2CollideEdgeAndCircle(b2Manifold* manifold, - const b2EdgeShape* edgeA, const b2Transform& xfA, - const b2CircleShape* circleB, const b2Transform& xfB) -{ - manifold->pointCount = 0; - - // Compute circle in frame of edge - b2Vec2 Q = b2MulT(xfA, b2Mul(xfB, circleB->m_p)); - - b2Vec2 A = edgeA->m_vertex1, B = edgeA->m_vertex2; - b2Vec2 e = B - A; - - // Barycentric coordinates - float32 u = b2Dot(e, B - Q); - float32 v = b2Dot(e, Q - A); - - float32 radius = edgeA->m_radius + circleB->m_radius; - - b2ContactFeature cf; - cf.indexB = 0; - cf.typeB = b2ContactFeature::e_vertex; - - // Region A - if (v <= 0.0f) - { - b2Vec2 P = A; - b2Vec2 d = Q - P; - float32 dd = b2Dot(d, d); - if (dd > radius * radius) - { - return; - } - - // Is there an edge connected to A? - if (edgeA->m_hasVertex0) - { - b2Vec2 A1 = edgeA->m_vertex0; - b2Vec2 B1 = A; - b2Vec2 e1 = B1 - A1; - float32 u1 = b2Dot(e1, B1 - Q); - - // Is the circle in Region AB of the previous edge? - if (u1 > 0.0f) - { - return; - } - } - - cf.indexA = 0; - cf.typeA = b2ContactFeature::e_vertex; - manifold->pointCount = 1; - manifold->type = b2Manifold::e_circles; - manifold->localNormal.SetZero(); - manifold->localPoint = P; - manifold->points[0].id.key = 0; - manifold->points[0].id.cf = cf; - manifold->points[0].localPoint = circleB->m_p; - return; - } - - // Region B - if (u <= 0.0f) - { - b2Vec2 P = B; - b2Vec2 d = Q - P; - float32 dd = b2Dot(d, d); - if (dd > radius * radius) - { - return; - } - - // Is there an edge connected to B? - if (edgeA->m_hasVertex3) - { - b2Vec2 B2 = edgeA->m_vertex3; - b2Vec2 A2 = B; - b2Vec2 e2 = B2 - A2; - float32 v2 = b2Dot(e2, Q - A2); - - // Is the circle in Region AB of the next edge? - if (v2 > 0.0f) - { - return; - } - } - - cf.indexA = 1; - cf.typeA = b2ContactFeature::e_vertex; - manifold->pointCount = 1; - manifold->type = b2Manifold::e_circles; - manifold->localNormal.SetZero(); - manifold->localPoint = P; - manifold->points[0].id.key = 0; - manifold->points[0].id.cf = cf; - manifold->points[0].localPoint = circleB->m_p; - return; - } - - // Region AB - float32 den = b2Dot(e, e); - b2Assert(den > 0.0f); - b2Vec2 P = (1.0f / den) * (u * A + v * B); - b2Vec2 d = Q - P; - float32 dd = b2Dot(d, d); - if (dd > radius * radius) - { - return; - } - - b2Vec2 n(-e.y, e.x); - if (b2Dot(n, Q - A) < 0.0f) - { - n.Set(-n.x, -n.y); - } - n.Normalize(); - - cf.indexA = 0; - cf.typeA = b2ContactFeature::e_face; - manifold->pointCount = 1; - manifold->type = b2Manifold::e_faceA; - manifold->localNormal = n; - manifold->localPoint = A; - manifold->points[0].id.key = 0; - manifold->points[0].id.cf = cf; - manifold->points[0].localPoint = circleB->m_p; -} - -struct b2EPAxis -{ - enum Type - { - e_unknown, - e_edgeA, - e_edgeB - }; - - Type type; - int32 index; - float32 separation; -}; - -// Edge shape plus more stuff. -struct b2FatEdge -{ - b2Vec2 v0, v1, v2, v3; - b2Vec2 normal; - bool hasVertex0, hasVertex3; -}; - -// This lets us treate and edge shape and a polygon in the same -// way in the SAT collider. -struct b2EPProxy -{ - b2Vec2 vertices[b2_maxPolygonVertices]; - b2Vec2 normals[b2_maxPolygonVertices]; - b2Vec2 centroid; - int32 count; -}; - -// This class collides and edge and a polygon, taking into account edge adjacency. -struct b2EPCollider -{ - b2EPCollider(const b2EdgeShape* edgeA, const b2Transform& xfA, - const b2PolygonShape* polygonB_in, const b2Transform& xfB); - - void Collide(b2Manifold* manifold); - - void ComputeAdjacency(); - b2EPAxis ComputeEdgeSeparation(); - b2EPAxis ComputePolygonSeparation(); - void FindIncidentEdge(b2ClipVertex c[2], const b2EPProxy* proxy1, int32 edge1, const b2EPProxy* proxy2); - - b2FatEdge m_edgeA; - - b2EPProxy m_proxyA, m_proxyB; - - b2Transform m_xf; - b2Vec2 m_normal0, m_normal2; - b2Vec2 m_limit11, m_limit12; - b2Vec2 m_limit21, m_limit22; - float32 m_radius; -}; - -b2EPCollider::b2EPCollider(const b2EdgeShape* edgeA, const b2Transform& xfA, - const b2PolygonShape* polygonB, const b2Transform& xfB) -{ - m_xf = b2MulT(xfA, xfB); - - // Edge geometry - m_edgeA.v0 = edgeA->m_vertex0; - m_edgeA.v1 = edgeA->m_vertex1; - m_edgeA.v2 = edgeA->m_vertex2; - m_edgeA.v3 = edgeA->m_vertex3; - b2Vec2 e = m_edgeA.v2 - m_edgeA.v1; - - // Normal points outwards in CCW order. - m_edgeA.normal.Set(e.y, -e.x); - m_edgeA.normal.Normalize(); - m_edgeA.hasVertex0 = edgeA->m_hasVertex0; - m_edgeA.hasVertex3 = edgeA->m_hasVertex3; - - // Proxy for edge - m_proxyA.vertices[0] = m_edgeA.v1; - m_proxyA.vertices[1] = m_edgeA.v2; - m_proxyA.normals[0] = m_edgeA.normal; - m_proxyA.normals[1] = -m_edgeA.normal; - m_proxyA.centroid = 0.5f * (m_edgeA.v1 + m_edgeA.v2); - m_proxyA.count = 2; - - // Proxy for polygon - m_proxyB.count = polygonB->m_vertexCount; - m_proxyB.centroid = b2Mul(m_xf, polygonB->m_centroid); - for (int32 i = 0; i < polygonB->m_vertexCount; ++i) - { - m_proxyB.vertices[i] = b2Mul(m_xf, polygonB->m_vertices[i]); - m_proxyB.normals[i] = b2Mul(m_xf.R, polygonB->m_normals[i]); - } - - m_radius = 2.0f * b2_polygonRadius; - - m_limit11.SetZero(); - m_limit12.SetZero(); - m_limit21.SetZero(); - m_limit22.SetZero(); -} - -// Collide an edge and polygon. This uses the SAT and clipping to produce up to 2 contact points. -// Edge adjacency is handle to produce locally valid contact points and normals. This is intended -// to allow the polygon to slide smoothly over an edge chain. -// -// Algorithm -// 1. Classify front-side or back-side collision with edge. -// 2. Compute separation -// 3. Process adjacent edges -// 4. Classify adjacent edge as convex, flat, null, or concave -// 5. Skip null or concave edges. Concave edges get a separate manifold. -// 6. If the edge is flat, compute contact points as normal. Discard boundary points. -// 7. If the edge is convex, compute it's separation. -// 8. Use the minimum separation of up to three edges. If the minimum separation -// is not the primary edge, return. -// 9. If the minimum separation is the primary edge, compute the contact points and return. -void b2EPCollider::Collide(b2Manifold* manifold) -{ - manifold->pointCount = 0; - - ComputeAdjacency(); - - b2EPAxis edgeAxis = ComputeEdgeSeparation(); - - // If no valid normal can be found than this edge should not collide. - // This can happen on the middle edge of a 3-edge zig-zag chain. - if (edgeAxis.type == b2EPAxis::e_unknown) - { - return; - } - - if (edgeAxis.separation > m_radius) - { - return; - } - - b2EPAxis polygonAxis = ComputePolygonSeparation(); - if (polygonAxis.type != b2EPAxis::e_unknown && polygonAxis.separation > m_radius) - { - return; - } - - // Use hysteresis for jitter reduction. - const float32 k_relativeTol = 0.98f; - const float32 k_absoluteTol = 0.001f; - - b2EPAxis primaryAxis; - if (polygonAxis.type == b2EPAxis::e_unknown) - { - primaryAxis = edgeAxis; - } - else if (polygonAxis.separation > k_relativeTol * edgeAxis.separation + k_absoluteTol) - { - primaryAxis = polygonAxis; - } - else - { - primaryAxis = edgeAxis; - } - - b2EPProxy* proxy1; - b2EPProxy* proxy2; - b2ClipVertex incidentEdge[2]; - if (primaryAxis.type == b2EPAxis::e_edgeA) - { - proxy1 = &m_proxyA; - proxy2 = &m_proxyB; - manifold->type = b2Manifold::e_faceA; - } - else - { - proxy1 = &m_proxyB; - proxy2 = &m_proxyA; - manifold->type = b2Manifold::e_faceB; - } - - int32 edge1 = primaryAxis.index; - - FindIncidentEdge(incidentEdge, proxy1, primaryAxis.index, proxy2); - int32 count1 = proxy1->count; - const b2Vec2* vertices1 = proxy1->vertices; - - int32 iv1 = edge1; - int32 iv2 = edge1 + 1 < count1 ? edge1 + 1 : 0; - - b2Vec2 v11 = vertices1[iv1]; - b2Vec2 v12 = vertices1[iv2]; - - b2Vec2 tangent = v12 - v11; - tangent.Normalize(); - - b2Vec2 normal = b2Cross(tangent, 1.0f); - b2Vec2 planePoint = 0.5f * (v11 + v12); - - // Face offset. - float32 frontOffset = b2Dot(normal, v11); - - // Side offsets, extended by polytope skin thickness. - float32 sideOffset1 = -b2Dot(tangent, v11) + m_radius; - float32 sideOffset2 = b2Dot(tangent, v12) + m_radius; - - // Clip incident edge against extruded edge1 side edges. - b2ClipVertex clipPoints1[2]; - b2ClipVertex clipPoints2[2]; - int np; - - // Clip to box side 1 - np = b2ClipSegmentToLine(clipPoints1, incidentEdge, -tangent, sideOffset1, iv1); - - if (np < b2_maxManifoldPoints) - { - return; - } - - // Clip to negative box side 1 - np = b2ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2, iv2); - - if (np < b2_maxManifoldPoints) - { - return; - } - - // Now clipPoints2 contains the clipped points. - if (primaryAxis.type == b2EPAxis::e_edgeA) - { - manifold->localNormal = normal; - manifold->localPoint = planePoint; - } - else - { - manifold->localNormal = b2MulT(m_xf.R, normal); - manifold->localPoint = b2MulT(m_xf, planePoint); - } - - int32 pointCount = 0; - for (int32 i = 0; i < b2_maxManifoldPoints; ++i) - { - float32 separation; - - separation = b2Dot(normal, clipPoints2[i].v) - frontOffset; - - if (separation <= m_radius) - { - b2ManifoldPoint* cp = manifold->points + pointCount; - - if (primaryAxis.type == b2EPAxis::e_edgeA) - { - cp->localPoint = b2MulT(m_xf, clipPoints2[i].v); - cp->id = clipPoints2[i].id; - } - else - { - cp->localPoint = clipPoints2[i].v; - cp->id.cf.typeA = clipPoints2[i].id.cf.typeB; - cp->id.cf.typeB = clipPoints2[i].id.cf.typeA; - cp->id.cf.indexA = clipPoints2[i].id.cf.indexB; - cp->id.cf.indexB = clipPoints2[i].id.cf.indexA; - } - - ++pointCount; - } - } - - manifold->pointCount = pointCount; -} - -// Compute allowable normal ranges based on adjacency. -// A normal n is allowable iff: -// cross(n, n1) >= 0.0f && cross(n2, n) >= 0.0f -// n points from A to B (edge to polygon) -void b2EPCollider::ComputeAdjacency() -{ - b2Vec2 v0 = m_edgeA.v0; - b2Vec2 v1 = m_edgeA.v1; - b2Vec2 v2 = m_edgeA.v2; - b2Vec2 v3 = m_edgeA.v3; - - // Determine allowable the normal regions based on adjacency. - // Note: it may be possible that no normal is admissable. - b2Vec2 centerB = m_proxyB.centroid; - if (m_edgeA.hasVertex0) - { - b2Vec2 e0 = v1 - v0; - b2Vec2 e1 = v2 - v1; - b2Vec2 n0(e0.y, -e0.x); - b2Vec2 n1(e1.y, -e1.x); - n0.Normalize(); - n1.Normalize(); - - bool convex = b2Cross(n0, n1) >= 0.0f; - bool front0 = b2Dot(n0, centerB - v0) >= 0.0f; - bool front1 = b2Dot(n1, centerB - v1) >= 0.0f; - - if (convex) - { - if (front0 || front1) - { - m_limit11 = n1; - m_limit12 = n0; - } - else - { - m_limit11 = -n1; - m_limit12 = -n0; - } - } - else - { - if (front0 && front1) - { - m_limit11 = n0; - m_limit12 = n1; - } - else - { - m_limit11 = -n0; - m_limit12 = -n1; - } - } - } - else - { - m_limit11.SetZero(); - m_limit12.SetZero(); - } - - if (m_edgeA.hasVertex3) - { - b2Vec2 e1 = v2 - v1; - b2Vec2 e2 = v3 - v2; - b2Vec2 n1(e1.y, -e1.x); - b2Vec2 n2(e2.y, -e2.x); - n1.Normalize(); - n2.Normalize(); - - bool convex = b2Cross(n1, n2) >= 0.0f; - bool front1 = b2Dot(n1, centerB - v1) >= 0.0f; - bool front2 = b2Dot(n2, centerB - v2) >= 0.0f; - - if (convex) - { - if (front1 || front2) - { - m_limit21 = n2; - m_limit22 = n1; - } - else - { - m_limit21 = -n2; - m_limit22 = -n1; - } - } - else - { - if (front1 && front2) - { - m_limit21 = n1; - m_limit22 = n2; - } - else - { - m_limit21 = -n1; - m_limit22 = -n2; - } - } - } - else - { - m_limit21.SetZero(); - m_limit22.SetZero(); - } -} - -b2EPAxis b2EPCollider::ComputeEdgeSeparation() -{ - // EdgeA separation - b2EPAxis bestAxis; - bestAxis.type = b2EPAxis::e_unknown; - bestAxis.index = -1; - bestAxis.separation = -FLT_MAX; - b2Vec2 normals[2] = {m_edgeA.normal, -m_edgeA.normal}; - - for (int32 i = 0; i < 2; ++i) - { - b2Vec2 n = normals[i]; - - // Adjacency - bool valid1 = b2Cross(n, m_limit11) >= -b2_angularSlop && b2Cross(m_limit12, n) >= -b2_angularSlop; - bool valid2 = b2Cross(n, m_limit21) >= -b2_angularSlop && b2Cross(m_limit22, n) >= -b2_angularSlop; - - if (valid1 == false || valid2 == false) - { - continue; - } - - b2EPAxis axis; - axis.type = b2EPAxis::e_edgeA; - axis.index = i; - axis.separation = FLT_MAX; - - for (int32 j = 0; j < m_proxyB.count; ++j) - { - float32 s = b2Dot(n, m_proxyB.vertices[j] - m_edgeA.v1); - if (s < axis.separation) - { - axis.separation = s; - } - } - - if (axis.separation > m_radius) - { - return axis; - } - - if (axis.separation > bestAxis.separation) - { - bestAxis = axis; - } - } - - return bestAxis; -} - -b2EPAxis b2EPCollider::ComputePolygonSeparation() -{ - b2EPAxis axis; - axis.type = b2EPAxis::e_unknown; - axis.index = -1; - axis.separation = -FLT_MAX; - for (int32 i = 0; i < m_proxyB.count; ++i) - { - b2Vec2 n = -m_proxyB.normals[i]; - - // Adjacency - bool valid1 = b2Cross(n, m_limit11) >= -b2_angularSlop && b2Cross(m_limit12, n) >= -b2_angularSlop; - bool valid2 = b2Cross(n, m_limit21) >= -b2_angularSlop && b2Cross(m_limit22, n) >= -b2_angularSlop; - - if (valid1 == false && valid2 == false) - { - continue; - } - - float32 s1 = b2Dot(n, m_proxyB.vertices[i] - m_edgeA.v1); - float32 s2 = b2Dot(n, m_proxyB.vertices[i] - m_edgeA.v2); - float32 s = b2Min(s1, s2); - - if (s > m_radius) - { - axis.type = b2EPAxis::e_edgeB; - axis.index = i; - axis.separation = s; - } - - if (s > axis.separation) - { - axis.type = b2EPAxis::e_edgeB; - axis.index = i; - axis.separation = s; - } - } - - return axis; -} - -void b2EPCollider::FindIncidentEdge(b2ClipVertex c[2], const b2EPProxy* proxy1, int32 edge1, const b2EPProxy* proxy2) -{ - int32 count1 = proxy1->count; - const b2Vec2* normals1 = proxy1->normals; - - int32 count2 = proxy2->count; - const b2Vec2* vertices2 = proxy2->vertices; - const b2Vec2* normals2 = proxy2->normals; - - b2Assert(0 <= edge1 && edge1 < count1); - - // Get the normal of the reference edge in proxy2's frame. - b2Vec2 normal1 = normals1[edge1]; - - // Find the incident edge on proxy2. - int32 index = 0; - float32 minDot = b2_maxFloat; - for (int32 i = 0; i < count2; ++i) - { - float32 dot = b2Dot(normal1, normals2[i]); - if (dot < minDot) - { - minDot = dot; - index = i; - } - } - - // Build the clip vertices for the incident edge. - int32 i1 = index; - int32 i2 = i1 + 1 < count2 ? i1 + 1 : 0; - - c[0].v = vertices2[i1]; - c[0].id.cf.indexA = (uint8)edge1; - c[0].id.cf.indexB = (uint8)i1; - c[0].id.cf.typeA = b2ContactFeature::e_face; - c[0].id.cf.typeB = b2ContactFeature::e_vertex; - - c[1].v = vertices2[i2]; - c[1].id.cf.indexA = (uint8)edge1; - c[1].id.cf.indexB = (uint8)i2; - c[1].id.cf.typeA = b2ContactFeature::e_face; - c[1].id.cf.typeB = b2ContactFeature::e_vertex; -} - -void b2CollideEdgeAndPolygon( b2Manifold* manifold, - const b2EdgeShape* edgeA, const b2Transform& xfA, - const b2PolygonShape* polygonB, const b2Transform& xfB) -{ - b2EPCollider collider(edgeA, xfA, polygonB, xfB); - collider.Collide(manifold); -} diff --git a/libs/box2d/src/Box2D/Collision/b2CollidePolygon.cpp b/libs/box2d/src/Box2D/Collision/b2CollidePolygon.cpp index bc53465..b37b7ba 100644 --- a/libs/box2d/src/Box2D/Collision/b2CollidePolygon.cpp +++ b/libs/box2d/src/Box2D/Collision/b2CollidePolygon.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -173,16 +173,14 @@ static void b2FindIncidentEdge(b2ClipVertex c[2], int32 i2 = i1 + 1 < count2 ? i1 + 1 : 0; c[0].v = b2Mul(xf2, vertices2[i1]); - c[0].id.cf.indexA = (uint8)edge1; - c[0].id.cf.indexB = (uint8)i1; - c[0].id.cf.typeA = b2ContactFeature::e_face; - c[0].id.cf.typeB = b2ContactFeature::e_vertex; + c[0].id.features.referenceEdge = (uint8)edge1; + c[0].id.features.incidentEdge = (uint8)i1; + c[0].id.features.incidentVertex = 0; c[1].v = b2Mul(xf2, vertices2[i2]); - c[1].id.cf.indexA = (uint8)edge1; - c[1].id.cf.indexB = (uint8)i2; - c[1].id.cf.typeA = b2ContactFeature::e_face; - c[1].id.cf.typeB = b2ContactFeature::e_vertex; + c[1].id.features.referenceEdge = (uint8)edge1; + c[1].id.features.incidentEdge = (uint8)i2; + c[1].id.features.incidentVertex = 1; } // Find edge normal of max separation on A - return if separating axis is found @@ -244,11 +242,8 @@ void b2CollidePolygons(b2Manifold* manifold, int32 count1 = poly1->m_vertexCount; const b2Vec2* vertices1 = poly1->m_vertices; - int32 iv1 = edge1; - int32 iv2 = edge1 + 1 < count1 ? edge1 + 1 : 0; - - b2Vec2 v11 = vertices1[iv1]; - b2Vec2 v12 = vertices1[iv2]; + b2Vec2 v11 = vertices1[edge1]; + b2Vec2 v12 = edge1 + 1 < count1 ? vertices1[edge1+1] : vertices1[0]; b2Vec2 localTangent = v12 - v11; localTangent.Normalize(); @@ -275,13 +270,13 @@ void b2CollidePolygons(b2Manifold* manifold, int np; // Clip to box side 1 - np = b2ClipSegmentToLine(clipPoints1, incidentEdge, -tangent, sideOffset1, iv1); + np = b2ClipSegmentToLine(clipPoints1, incidentEdge, -tangent, sideOffset1); if (np < 2) return; // Clip to negative box side 1 - np = b2ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2, iv2); + np = b2ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2); if (np < 2) { @@ -302,15 +297,7 @@ void b2CollidePolygons(b2Manifold* manifold, b2ManifoldPoint* cp = manifold->points + pointCount; cp->localPoint = b2MulT(xf2, clipPoints2[i].v); cp->id = clipPoints2[i].id; - if (flip) - { - // Swap features - b2ContactFeature cf = cp->id.cf; - cp->id.cf.indexA = cf.indexB; - cp->id.cf.indexB = cf.indexA; - cp->id.cf.typeA = cf.typeB; - cp->id.cf.typeB = cf.typeA; - } + cp->id.features.flip = flip; ++pointCount; } } diff --git a/libs/box2d/src/Box2D/Collision/b2Collision.cpp b/libs/box2d/src/Box2D/Collision/b2Collision.cpp index f317cb9..a86c7c5 100644 --- a/libs/box2d/src/Box2D/Collision/b2Collision.cpp +++ b/libs/box2d/src/Box2D/Collision/b2Collision.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2007-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 @@ -196,7 +196,7 @@ bool b2AABB::RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const // Sutherland-Hodgman clipping. int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2], - const b2Vec2& normal, float32 offset, int32 vertexIndexA) + const b2Vec2& normal, float32 offset) { // Start with no output points int32 numOut = 0; @@ -215,25 +215,26 @@ int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2], // Find intersection point of edge and plane float32 interp = distance0 / (distance0 - distance1); vOut[numOut].v = vIn[0].v + interp * (vIn[1].v - vIn[0].v); - - // VertexA is hitting edgeB. - vOut[numOut].id.cf.indexA = vertexIndexA; - vOut[numOut].id.cf.indexB = vIn[0].id.cf.indexB; - vOut[numOut].id.cf.typeA = b2ContactFeature::e_vertex; - vOut[numOut].id.cf.typeB = b2ContactFeature::e_face; + if (distance0 > 0.0f) + { + vOut[numOut].id = vIn[0].id; + } + else + { + vOut[numOut].id = vIn[1].id; + } ++numOut; } return numOut; } -bool b2TestOverlap( const b2Shape* shapeA, int32 indexA, - const b2Shape* shapeB, int32 indexB, - const b2Transform& xfA, const b2Transform& xfB) +bool b2TestOverlap(const b2Shape* shapeA, const b2Shape* shapeB, + const b2Transform& xfA, const b2Transform& xfB) { b2DistanceInput input; - input.proxyA.Set(shapeA, indexA); - input.proxyB.Set(shapeB, indexB); + input.proxyA.Set(shapeA); + input.proxyB.Set(shapeB); input.transformA = xfA; input.transformB = xfB; input.useRadii = true; diff --git a/libs/box2d/src/Box2D/Collision/b2Collision.h b/libs/box2d/src/Box2D/Collision/b2Collision.h index 2bc110e..baffdbd 100644 --- a/libs/box2d/src/Box2D/Collision/b2Collision.h +++ b/libs/box2d/src/Box2D/Collision/b2Collision.h @@ -1,5 +1,5 @@ /* -* 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 @@ -28,31 +28,21 @@ class b2Shape; class b2CircleShape; -class b2EdgeShape; class b2PolygonShape; const uint8 b2_nullFeature = UCHAR_MAX; -/// The features that intersect to form the contact point -/// This must be 4 bytes or less. -struct b2ContactFeature -{ - enum Type - { - e_vertex = 0, - e_face = 1 - }; - - uint8 indexA; ///< Feature index on shapeA - uint8 indexB; ///< Feature index on shapeB - uint8 typeA; ///< The feature type on shapeA - uint8 typeB; ///< The feature type on shapeB -}; - /// Contact ids to facilitate warm starting. union b2ContactID { - b2ContactFeature cf; + /// The features that intersect to form the contact point + struct Features + { + uint8 referenceEdge; ///< The edge that defines the outward contact normal. + uint8 incidentEdge; ///< The edge most anti-parallel to the reference edge. + uint8 incidentVertex; ///< The vertex (0 or 1) on the incident edge that was clipped. + uint8 flip; ///< A value of 1 indicates that the reference edge is on shape2. + } features; uint32 key; ///< Used to quickly compare contact ids. }; @@ -175,21 +165,6 @@ struct b2AABB return 0.5f * (upperBound - lowerBound); } - /// Get the perimeter length - float32 GetPerimeter() const - { - float32 wx = upperBound.x - lowerBound.x; - float32 wy = upperBound.y - lowerBound.y; - return 2.0f * (wx + wy); - } - - /// Combine an AABB into this one. - void Combine(const b2AABB& aabb) - { - lowerBound = b2Min(lowerBound, aabb.lowerBound); - upperBound = b2Max(upperBound, aabb.upperBound); - } - /// Combine two AABBs into this one. void Combine(const b2AABB& aabb1, const b2AABB& aabb2) { @@ -216,37 +191,26 @@ struct b2AABB /// Compute the collision manifold between two circles. void b2CollideCircles(b2Manifold* manifold, - const b2CircleShape* circleA, const b2Transform& xfA, - const b2CircleShape* circleB, const b2Transform& xfB); + const b2CircleShape* circle1, const b2Transform& xf1, + const b2CircleShape* circle2, const b2Transform& xf2); /// Compute the collision manifold between a polygon and a circle. void b2CollidePolygonAndCircle(b2Manifold* manifold, - const b2PolygonShape* polygonA, const b2Transform& xfA, - const b2CircleShape* circleB, const b2Transform& xfB); + const b2PolygonShape* polygon, const b2Transform& xf1, + const b2CircleShape* circle, const b2Transform& xf2); /// Compute the collision manifold between two polygons. void b2CollidePolygons(b2Manifold* manifold, - const b2PolygonShape* polygonA, const b2Transform& xfA, - const b2PolygonShape* polygonB, const b2Transform& xfB); - -/// Compute the collision manifold between an edge and a circle. -void b2CollideEdgeAndCircle(b2Manifold* manifold, - const b2EdgeShape* polygonA, const b2Transform& xfA, - const b2CircleShape* circleB, const b2Transform& xfB); - -/// Compute the collision manifold between an edge and a circle. -void b2CollideEdgeAndPolygon(b2Manifold* manifold, - const b2EdgeShape* edgeA, const b2Transform& xfA, - const b2PolygonShape* circleB, const b2Transform& xfB); + const b2PolygonShape* polygon1, const b2Transform& xf1, + const b2PolygonShape* polygon2, const b2Transform& xf2); /// Clipping for contact manifolds. int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2], - const b2Vec2& normal, float32 offset, int32 vertexIndexA); + const b2Vec2& normal, float32 offset); /// Determine if two generic shapes overlap. -bool b2TestOverlap( const b2Shape* shapeA, int32 indexA, - const b2Shape* shapeB, int32 indexB, - const b2Transform& xfA, const b2Transform& xfB); +bool b2TestOverlap(const b2Shape* shapeA, const b2Shape* shapeB, + const b2Transform& xfA, const b2Transform& xfB); // ---------------- Inline Functions ------------------------------------------ diff --git a/libs/box2d/src/Box2D/Collision/b2Distance.cpp b/libs/box2d/src/Box2D/Collision/b2Distance.cpp index 39567dd..f95c82f 100644 --- a/libs/box2d/src/Box2D/Collision/b2Distance.cpp +++ b/libs/box2d/src/Box2D/Collision/b2Distance.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2007-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 @@ -18,14 +18,12 @@ #include #include -#include -#include #include // GJK using Voronoi regions (Christer Ericson) and Barycentric coordinates. int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters; -void b2DistanceProxy::Set(const b2Shape* shape, int32 index) +void b2DistanceProxy::Set(const b2Shape* shape) { switch (shape->GetType()) { @@ -47,36 +45,6 @@ void b2DistanceProxy::Set(const b2Shape* shape, int32 index) } break; - case b2Shape::e_loop: - { - const b2LoopShape* loop = (b2LoopShape*)shape; - b2Assert(0 <= index && index < loop->GetCount()); - - m_buffer[0] = loop->GetVertex(index); - if (index + 1 < loop->GetCount()) - { - m_buffer[1] = loop->GetVertex(index + 1); - } - else - { - m_buffer[1] = loop->GetVertex(0); - } - - m_vertices = m_buffer; - m_count = 2; - m_radius = loop->m_radius; - } - break; - - case b2Shape::e_edge: - { - const b2EdgeShape* edge = (b2EdgeShape*)shape; - m_vertices = &edge->m_vertex1; - m_count = 2; - m_radius = edge->m_radius; - } - break; - default: b2Assert(false); } diff --git a/libs/box2d/src/Box2D/Collision/b2Distance.h b/libs/box2d/src/Box2D/Collision/b2Distance.h index 54ed1e1..e56ea0a 100644 --- a/libs/box2d/src/Box2D/Collision/b2Distance.h +++ b/libs/box2d/src/Box2D/Collision/b2Distance.h @@ -1,6 +1,6 @@ /* -* 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 @@ -21,6 +21,7 @@ #define B2_DISTANCE_H #include +#include class b2Shape; @@ -32,7 +33,7 @@ struct b2DistanceProxy /// Initialize the proxy using the given shape. The shape /// must remain in scope while the proxy is in use. - void Set(const b2Shape* shape, int32 index); + void Set(const b2Shape* shape); /// Get the supporting vertex index in the given direction. int32 GetSupport(const b2Vec2& d) const; @@ -46,7 +47,6 @@ struct b2DistanceProxy /// Get a vertex by index. Used by b2Distance. const b2Vec2& GetVertex(int32 index) const; - b2Vec2 m_buffer[2]; const b2Vec2* m_vertices; int32 m_count; float32 m_radius; diff --git a/libs/box2d/src/Box2D/Collision/b2DynamicTree.cpp b/libs/box2d/src/Box2D/Collision/b2DynamicTree.cpp index f43ea1e..d8a05eb 100644 --- a/libs/box2d/src/Box2D/Collision/b2DynamicTree.cpp +++ b/libs/box2d/src/Box2D/Collision/b2DynamicTree.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2009 Erin Catto http://www.box2d.org +* Copyright (c) 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 @@ -19,10 +19,6 @@ #include #include #include -using namespace std; - - -#if B2_USE_DYNAMIC_TREE b2DynamicTree::b2DynamicTree() { @@ -30,17 +26,15 @@ b2DynamicTree::b2DynamicTree() m_nodeCapacity = 16; m_nodeCount = 0; - m_nodes = (b2TreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2TreeNode)); - memset(m_nodes, 0, m_nodeCapacity * sizeof(b2TreeNode)); + m_nodes = (b2DynamicTreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2DynamicTreeNode)); + memset(m_nodes, 0, m_nodeCapacity * sizeof(b2DynamicTreeNode)); // Build a linked list for the free list. for (int32 i = 0; i < m_nodeCapacity - 1; ++i) { m_nodes[i].next = i + 1; - m_nodes[i].height = -1; } m_nodes[m_nodeCapacity-1].next = b2_nullNode; - m_nodes[m_nodeCapacity-1].height = -1; m_freeList = 0; m_path = 0; @@ -63,10 +57,10 @@ int32 b2DynamicTree::AllocateNode() b2Assert(m_nodeCount == m_nodeCapacity); // The free list is empty. Rebuild a bigger pool. - b2TreeNode* oldNodes = m_nodes; + b2DynamicTreeNode* oldNodes = m_nodes; m_nodeCapacity *= 2; - m_nodes = (b2TreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2TreeNode)); - memcpy(m_nodes, oldNodes, m_nodeCount * sizeof(b2TreeNode)); + m_nodes = (b2DynamicTreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2DynamicTreeNode)); + memcpy(m_nodes, oldNodes, m_nodeCount * sizeof(b2DynamicTreeNode)); b2Free(oldNodes); // Build a linked list for the free list. The parent @@ -74,10 +68,8 @@ int32 b2DynamicTree::AllocateNode() for (int32 i = m_nodeCount; i < m_nodeCapacity - 1; ++i) { m_nodes[i].next = i + 1; - m_nodes[i].height = -1; } m_nodes[m_nodeCapacity-1].next = b2_nullNode; - m_nodes[m_nodeCapacity-1].height = -1; m_freeList = m_nodeCount; } @@ -87,8 +79,6 @@ int32 b2DynamicTree::AllocateNode() m_nodes[nodeId].parent = b2_nullNode; m_nodes[nodeId].child1 = b2_nullNode; m_nodes[nodeId].child2 = b2_nullNode; - m_nodes[nodeId].height = 0; - m_nodes[nodeId].userData = NULL; ++m_nodeCount; return nodeId; } @@ -99,7 +89,6 @@ void b2DynamicTree::FreeNode(int32 nodeId) b2Assert(0 <= nodeId && nodeId < m_nodeCapacity); b2Assert(0 < m_nodeCount); m_nodes[nodeId].next = m_freeList; - m_nodes[nodeId].height = -1; m_freeList = nodeId; --m_nodeCount; } @@ -116,10 +105,20 @@ int32 b2DynamicTree::CreateProxy(const b2AABB& aabb, void* userData) m_nodes[proxyId].aabb.lowerBound = aabb.lowerBound - r; m_nodes[proxyId].aabb.upperBound = aabb.upperBound + r; m_nodes[proxyId].userData = userData; - m_nodes[proxyId].height = 0; InsertLeaf(proxyId); + // Rebalance if necessary. + int32 iterationCount = m_nodeCount >> 4; + int32 tryCount = 0; + int32 height = ComputeHeight(); + while (height > 64 && tryCount < 10) + { + Rebalance(iterationCount); + height = ComputeHeight(); + ++tryCount; + } + return proxyId; } @@ -189,133 +188,79 @@ void b2DynamicTree::InsertLeaf(int32 leaf) return; } - // Find the best sibling for this node - b2AABB leafAABB = m_nodes[leaf].aabb; - int32 index = m_root; - while (m_nodes[index].IsLeaf() == false) + // Find the best sibling for this node. + b2Vec2 center = m_nodes[leaf].aabb.GetCenter(); + int32 sibling = m_root; + if (m_nodes[sibling].IsLeaf() == false) { - int32 child1 = m_nodes[index].child1; - int32 child2 = m_nodes[index].child2; - - float32 area = m_nodes[index].aabb.GetPerimeter(); + do + { + int32 child1 = m_nodes[sibling].child1; + int32 child2 = m_nodes[sibling].child2; - b2AABB combinedAABB; - combinedAABB.Combine(m_nodes[index].aabb, leafAABB); - float32 combinedArea = combinedAABB.GetPerimeter(); + b2Vec2 delta1 = b2Abs(m_nodes[child1].aabb.GetCenter() - center); + b2Vec2 delta2 = b2Abs(m_nodes[child2].aabb.GetCenter() - center); - // Cost of creating a new parent for this node and the new leaf - float32 cost = 2.0f * combinedArea; + float32 norm1 = delta1.x + delta1.y; + float32 norm2 = delta2.x + delta2.y; - // Minimum cost of pushing the leaf further down the tree - float32 inheritanceCost = 2.0f * (combinedArea - area); + if (norm1 < norm2) + { + sibling = child1; + } + else + { + sibling = child2; + } - // Cost of descending into child1 - float32 cost1; - if (m_nodes[child1].IsLeaf()) - { - b2AABB aabb; - aabb.Combine(leafAABB, m_nodes[child1].aabb); - cost1 = aabb.GetPerimeter() + inheritanceCost; - } - else - { - b2AABB aabb; - aabb.Combine(leafAABB, m_nodes[child1].aabb); - float32 oldArea = m_nodes[child1].aabb.GetPerimeter(); - float32 newArea = aabb.GetPerimeter(); - cost1 = (newArea - oldArea) + inheritanceCost; - } - - // Cost of descending into child2 - float32 cost2; - if (m_nodes[child2].IsLeaf()) - { - b2AABB aabb; - aabb.Combine(leafAABB, m_nodes[child2].aabb); - cost2 = aabb.GetPerimeter() + inheritanceCost; - } - else - { - b2AABB aabb; - aabb.Combine(leafAABB, m_nodes[child2].aabb); - float32 oldArea = m_nodes[child2].aabb.GetPerimeter(); - float32 newArea = aabb.GetPerimeter(); - cost2 = newArea - oldArea + inheritanceCost; } + while(m_nodes[sibling].IsLeaf() == false); + } - // Descend according to the minimum cost. - if (cost < cost1 && cost < cost2) - { - break; - } + // Create a parent for the siblings. + int32 node1 = m_nodes[sibling].parent; + int32 node2 = AllocateNode(); + m_nodes[node2].parent = node1; + m_nodes[node2].userData = NULL; + m_nodes[node2].aabb.Combine(m_nodes[leaf].aabb, m_nodes[sibling].aabb); - // Descend - if (cost1 < cost2) + if (node1 != b2_nullNode) + { + if (m_nodes[m_nodes[sibling].parent].child1 == sibling) { - index = child1; + m_nodes[node1].child1 = node2; } else { - index = child2; + m_nodes[node1].child2 = node2; } - } - int32 sibling = index; + m_nodes[node2].child1 = sibling; + m_nodes[node2].child2 = leaf; + m_nodes[sibling].parent = node2; + m_nodes[leaf].parent = node2; - // Create a new parent. - int32 oldParent = m_nodes[sibling].parent; - int32 newParent = AllocateNode(); - m_nodes[newParent].parent = oldParent; - m_nodes[newParent].userData = NULL; - m_nodes[newParent].aabb.Combine(leafAABB, m_nodes[sibling].aabb); - m_nodes[newParent].height = m_nodes[sibling].height + 1; - - if (oldParent != b2_nullNode) - { - // The sibling was not the root. - if (m_nodes[oldParent].child1 == sibling) - { - m_nodes[oldParent].child1 = newParent; - } - else + do { - m_nodes[oldParent].child2 = newParent; - } + if (m_nodes[node1].aabb.Contains(m_nodes[node2].aabb)) + { + break; + } - m_nodes[newParent].child1 = sibling; - m_nodes[newParent].child2 = leaf; - m_nodes[sibling].parent = newParent; - m_nodes[leaf].parent = newParent; + m_nodes[node1].aabb.Combine(m_nodes[m_nodes[node1].child1].aabb, m_nodes[m_nodes[node1].child2].aabb); + node2 = node1; + node1 = m_nodes[node1].parent; + } + while(node1 != b2_nullNode); } else { - // The sibling was the root. - m_nodes[newParent].child1 = sibling; - m_nodes[newParent].child2 = leaf; - m_nodes[sibling].parent = newParent; - m_nodes[leaf].parent = newParent; - m_root = newParent; + m_nodes[node2].child1 = sibling; + m_nodes[node2].child2 = leaf; + m_nodes[sibling].parent = node2; + m_nodes[leaf].parent = node2; + m_root = node2; } - - // Walk back up the tree fixing heights and AABBs - index = m_nodes[leaf].parent; - while (index != b2_nullNode) - { - index = Balance(index); - - int32 child1 = m_nodes[index].child1; - int32 child2 = m_nodes[index].child2; - - b2Assert(child1 != b2_nullNode); - b2Assert(child2 != b2_nullNode); - - m_nodes[index].height = 1 + b2Max(m_nodes[child1].height, m_nodes[child2].height); - m_nodes[index].aabb.Combine(m_nodes[child1].aabb, m_nodes[child2].aabb); - - index = m_nodes[index].parent; - } - - //Validate(); } void b2DynamicTree::RemoveLeaf(int32 leaf) @@ -326,250 +271,89 @@ void b2DynamicTree::RemoveLeaf(int32 leaf) return; } - int32 parent = m_nodes[leaf].parent; - int32 grandParent = m_nodes[parent].parent; + int32 node2 = m_nodes[leaf].parent; + int32 node1 = m_nodes[node2].parent; int32 sibling; - if (m_nodes[parent].child1 == leaf) + if (m_nodes[node2].child1 == leaf) { - sibling = m_nodes[parent].child2; + sibling = m_nodes[node2].child2; } else { - sibling = m_nodes[parent].child1; + sibling = m_nodes[node2].child1; } - if (grandParent != b2_nullNode) + if (node1 != b2_nullNode) { - // Destroy parent and connect sibling to grandParent. - if (m_nodes[grandParent].child1 == parent) + // Destroy node2 and connect node1 to sibling. + if (m_nodes[node1].child1 == node2) { - m_nodes[grandParent].child1 = sibling; + m_nodes[node1].child1 = sibling; } else { - m_nodes[grandParent].child2 = sibling; + m_nodes[node1].child2 = sibling; } - m_nodes[sibling].parent = grandParent; - FreeNode(parent); + m_nodes[sibling].parent = node1; + FreeNode(node2); // Adjust ancestor bounds. - int32 index = grandParent; - while (index != b2_nullNode) + while (node1 != b2_nullNode) { - index = Balance(index); + b2AABB oldAABB = m_nodes[node1].aabb; + m_nodes[node1].aabb.Combine(m_nodes[m_nodes[node1].child1].aabb, m_nodes[m_nodes[node1].child2].aabb); - int32 child1 = m_nodes[index].child1; - int32 child2 = m_nodes[index].child2; - - m_nodes[index].aabb.Combine(m_nodes[child1].aabb, m_nodes[child2].aabb); - m_nodes[index].height = 1 + b2Max(m_nodes[child1].height, m_nodes[child2].height); + if (oldAABB.Contains(m_nodes[node1].aabb)) + { + break; + } - index = m_nodes[index].parent; + node1 = m_nodes[node1].parent; } } else { m_root = sibling; m_nodes[sibling].parent = b2_nullNode; - FreeNode(parent); - } - - //Validate(); -} - -// Perform a left or right rotation if node A is imbalanced. -// Returns the new root index. -int32 b2DynamicTree::Balance(int32 iA) -{ - b2Assert(iA != b2_nullNode); - - b2TreeNode* A = m_nodes + iA; - if (A->IsLeaf() || A->height < 2) - { - return iA; - } - - int32 iB = A->child1; - int32 iC = A->child2; - b2Assert(0 <= iB && iB < m_nodeCapacity); - b2Assert(0 <= iC && iC < m_nodeCapacity); - - b2TreeNode* B = m_nodes + iB; - b2TreeNode* C = m_nodes + iC; - - int32 balance = C->height - B->height; - - // Rotate C up - if (balance > 1) - { - int32 iF = C->child1; - int32 iG = C->child2; - b2TreeNode* F = m_nodes + iF; - b2TreeNode* G = m_nodes + iG; - b2Assert(0 <= iF && iF < m_nodeCapacity); - b2Assert(0 <= iG && iG < m_nodeCapacity); - - // Swap A and C - C->child1 = iA; - C->parent = A->parent; - A->parent = iC; - - // A's old parent should point to C - if (C->parent != b2_nullNode) - { - if (m_nodes[C->parent].child1 == iA) - { - m_nodes[C->parent].child1 = iC; - } - else - { - b2Assert(m_nodes[C->parent].child2 == iA); - m_nodes[C->parent].child2 = iC; - } - } - else - { - m_root = iC; - } - - // Rotate - if (F->height > G->height) - { - C->child2 = iF; - A->child2 = iG; - G->parent = iA; - A->aabb.Combine(B->aabb, G->aabb); - C->aabb.Combine(A->aabb, F->aabb); - - A->height = 1 + b2Max(B->height, G->height); - C->height = 1 + b2Max(A->height, F->height); - } - else - { - C->child2 = iG; - A->child2 = iF; - F->parent = iA; - A->aabb.Combine(B->aabb, F->aabb); - C->aabb.Combine(A->aabb, G->aabb); - - A->height = 1 + b2Max(B->height, F->height); - C->height = 1 + b2Max(A->height, G->height); - } - - return iC; + FreeNode(node2); } - - // Rotate B up - if (balance < -1) - { - int32 iD = B->child1; - int32 iE = B->child2; - b2TreeNode* D = m_nodes + iD; - b2TreeNode* E = m_nodes + iE; - b2Assert(0 <= iD && iD < m_nodeCapacity); - b2Assert(0 <= iE && iE < m_nodeCapacity); - - // Swap A and B - B->child1 = iA; - B->parent = A->parent; - A->parent = iB; - - // A's old parent should point to B - if (B->parent != b2_nullNode) - { - if (m_nodes[B->parent].child1 == iA) - { - m_nodes[B->parent].child1 = iB; - } - else - { - b2Assert(m_nodes[B->parent].child2 == iA); - m_nodes[B->parent].child2 = iB; - } - } - else - { - m_root = iB; - } - - // Rotate - if (D->height > E->height) - { - B->child2 = iD; - A->child1 = iE; - E->parent = iA; - A->aabb.Combine(C->aabb, E->aabb); - B->aabb.Combine(A->aabb, D->aabb); - - A->height = 1 + b2Max(C->height, E->height); - B->height = 1 + b2Max(A->height, D->height); - } - else - { - B->child2 = iE; - A->child1 = iD; - D->parent = iA; - A->aabb.Combine(C->aabb, D->aabb); - B->aabb.Combine(A->aabb, E->aabb); - - A->height = 1 + b2Max(C->height, D->height); - B->height = 1 + b2Max(A->height, E->height); - } - - return iB; - } - - return iA; } -int32 b2DynamicTree::GetHeight() const +void b2DynamicTree::Rebalance(int32 iterations) { if (m_root == b2_nullNode) { - return 0; + return; } - return m_nodes[m_root].height; -} - -// -float32 b2DynamicTree::GetAreaRatio() const -{ - if (m_root == b2_nullNode) + for (int32 i = 0; i < iterations; ++i) { - return 0.0f; - } + int32 node = m_root; - const b2TreeNode* root = m_nodes + m_root; - float32 rootArea = root->aabb.GetPerimeter(); - - float32 totalArea = 0.0f; - for (int32 i = 0; i < m_nodeCapacity; ++i) - { - const b2TreeNode* node = m_nodes + i; - if (node->height < 0) + uint32 bit = 0; + while (m_nodes[node].IsLeaf() == false) { - // Free node in pool - continue; + int32* children = &m_nodes[node].child1; + node = children[(m_path >> bit) & 1]; + bit = (bit + 1) & (8* sizeof(uint32) - 1); } + ++m_path; - totalArea += node->aabb.GetPerimeter(); + RemoveLeaf(node); + InsertLeaf(node); } - - return totalArea / rootArea; } // Compute the height of a sub-tree. int32 b2DynamicTree::ComputeHeight(int32 nodeId) const { - b2Assert(0 <= nodeId && nodeId < m_nodeCapacity); - b2TreeNode* node = m_nodes + nodeId; - - if (node->IsLeaf()) + if (nodeId == b2_nullNode) { return 0; } + b2Assert(0 <= nodeId && nodeId < m_nodeCapacity); + b2DynamicTreeNode* node = m_nodes + nodeId; int32 height1 = ComputeHeight(node->child1); int32 height2 = ComputeHeight(node->child2); return 1 + b2Max(height1, height2); @@ -577,359 +361,5 @@ int32 b2DynamicTree::ComputeHeight(int32 nodeId) const int32 b2DynamicTree::ComputeHeight() const { - int32 height = ComputeHeight(m_root); - return height; -} - -void b2DynamicTree::ValidateStructure(int32 index) const -{ - if (index == b2_nullNode) - { - return; - } - - if (index == m_root) - { - b2Assert(m_nodes[index].parent == b2_nullNode); - } - - const b2TreeNode* node = m_nodes + index; - - int32 child1 = node->child1; - int32 child2 = node->child2; - - if (node->IsLeaf()) - { - b2Assert(child1 == b2_nullNode); - b2Assert(child2 == b2_nullNode); - b2Assert(node->height == 0); - return; - } - - b2Assert(0 <= child1 && child1 < m_nodeCapacity); - b2Assert(0 <= child2 && child2 < m_nodeCapacity); - - b2Assert(m_nodes[child1].parent == index); - b2Assert(m_nodes[child2].parent == index); - - ValidateStructure(child1); - ValidateStructure(child2); -} - -void b2DynamicTree::ValidateMetrics(int32 index) const -{ - if (index == b2_nullNode) - { - return; - } - - const b2TreeNode* node = m_nodes + index; - - int32 child1 = node->child1; - int32 child2 = node->child2; - - if (node->IsLeaf()) - { - b2Assert(child1 == b2_nullNode); - b2Assert(child2 == b2_nullNode); - b2Assert(node->height == 0); - return; - } - - b2Assert(0 <= child1 && child1 < m_nodeCapacity); - b2Assert(0 <= child2 && child2 < m_nodeCapacity); - - int32 height1 = m_nodes[child1].height; - int32 height2 = m_nodes[child2].height; - int32 height = 1 + b2Max(height1, height2); - b2Assert(node->height == height); - - b2AABB aabb; - aabb.Combine(m_nodes[child1].aabb, m_nodes[child2].aabb); - - b2Assert(aabb.lowerBound == node->aabb.lowerBound); - b2Assert(aabb.upperBound == node->aabb.upperBound); - - ValidateMetrics(child1); - ValidateMetrics(child2); -} - -void b2DynamicTree::Validate() const -{ - ValidateStructure(m_root); - ValidateMetrics(m_root); - - int32 freeCount = 0; - int32 freeIndex = m_freeList; - while (freeIndex != b2_nullNode) - { - b2Assert(0 <= freeIndex && freeIndex < m_nodeCapacity); - freeIndex = m_nodes[freeIndex].next; - ++freeCount; - } - - b2Assert(GetHeight() == ComputeHeight()); - - b2Assert(m_nodeCount + freeCount == m_nodeCapacity); -} - -int32 b2DynamicTree::GetMaxBalance() const -{ - int32 maxBalance = 0; - for (int32 i = 0; i < m_nodeCapacity; ++i) - { - const b2TreeNode* node = m_nodes + i; - if (node->height <= 1) - { - continue; - } - - b2Assert(node->IsLeaf() == false); - - int32 child1 = node->child1; - int32 child2 = node->child2; - int32 balance = b2Abs(m_nodes[child2].height - m_nodes[child1].height); - maxBalance = b2Max(maxBalance, balance); - } - - return maxBalance; -} - -void b2DynamicTree::RebuildBottomUp() -{ - int32* nodes = (int32*)b2Alloc(m_nodeCount * sizeof(int32)); - int32 count = 0; - - // Build array of leaves. Free the rest. - for (int32 i = 0; i < m_nodeCapacity; ++i) - { - if (m_nodes[i].height < 0) - { - // free node in pool - continue; - } - - if (m_nodes[i].IsLeaf()) - { - m_nodes[i].parent = b2_nullNode; - nodes[count] = i; - ++count; - } - else - { - FreeNode(i); - } - } - - while (count > 1) - { - float32 minCost = b2_maxFloat; - int32 iMin = -1, jMin = -1; - for (int32 i = 0; i < count; ++i) - { - b2AABB aabbi = m_nodes[nodes[i]].aabb; - - for (int32 j = i + 1; j < count; ++j) - { - b2AABB aabbj = m_nodes[nodes[j]].aabb; - b2AABB b; - b.Combine(aabbi, aabbj); - float32 cost = b.GetPerimeter(); - if (cost < minCost) - { - iMin = i; - jMin = j; - minCost = cost; - } - } - } - - int32 index1 = nodes[iMin]; - int32 index2 = nodes[jMin]; - b2TreeNode* child1 = m_nodes + index1; - b2TreeNode* child2 = m_nodes + index2; - - int32 parentIndex = AllocateNode(); - b2TreeNode* parent = m_nodes + parentIndex; - parent->child1 = index1; - parent->child2 = index2; - parent->height = 1 + b2Max(child1->height, child2->height); - parent->aabb.Combine(child1->aabb, child2->aabb); - parent->parent = b2_nullNode; - - child1->parent = parentIndex; - child2->parent = parentIndex; - - nodes[jMin] = nodes[count-1]; - nodes[iMin] = parentIndex; - --count; - } - - m_root = nodes[0]; - b2Free(nodes); - - Validate(); -} - -#elif B2_USE_BRUTE_FORCE - -b2DynamicTree::b2DynamicTree() -{ - m_proxyCapacity = 128; - m_proxyCount = 0; - - m_proxyMap = (int32*)b2Alloc(m_proxyCapacity * sizeof(int32)); - m_proxies = (b2Proxy*)b2Alloc(m_proxyCapacity * sizeof(b2Proxy)); - - // Build the free list - m_freeId = 0; - int32 last = m_proxyCapacity - 1; - for (int32 i = m_freeId; i < last; ++i) - { - m_proxyMap[i] = i + 1; - } - - m_proxyMap[last] = b2_nullNode; -} - -b2DynamicTree::~b2DynamicTree() -{ - b2Free(m_proxyMap); - b2Free(m_proxies); -} - -int32 b2DynamicTree::CreateProxy(const b2AABB& aabb, void* userData) -{ - if (m_proxyCount == m_proxyCapacity) - { - m_proxyCapacity *= 2; - int32* proxyMap = (int32*)b2Alloc(m_proxyCapacity * sizeof(int32)); - b2Proxy* proxies = (b2Proxy*)b2Alloc(m_proxyCapacity * sizeof(b2Proxy)); - - memcpy(proxyMap, m_proxyMap, m_proxyCount * sizeof(int32)); - memcpy(proxies, m_proxies, m_proxyCount * sizeof(b2Proxy)); - - b2Free(m_proxyMap); - b2Free(m_proxies); - m_proxyMap = proxyMap; - m_proxies = proxies; - proxyMap = NULL; - proxies = NULL; - - m_freeId = m_proxyCount; - int32 last = m_proxyCapacity - 1; - for (int32 i = m_freeId; i < last; ++i) - { - m_proxyMap[i] = i + 1; - } - - m_proxyMap[last] = b2_nullNode; - } - - b2Assert(0 <= m_freeId && m_freeId < m_proxyCapacity); - int32 id = m_freeId; - m_freeId = m_proxyMap[id]; - int32 index = m_proxyCount; - - m_proxies[index].aabb = aabb; - m_proxies[index].userData = userData; - m_proxies[index].id = id; - m_proxyMap[id] = index; - ++m_proxyCount; - - return id; -} - -void b2DynamicTree::DestroyProxy(int32 proxyId) -{ - b2Assert(0 < m_proxyCount && 0 <= proxyId && proxyId < m_proxyCapacity); - int32 index = m_proxyMap[proxyId]; - - // Add to free list - m_proxyMap[proxyId] = m_freeId; - m_freeId = proxyId; - - // Keep proxy array contiguous - if (index < m_proxyCount - 1) - { - m_proxies[index] = m_proxies[m_proxyCount-1]; - int32 id = m_proxies[index].id; - m_proxyMap[id] = index; - } - - --m_proxyCount; - - Validate(); + return ComputeHeight(m_root); } - -bool b2DynamicTree::MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement) -{ - b2Assert(0 < m_proxyCount && 0 <= proxyId && proxyId < m_proxyCapacity); - B2_NOT_USED(displacement); - - int32 index = m_proxyMap[proxyId]; - - if (m_proxies[index].aabb.Contains(aabb)) - { - return false; - } - - // Extend AABB. - b2AABB b = aabb; - b2Vec2 r(b2_aabbExtension, b2_aabbExtension); - b.lowerBound = b.lowerBound - r; - b.upperBound = b.upperBound + r; - - // Predict AABB displacement. - b2Vec2 d = b2_aabbMultiplier * displacement; - - if (d.x < 0.0f) - { - b.lowerBound.x += d.x; - } - else - { - b.upperBound.x += d.x; - } - - if (d.y < 0.0f) - { - b.lowerBound.y += d.y; - } - else - { - b.upperBound.y += d.y; - } - - m_proxies[index].aabb = b; - - return true; -} - -void b2DynamicTree::Validate() const -{ - b2Assert(m_proxyCount > 0 || m_freeId == b2_nullNode); - b2Assert(m_freeId == b2_nullNode || m_freeId < m_proxyCapacity); - - int32 id = m_freeId; - int32 freeCount = 0; - while (id != b2_nullNode) - { - ++freeCount; - b2Assert(freeCount <= m_proxyCapacity); - id = m_proxyMap[id]; - } - - b2Assert(freeCount + m_proxyCount == m_proxyCapacity); - - b2Assert(m_proxyCount <= m_proxyCapacity); - - for (int32 i = 0; i < m_proxyCount; ++i) - { - int32 id = m_proxies[i].id; - - b2Assert(m_proxyMap[id] == i); - } -} - -#endif diff --git a/libs/box2d/src/Box2D/Collision/b2DynamicTree.h b/libs/box2d/src/Box2D/Collision/b2DynamicTree.h index 8afaa6d..b67686b 100644 --- a/libs/box2d/src/Box2D/Collision/b2DynamicTree.h +++ b/libs/box2d/src/Box2D/Collision/b2DynamicTree.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2009 Erin Catto http://www.box2d.org +* Copyright (c) 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 @@ -20,26 +20,23 @@ #define B2_DYNAMIC_TREE_H #include -#include -#define b2_nullNode (-1) - -#define B2_USE_DYNAMIC_TREE 1 -#define B2_USE_BRUTE_FORCE 0 +/// A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt. -#if B2_USE_DYNAMIC_TREE +#define b2_nullNode (-1) /// A node in the dynamic tree. The client does not interact with this directly. -struct b2TreeNode +struct b2DynamicTreeNode { bool IsLeaf() const { return child1 == b2_nullNode; } - /// Enlarged AABB + /// This is the fattened AABB. b2AABB aabb; + //int32 userData; void* userData; union @@ -50,12 +47,8 @@ struct b2TreeNode int32 child1; int32 child2; - - // leaf = 0, free node = -1 - int32 height; }; -/// A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt. /// A dynamic tree arranges data in a binary tree to accelerate /// queries such as volume queries and ray casts. Leafs are proxies /// with an AABB. In the tree we expand the proxy AABB by b2_fatAABBFactor @@ -66,6 +59,7 @@ struct b2TreeNode class b2DynamicTree { public: + /// Constructing the tree initializes the node pool. b2DynamicTree(); @@ -84,6 +78,9 @@ public: /// @return true if the proxy was re-inserted. bool MoveProxy(int32 proxyId, const b2AABB& aabb1, const b2Vec2& displacement); + /// Perform some iterations to re-balance the tree. + void Rebalance(int32 iterations); + /// Get proxy user data. /// @return the proxy user data or 0 if the id is invalid. void* GetUserData(int32 proxyId) const; @@ -91,6 +88,9 @@ public: /// Get the fat AABB for a proxy. const b2AABB& GetFatAABB(int32 proxyId) const; + /// Compute the height of the tree. + int32 ComputeHeight() const; + /// Query an AABB for overlapping proxies. The callback class /// is called for each proxy that overlaps the supplied AABB. template @@ -106,23 +106,6 @@ public: template void RayCast(T* callback, const b2RayCastInput& input) const; - /// Validate this tree. For testing. - void Validate() const; - - /// Compute the height of the binary tree in O(N) time. Should not be - /// called often. - int32 GetHeight() const; - - /// Get the maximum balance of an node in the tree. The balance is the difference - /// in height of the two children of a node. - int32 GetMaxBalance() const; - - /// Get the ratio of the sum of the node areas to the root area. - float32 GetAreaRatio() const; - - /// Build an optimal tree. Very expensive. For testing. - void RebuildBottomUp(); - private: int32 AllocateNode(); @@ -131,23 +114,17 @@ private: void InsertLeaf(int32 node); void RemoveLeaf(int32 node); - int32 Balance(int32 index); - - int32 ComputeHeight() const; int32 ComputeHeight(int32 nodeId) const; - void ValidateStructure(int32 index) const; - void ValidateMetrics(int32 index) const; - int32 m_root; - b2TreeNode* m_nodes; + b2DynamicTreeNode* m_nodes; int32 m_nodeCount; int32 m_nodeCapacity; int32 m_freeList; - /// This is used to incrementally traverse the tree for re-balancing. + /// This is used incrementally traverse the tree for re-balancing. uint32 m_path; int32 m_insertionCount; @@ -168,18 +145,21 @@ inline const b2AABB& b2DynamicTree::GetFatAABB(int32 proxyId) const template inline void b2DynamicTree::Query(T* callback, const b2AABB& aabb) const { - b2GrowableStack stack; - stack.Push(m_root); + const int32 k_stackSize = 128; + int32 stack[k_stackSize]; + + int32 count = 0; + stack[count++] = m_root; - while (stack.GetCount() > 0) + while (count > 0) { - int32 nodeId = stack.Pop(); + int32 nodeId = stack[--count]; if (nodeId == b2_nullNode) { continue; } - const b2TreeNode* node = m_nodes + nodeId; + const b2DynamicTreeNode* node = m_nodes + nodeId; if (b2TestOverlap(node->aabb, aabb)) { @@ -193,8 +173,15 @@ inline void b2DynamicTree::Query(T* callback, const b2AABB& aabb) const } else { - stack.Push(node->child1); - stack.Push(node->child2); + if (count < k_stackSize) + { + stack[count++] = node->child1; + } + + if (count < k_stackSize) + { + stack[count++] = node->child2; + } } } } @@ -226,18 +213,21 @@ inline void b2DynamicTree::RayCast(T* callback, const b2RayCastInput& input) con segmentAABB.upperBound = b2Max(p1, t); } - b2GrowableStack stack; - stack.Push(m_root); + const int32 k_stackSize = 128; + int32 stack[k_stackSize]; - while (stack.GetCount() > 0) + int32 count = 0; + stack[count++] = m_root; + + while (count > 0) { - int32 nodeId = stack.Pop(); + int32 nodeId = stack[--count]; if (nodeId == b2_nullNode) { continue; } - const b2TreeNode* node = m_nodes + nodeId; + const b2DynamicTreeNode* node = m_nodes + nodeId; if (b2TestOverlap(node->aabb, segmentAABB) == false) { @@ -280,196 +270,17 @@ inline void b2DynamicTree::RayCast(T* callback, const b2RayCastInput& input) con } else { - stack.Push(node->child1); - stack.Push(node->child2); - } - } -} - -#elif B2_USE_BRUTE_FORCE 0 - -struct b2Proxy -{ - /// This is the fattened AABB. - b2AABB aabb; - void* userData; - int32 id; -}; - -/// This implementation is not a tree at all. It is just a cache friendly array of AABBs. -class b2DynamicTree -{ -public: - - /// Constructing the tree initializes the node pool. - b2DynamicTree(); - - /// Destroy the tree, freeing the node pool. - ~b2DynamicTree(); - - /// Create a proxy. Provide a tight fitting AABB and a userData pointer. - int32 CreateProxy(const b2AABB& aabb, void* userData); - - /// Destroy a proxy. This asserts if the id is invalid. - void DestroyProxy(int32 proxyId); - - /// Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, - /// then the proxy is removed from the tree and re-inserted. Otherwise - /// the function returns immediately. - /// @return true if the proxy was re-inserted. - bool MoveProxy(int32 proxyId, const b2AABB& aabb1, const b2Vec2& displacement); - - /// Perform some iterations to re-balance the tree. - void Rebalance(int32 iterations) - { - B2_NOT_USED(iterations); - } - - /// Get proxy user data. - /// @return the proxy user data or 0 if the id is invalid. - void* GetUserData(int32 proxyId) const; - - /// Get the fat AABB for a proxy. - const b2AABB& GetFatAABB(int32 proxyId) const; - - /// Compute the height of the binary tree in O(N) time. Should not be - /// called often. - int32 ComputeHeight() const - { - return 0; - } - - /// Query an AABB for overlapping proxies. The callback class - /// is called for each proxy that overlaps the supplied AABB. - template - void Query(T* callback, const b2AABB& aabb) const; - - /// Ray-cast against the proxies in the tree. This relies on the callback - /// to perform a exact ray-cast in the case were the proxy contains a shape. - /// The callback also performs the any collision filtering. This has performance - /// roughly equal to k * log(n), where k is the number of collisions and n is the - /// number of proxies in the tree. - /// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). - /// @param callback a callback class that is called for each proxy that is hit by the ray. - template - void RayCast(T* callback, const b2RayCastInput& input) const; - - void Validate() const; - -private: - - // Map of ids to proxies indices. This may have holes (which contain a free list). - int32* m_proxyMap; - - // Contiguous array of proxies - b2Proxy* m_proxies; - - int32 m_proxyCount; - int32 m_proxyCapacity; - - int32 m_freeId; -}; - -inline void* b2DynamicTree::GetUserData(int32 proxyId) const -{ - b2Assert(0 <= proxyId && proxyId < m_proxyCapacity); - int32 index = m_proxyMap[proxyId]; - return m_proxies[index].userData; -} - -inline const b2AABB& b2DynamicTree::GetFatAABB(int32 proxyId) const -{ - b2Assert(0 <= proxyId && proxyId < m_proxyCapacity); - int32 index = m_proxyMap[proxyId]; - return m_proxies[index].aabb; -} - -template -inline void b2DynamicTree::Query(T* callback, const b2AABB& aabb) const -{ - for (int32 i = 0; i < m_proxyCount; ++i) - { - if (b2TestOverlap(m_proxies[i].aabb, aabb)) - { - bool proceed = callback->QueryCallback(m_proxies[i].id); - if (proceed == false) + if (count < k_stackSize) { - return; + stack[count++] = node->child1; } - } - } -} - -template -inline void b2DynamicTree::RayCast(T* callback, const b2RayCastInput& input) const -{ - b2Vec2 p1 = input.p1; - b2Vec2 p2 = input.p2; - b2Vec2 r = p2 - p1; - b2Assert(r.LengthSquared() > 0.0f); - r.Normalize(); - // v is perpendicular to the segment. - b2Vec2 v = b2Cross(1.0f, r); - b2Vec2 abs_v = b2Abs(v); - - // Separating axis for segment (Gino, p80). - // |dot(v, p1 - c)| > dot(|v|, h) - - float32 maxFraction = input.maxFraction; - - // Build a bounding box for the segment. - b2AABB segmentAABB; - { - b2Vec2 t = p1 + maxFraction * (p2 - p1); - segmentAABB.lowerBound = b2Min(p1, t); - segmentAABB.upperBound = b2Max(p1, t); - } - - for (int32 i = 0; i < m_proxyCount; ++i) - { - const b2Proxy* proxy = m_proxies + i; - b2AABB proxyAABB = proxy->aabb; - - if (b2TestOverlap(proxyAABB, segmentAABB) == false) - { - continue; - } - - // Separating axis for segment (Gino, p80). - // |dot(v, p1 - c)| > dot(|v|, h) - b2Vec2 c = proxyAABB.GetCenter(); - b2Vec2 h = proxyAABB.GetExtents(); - float32 separation = b2Abs(b2Dot(v, p1 - c)) - b2Dot(abs_v, h); - if (separation > 0.0f) - { - continue; - } - - b2RayCastInput subInput; - subInput.p1 = input.p1; - subInput.p2 = input.p2; - subInput.maxFraction = maxFraction; - - float32 value = callback->RayCastCallback(subInput, proxy->id); - - if (value == 0.0f) - { - // The client has terminated the ray cast. - return; - } - - if (value > 0.0f) - { - // Update segment bounding box. - maxFraction = value; - b2Vec2 t = p1 + maxFraction * (p2 - p1); - segmentAABB.lowerBound = b2Min(p1, t); - segmentAABB.upperBound = b2Max(p1, t); + if (count < k_stackSize) + { + stack[count++] = node->child2; + } } } } #endif - -#endif diff --git a/libs/box2d/src/Box2D/Collision/b2TimeOfImpact.cpp b/libs/box2d/src/Box2D/Collision/b2TimeOfImpact.cpp index 2fef964..b1f2f4e 100644 --- a/libs/box2d/src/Box2D/Collision/b2TimeOfImpact.cpp +++ b/libs/box2d/src/Box2D/Collision/b2TimeOfImpact.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2007-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 @@ -23,11 +23,12 @@ #include #include -using namespace std; int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters; int32 b2_toiRootIters, b2_toiMaxRootIters; +int32 b2_toiMaxOptIters; + struct b2SeparationFunction { enum Type @@ -41,8 +42,7 @@ struct b2SeparationFunction float32 Initialize(const b2SimplexCache* cache, const b2DistanceProxy* proxyA, const b2Sweep& sweepA, - const b2DistanceProxy* proxyB, const b2Sweep& sweepB, - float32 t1) + const b2DistanceProxy* proxyB, const b2Sweep& sweepB) { m_proxyA = proxyA; m_proxyB = proxyB; @@ -53,8 +53,8 @@ struct b2SeparationFunction m_sweepB = sweepB; b2Transform xfA, xfB; - m_sweepA.GetTransform(&xfA, t1); - m_sweepB.GetTransform(&xfB, t1); + m_sweepA.GetTransform(&xfA, 0.0f); + m_sweepB.GetTransform(&xfB, 0.0f); if (count == 1) { @@ -325,7 +325,7 @@ void b2TimeOfImpact(b2TOIOutput* output, const b2TOIInput* input) // Initialize the separating axis. b2SeparationFunction fcn; - fcn.Initialize(&cache, proxyA, sweepA, proxyB, sweepB, t1); + fcn.Initialize(&cache, proxyA, sweepA, proxyB, sweepB); #if 0 // Dump the curve seen by the root finder { diff --git a/libs/box2d/src/Box2D/Collision/b2TimeOfImpact.h b/libs/box2d/src/Box2D/Collision/b2TimeOfImpact.h index 179a170..b59fb83 100644 --- a/libs/box2d/src/Box2D/Collision/b2TimeOfImpact.h +++ b/libs/box2d/src/Box2D/Collision/b2TimeOfImpact.h @@ -1,5 +1,5 @@ /* -* 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 @@ -21,6 +21,7 @@ #include #include +#include /// Input parameters for b2TimeOfImpact struct b2TOIInput diff --git a/libs/box2d/src/Box2D/Common/b2BlockAllocator.cpp b/libs/box2d/src/Box2D/Common/b2BlockAllocator.cpp index f5060da..ba06f04 100644 --- a/libs/box2d/src/Box2D/Common/b2BlockAllocator.cpp +++ b/libs/box2d/src/Box2D/Common/b2BlockAllocator.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -21,7 +21,6 @@ #include #include #include -using namespace std; int32 b2BlockAllocator::s_blockSizes[b2_blockSizes] = { @@ -101,12 +100,7 @@ void* b2BlockAllocator::Allocate(int32 size) if (size == 0) return NULL; - b2Assert(0 < size); - - if (size > b2_maxBlockSize) - { - return b2Alloc(size); - } + b2Assert(0 < size && size <= b2_maxBlockSize); int32 index = s_blockSizeLookup[size]; b2Assert(0 <= index && index < b2_blockSizes); @@ -161,13 +155,7 @@ void b2BlockAllocator::Free(void* p, int32 size) return; } - b2Assert(0 < size); - - if (size > b2_maxBlockSize) - { - b2Free(p); - return; - } + b2Assert(0 < size && size <= b2_maxBlockSize); int32 index = s_blockSizeLookup[size]; b2Assert(0 <= index && index < b2_blockSizes); diff --git a/libs/box2d/src/Box2D/Common/b2BlockAllocator.h b/libs/box2d/src/Box2D/Common/b2BlockAllocator.h index 8ba29a5..93eb2e3 100644 --- a/libs/box2d/src/Box2D/Common/b2BlockAllocator.h +++ b/libs/box2d/src/Box2D/Common/b2BlockAllocator.h @@ -1,5 +1,5 @@ /* -* 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 @@ -21,7 +21,7 @@ #include -const int32 b2_chunkSize = 16 * 1024; +const int32 b2_chunkSize = 4096; const int32 b2_maxBlockSize = 640; const int32 b2_blockSizes = 14; const int32 b2_chunkArrayIncrement = 128; @@ -29,19 +29,16 @@ const int32 b2_chunkArrayIncrement = 128; struct b2Block; struct b2Chunk; -/// This is a small object allocator used for allocating small -/// objects that persist for more than one time step. -/// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp +// This is a small object allocator used for allocating small +// objects that persist for more than one time step. +// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp class b2BlockAllocator { public: b2BlockAllocator(); ~b2BlockAllocator(); - /// Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize. void* Allocate(int32 size); - - /// Free memory. This will use b2Free if the size is larger than b2_maxBlockSize. void Free(void* p, int32 size); void Clear(); diff --git a/libs/box2d/src/Box2D/Common/b2Draw.cpp b/libs/box2d/src/Box2D/Common/b2Draw.cpp deleted file mode 100644 index 327b580..0000000 --- a/libs/box2d/src/Box2D/Common/b2Draw.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* -* Copyright (c) 2011 Erin Catto http://box2d.org -* -* 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 - -b2Draw::b2Draw() -{ - m_drawFlags = 0; -} - -void b2Draw::SetFlags(uint32 flags) -{ - m_drawFlags = flags; -} - -uint32 b2Draw::GetFlags() const -{ - return m_drawFlags; -} - -void b2Draw::AppendFlags(uint32 flags) -{ - m_drawFlags |= flags; -} - -void b2Draw::ClearFlags(uint32 flags) -{ - m_drawFlags &= ~flags; -} diff --git a/libs/box2d/src/Box2D/Common/b2Draw.h b/libs/box2d/src/Box2D/Common/b2Draw.h deleted file mode 100644 index de62dd6..0000000 --- a/libs/box2d/src/Box2D/Common/b2Draw.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -* Copyright (c) 2011 Erin Catto http://box2d.org -* -* 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 - -/// Color for debug drawing. Each value has the range [0,1]. -struct b2Color -{ - b2Color() {} - b2Color(float32 r, float32 g, float32 b) : r(r), g(g), b(b) {} - void Set(float32 ri, float32 gi, float32 bi) { r = ri; g = gi; b = bi; } - float32 r, g, b; -}; - -/// Implement and register this class with a b2World to provide debug drawing of physics -/// entities in your game. -class b2Draw -{ -public: - b2Draw(); - - virtual ~b2Draw() {} - - enum - { - e_shapeBit = 0x0001, ///< draw shapes - e_jointBit = 0x0002, ///< draw joint connections - e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes - e_pairBit = 0x0008, ///< draw broad-phase pairs - e_centerOfMassBit = 0x0010 ///< draw center of mass frame - }; - - /// Set the drawing flags. - void SetFlags(uint32 flags); - - /// Get the drawing flags. - uint32 GetFlags() const; - - /// Append flags to the current flags. - void AppendFlags(uint32 flags); - - /// Clear flags from the current flags. - void ClearFlags(uint32 flags); - - /// Draw a closed polygon provided in CCW order. - virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0; - - /// Draw a solid closed polygon provided in CCW order. - virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0; - - /// Draw a circle. - virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) = 0; - - /// Draw a solid circle. - virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) = 0; - - /// Draw a line segment. - virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0; - - /// Draw a transform. Choose your own length scale. - /// @param xf a transform. - virtual void DrawTransform(const b2Transform& xf) = 0; - -protected: - uint32 m_drawFlags; -}; diff --git a/libs/box2d/src/Box2D/Common/b2GrowableStack.h b/libs/box2d/src/Box2D/Common/b2GrowableStack.h deleted file mode 100644 index d2e0712..0000000 --- a/libs/box2d/src/Box2D/Common/b2GrowableStack.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -* Copyright (c) 2010 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef B2_GROWABLE_STACK_H -#define B2_GROWABLE_STACK_H -#include -#include - -/// This is a growable LIFO stack with an initial capacity of N. -/// If the stack size exceeds the initial capacity, the heap is used -/// to increase the size of the stack. -template -class b2GrowableStack -{ -public: - b2GrowableStack() - { - m_stack = m_array; - m_count = 0; - m_capacity = N; - } - - ~b2GrowableStack() - { - if (m_stack != m_array) - { - b2Free(m_stack); - m_stack = NULL; - } - } - - void Push(const T& element) - { - if (m_count == m_capacity) - { - T* old = m_stack; - m_capacity *= 2; - m_stack = (T*)b2Alloc(m_capacity * sizeof(T)); - std::memcpy(m_stack, old, m_count * sizeof(T)); - if (old != m_array) - { - b2Free(old); - } - } - - m_stack[m_count] = element; - ++m_count; - } - - T Pop() - { - b2Assert(m_count > 0); - --m_count; - return m_stack[m_count]; - } - - int32 GetCount() - { - return m_count; - } - -private: - T* m_stack; - T m_array[N]; - int32 m_count; - int32 m_capacity; -}; - - -#endif diff --git a/libs/box2d/src/Box2D/Common/b2Math.cpp b/libs/box2d/src/Box2D/Common/b2Math.cpp index c44f474..f15a43b 100644 --- a/libs/box2d/src/Box2D/Common/b2Math.cpp +++ b/libs/box2d/src/Box2D/Common/b2Math.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2007-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 diff --git a/libs/box2d/src/Box2D/Common/b2Math.h b/libs/box2d/src/Box2D/Common/b2Math.h index 8eade76..c29f594 100644 --- a/libs/box2d/src/Box2D/Common/b2Math.h +++ b/libs/box2d/src/Box2D/Common/b2Math.h @@ -1,5 +1,5 @@ /* -* 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 @@ -57,8 +57,13 @@ inline float32 b2InvSqrt(float32 x) return x; } -#define b2Sqrt(x) std::sqrt(x) -#define b2Atan2(y, x) std::atan2(y, x) +#define b2Sqrt(x) sqrtf(x) +#define b2Atan2(y, x) atan2f(y, x) + +inline float32 b2Abs(float32 a) +{ + return a > 0.0f ? a : -a; +} /// A 2D column vector. struct b2Vec2 @@ -142,12 +147,6 @@ struct b2Vec2 return b2IsValid(x) && b2IsValid(y); } - /// Get the skew vector such that dot(skew_vec, other) == cross(vec, other) - b2Vec2 Skew() const - { - return b2Vec2(-y, x); - } - float32 x, y; }; @@ -365,12 +364,12 @@ struct b2Transform struct b2Sweep { /// Get the interpolated transform at a specific time. - /// @param beta is a factor in [0,1], where 0 indicates alpha0. - void GetTransform(b2Transform* xf, float32 beta) const; + /// @param alpha is a factor in [0,1], where 0 indicates t0. + void GetTransform(b2Transform* xf, float32 alpha) const; /// Advance the sweep forward, yielding a new initial state. - /// @param alpha the new initial time. - void Advance(float32 alpha); + /// @param t the new initial time. + void Advance(float32 t); /// Normalize the angles. void Normalize(); @@ -378,10 +377,6 @@ struct b2Sweep b2Vec2 localCenter; ///< local center of mass position b2Vec2 c0, c; ///< center world positions float32 a0, a; ///< world angles - - /// Fraction of the current time step in the range [0,1] - /// c0 and a0 are the positions at alpha0. - float32 alpha0; }; @@ -530,21 +525,6 @@ inline b2Vec2 b2MulT(const b2Transform& T, const b2Vec2& v) return b2MulT(T.R, v - T.position); } -// v2 = A.R' * (B.R * v1 + B.p - A.p) = (A.R' * B.R) * v1 + (B.p - A.p) -inline b2Transform b2MulT(const b2Transform& A, const b2Transform& B) -{ - b2Transform C; - C.R = b2MulT(A.R, B.R); - C.position = B.position - A.position; - return C; -} - -template -inline T b2Abs(T a) -{ - return a > T(0) ? a : -a; -} - inline b2Vec2 b2Abs(const b2Vec2& a) { return b2Vec2(b2Abs(a.x), b2Abs(a.y)); @@ -616,23 +596,20 @@ inline bool b2IsPowerOfTwo(uint32 x) return result; } -inline void b2Sweep::GetTransform(b2Transform* xf, float32 beta) const +inline void b2Sweep::GetTransform(b2Transform* xf, float32 alpha) const { - xf->position = (1.0f - beta) * c0 + beta * c; - float32 angle = (1.0f - beta) * a0 + beta * a; + xf->position = (1.0f - alpha) * c0 + alpha * c; + float32 angle = (1.0f - alpha) * a0 + alpha * a; xf->R.Set(angle); // Shift to origin xf->position -= b2Mul(xf->R, localCenter); } -inline void b2Sweep::Advance(float32 alpha) +inline void b2Sweep::Advance(float32 t) { - b2Assert(alpha0 < 1.0f); - float32 beta = (alpha - alpha0) / (1.0f - alpha0); - c0 = (1.0f - beta) * c0 + beta * c; - a0 = (1.0f - beta) * a0 + beta * a; - alpha0 = alpha; + c0 = (1.0f - t) * c0 + t * c; + a0 = (1.0f - t) * a0 + t * a; } /// Normalize an angle in radians to be between -pi and pi diff --git a/libs/box2d/src/Box2D/Common/b2Settings.cpp b/libs/box2d/src/Box2D/Common/b2Settings.cpp index 97f5283..da30814 100644 --- a/libs/box2d/src/Box2D/Common/b2Settings.cpp +++ b/libs/box2d/src/Box2D/Common/b2Settings.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -19,7 +19,7 @@ #include #include -b2Version b2_version = {2, 2, 0}; +b2Version b2_version = {2, 1, 2}; // Memory allocators. Modify these to use your own allocator. void* b2Alloc(int32 size) diff --git a/libs/box2d/src/Box2D/Common/b2Settings.h b/libs/box2d/src/Box2D/Common/b2Settings.h index 43b5f2a..1aa8c26 100644 --- a/libs/box2d/src/Box2D/Common/b2Settings.h +++ b/libs/box2d/src/Box2D/Common/b2Settings.h @@ -1,5 +1,5 @@ /* -* 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 @@ -32,7 +32,6 @@ typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned int uint32; typedef float float32; -typedef double float64; #define b2_maxFloat FLT_MAX #define b2_epsilon FLT_EPSILON @@ -47,8 +46,7 @@ typedef double float64; /// The maximum number of contact points between two convex shapes. #define b2_maxManifoldPoints 2 -/// The maximum number of vertices on a convex polygon. You cannot increase -/// this too much because b2BlockAllocator has a maximum object size. +/// The maximum number of vertices on a convex polygon. #define b2_maxPolygonVertices 8 /// This is used to fatten AABBs in the dynamic tree. This allows proxies @@ -74,9 +72,6 @@ typedef double float64; /// Making it larger may create artifacts for vertex collision. #define b2_polygonRadius (2.0f * b2_linearSlop) -/// Maximum number of sub-steps per contact in continuous physics simulation. -#define b2_maxSubSteps 8 - // Dynamics @@ -110,7 +105,6 @@ typedef double float64; /// to overshoot. #define b2_contactBaumgarte 0.2f - // Sleep /// The time that a body must be still before it will go to sleep. @@ -142,4 +136,16 @@ struct b2Version /// Current version. extern b2Version b2_version; +/// Friction mixing law. Feel free to customize this. +inline float32 b2MixFriction(float32 friction1, float32 friction2) +{ + return sqrtf(friction1 * friction2); +} + +/// Restitution mixing law. Feel free to customize this. +inline float32 b2MixRestitution(float32 restitution1, float32 restitution2) +{ + return restitution1 > restitution2 ? restitution1 : restitution2; +} + #endif diff --git a/libs/box2d/src/Box2D/Common/b2StackAllocator.cpp b/libs/box2d/src/Box2D/Common/b2StackAllocator.cpp index 4a86283..cb2c42e 100644 --- a/libs/box2d/src/Box2D/Common/b2StackAllocator.cpp +++ b/libs/box2d/src/Box2D/Common/b2StackAllocator.cpp @@ -1,5 +1,5 @@ /* -* 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 diff --git a/libs/box2d/src/Box2D/Common/b2StackAllocator.h b/libs/box2d/src/Box2D/Common/b2StackAllocator.h index 796c51d..315cc02 100644 --- a/libs/box2d/src/Box2D/Common/b2StackAllocator.h +++ b/libs/box2d/src/Box2D/Common/b2StackAllocator.h @@ -1,5 +1,5 @@ /* -* 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 diff --git a/libs/box2d/src/Box2D/Common/b2Timer.cpp b/libs/box2d/src/Box2D/Common/b2Timer.cpp deleted file mode 100644 index ec7f2c3..0000000 --- a/libs/box2d/src/Box2D/Common/b2Timer.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* -* Copyright (c) 2011 Erin Catto http://box2d.org -* -* 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 - -float64 b2Timer::s_invFrequency = 0.0f; - -#if defined(WIN32) - -#include - -b2Timer::b2Timer() -{ - LARGE_INTEGER largeInteger; - - if (s_invFrequency == 0.0f) - { - QueryPerformanceFrequency(&largeInteger); - s_invFrequency = float64(largeInteger.QuadPart); - if (s_invFrequency > 0.0f) - { - s_invFrequency = 1000.0f / s_invFrequency; - } - } - - QueryPerformanceCounter(&largeInteger); - m_start = float64(largeInteger.QuadPart); -} - -void b2Timer::Reset() -{ - LARGE_INTEGER largeInteger; - QueryPerformanceCounter(&largeInteger); - m_start = float64(largeInteger.QuadPart); -} - -float32 b2Timer::GetMilliseconds() const -{ - LARGE_INTEGER largeInteger; - QueryPerformanceCounter(&largeInteger); - float64 count = float64(largeInteger.QuadPart); - float32 ms = float32(s_invFrequency * (count - m_start)); - return ms; -} - -#else - -b2Timer::b2Timer() -{ -} - -void b2Timer::Reset() -{ -} - -float32 b2Timer::GetMilliseconds() const -{ - return 0.0f; -} - -#endif diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2CircleContact.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2CircleContact.cpp index 584ef2f..6df0091 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2CircleContact.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2CircleContact.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -24,9 +24,8 @@ #include #include -using namespace std; -b2Contact* b2CircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) +b2Contact* b2CircleContact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator) { void* mem = allocator->Allocate(sizeof(b2CircleContact)); return new (mem) b2CircleContact(fixtureA, fixtureB); @@ -39,7 +38,7 @@ void b2CircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) } b2CircleContact::b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) - : b2Contact(fixtureA, 0, fixtureB, 0) + : b2Contact(fixtureA, fixtureB) { b2Assert(m_fixtureA->GetType() == b2Shape::e_circle); b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2CircleContact.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2CircleContact.h index aac1f0b..afc277a 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2CircleContact.h +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2CircleContact.h @@ -1,5 +1,5 @@ /* -* 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 @@ -26,8 +26,7 @@ class b2BlockAllocator; class b2CircleContact : public b2Contact { public: - static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, - b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); + static b2Contact* Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator); static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2Contact.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2Contact.cpp index fd19801..e7ad1ca 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2Contact.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2Contact.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -20,10 +20,6 @@ #include #include #include -#include -#include -#include -#include #include #include @@ -42,10 +38,6 @@ void b2Contact::InitializeRegisters() AddType(b2CircleContact::Create, b2CircleContact::Destroy, b2Shape::e_circle, b2Shape::e_circle); AddType(b2PolygonAndCircleContact::Create, b2PolygonAndCircleContact::Destroy, b2Shape::e_polygon, b2Shape::e_circle); AddType(b2PolygonContact::Create, b2PolygonContact::Destroy, b2Shape::e_polygon, b2Shape::e_polygon); - AddType(b2EdgeAndCircleContact::Create, b2EdgeAndCircleContact::Destroy, b2Shape::e_edge, b2Shape::e_circle); - AddType(b2EdgeAndPolygonContact::Create, b2EdgeAndPolygonContact::Destroy, b2Shape::e_edge, b2Shape::e_polygon); - AddType(b2LoopAndCircleContact::Create, b2LoopAndCircleContact::Destroy, b2Shape::e_loop, b2Shape::e_circle); - AddType(b2LoopAndPolygonContact::Create, b2LoopAndPolygonContact::Destroy, b2Shape::e_loop, b2Shape::e_polygon); } void b2Contact::AddType(b2ContactCreateFcn* createFcn, b2ContactDestroyFcn* destoryFcn, @@ -66,7 +58,7 @@ void b2Contact::AddType(b2ContactCreateFcn* createFcn, b2ContactDestroyFcn* dest } } -b2Contact* b2Contact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator) +b2Contact* b2Contact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator) { if (s_initialized == false) { @@ -85,11 +77,11 @@ b2Contact* b2Contact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtu { if (s_registers[type1][type2].primary) { - return createFcn(fixtureA, indexA, fixtureB, indexB, allocator); + return createFcn(fixtureA, fixtureB, allocator); } else { - return createFcn(fixtureB, indexB, fixtureA, indexA, allocator); + return createFcn(fixtureB, fixtureA, allocator); } } else @@ -118,16 +110,13 @@ void b2Contact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) destroyFcn(contact, allocator); } -b2Contact::b2Contact(b2Fixture* fA, int32 indexA, b2Fixture* fB, int32 indexB) +b2Contact::b2Contact(b2Fixture* fA, b2Fixture* fB) { m_flags = e_enabledFlag; m_fixtureA = fA; m_fixtureB = fB; - m_indexA = indexA; - m_indexB = indexB; - m_manifold.pointCount = 0; m_prev = NULL; @@ -144,9 +133,6 @@ b2Contact::b2Contact(b2Fixture* fA, int32 indexA, b2Fixture* fB, int32 indexB) m_nodeB.other = NULL; m_toiCount = 0; - - m_friction = b2MixFriction(m_fixtureA->m_friction, m_fixtureB->m_friction); - m_restitution = b2MixRestitution(m_fixtureA->m_restitution, m_fixtureB->m_restitution); } // Update the contact manifold and touching status. @@ -175,7 +161,7 @@ void b2Contact::Update(b2ContactListener* listener) { const b2Shape* shapeA = m_fixtureA->GetShape(); const b2Shape* shapeB = m_fixtureB->GetShape(); - touching = b2TestOverlap(shapeA, m_indexA, shapeB, m_indexB, xfA, xfB); + touching = b2TestOverlap(shapeA, shapeB, xfA, xfB); // Sensors don't generate manifolds. m_manifold.pointCount = 0; diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2Contact.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2Contact.h index 7b5a6ab..a6add3d 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2Contact.h +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2Contact.h @@ -1,5 +1,5 @@ /* -* 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 @@ -22,6 +22,7 @@ #include #include #include +#include #include class b2Body; @@ -32,23 +33,7 @@ class b2BlockAllocator; class b2StackAllocator; class b2ContactListener; -/// Friction mixing law. The idea is to allow either fixture to drive the restitution to zero. -/// For example, anything slides on ice. -inline float32 b2MixFriction(float32 friction1, float32 friction2) -{ - return std::sqrt(friction1 * friction2); -} - -/// Restitution mixing law. The idea is allow for anything to bounce off an inelastic surface. -/// For example, a superball bounces on anything. -inline float32 b2MixRestitution(float32 restitution1, float32 restitution2) -{ - return restitution1 > restitution2 ? restitution1 : restitution2; -} - -typedef b2Contact* b2ContactCreateFcn( b2Fixture* fixtureA, int32 indexA, - b2Fixture* fixtureB, int32 indexB, - b2BlockAllocator* allocator); +typedef b2Contact* b2ContactCreateFcn(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator); typedef void b2ContactDestroyFcn(b2Contact* contact, b2BlockAllocator* allocator); struct b2ContactRegister @@ -101,40 +86,14 @@ public: b2Contact* GetNext(); const b2Contact* GetNext() const; - /// Get fixture A in this contact. + /// Get the first fixture in this contact. b2Fixture* GetFixtureA(); const b2Fixture* GetFixtureA() const; - /// Get the child primitive index for fixture A. - int32 GetChildIndexA() const; - - /// Get fixture B in this contact. + /// Get the second fixture in this contact. b2Fixture* GetFixtureB(); const b2Fixture* GetFixtureB() const; - /// Get the child primitive index for fixture B. - int32 GetChildIndexB() const; - - /// Override the default friction mixture. You can call this in b2ContactListener::PreSolve. - /// This value persists until set or reset. - void SetFriction(float32 friction); - - /// Get the friction. - float32 GetFriction() const; - - /// Reset the friction mixture to the default value. - void ResetFriction(); - - /// Override the default restitution mixture. You can call this in b2ContactListener::PreSolve. - /// The value persists until you set or reset. - void SetRestitution(float32 restitution); - - /// Get the restitution. - float32 GetRestitution() const; - - /// Reset the restitution to the default value. - void ResetRestitution(); - /// Evaluate this contact with your own manifold and transforms. virtual void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) = 0; @@ -163,8 +122,6 @@ protected: // This bullet contact had a TOI event e_bulletHitFlag = 0x0010, - // This contact has a valid TOI in m_toi - e_toiFlag = 0x0020 }; /// Flag this contact for filtering. Filtering will occur the next time step. @@ -173,12 +130,12 @@ protected: static void AddType(b2ContactCreateFcn* createFcn, b2ContactDestroyFcn* destroyFcn, b2Shape::Type typeA, b2Shape::Type typeB); static void InitializeRegisters(); - static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); + static b2Contact* Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator); static void Destroy(b2Contact* contact, b2Shape::Type typeA, b2Shape::Type typeB, b2BlockAllocator* allocator); static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); b2Contact() : m_fixtureA(NULL), m_fixtureB(NULL) {} - b2Contact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); + b2Contact(b2Fixture* fixtureA, b2Fixture* fixtureB); virtual ~b2Contact() {} void Update(b2ContactListener* listener); @@ -199,16 +156,10 @@ protected: b2Fixture* m_fixtureA; b2Fixture* m_fixtureB; - int32 m_indexA; - int32 m_indexB; - b2Manifold m_manifold; int32 m_toiCount; - float32 m_toi; - - float32 m_friction; - float32 m_restitution; +// float32 m_toi; }; inline b2Manifold* b2Contact::GetManifold() @@ -278,54 +229,14 @@ inline b2Fixture* b2Contact::GetFixtureB() return m_fixtureB; } -inline int32 b2Contact::GetChildIndexA() const -{ - return m_indexA; -} - inline const b2Fixture* b2Contact::GetFixtureB() const { return m_fixtureB; } -inline int32 b2Contact::GetChildIndexB() const -{ - return m_indexB; -} - inline void b2Contact::FlagForFiltering() { m_flags |= e_filterFlag; } -inline void b2Contact::SetFriction(float32 friction) -{ - m_friction = friction; -} - -inline float32 b2Contact::GetFriction() const -{ - return m_friction; -} - -inline void b2Contact::ResetFriction() -{ - m_friction = b2MixFriction(m_fixtureA->m_friction, m_fixtureB->m_friction); -} - -inline void b2Contact::SetRestitution(float32 restitution) -{ - m_restitution = restitution; -} - -inline float32 b2Contact::GetRestitution() const -{ - return m_restitution; -} - -inline void b2Contact::ResetRestitution() -{ - m_restitution = b2MixRestitution(m_fixtureA->m_restitution, m_fixtureB->m_restitution); -} - #endif diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2ContactSolver.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2ContactSolver.cpp index cd99b0b..f65fb60 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2ContactSolver.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2ContactSolver.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -17,8 +17,6 @@ */ #include - - #include #include #include @@ -27,17 +25,17 @@ #define B2_DEBUG_SOLVER 0 -b2ContactSolver::b2ContactSolver(b2ContactSolverDef* def) +b2ContactSolver::b2ContactSolver(b2Contact** contacts, int32 contactCount, + b2StackAllocator* allocator, float32 impulseRatio) { - m_allocator = def->allocator; + m_allocator = allocator; - m_count = def->count; - m_constraints = (b2ContactConstraint*)m_allocator->Allocate(m_count * sizeof(b2ContactConstraint)); + m_constraintCount = contactCount; + m_constraints = (b2ContactConstraint*)m_allocator->Allocate(m_constraintCount * sizeof(b2ContactConstraint)); - // Initialize position independent portions of the constraints. - for (int32 i = 0; i < m_count; ++i) + for (int32 i = 0; i < m_constraintCount; ++i) { - b2Contact* contact = def->contacts[i]; + b2Contact* contact = contacts[i]; b2Fixture* fixtureA = contact->m_fixtureA; b2Fixture* fixtureB = contact->m_fixtureB; @@ -49,21 +47,30 @@ b2ContactSolver::b2ContactSolver(b2ContactSolverDef* def) b2Body* bodyB = fixtureB->GetBody(); b2Manifold* manifold = contact->GetManifold(); + float32 friction = b2MixFriction(fixtureA->GetFriction(), fixtureB->GetFriction()); + float32 restitution = b2MixRestitution(fixtureA->GetRestitution(), fixtureB->GetRestitution()); + + b2Vec2 vA = bodyA->m_linearVelocity; + b2Vec2 vB = bodyB->m_linearVelocity; + float32 wA = bodyA->m_angularVelocity; + float32 wB = bodyB->m_angularVelocity; + b2Assert(manifold->pointCount > 0); + b2WorldManifold worldManifold; + worldManifold.Initialize(manifold, bodyA->m_xf, radiusA, bodyB->m_xf, radiusB); + b2ContactConstraint* cc = m_constraints + i; - cc->friction = contact->m_friction; - cc->restitution = contact->m_restitution; cc->bodyA = bodyA; cc->bodyB = bodyB; cc->manifold = manifold; - cc->normal.SetZero(); + cc->normal = worldManifold.normal; cc->pointCount = manifold->pointCount; + cc->friction = friction; cc->localNormal = manifold->localNormal; cc->localPoint = manifold->localPoint; - cc->radiusA = radiusA; - cc->radiusB = radiusB; + cc->radius = radiusA + radiusB; cc->type = manifold->type; for (int32 j = 0; j < cc->pointCount; ++j) @@ -71,63 +78,10 @@ b2ContactSolver::b2ContactSolver(b2ContactSolverDef* def) b2ManifoldPoint* cp = manifold->points + j; b2ContactConstraintPoint* ccp = cc->points + j; - if (def->warmStarting) - { - ccp->normalImpulse = def->impulseRatio * cp->normalImpulse; - ccp->tangentImpulse = def->impulseRatio * cp->tangentImpulse; - } - else - { - ccp->normalImpulse = 0.0f; - ccp->tangentImpulse = 0.0f; - } + ccp->normalImpulse = impulseRatio * cp->normalImpulse; + ccp->tangentImpulse = impulseRatio * cp->tangentImpulse; ccp->localPoint = cp->localPoint; - ccp->rA.SetZero(); - ccp->rB.SetZero(); - ccp->normalMass = 0.0f; - ccp->tangentMass = 0.0f; - ccp->velocityBias = 0.0f; - } - - cc->K.SetZero(); - cc->normalMass.SetZero(); - } -} - -b2ContactSolver::~b2ContactSolver() -{ - m_allocator->Free(m_constraints); -} - -// Initialize position dependent portions of the velocity constraints. -void b2ContactSolver::InitializeVelocityConstraints() -{ - for (int32 i = 0; i < m_count; ++i) - { - b2ContactConstraint* cc = m_constraints + i; - - float32 radiusA = cc->radiusA; - float32 radiusB = cc->radiusB; - b2Body* bodyA = cc->bodyA; - b2Body* bodyB = cc->bodyB; - b2Manifold* manifold = cc->manifold; - - b2Vec2 vA = bodyA->m_linearVelocity; - b2Vec2 vB = bodyB->m_linearVelocity; - float32 wA = bodyA->m_angularVelocity; - float32 wB = bodyB->m_angularVelocity; - - b2Assert(manifold->pointCount > 0); - - b2WorldManifold worldManifold; - worldManifold.Initialize(manifold, bodyA->m_xf, radiusA, bodyB->m_xf, radiusB); - - cc->normal = worldManifold.normal; - - for (int32 j = 0; j < cc->pointCount; ++j) - { - b2ContactConstraintPoint* ccp = cc->points + j; ccp->rA = worldManifold.points[j] - bodyA->m_sweep.c; ccp->rB = worldManifold.points[j] - bodyB->m_sweep.c; @@ -159,7 +113,7 @@ void b2ContactSolver::InitializeVelocityConstraints() float32 vRel = b2Dot(cc->normal, vB + b2Cross(wB, ccp->rB) - vA - b2Cross(wA, ccp->rA)); if (vRel < -b2_velocityThreshold) { - ccp->velocityBias = -cc->restitution * vRel; + ccp->velocityBias = -restitution * vRel; } } @@ -168,7 +122,7 @@ void b2ContactSolver::InitializeVelocityConstraints() { b2ContactConstraintPoint* ccp1 = cc->points + 0; b2ContactConstraintPoint* ccp2 = cc->points + 1; - + float32 invMassA = bodyA->m_invMass; float32 invIA = bodyA->m_invI; float32 invMassB = bodyB->m_invMass; @@ -184,7 +138,7 @@ void b2ContactSolver::InitializeVelocityConstraints() float32 k12 = invMassA + invMassB + invIA * rn1A * rn2A + invIB * rn1B * rn2B; // Ensure a reasonable condition number. - const float32 k_maxConditionNumber = 1000.0f; + const float32 k_maxConditionNumber = 100.0f; if (k11 * k11 < k_maxConditionNumber * (k11 * k22 - k12 * k12)) { // K is safe to invert. @@ -202,10 +156,15 @@ void b2ContactSolver::InitializeVelocityConstraints() } } +b2ContactSolver::~b2ContactSolver() +{ + m_allocator->Free(m_constraints); +} + void b2ContactSolver::WarmStart() { // Warm start. - for (int32 i = 0; i < m_count; ++i) + for (int32 i = 0; i < m_constraintCount; ++i) { b2ContactConstraint* c = m_constraints + i; @@ -232,7 +191,7 @@ void b2ContactSolver::WarmStart() void b2ContactSolver::SolveVelocityConstraints() { - for (int32 i = 0; i < m_count; ++i) + for (int32 i = 0; i < m_constraintCount; ++i) { b2ContactConstraint* c = m_constraints + i; b2Body* bodyA = c->bodyA; @@ -531,7 +490,7 @@ void b2ContactSolver::SolveVelocityConstraints() void b2ContactSolver::StoreImpulses() { - for (int32 i = 0; i < m_count; ++i) + for (int32 i = 0; i < m_constraintCount; ++i) { b2ContactConstraint* c = m_constraints + i; b2Manifold* m = c->manifold; @@ -567,7 +526,7 @@ struct b2PositionSolverManifold } point = 0.5f * (pointA + pointB); - separation = b2Dot(pointB - pointA, normal) - cc->radiusA - cc->radiusB; + separation = b2Dot(pointB - pointA, normal) - cc->radius; } break; @@ -577,7 +536,7 @@ struct b2PositionSolverManifold b2Vec2 planePoint = cc->bodyA->GetWorldPoint(cc->localPoint); b2Vec2 clipPoint = cc->bodyB->GetWorldPoint(cc->points[index].localPoint); - separation = b2Dot(clipPoint - planePoint, normal) - cc->radiusA - cc->radiusB; + separation = b2Dot(clipPoint - planePoint, normal) - cc->radius; point = clipPoint; } break; @@ -588,7 +547,7 @@ struct b2PositionSolverManifold b2Vec2 planePoint = cc->bodyB->GetWorldPoint(cc->localPoint); b2Vec2 clipPoint = cc->bodyA->GetWorldPoint(cc->points[index].localPoint); - separation = b2Dot(clipPoint - planePoint, normal) - cc->radiusA - cc->radiusB; + separation = b2Dot(clipPoint - planePoint, normal) - cc->radius; point = clipPoint; // Ensure normal points from A to B @@ -608,7 +567,7 @@ bool b2ContactSolver::SolvePositionConstraints(float32 baumgarte) { float32 minSeparation = 0.0f; - for (int32 i = 0; i < m_count; ++i) + for (int32 i = 0; i < m_constraintCount; ++i) { b2ContactConstraint* c = m_constraints + i; b2Body* bodyA = c->bodyA; @@ -662,75 +621,3 @@ bool b2ContactSolver::SolvePositionConstraints(float32 baumgarte) // push the separation above -b2_linearSlop. return minSeparation >= -1.5f * b2_linearSlop; } - -// Sequential position solver for position constraints. -bool b2ContactSolver::SolveTOIPositionConstraints(float32 baumgarte, const b2Body* toiBodyA, const b2Body* toiBodyB) -{ - float32 minSeparation = 0.0f; - - for (int32 i = 0; i < m_count; ++i) - { - b2ContactConstraint* c = m_constraints + i; - b2Body* bodyA = c->bodyA; - b2Body* bodyB = c->bodyB; - - float32 massA = 0.0f; - if (bodyA == toiBodyA || bodyA == toiBodyB) - { - massA = bodyA->m_mass; - } - - float32 massB = 0.0f; - if (bodyB == toiBodyA || bodyB == toiBodyB) - { - massB = bodyB->m_mass; - } - - float32 invMassA = bodyA->m_mass * bodyA->m_invMass; - float32 invIA = bodyA->m_mass * bodyA->m_invI; - float32 invMassB = bodyB->m_mass * bodyB->m_invMass; - float32 invIB = bodyB->m_mass * bodyB->m_invI; - - // Solve normal constraints - for (int32 j = 0; j < c->pointCount; ++j) - { - b2PositionSolverManifold psm; - psm.Initialize(c, j); - b2Vec2 normal = psm.normal; - - b2Vec2 point = psm.point; - float32 separation = psm.separation; - - b2Vec2 rA = point - bodyA->m_sweep.c; - b2Vec2 rB = point - bodyB->m_sweep.c; - - // Track max constraint error. - minSeparation = b2Min(minSeparation, separation); - - // Prevent large corrections and allow slop. - float32 C = b2Clamp(baumgarte * (separation + b2_linearSlop), -b2_maxLinearCorrection, 0.0f); - - // Compute the effective mass. - float32 rnA = b2Cross(rA, normal); - float32 rnB = b2Cross(rB, normal); - float32 K = invMassA + invMassB + invIA * rnA * rnA + invIB * rnB * rnB; - - // Compute normal impulse - float32 impulse = K > 0.0f ? - C / K : 0.0f; - - b2Vec2 P = impulse * normal; - - bodyA->m_sweep.c -= invMassA * P; - bodyA->m_sweep.a -= invIA * b2Cross(rA, P); - bodyA->SynchronizeTransform(); - - bodyB->m_sweep.c += invMassB * P; - bodyB->m_sweep.a += invIB * b2Cross(rB, P); - bodyB->SynchronizeTransform(); - } - } - - // We can't expect minSpeparation >= -b2_linearSlop because we don't - // push the separation above -b2_linearSlop. - return minSeparation >= -1.5f * b2_linearSlop; -} diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2ContactSolver.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2ContactSolver.h index 93698d0..b8555bb 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2ContactSolver.h +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2ContactSolver.h @@ -1,5 +1,5 @@ /* -* 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 @@ -50,41 +50,29 @@ struct b2ContactConstraint b2Body* bodyA; b2Body* bodyB; b2Manifold::Type type; - float32 radiusA, radiusB; + float32 radius; float32 friction; - float32 restitution; int32 pointCount; b2Manifold* manifold; }; -struct b2ContactSolverDef -{ - b2Contact** contacts; - int32 count; - b2StackAllocator* allocator; - float32 impulseRatio; - bool warmStarting; -}; - class b2ContactSolver { public: - b2ContactSolver(b2ContactSolverDef* def); - ~b2ContactSolver(); + b2ContactSolver(b2Contact** contacts, int32 contactCount, + b2StackAllocator* allocator, float32 impulseRatio); - void InitializeVelocityConstraints(); + ~b2ContactSolver(); void WarmStart(); void SolveVelocityConstraints(); void StoreImpulses(); bool SolvePositionConstraints(float32 baumgarte); - bool SolveTOIPositionConstraints(float32 baumgarte, const b2Body* toiBodyA, const b2Body* toiBodyB); b2StackAllocator* m_allocator; b2ContactConstraint* m_constraints; - int m_count; + int m_constraintCount; }; #endif - diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp deleted file mode 100644 index 0433650..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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 -#include -#include - -#include -using namespace std; - -b2Contact* b2EdgeAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) -{ - void* mem = allocator->Allocate(sizeof(b2EdgeAndCircleContact)); - return new (mem) b2EdgeAndCircleContact(fixtureA, fixtureB); -} - -void b2EdgeAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) -{ - ((b2EdgeAndCircleContact*)contact)->~b2EdgeAndCircleContact(); - allocator->Free(contact, sizeof(b2EdgeAndCircleContact)); -} - -b2EdgeAndCircleContact::b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) -: b2Contact(fixtureA, 0, fixtureB, 0) -{ - b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); - b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); -} - -void b2EdgeAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) -{ - b2CollideEdgeAndCircle( manifold, - (b2EdgeShape*)m_fixtureA->GetShape(), xfA, - (b2CircleShape*)m_fixtureB->GetShape(), xfB); -} diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h deleted file mode 100644 index 11b61b8..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef B2_EDGE_AND_CIRCLE_CONTACT_H -#define B2_EDGE_AND_CIRCLE_CONTACT_H - -#include - -class b2BlockAllocator; - -class b2EdgeAndCircleContact : public b2Contact -{ -public: - static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, - b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); - static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); - - b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); - ~b2EdgeAndCircleContact() {} - - void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); -}; - -#endif diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp deleted file mode 100644 index 8bac536..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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 -#include -#include - -#include -using namespace std; - -b2Contact* b2EdgeAndPolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) -{ - void* mem = allocator->Allocate(sizeof(b2EdgeAndPolygonContact)); - return new (mem) b2EdgeAndPolygonContact(fixtureA, fixtureB); -} - -void b2EdgeAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) -{ - ((b2EdgeAndPolygonContact*)contact)->~b2EdgeAndPolygonContact(); - allocator->Free(contact, sizeof(b2EdgeAndPolygonContact)); -} - -b2EdgeAndPolygonContact::b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) -: b2Contact(fixtureA, 0, fixtureB, 0) -{ - b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); - b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); -} - -void b2EdgeAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) -{ - b2CollideEdgeAndPolygon( manifold, - (b2EdgeShape*)m_fixtureA->GetShape(), xfA, - (b2PolygonShape*)m_fixtureB->GetShape(), xfB); -} diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h deleted file mode 100644 index 74b27ee..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef B2_EDGE_AND_POLYGON_CONTACT_H -#define B2_EDGE_AND_POLYGON_CONTACT_H - -#include - -class b2BlockAllocator; - -class b2EdgeAndPolygonContact : public b2Contact -{ -public: - static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, - b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); - static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); - - b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); - ~b2EdgeAndPolygonContact() {} - - void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); -}; - -#endif diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndCircleContact.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndCircleContact.cpp deleted file mode 100644 index c1e4ab2..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndCircleContact.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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 -#include -#include -#include -#include - -#include -using namespace std; - -b2Contact* b2LoopAndCircleContact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator) -{ - void* mem = allocator->Allocate(sizeof(b2LoopAndCircleContact)); - return new (mem) b2LoopAndCircleContact(fixtureA, indexA, fixtureB, indexB); -} - -void b2LoopAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) -{ - ((b2LoopAndCircleContact*)contact)->~b2LoopAndCircleContact(); - allocator->Free(contact, sizeof(b2LoopAndCircleContact)); -} - -b2LoopAndCircleContact::b2LoopAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB) -: b2Contact(fixtureA, indexA, fixtureB, indexB) -{ - b2Assert(m_fixtureA->GetType() == b2Shape::e_loop); - b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); -} - -void b2LoopAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) -{ - b2LoopShape* loop = (b2LoopShape*)m_fixtureA->GetShape(); - b2EdgeShape edge; - loop->GetChildEdge(&edge, m_indexA); - b2CollideEdgeAndCircle( manifold, &edge, xfA, - (b2CircleShape*)m_fixtureB->GetShape(), xfB); -} diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndCircleContact.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndCircleContact.h deleted file mode 100644 index 33d6a41..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndCircleContact.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef B2_LOOP_AND_CIRCLE_CONTACT_H -#define B2_LOOP_AND_CIRCLE_CONTACT_H - -#include - -class b2BlockAllocator; - -class b2LoopAndCircleContact : public b2Contact -{ -public: - static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, - b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); - static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); - - b2LoopAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); - ~b2LoopAndCircleContact() {} - - void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); -}; - -#endif diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndPolygonContact.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndPolygonContact.cpp deleted file mode 100644 index 8bd0795..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndPolygonContact.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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 -#include -#include -#include -#include - -#include -using namespace std; - -b2Contact* b2LoopAndPolygonContact::Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator) -{ - void* mem = allocator->Allocate(sizeof(b2LoopAndPolygonContact)); - return new (mem) b2LoopAndPolygonContact(fixtureA, indexA, fixtureB, indexB); -} - -void b2LoopAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) -{ - ((b2LoopAndPolygonContact*)contact)->~b2LoopAndPolygonContact(); - allocator->Free(contact, sizeof(b2LoopAndPolygonContact)); -} - -b2LoopAndPolygonContact::b2LoopAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB) -: b2Contact(fixtureA, indexA, fixtureB, indexB) -{ - b2Assert(m_fixtureA->GetType() == b2Shape::e_loop); - b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); -} - -void b2LoopAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) -{ - b2LoopShape* loop = (b2LoopShape*)m_fixtureA->GetShape(); - b2EdgeShape edge; - loop->GetChildEdge(&edge, m_indexA); - b2CollideEdgeAndPolygon( manifold, &edge, xfA, - (b2PolygonShape*)m_fixtureB->GetShape(), xfB); -} diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndPolygonContact.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndPolygonContact.h deleted file mode 100644 index 7e96abc..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2LoopAndPolygonContact.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef B2_LOOP_AND_POLYGON_CONTACT_H -#define B2_LOOP_AND_POLYGON_CONTACT_H - -#include - -class b2BlockAllocator; - -class b2LoopAndPolygonContact : public b2Contact -{ -public: - static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, - b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); - static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); - - b2LoopAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); - ~b2LoopAndPolygonContact() {} - - void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); -}; - -#endif diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp index 880f83e..837722d 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -18,12 +18,14 @@ #include #include +#include +#include #include +#include #include -using namespace std; -b2Contact* b2PolygonAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) +b2Contact* b2PolygonAndCircleContact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator) { void* mem = allocator->Allocate(sizeof(b2PolygonAndCircleContact)); return new (mem) b2PolygonAndCircleContact(fixtureA, fixtureB); @@ -36,7 +38,7 @@ void b2PolygonAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* al } b2PolygonAndCircleContact::b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) -: b2Contact(fixtureA, 0, fixtureB, 0) +: b2Contact(fixtureA, fixtureB) { b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h index 6beca16..684b2ae 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h @@ -1,5 +1,5 @@ /* -* 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 @@ -26,7 +26,7 @@ class b2BlockAllocator; class b2PolygonAndCircleContact : public b2Contact { public: - static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); + static b2Contact* Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator); static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonContact.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonContact.cpp index 52e1be8..eab2af5 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonContact.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonContact.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -24,9 +24,8 @@ #include #include -using namespace std; -b2Contact* b2PolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) +b2Contact* b2PolygonContact::Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator) { void* mem = allocator->Allocate(sizeof(b2PolygonContact)); return new (mem) b2PolygonContact(fixtureA, fixtureB); @@ -39,7 +38,7 @@ void b2PolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) } b2PolygonContact::b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) - : b2Contact(fixtureA, 0, fixtureB, 0) + : b2Contact(fixtureA, fixtureB) { b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonContact.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonContact.h index 4593214..af544c2 100644 --- a/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonContact.h +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2PolygonContact.h @@ -1,5 +1,5 @@ /* -* 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 @@ -26,8 +26,7 @@ class b2BlockAllocator; class b2PolygonContact : public b2Contact { public: - static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, - b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); + static b2Contact* Create(b2Fixture* fixtureA, b2Fixture* fixtureB, b2BlockAllocator* allocator); static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); diff --git a/libs/box2d/src/Box2D/Dynamics/Contacts/b2TOISolver.cpp b/libs/box2d/src/Box2D/Dynamics/Contacts/b2TOISolver.cpp new file mode 100644 index 0000000..567cd71 --- /dev/null +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2TOISolver.cpp @@ -0,0 +1,231 @@ +/* +* Copyright (c) 2006-2010 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 +#include +#include +#include +#include + +struct b2TOIConstraint +{ + b2Vec2 localPoints[b2_maxManifoldPoints]; + b2Vec2 localNormal; + b2Vec2 localPoint; + b2Manifold::Type type; + float32 radius; + int32 pointCount; + b2Body* bodyA; + b2Body* bodyB; +}; + +b2TOISolver::b2TOISolver(b2StackAllocator* allocator) +{ + m_allocator = allocator; + m_constraints = NULL; + m_count = NULL; + m_toiBody = NULL; +} + +b2TOISolver::~b2TOISolver() +{ + Clear(); +} + +void b2TOISolver::Clear() +{ + if (m_allocator && m_constraints) + { + m_allocator->Free(m_constraints); + m_constraints = NULL; + } +} + +void b2TOISolver::Initialize(b2Contact** contacts, int32 count, b2Body* toiBody) +{ + Clear(); + + m_count = count; + m_toiBody = toiBody; + + m_constraints = (b2TOIConstraint*) m_allocator->Allocate(m_count * sizeof(b2TOIConstraint)); + + for (int32 i = 0; i < m_count; ++i) + { + b2Contact* contact = contacts[i]; + + b2Fixture* fixtureA = contact->GetFixtureA(); + b2Fixture* fixtureB = contact->GetFixtureB(); + b2Shape* shapeA = fixtureA->GetShape(); + b2Shape* shapeB = fixtureB->GetShape(); + float32 radiusA = shapeA->m_radius; + float32 radiusB = shapeB->m_radius; + b2Body* bodyA = fixtureA->GetBody(); + b2Body* bodyB = fixtureB->GetBody(); + b2Manifold* manifold = contact->GetManifold(); + + b2Assert(manifold->pointCount > 0); + + b2TOIConstraint* constraint = m_constraints + i; + constraint->bodyA = bodyA; + constraint->bodyB = bodyB; + constraint->localNormal = manifold->localNormal; + constraint->localPoint = manifold->localPoint; + constraint->type = manifold->type; + constraint->pointCount = manifold->pointCount; + constraint->radius = radiusA + radiusB; + + for (int32 j = 0; j < constraint->pointCount; ++j) + { + b2ManifoldPoint* cp = manifold->points + j; + constraint->localPoints[j] = cp->localPoint; + } + } +} + +struct b2TOISolverManifold +{ + void Initialize(b2TOIConstraint* cc, int32 index) + { + b2Assert(cc->pointCount > 0); + + switch (cc->type) + { + case b2Manifold::e_circles: + { + b2Vec2 pointA = cc->bodyA->GetWorldPoint(cc->localPoint); + b2Vec2 pointB = cc->bodyB->GetWorldPoint(cc->localPoints[0]); + if (b2DistanceSquared(pointA, pointB) > b2_epsilon * b2_epsilon) + { + normal = pointB - pointA; + normal.Normalize(); + } + else + { + normal.Set(1.0f, 0.0f); + } + + point = 0.5f * (pointA + pointB); + separation = b2Dot(pointB - pointA, normal) - cc->radius; + } + break; + + case b2Manifold::e_faceA: + { + normal = cc->bodyA->GetWorldVector(cc->localNormal); + b2Vec2 planePoint = cc->bodyA->GetWorldPoint(cc->localPoint); + + b2Vec2 clipPoint = cc->bodyB->GetWorldPoint(cc->localPoints[index]); + separation = b2Dot(clipPoint - planePoint, normal) - cc->radius; + point = clipPoint; + } + break; + + case b2Manifold::e_faceB: + { + normal = cc->bodyB->GetWorldVector(cc->localNormal); + b2Vec2 planePoint = cc->bodyB->GetWorldPoint(cc->localPoint); + + b2Vec2 clipPoint = cc->bodyA->GetWorldPoint(cc->localPoints[index]); + separation = b2Dot(clipPoint - planePoint, normal) - cc->radius; + point = clipPoint; + + // Ensure normal points from A to B + normal = -normal; + } + break; + } + } + + b2Vec2 normal; + b2Vec2 point; + float32 separation; +}; + +// Push out the toi body to provide clearance for further simulation. +bool b2TOISolver::Solve(float32 baumgarte) +{ + float32 minSeparation = 0.0f; + + for (int32 i = 0; i < m_count; ++i) + { + b2TOIConstraint* c = m_constraints + i; + b2Body* bodyA = c->bodyA; + b2Body* bodyB = c->bodyB; + + float32 massA = bodyA->m_mass; + float32 massB = bodyB->m_mass; + + // Only the TOI body should move. + if (bodyA == m_toiBody) + { + massB = 0.0f; + } + else + { + massA = 0.0f; + } + + float32 invMassA = massA * bodyA->m_invMass; + float32 invIA = massA * bodyA->m_invI; + float32 invMassB = massB * bodyB->m_invMass; + float32 invIB = massB * bodyB->m_invI; + + // Solve normal constraints + for (int32 j = 0; j < c->pointCount; ++j) + { + b2TOISolverManifold psm; + psm.Initialize(c, j); + b2Vec2 normal = psm.normal; + + b2Vec2 point = psm.point; + float32 separation = psm.separation; + + b2Vec2 rA = point - bodyA->m_sweep.c; + b2Vec2 rB = point - bodyB->m_sweep.c; + + // Track max constraint error. + minSeparation = b2Min(minSeparation, separation); + + // Prevent large corrections and allow slop. + float32 C = b2Clamp(baumgarte * (separation + b2_linearSlop), -b2_maxLinearCorrection, 0.0f); + + // Compute the effective mass. + float32 rnA = b2Cross(rA, normal); + float32 rnB = b2Cross(rB, normal); + float32 K = invMassA + invMassB + invIA * rnA * rnA + invIB * rnB * rnB; + + // Compute normal impulse + float32 impulse = K > 0.0f ? - C / K : 0.0f; + + b2Vec2 P = impulse * normal; + + bodyA->m_sweep.c -= invMassA * P; + bodyA->m_sweep.a -= invIA * b2Cross(rA, P); + bodyA->SynchronizeTransform(); + + bodyB->m_sweep.c += invMassB * P; + bodyB->m_sweep.a += invIB * b2Cross(rB, P); + bodyB->SynchronizeTransform(); + } + } + + // We can't expect minSpeparation >= -b2_linearSlop because we don't + // push the separation above -b2_linearSlop. + return minSeparation >= -1.5f * b2_linearSlop; +} diff --git a/libs/box2d/src/Box2D/Common/b2Timer.h b/libs/box2d/src/Box2D/Dynamics/Contacts/b2TOISolver.h similarity index 53% rename from libs/box2d/src/Box2D/Common/b2Timer.h rename to libs/box2d/src/Box2D/Dynamics/Contacts/b2TOISolver.h index 14e1437..c092e2a 100644 --- a/libs/box2d/src/Box2D/Common/b2Timer.h +++ b/libs/box2d/src/Box2D/Dynamics/Contacts/b2TOISolver.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2011 Erin Catto http://box2d.org +* Copyright (c) 2006-2010 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 @@ -16,25 +16,36 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#ifndef B2_TOI_SOLVER_H +#define B2_TOI_SOLVER_H -/// Timer for profiling. This has platform specific code and may -/// not work on every platform. -class b2Timer +#include + +class b2Contact; +class b2Body; +struct b2TOIConstraint; +class b2StackAllocator; + +/// This is a pure position solver for a single movable body in contact with +/// multiple non-moving bodies. +class b2TOISolver { public: + b2TOISolver(b2StackAllocator* allocator); + ~b2TOISolver(); - /// Constructor - b2Timer(); + void Initialize(b2Contact** contacts, int32 contactCount, b2Body* toiBody); + void Clear(); - /// Reset the timer. - void Reset(); - - /// Get the time since construction or the last reset. - float32 GetMilliseconds() const; + // Perform one solver iteration. Returns true if converged. + bool Solve(float32 baumgarte); private: - float64 m_start; - static float64 s_invFrequency; + b2TOIConstraint* m_constraints; + int32 m_count; + b2Body* m_toiBody; + b2StackAllocator* m_allocator; }; + +#endif diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2DistanceJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2DistanceJoint.cpp index 3112279..3469bd9 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2DistanceJoint.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2DistanceJoint.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -46,6 +46,7 @@ void b2DistanceJointDef::Initialize(b2Body* b1, b2Body* b2, length = d.Length(); } + b2DistanceJoint::b2DistanceJoint(const b2DistanceJointDef* def) : b2Joint(def) { diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2DistanceJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2DistanceJoint.h index f2a9732..448faa6 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2DistanceJoint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2DistanceJoint.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -70,12 +70,7 @@ public: b2Vec2 GetAnchorA() const; b2Vec2 GetAnchorB() const; - /// Get the reaction force given the inverse time step. - /// Unit is N. b2Vec2 GetReactionForce(float32 inv_dt) const; - - /// Get the reaction torque given the inverse time step. - /// Unit is N*m. This is always zero for a distance joint. float32 GetReactionTorque(float32 inv_dt) const; /// Set/get the natural length. diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2FrictionJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2FrictionJoint.cpp index 83e9e7e..9097dee 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2FrictionJoint.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2FrictionJoint.cpp @@ -1,5 +1,5 @@ /* -* 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 diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2FrictionJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2FrictionJoint.h index bba5133..b4c4af2 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2FrictionJoint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2FrictionJoint.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2GearJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2GearJoint.cpp index 83433d2..89b17ee 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2GearJoint.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2GearJoint.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007 Erin Catto http://www.box2d.org +* Copyright (c) 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 diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2GearJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2GearJoint.h index cea3a10..eccca0d 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2GearJoint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2GearJoint.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2Joint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2Joint.cpp index eee195a..a7e19d3 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2Joint.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2Joint.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -81,10 +80,10 @@ b2Joint* b2Joint::Create(const b2JointDef* def, b2BlockAllocator* allocator) } break; - case e_wheelJoint: + case e_lineJoint: { - void* mem = allocator->Allocate(sizeof(b2WheelJoint)); - joint = new (mem) b2WheelJoint((b2WheelJointDef*)def); + void* mem = allocator->Allocate(sizeof(b2LineJoint)); + joint = new (mem) b2LineJoint((b2LineJointDef*)def); } break; @@ -102,13 +101,6 @@ b2Joint* b2Joint::Create(const b2JointDef* def, b2BlockAllocator* allocator) } break; - case e_ropeJoint: - { - void* mem = allocator->Allocate(sizeof(b2RopeJoint)); - joint = new (mem) b2RopeJoint((b2RopeJointDef*)def); - } - break; - default: b2Assert(false); break; @@ -146,8 +138,8 @@ void b2Joint::Destroy(b2Joint* joint, b2BlockAllocator* allocator) allocator->Free(joint, sizeof(b2GearJoint)); break; - case e_wheelJoint: - allocator->Free(joint, sizeof(b2WheelJoint)); + case e_lineJoint: + allocator->Free(joint, sizeof(b2LineJoint)); break; case e_weldJoint: @@ -158,10 +150,6 @@ void b2Joint::Destroy(b2Joint* joint, b2BlockAllocator* allocator) allocator->Free(joint, sizeof(b2FrictionJoint)); break; - case e_ropeJoint: - allocator->Free(joint, sizeof(b2RopeJoint)); - break; - default: b2Assert(false); break; diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2Joint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2Joint.h index baffab3..213ad7d 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2Joint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2Joint.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -35,10 +35,9 @@ enum b2JointType e_pulleyJoint, e_mouseJoint, e_gearJoint, - e_wheelJoint, + e_lineJoint, e_weldJoint, e_frictionJoint, - e_ropeJoint }; enum b2LimitState @@ -131,7 +130,6 @@ public: /// Get the next joint the world joint list. b2Joint* GetNext(); - const b2Joint* GetNext() const; /// Get the user data pointer. void* GetUserData() const; @@ -142,11 +140,6 @@ public: /// Short-cut function to determine if either body is inactive. bool IsActive() const; - /// Get collide connected. - /// Note: modifying the collide connect flag won't work correctly because - /// the flag is only checked when fixture AABBs begin to overlap. - bool GetCollideConnected() const; - protected: friend class b2World; friend class b2Body; @@ -178,7 +171,6 @@ protected: void* m_userData; // Cache here per time step to reduce cache misses. - // TODO_ERIN nuke b2Vec2 m_localCenterA, m_localCenterB; float32 m_invMassA, m_invIA; float32 m_invMassB, m_invIB; @@ -221,11 +213,6 @@ inline b2Joint* b2Joint::GetNext() return m_next; } -inline const b2Joint* b2Joint::GetNext() const -{ - return m_next; -} - inline void* b2Joint::GetUserData() const { return m_userData; @@ -236,9 +223,4 @@ inline void b2Joint::SetUserData(void* data) m_userData = data; } -inline bool b2Joint::GetCollideConnected() const -{ - return m_collideConnected; -} - #endif diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2LineJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2LineJoint.cpp new file mode 100644 index 0000000..b6b0a1c --- /dev/null +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2LineJoint.cpp @@ -0,0 +1,591 @@ +/* +* 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 +#include +#include + +// Linear constraint (point-to-line) +// d = p2 - p1 = x2 + r2 - x1 - r1 +// C = dot(perp, d) +// Cdot = dot(d, cross(w1, perp)) + dot(perp, v2 + cross(w2, r2) - v1 - cross(w1, r1)) +// = -dot(perp, v1) - dot(cross(d + r1, perp), w1) + dot(perp, v2) + dot(cross(r2, perp), v2) +// J = [-perp, -cross(d + r1, perp), perp, cross(r2,perp)] +// +// K = J * invM * JT +// +// J = [-a -s1 a s2] +// a = perp +// s1 = cross(d + r1, a) = cross(p2 - x1, a) +// s2 = cross(r2, a) = cross(p2 - x2, a) + + +// Motor/Limit linear constraint +// C = dot(ax1, d) +// Cdot = = -dot(ax1, v1) - dot(cross(d + r1, ax1), w1) + dot(ax1, v2) + dot(cross(r2, ax1), v2) +// J = [-ax1 -cross(d+r1,ax1) ax1 cross(r2,ax1)] + +// Block Solver +// We develop a block solver that includes the joint limit. This makes the limit stiff (inelastic) even +// when the mass has poor distribution (leading to large torques about the joint anchor points). +// +// The Jacobian has 3 rows: +// J = [-uT -s1 uT s2] // linear +// [-vT -a1 vT a2] // limit +// +// u = perp +// v = axis +// s1 = cross(d + r1, u), s2 = cross(r2, u) +// a1 = cross(d + r1, v), a2 = cross(r2, v) + +// M * (v2 - v1) = JT * df +// J * v2 = bias +// +// v2 = v1 + invM * JT * df +// J * (v1 + invM * JT * df) = bias +// K * df = bias - J * v1 = -Cdot +// K = J * invM * JT +// Cdot = J * v1 - bias +// +// Now solve for f2. +// df = f2 - f1 +// K * (f2 - f1) = -Cdot +// f2 = invK * (-Cdot) + f1 +// +// Clamp accumulated limit impulse. +// lower: f2(2) = max(f2(2), 0) +// upper: f2(2) = min(f2(2), 0) +// +// Solve for correct f2(1) +// K(1,1) * f2(1) = -Cdot(1) - K(1,2) * f2(2) + K(1,1:2) * f1 +// = -Cdot(1) - K(1,2) * f2(2) + K(1,1) * f1(1) + K(1,2) * f1(2) +// K(1,1) * f2(1) = -Cdot(1) - K(1,2) * (f2(2) - f1(2)) + K(1,1) * f1(1) +// f2(1) = invK(1,1) * (-Cdot(1) - K(1,2) * (f2(2) - f1(2))) + f1(1) +// +// Now compute impulse to be applied: +// df = f2 - f1 + +void b2LineJointDef::Initialize(b2Body* b1, b2Body* b2, const b2Vec2& anchor, const b2Vec2& axis) +{ + bodyA = b1; + bodyB = b2; + localAnchorA = bodyA->GetLocalPoint(anchor); + localAnchorB = bodyB->GetLocalPoint(anchor); + localAxisA = bodyA->GetLocalVector(axis); +} + +b2LineJoint::b2LineJoint(const b2LineJointDef* def) +: b2Joint(def) +{ + m_localAnchor1 = def->localAnchorA; + m_localAnchor2 = def->localAnchorB; + m_localXAxis1 = def->localAxisA; + m_localYAxis1 = b2Cross(1.0f, m_localXAxis1); + + m_impulse.SetZero(); + m_motorMass = 0.0; + m_motorImpulse = 0.0f; + + m_lowerTranslation = def->lowerTranslation; + m_upperTranslation = def->upperTranslation; + m_maxMotorForce = def->maxMotorForce; + m_motorSpeed = def->motorSpeed; + m_enableLimit = def->enableLimit; + m_enableMotor = def->enableMotor; + m_limitState = e_inactiveLimit; + + m_axis.SetZero(); + m_perp.SetZero(); +} + +void b2LineJoint::InitVelocityConstraints(const b2TimeStep& step) +{ + b2Body* b1 = m_bodyA; + b2Body* b2 = m_bodyB; + + m_localCenterA = b1->GetLocalCenter(); + m_localCenterB = b2->GetLocalCenter(); + + b2Transform xf1 = b1->GetTransform(); + b2Transform xf2 = b2->GetTransform(); + + // Compute the effective masses. + b2Vec2 r1 = b2Mul(xf1.R, m_localAnchor1 - m_localCenterA); + b2Vec2 r2 = b2Mul(xf2.R, m_localAnchor2 - m_localCenterB); + b2Vec2 d = b2->m_sweep.c + r2 - b1->m_sweep.c - r1; + + m_invMassA = b1->m_invMass; + m_invIA = b1->m_invI; + m_invMassB = b2->m_invMass; + m_invIB = b2->m_invI; + + // Compute motor Jacobian and effective mass. + { + m_axis = b2Mul(xf1.R, m_localXAxis1); + m_a1 = b2Cross(d + r1, m_axis); + m_a2 = b2Cross(r2, m_axis); + + m_motorMass = m_invMassA + m_invMassB + m_invIA * m_a1 * m_a1 + m_invIB * m_a2 * m_a2; + if (m_motorMass > b2_epsilon) + { + m_motorMass = 1.0f / m_motorMass; + } + else + { + m_motorMass = 0.0f; + } + } + + // Prismatic constraint. + { + m_perp = b2Mul(xf1.R, m_localYAxis1); + + m_s1 = b2Cross(d + r1, m_perp); + m_s2 = b2Cross(r2, m_perp); + + float32 m1 = m_invMassA, m2 = m_invMassB; + float32 i1 = m_invIA, i2 = m_invIB; + + float32 k11 = m1 + m2 + i1 * m_s1 * m_s1 + i2 * m_s2 * m_s2; + float32 k12 = i1 * m_s1 * m_a1 + i2 * m_s2 * m_a2; + float32 k22 = m1 + m2 + i1 * m_a1 * m_a1 + i2 * m_a2 * m_a2; + + m_K.col1.Set(k11, k12); + m_K.col2.Set(k12, k22); + } + + // Compute motor and limit terms. + if (m_enableLimit) + { + float32 jointTranslation = b2Dot(m_axis, d); + if (b2Abs(m_upperTranslation - m_lowerTranslation) < 2.0f * b2_linearSlop) + { + m_limitState = e_equalLimits; + } + else if (jointTranslation <= m_lowerTranslation) + { + if (m_limitState != e_atLowerLimit) + { + m_limitState = e_atLowerLimit; + m_impulse.y = 0.0f; + } + } + else if (jointTranslation >= m_upperTranslation) + { + if (m_limitState != e_atUpperLimit) + { + m_limitState = e_atUpperLimit; + m_impulse.y = 0.0f; + } + } + else + { + m_limitState = e_inactiveLimit; + m_impulse.y = 0.0f; + } + } + else + { + m_limitState = e_inactiveLimit; + } + + if (m_enableMotor == false) + { + m_motorImpulse = 0.0f; + } + + if (step.warmStarting) + { + // Account for variable time step. + m_impulse *= step.dtRatio; + m_motorImpulse *= step.dtRatio; + + b2Vec2 P = m_impulse.x * m_perp + (m_motorImpulse + m_impulse.y) * m_axis; + float32 L1 = m_impulse.x * m_s1 + (m_motorImpulse + m_impulse.y) * m_a1; + float32 L2 = m_impulse.x * m_s2 + (m_motorImpulse + m_impulse.y) * m_a2; + + b1->m_linearVelocity -= m_invMassA * P; + b1->m_angularVelocity -= m_invIA * L1; + + b2->m_linearVelocity += m_invMassB * P; + b2->m_angularVelocity += m_invIB * L2; + } + else + { + m_impulse.SetZero(); + m_motorImpulse = 0.0f; + } +} + +void b2LineJoint::SolveVelocityConstraints(const b2TimeStep& step) +{ + b2Body* b1 = m_bodyA; + b2Body* b2 = m_bodyB; + + b2Vec2 v1 = b1->m_linearVelocity; + float32 w1 = b1->m_angularVelocity; + b2Vec2 v2 = b2->m_linearVelocity; + float32 w2 = b2->m_angularVelocity; + + // Solve linear motor constraint. + if (m_enableMotor && m_limitState != e_equalLimits) + { + float32 Cdot = b2Dot(m_axis, v2 - v1) + m_a2 * w2 - m_a1 * w1; + float32 impulse = m_motorMass * (m_motorSpeed - Cdot); + float32 oldImpulse = m_motorImpulse; + float32 maxImpulse = step.dt * m_maxMotorForce; + m_motorImpulse = b2Clamp(m_motorImpulse + impulse, -maxImpulse, maxImpulse); + impulse = m_motorImpulse - oldImpulse; + + b2Vec2 P = impulse * m_axis; + float32 L1 = impulse * m_a1; + float32 L2 = impulse * m_a2; + + v1 -= m_invMassA * P; + w1 -= m_invIA * L1; + + v2 += m_invMassB * P; + w2 += m_invIB * L2; + } + + float32 Cdot1 = b2Dot(m_perp, v2 - v1) + m_s2 * w2 - m_s1 * w1; + + if (m_enableLimit && m_limitState != e_inactiveLimit) + { + // Solve prismatic and limit constraint in block form. + float32 Cdot2 = b2Dot(m_axis, v2 - v1) + m_a2 * w2 - m_a1 * w1; + b2Vec2 Cdot(Cdot1, Cdot2); + + b2Vec2 f1 = m_impulse; + b2Vec2 df = m_K.Solve(-Cdot); + m_impulse += df; + + if (m_limitState == e_atLowerLimit) + { + m_impulse.y = b2Max(m_impulse.y, 0.0f); + } + else if (m_limitState == e_atUpperLimit) + { + m_impulse.y = b2Min(m_impulse.y, 0.0f); + } + + // f2(1) = invK(1,1) * (-Cdot(1) - K(1,2) * (f2(2) - f1(2))) + f1(1) + float32 b = -Cdot1 - (m_impulse.y - f1.y) * m_K.col2.x; + float32 f2r; + if (m_K.col1.x != 0.0f) + { + f2r = b / m_K.col1.x + f1.x; + } + else + { + f2r = f1.x; + } + + m_impulse.x = f2r; + + df = m_impulse - f1; + + b2Vec2 P = df.x * m_perp + df.y * m_axis; + float32 L1 = df.x * m_s1 + df.y * m_a1; + float32 L2 = df.x * m_s2 + df.y * m_a2; + + v1 -= m_invMassA * P; + w1 -= m_invIA * L1; + + v2 += m_invMassB * P; + w2 += m_invIB * L2; + } + else + { + // Limit is inactive, just solve the prismatic constraint in block form. + float32 df; + if (m_K.col1.x != 0.0f) + { + df = - Cdot1 / m_K.col1.x; + } + else + { + df = 0.0f; + } + m_impulse.x += df; + + b2Vec2 P = df * m_perp; + float32 L1 = df * m_s1; + float32 L2 = df * m_s2; + + v1 -= m_invMassA * P; + w1 -= m_invIA * L1; + + v2 += m_invMassB * P; + w2 += m_invIB * L2; + } + + b1->m_linearVelocity = v1; + b1->m_angularVelocity = w1; + b2->m_linearVelocity = v2; + b2->m_angularVelocity = w2; +} + +bool b2LineJoint::SolvePositionConstraints(float32 baumgarte) +{ + B2_NOT_USED(baumgarte); + + b2Body* b1 = m_bodyA; + b2Body* b2 = m_bodyB; + + b2Vec2 c1 = b1->m_sweep.c; + float32 a1 = b1->m_sweep.a; + + b2Vec2 c2 = b2->m_sweep.c; + float32 a2 = b2->m_sweep.a; + + // Solve linear limit constraint. + float32 linearError = 0.0f, angularError = 0.0f; + bool active = false; + float32 C2 = 0.0f; + + b2Mat22 R1(a1), R2(a2); + + b2Vec2 r1 = b2Mul(R1, m_localAnchor1 - m_localCenterA); + b2Vec2 r2 = b2Mul(R2, m_localAnchor2 - m_localCenterB); + b2Vec2 d = c2 + r2 - c1 - r1; + + if (m_enableLimit) + { + m_axis = b2Mul(R1, m_localXAxis1); + + m_a1 = b2Cross(d + r1, m_axis); + m_a2 = b2Cross(r2, m_axis); + + float32 translation = b2Dot(m_axis, d); + if (b2Abs(m_upperTranslation - m_lowerTranslation) < 2.0f * b2_linearSlop) + { + // Prevent large angular corrections + C2 = b2Clamp(translation, -b2_maxLinearCorrection, b2_maxLinearCorrection); + linearError = b2Abs(translation); + active = true; + } + else if (translation <= m_lowerTranslation) + { + // Prevent large linear corrections and allow some slop. + C2 = b2Clamp(translation - m_lowerTranslation + b2_linearSlop, -b2_maxLinearCorrection, 0.0f); + linearError = m_lowerTranslation - translation; + active = true; + } + else if (translation >= m_upperTranslation) + { + // Prevent large linear corrections and allow some slop. + C2 = b2Clamp(translation - m_upperTranslation - b2_linearSlop, 0.0f, b2_maxLinearCorrection); + linearError = translation - m_upperTranslation; + active = true; + } + } + + m_perp = b2Mul(R1, m_localYAxis1); + + m_s1 = b2Cross(d + r1, m_perp); + m_s2 = b2Cross(r2, m_perp); + + b2Vec2 impulse; + float32 C1; + C1 = b2Dot(m_perp, d); + + linearError = b2Max(linearError, b2Abs(C1)); + angularError = 0.0f; + + if (active) + { + float32 m1 = m_invMassA, m2 = m_invMassB; + float32 i1 = m_invIA, i2 = m_invIB; + + float32 k11 = m1 + m2 + i1 * m_s1 * m_s1 + i2 * m_s2 * m_s2; + float32 k12 = i1 * m_s1 * m_a1 + i2 * m_s2 * m_a2; + float32 k22 = m1 + m2 + i1 * m_a1 * m_a1 + i2 * m_a2 * m_a2; + + m_K.col1.Set(k11, k12); + m_K.col2.Set(k12, k22); + + b2Vec2 C; + C.x = C1; + C.y = C2; + + impulse = m_K.Solve(-C); + } + else + { + float32 m1 = m_invMassA, m2 = m_invMassB; + float32 i1 = m_invIA, i2 = m_invIB; + + float32 k11 = m1 + m2 + i1 * m_s1 * m_s1 + i2 * m_s2 * m_s2; + + float32 impulse1; + if (k11 != 0.0f) + { + impulse1 = - C1 / k11; + } + else + { + impulse1 = 0.0f; + } + + impulse.x = impulse1; + impulse.y = 0.0f; + } + + b2Vec2 P = impulse.x * m_perp + impulse.y * m_axis; + float32 L1 = impulse.x * m_s1 + impulse.y * m_a1; + float32 L2 = impulse.x * m_s2 + impulse.y * m_a2; + + c1 -= m_invMassA * P; + a1 -= m_invIA * L1; + c2 += m_invMassB * P; + a2 += m_invIB * L2; + + // TODO_ERIN remove need for this. + b1->m_sweep.c = c1; + b1->m_sweep.a = a1; + b2->m_sweep.c = c2; + b2->m_sweep.a = a2; + b1->SynchronizeTransform(); + b2->SynchronizeTransform(); + + return linearError <= b2_linearSlop && angularError <= b2_angularSlop; +} + +b2Vec2 b2LineJoint::GetAnchorA() const +{ + return m_bodyA->GetWorldPoint(m_localAnchor1); +} + +b2Vec2 b2LineJoint::GetAnchorB() const +{ + return m_bodyB->GetWorldPoint(m_localAnchor2); +} + +b2Vec2 b2LineJoint::GetReactionForce(float32 inv_dt) const +{ + return inv_dt * (m_impulse.x * m_perp + (m_motorImpulse + m_impulse.y) * m_axis); +} + +float32 b2LineJoint::GetReactionTorque(float32 inv_dt) const +{ + B2_NOT_USED(inv_dt); + return 0.0f; +} + +float32 b2LineJoint::GetJointTranslation() const +{ + b2Body* b1 = m_bodyA; + b2Body* b2 = m_bodyB; + + b2Vec2 p1 = b1->GetWorldPoint(m_localAnchor1); + b2Vec2 p2 = b2->GetWorldPoint(m_localAnchor2); + b2Vec2 d = p2 - p1; + b2Vec2 axis = b1->GetWorldVector(m_localXAxis1); + + float32 translation = b2Dot(d, axis); + return translation; +} + +float32 b2LineJoint::GetJointSpeed() const +{ + b2Body* b1 = m_bodyA; + b2Body* b2 = m_bodyB; + + b2Vec2 r1 = b2Mul(b1->GetTransform().R, m_localAnchor1 - b1->GetLocalCenter()); + b2Vec2 r2 = b2Mul(b2->GetTransform().R, m_localAnchor2 - b2->GetLocalCenter()); + b2Vec2 p1 = b1->m_sweep.c + r1; + b2Vec2 p2 = b2->m_sweep.c + r2; + b2Vec2 d = p2 - p1; + b2Vec2 axis = b1->GetWorldVector(m_localXAxis1); + + b2Vec2 v1 = b1->m_linearVelocity; + b2Vec2 v2 = b2->m_linearVelocity; + float32 w1 = b1->m_angularVelocity; + float32 w2 = b2->m_angularVelocity; + + float32 speed = b2Dot(d, b2Cross(w1, axis)) + b2Dot(axis, v2 + b2Cross(w2, r2) - v1 - b2Cross(w1, r1)); + return speed; +} + +bool b2LineJoint::IsLimitEnabled() const +{ + return m_enableLimit; +} + +void b2LineJoint::EnableLimit(bool flag) +{ + m_bodyA->SetAwake(true); + m_bodyB->SetAwake(true); + m_enableLimit = flag; +} + +float32 b2LineJoint::GetLowerLimit() const +{ + return m_lowerTranslation; +} + +float32 b2LineJoint::GetUpperLimit() const +{ + return m_upperTranslation; +} + +void b2LineJoint::SetLimits(float32 lower, float32 upper) +{ + b2Assert(lower <= upper); + m_bodyA->SetAwake(true); + m_bodyB->SetAwake(true); + m_lowerTranslation = lower; + m_upperTranslation = upper; +} + +bool b2LineJoint::IsMotorEnabled() const +{ + return m_enableMotor; +} + +void b2LineJoint::EnableMotor(bool flag) +{ + m_bodyA->SetAwake(true); + m_bodyB->SetAwake(true); + m_enableMotor = flag; +} + +void b2LineJoint::SetMotorSpeed(float32 speed) +{ + m_bodyA->SetAwake(true); + m_bodyB->SetAwake(true); + m_motorSpeed = speed; +} + +void b2LineJoint::SetMaxMotorForce(float32 force) +{ + m_bodyA->SetAwake(true); + m_bodyB->SetAwake(true); + m_maxMotorForce = force; +} + +float32 b2LineJoint::GetMotorForce() const +{ + return m_motorImpulse; +} + + + + + diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2WheelJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2LineJoint.h similarity index 54% rename from libs/box2d/src/Box2D/Dynamics/Joints/b2WheelJoint.h rename to libs/box2d/src/Box2D/Dynamics/Joints/b2LineJoint.h index 5c9a90e..803e4c1 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2WheelJoint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2LineJoint.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org +* 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 @@ -16,30 +16,31 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#ifndef B2_WHEEL_JOINT_H -#define B2_WHEEL_JOINT_H +#ifndef B2_LINE_JOINT_H +#define B2_LINE_JOINT_H #include -/// Wheel joint definition. This requires defining a line of +/// Line joint definition. This requires defining a line of /// motion using an axis and an anchor point. The definition uses local /// anchor points and a local axis so that the initial configuration /// can violate the constraint slightly. The joint translation is zero /// when the local anchor points coincide in world space. Using local /// anchors and a local axis helps when saving and loading a game. -struct b2WheelJointDef : public b2JointDef +struct b2LineJointDef : public b2JointDef { - b2WheelJointDef() + b2LineJointDef() { - type = e_wheelJoint; + type = e_lineJoint; localAnchorA.SetZero(); localAnchorB.SetZero(); localAxisA.Set(1.0f, 0.0f); + enableLimit = false; + lowerTranslation = 0.0f; + upperTranslation = 0.0f; enableMotor = false; - maxMotorTorque = 0.0f; + maxMotorForce = 0.0f; motorSpeed = 0.0f; - frequencyHz = 2.0f; - dampingRatio = 0.7f; } /// Initialize the bodies, anchors, axis, and reference angle using the world @@ -55,28 +56,30 @@ struct b2WheelJointDef : public b2JointDef /// The local translation axis in body1. b2Vec2 localAxisA; + /// Enable/disable the joint limit. + bool enableLimit; + + /// The lower translation limit, usually in meters. + float32 lowerTranslation; + + /// The upper translation limit, usually in meters. + float32 upperTranslation; + /// Enable/disable the joint motor. bool enableMotor; /// The maximum motor torque, usually in N-m. - float32 maxMotorTorque; + float32 maxMotorForce; /// The desired motor speed in radians per second. float32 motorSpeed; - - /// Suspension frequency, zero indicates no suspension - float32 frequencyHz; - - /// Suspension damping ratio, one indicates critical damping - float32 dampingRatio; }; -/// A wheel joint. This joint provides two degrees of freedom: translation +/// A line joint. This joint provides two degrees of freedom: translation /// along an axis fixed in body1 and rotation in the plane. You can use a /// joint limit to restrict the range of motion and a joint motor to drive -/// the rotation or to model rotational friction. -/// This joint is designed for vehicle suspensions. -class b2WheelJoint : public b2Joint +/// the motion or to model joint friction. +class b2LineJoint : public b2Joint { public: b2Vec2 GetAnchorA() const; @@ -91,96 +94,77 @@ public: /// Get the current joint translation speed, usually in meters per second. float32 GetJointSpeed() const; + /// Is the joint limit enabled? + bool IsLimitEnabled() const; + + /// Enable/disable the joint limit. + void EnableLimit(bool flag); + + /// Get the lower joint limit, usually in meters. + float32 GetLowerLimit() const; + + /// Get the upper joint limit, usually in meters. + float32 GetUpperLimit() const; + + /// Set the joint limits, usually in meters. + void SetLimits(float32 lower, float32 upper); + /// Is the joint motor enabled? bool IsMotorEnabled() const; /// Enable/disable the joint motor. void EnableMotor(bool flag); - /// Set the motor speed, usually in radians per second. + /// Set the motor speed, usually in meters per second. void SetMotorSpeed(float32 speed); - /// Get the motor speed, usually in radians per second. + /// Get the motor speed, usually in meters per second. float32 GetMotorSpeed() const; - /// Set/Get the maximum motor force, usually in N-m. - void SetMaxMotorTorque(float32 torque); - float32 GetMaxMotorTorque() const; - - /// Get the current motor torque given the inverse time step, usually in N-m. - float32 GetMotorTorque(float32 inv_dt) const; + /// Set/Get the maximum motor force, usually in N. + void SetMaxMotorForce(float32 force); + float32 GetMaxMotorForce() const; - /// Set/Get the spring frequency in hertz. Setting the frequency to zero disables the spring. - void SetSpringFrequencyHz(float32 hz); - float32 GetSpringFrequencyHz() const; - - /// Set/Get the spring damping ratio - void SetSpringDampingRatio(float32 ratio); - float32 GetSpringDampingRatio() const; + /// Get the current motor force, usually in N. + float32 GetMotorForce() const; protected: friend class b2Joint; - b2WheelJoint(const b2WheelJointDef* def); + b2LineJoint(const b2LineJointDef* def); void InitVelocityConstraints(const b2TimeStep& step); void SolveVelocityConstraints(const b2TimeStep& step); bool SolvePositionConstraints(float32 baumgarte); - b2Vec2 m_localAnchorA; - b2Vec2 m_localAnchorB; - b2Vec2 m_localXAxisA; - b2Vec2 m_localYAxisA; + b2Vec2 m_localAnchor1; + b2Vec2 m_localAnchor2; + b2Vec2 m_localXAxis1; + b2Vec2 m_localYAxis1; + + b2Vec2 m_axis, m_perp; + float32 m_s1, m_s2; + float32 m_a1, m_a2; - b2Vec2 m_ax, m_ay; - float32 m_sAx, m_sBx; - float32 m_sAy, m_sBy; + b2Mat22 m_K; + b2Vec2 m_impulse; - float32 m_mass; - float32 m_impulse; - float32 m_motorMass; + float32 m_motorMass; // effective mass for motor/limit translational constraint. float32 m_motorImpulse; - float32 m_springMass; - float32 m_springImpulse; - float32 m_maxMotorTorque; + float32 m_lowerTranslation; + float32 m_upperTranslation; + float32 m_maxMotorForce; float32 m_motorSpeed; - float32 m_frequencyHz; - float32 m_dampingRatio; - float32 m_bias; - float32 m_gamma; + bool m_enableLimit; bool m_enableMotor; + b2LimitState m_limitState; }; -inline float32 b2WheelJoint::GetMotorSpeed() const +inline float32 b2LineJoint::GetMotorSpeed() const { return m_motorSpeed; } -inline float32 b2WheelJoint::GetMaxMotorTorque() const -{ - return m_maxMotorTorque; -} - -inline void b2WheelJoint::SetSpringFrequencyHz(float32 hz) -{ - m_frequencyHz = hz; -} - -inline float32 b2WheelJoint::GetSpringFrequencyHz() const -{ - return m_frequencyHz; -} - -inline void b2WheelJoint::SetSpringDampingRatio(float32 ratio) -{ - m_dampingRatio = ratio; -} - -inline float32 b2WheelJoint::GetSpringDampingRatio() const -{ - return m_dampingRatio; -} - #endif diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2MouseJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2MouseJoint.cpp index 2b01ef3..b72ac5f 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2MouseJoint.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2MouseJoint.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2MouseJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2MouseJoint.h index 1f000e6..cd1959a 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2MouseJoint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2MouseJoint.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp index 94e9aab..a019888 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -150,7 +150,7 @@ void b2PrismaticJoint::InitVelocityConstraints(const b2TimeStep& step) m_a2 = b2Cross(r2, m_axis); m_motorMass = m_invMassA + m_invMassB + m_invIA * m_a1 * m_a1 + m_invIB * m_a2 * m_a2; - if (m_motorMass > 0.0f) + if (m_motorMass > b2_epsilon) { m_motorMass = 1.0f / m_motorMass; } @@ -170,10 +170,6 @@ void b2PrismaticJoint::InitVelocityConstraints(const b2TimeStep& step) float32 k12 = i1 * m_s1 + i2 * m_s2; float32 k13 = i1 * m_s1 * m_a1 + i2 * m_s2 * m_a2; float32 k22 = i1 + i2; - if (k22 == 0.0f) - { - k22 = 1.0f; - } float32 k23 = i1 * m_a1 + i2 * m_a2; float32 k33 = m1 + m2 + i1 * m_a1 * m_a1 + i2 * m_a2 * m_a2; @@ -420,10 +416,6 @@ bool b2PrismaticJoint::SolvePositionConstraints(float32 baumgarte) float32 k12 = i1 * m_s1 + i2 * m_s2; float32 k13 = i1 * m_s1 * m_a1 + i2 * m_s2 * m_a2; float32 k22 = i1 + i2; - if (k22 == 0.0f) - { - k22 = 1.0f; - } float32 k23 = i1 * m_a1 + i2 * m_a2; float32 k33 = m1 + m2 + i1 * m_a1 * m_a1 + i2 * m_a2 * m_a2; @@ -446,10 +438,6 @@ bool b2PrismaticJoint::SolvePositionConstraints(float32 baumgarte) float32 k11 = m1 + m2 + i1 * m_s1 * m_s1 + i2 * m_s2 * m_s2; float32 k12 = i1 * m_s1 + i2 * m_s2; float32 k22 = i1 + i2; - if (k22 == 0.0f) - { - k22 = 1.0f; - } m_K.col1.Set(k11, k12, 0.0f); m_K.col2.Set(k12, k22, 0.0f); @@ -542,13 +530,9 @@ bool b2PrismaticJoint::IsLimitEnabled() const void b2PrismaticJoint::EnableLimit(bool flag) { - if (flag != m_enableLimit) - { - m_bodyA->SetAwake(true); - m_bodyB->SetAwake(true); - m_enableLimit = flag; - m_impulse.z = 0.0f; - } + m_bodyA->SetAwake(true); + m_bodyB->SetAwake(true); + m_enableLimit = flag; } float32 b2PrismaticJoint::GetLowerLimit() const @@ -564,14 +548,10 @@ float32 b2PrismaticJoint::GetUpperLimit() const void b2PrismaticJoint::SetLimits(float32 lower, float32 upper) { b2Assert(lower <= upper); - if (lower != m_lowerTranslation || upper != m_upperTranslation) - { - m_bodyA->SetAwake(true); - m_bodyB->SetAwake(true); - m_lowerTranslation = lower; - m_upperTranslation = upper; - m_impulse.z = 0.0f; - } + m_bodyA->SetAwake(true); + m_bodyB->SetAwake(true); + m_lowerTranslation = lower; + m_upperTranslation = upper; } bool b2PrismaticJoint::IsMotorEnabled() const @@ -600,7 +580,7 @@ void b2PrismaticJoint::SetMaxMotorForce(float32 force) m_maxMotorForce = force; } -float32 b2PrismaticJoint::GetMotorForce(float32 inv_dt) const +float32 b2PrismaticJoint::GetMotorForce() const { - return inv_dt * m_motorImpulse; + return m_motorImpulse; } diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2PrismaticJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2PrismaticJoint.h index 7ccdd3e..7a12c5d 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2PrismaticJoint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2PrismaticJoint.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -129,8 +129,8 @@ public: /// Set the maximum motor force, usually in N. void SetMaxMotorForce(float32 force); - /// Get the current motor force given the inverse time step, usually in N. - float32 GetMotorForce(float32 inv_dt) const; + /// Get the current motor force, usually in N. + float32 GetMotorForce() const; protected: friend class b2Joint; diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2PulleyJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2PulleyJoint.cpp index 141c797..beb7db8 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2PulleyJoint.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2PulleyJoint.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007 Erin Catto http://www.box2d.org +* Copyright (c) 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 @@ -24,13 +24,20 @@ // length1 = norm(p1 - s1) // length2 = norm(p2 - s2) // C0 = (length1 + ratio * length2)_initial -// C = C0 - (length1 + ratio * length2) +// C = C0 - (length1 + ratio * length2) >= 0 // u1 = (p1 - s1) / norm(p1 - s1) // u2 = (p2 - s2) / norm(p2 - s2) // Cdot = -dot(u1, v1 + cross(w1, r1)) - ratio * dot(u2, v2 + cross(w2, r2)) // J = -[u1 cross(r1, u1) ratio * u2 ratio * cross(r2, u2)] // K = J * invM * JT // = invMass1 + invI1 * cross(r1, u1)^2 + ratio^2 * (invMass2 + invI2 * cross(r2, u2)^2) +// +// Limit: +// C = maxLength - length +// u = (p - s) / norm(p - s) +// Cdot = -dot(u, v + cross(w, r)) +// K = invMass + invI * cross(r, u)^2 +// 0 <= impulse void b2PulleyJointDef::Initialize(b2Body* b1, b2Body* b2, const b2Vec2& ga1, const b2Vec2& ga2, @@ -50,6 +57,8 @@ void b2PulleyJointDef::Initialize(b2Body* b1, b2Body* b2, ratio = r; b2Assert(ratio > b2_epsilon); float32 C = lengthA + ratio * lengthB; + maxLengthA = C - ratio * b2_minPulleyLength; + maxLengthB = (C - b2_minPulleyLength) / ratio; } b2PulleyJoint::b2PulleyJoint(const b2PulleyJointDef* def) @@ -65,7 +74,12 @@ b2PulleyJoint::b2PulleyJoint(const b2PulleyJointDef* def) m_constant = def->lengthA + m_ratio * def->lengthB; + m_maxLength1 = b2Min(def->maxLengthA, m_constant - m_ratio * b2_minPulleyLength); + m_maxLength2 = b2Min(def->maxLengthB, (m_constant - b2_minPulleyLength) / m_ratio); + m_impulse = 0.0f; + m_limitImpulse1 = 0.0f; + m_limitImpulse2 = 0.0f; } void b2PulleyJoint::InitVelocityConstraints(const b2TimeStep& step) @@ -89,7 +103,7 @@ void b2PulleyJoint::InitVelocityConstraints(const b2TimeStep& step) float32 length1 = m_u1.Length(); float32 length2 = m_u2.Length(); - if (length1 > 10.0f * b2_linearSlop) + if (length1 > b2_linearSlop) { m_u1 *= 1.0f / length1; } @@ -98,7 +112,7 @@ void b2PulleyJoint::InitVelocityConstraints(const b2TimeStep& step) m_u1.SetZero(); } - if (length2 > 10.0f * b2_linearSlop) + if (length2 > b2_linearSlop) { m_u2 *= 1.0f / length2; } @@ -107,28 +121,61 @@ void b2PulleyJoint::InitVelocityConstraints(const b2TimeStep& step) m_u2.SetZero(); } - // Compute effective mass. - float32 cr1u1 = b2Cross(r1, m_u1); - float32 cr2u2 = b2Cross(r2, m_u2); - - float32 m1 = b1->m_invMass + b1->m_invI * cr1u1 * cr1u1; - float32 m2 = b2->m_invMass + b2->m_invI * cr2u2 * cr2u2; + float32 C = m_constant - length1 - m_ratio * length2; + if (C > 0.0f) + { + m_state = e_inactiveLimit; + m_impulse = 0.0f; + } + else + { + m_state = e_atUpperLimit; + } - m_pulleyMass = m1 + m_ratio * m_ratio * m2; + if (length1 < m_maxLength1) + { + m_limitState1 = e_inactiveLimit; + m_limitImpulse1 = 0.0f; + } + else + { + m_limitState1 = e_atUpperLimit; + } - if (m_pulleyMass > 0.0f) + if (length2 < m_maxLength2) { - m_pulleyMass = 1.0f / m_pulleyMass; + m_limitState2 = e_inactiveLimit; + m_limitImpulse2 = 0.0f; } + else + { + m_limitState2 = e_atUpperLimit; + } + + // Compute effective mass. + float32 cr1u1 = b2Cross(r1, m_u1); + float32 cr2u2 = b2Cross(r2, m_u2); + + m_limitMass1 = b1->m_invMass + b1->m_invI * cr1u1 * cr1u1; + m_limitMass2 = b2->m_invMass + b2->m_invI * cr2u2 * cr2u2; + m_pulleyMass = m_limitMass1 + m_ratio * m_ratio * m_limitMass2; + b2Assert(m_limitMass1 > b2_epsilon); + b2Assert(m_limitMass2 > b2_epsilon); + b2Assert(m_pulleyMass > b2_epsilon); + m_limitMass1 = 1.0f / m_limitMass1; + m_limitMass2 = 1.0f / m_limitMass2; + m_pulleyMass = 1.0f / m_pulleyMass; if (step.warmStarting) { // Scale impulses to support variable time steps. m_impulse *= step.dtRatio; + m_limitImpulse1 *= step.dtRatio; + m_limitImpulse2 *= step.dtRatio; // Warm starting. - b2Vec2 P1 = -(m_impulse) * m_u1; - b2Vec2 P2 = (-m_ratio * m_impulse) * m_u2; + b2Vec2 P1 = -(m_impulse + m_limitImpulse1) * m_u1; + b2Vec2 P2 = (-m_ratio * m_impulse - m_limitImpulse2) * m_u2; b1->m_linearVelocity += b1->m_invMass * P1; b1->m_angularVelocity += b1->m_invI * b2Cross(r1, P1); b2->m_linearVelocity += b2->m_invMass * P2; @@ -137,6 +184,8 @@ void b2PulleyJoint::InitVelocityConstraints(const b2TimeStep& step) else { m_impulse = 0.0f; + m_limitImpulse1 = 0.0f; + m_limitImpulse2 = 0.0f; } } @@ -150,13 +199,16 @@ void b2PulleyJoint::SolveVelocityConstraints(const b2TimeStep& step) b2Vec2 r1 = b2Mul(b1->GetTransform().R, m_localAnchor1 - b1->GetLocalCenter()); b2Vec2 r2 = b2Mul(b2->GetTransform().R, m_localAnchor2 - b2->GetLocalCenter()); + if (m_state == e_atUpperLimit) { b2Vec2 v1 = b1->m_linearVelocity + b2Cross(b1->m_angularVelocity, r1); b2Vec2 v2 = b2->m_linearVelocity + b2Cross(b2->m_angularVelocity, r2); float32 Cdot = -b2Dot(m_u1, v1) - m_ratio * b2Dot(m_u2, v2); float32 impulse = m_pulleyMass * (-Cdot); - m_impulse += impulse; + float32 oldImpulse = m_impulse; + m_impulse = b2Max(0.0f, m_impulse + impulse); + impulse = m_impulse - oldImpulse; b2Vec2 P1 = -impulse * m_u1; b2Vec2 P2 = -m_ratio * impulse * m_u2; @@ -165,6 +217,36 @@ void b2PulleyJoint::SolveVelocityConstraints(const b2TimeStep& step) b2->m_linearVelocity += b2->m_invMass * P2; b2->m_angularVelocity += b2->m_invI * b2Cross(r2, P2); } + + if (m_limitState1 == e_atUpperLimit) + { + b2Vec2 v1 = b1->m_linearVelocity + b2Cross(b1->m_angularVelocity, r1); + + float32 Cdot = -b2Dot(m_u1, v1); + float32 impulse = -m_limitMass1 * Cdot; + float32 oldImpulse = m_limitImpulse1; + m_limitImpulse1 = b2Max(0.0f, m_limitImpulse1 + impulse); + impulse = m_limitImpulse1 - oldImpulse; + + b2Vec2 P1 = -impulse * m_u1; + b1->m_linearVelocity += b1->m_invMass * P1; + b1->m_angularVelocity += b1->m_invI * b2Cross(r1, P1); + } + + if (m_limitState2 == e_atUpperLimit) + { + b2Vec2 v2 = b2->m_linearVelocity + b2Cross(b2->m_angularVelocity, r2); + + float32 Cdot = -b2Dot(m_u2, v2); + float32 impulse = -m_limitMass2 * Cdot; + float32 oldImpulse = m_limitImpulse2; + m_limitImpulse2 = b2Max(0.0f, m_limitImpulse2 + impulse); + impulse = m_limitImpulse2 - oldImpulse; + + b2Vec2 P2 = -impulse * m_u2; + b2->m_linearVelocity += b2->m_invMass * P2; + b2->m_angularVelocity += b2->m_invI * b2Cross(r2, P2); + } } bool b2PulleyJoint::SolvePositionConstraints(float32 baumgarte) @@ -177,67 +259,117 @@ bool b2PulleyJoint::SolvePositionConstraints(float32 baumgarte) b2Vec2 s1 = m_groundAnchor1; b2Vec2 s2 = m_groundAnchor2; - b2Vec2 r1 = b2Mul(b1->m_xf.R, m_localAnchor1 - b1->GetLocalCenter()); - b2Vec2 r2 = b2Mul(b2->m_xf.R, m_localAnchor2 - b2->GetLocalCenter()); + float32 linearError = 0.0f; - b2Vec2 p1 = b1->m_sweep.c + r1; - b2Vec2 p2 = b2->m_sweep.c + r2; + if (m_state == e_atUpperLimit) + { + b2Vec2 r1 = b2Mul(b1->GetTransform().R, m_localAnchor1 - b1->GetLocalCenter()); + b2Vec2 r2 = b2Mul(b2->GetTransform().R, m_localAnchor2 - b2->GetLocalCenter()); + + b2Vec2 p1 = b1->m_sweep.c + r1; + b2Vec2 p2 = b2->m_sweep.c + r2; + + // Get the pulley axes. + m_u1 = p1 - s1; + m_u2 = p2 - s2; + + float32 length1 = m_u1.Length(); + float32 length2 = m_u2.Length(); + + if (length1 > b2_linearSlop) + { + m_u1 *= 1.0f / length1; + } + else + { + m_u1.SetZero(); + } + + if (length2 > b2_linearSlop) + { + m_u2 *= 1.0f / length2; + } + else + { + m_u2.SetZero(); + } + + float32 C = m_constant - length1 - m_ratio * length2; + linearError = b2Max(linearError, -C); + + C = b2Clamp(C + b2_linearSlop, -b2_maxLinearCorrection, 0.0f); + float32 impulse = -m_pulleyMass * C; - // Get the pulley axes. - b2Vec2 u1 = p1 - s1; - b2Vec2 u2 = p2 - s2; + b2Vec2 P1 = -impulse * m_u1; + b2Vec2 P2 = -m_ratio * impulse * m_u2; - float32 length1 = u1.Length(); - float32 length2 = u2.Length(); + b1->m_sweep.c += b1->m_invMass * P1; + b1->m_sweep.a += b1->m_invI * b2Cross(r1, P1); + b2->m_sweep.c += b2->m_invMass * P2; + b2->m_sweep.a += b2->m_invI * b2Cross(r2, P2); - if (length1 > 10.0f * b2_linearSlop) - { - u1 *= 1.0f / length1; - } - else - { - u1.SetZero(); + b1->SynchronizeTransform(); + b2->SynchronizeTransform(); } - if (length2 > 10.0f * b2_linearSlop) - { - u2 *= 1.0f / length2; - } - else + if (m_limitState1 == e_atUpperLimit) { - u2.SetZero(); - } - - // Compute effective mass. - float32 cr1u1 = b2Cross(r1, u1); - float32 cr2u2 = b2Cross(r2, u2); + b2Vec2 r1 = b2Mul(b1->GetTransform().R, m_localAnchor1 - b1->GetLocalCenter()); + b2Vec2 p1 = b1->m_sweep.c + r1; + + m_u1 = p1 - s1; + float32 length1 = m_u1.Length(); + + if (length1 > b2_linearSlop) + { + m_u1 *= 1.0f / length1; + } + else + { + m_u1.SetZero(); + } + + float32 C = m_maxLength1 - length1; + linearError = b2Max(linearError, -C); + C = b2Clamp(C + b2_linearSlop, -b2_maxLinearCorrection, 0.0f); + float32 impulse = -m_limitMass1 * C; - float32 m1 = b1->m_invMass + b1->m_invI * cr1u1 * cr1u1; - float32 m2 = b2->m_invMass + b2->m_invI * cr2u2 * cr2u2; + b2Vec2 P1 = -impulse * m_u1; + b1->m_sweep.c += b1->m_invMass * P1; + b1->m_sweep.a += b1->m_invI * b2Cross(r1, P1); - float32 mass = m1 + m_ratio * m_ratio * m2; + b1->SynchronizeTransform(); + } - if (mass > 0.0f) + if (m_limitState2 == e_atUpperLimit) { - mass = 1.0f / mass; + b2Vec2 r2 = b2Mul(b2->GetTransform().R, m_localAnchor2 - b2->GetLocalCenter()); + b2Vec2 p2 = b2->m_sweep.c + r2; + + m_u2 = p2 - s2; + float32 length2 = m_u2.Length(); + + if (length2 > b2_linearSlop) + { + m_u2 *= 1.0f / length2; + } + else + { + m_u2.SetZero(); + } + + float32 C = m_maxLength2 - length2; + linearError = b2Max(linearError, -C); + C = b2Clamp(C + b2_linearSlop, -b2_maxLinearCorrection, 0.0f); + float32 impulse = -m_limitMass2 * C; + + b2Vec2 P2 = -impulse * m_u2; + b2->m_sweep.c += b2->m_invMass * P2; + b2->m_sweep.a += b2->m_invI * b2Cross(r2, P2); + + b2->SynchronizeTransform(); } - float32 C = m_constant - length1 - m_ratio * length2; - float32 linearError = b2Abs(C); - - float32 impulse = -mass * C; - - b2Vec2 P1 = -impulse * u1; - b2Vec2 P2 = -m_ratio * impulse * u2; - - b1->m_sweep.c += b1->m_invMass * P1; - b1->m_sweep.a += b1->m_invI * b2Cross(r1, P1); - b2->m_sweep.c += b2->m_invMass * P2; - b2->m_sweep.a += b2->m_invI * b2Cross(r2, P2); - - b1->SynchronizeTransform(); - b2->SynchronizeTransform(); - return linearError < b2_linearSlop; } diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2PulleyJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2PulleyJoint.h index 2e0af79..189decb 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2PulleyJoint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2PulleyJoint.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -24,7 +24,8 @@ const float32 b2_minPulleyLength = 2.0f; /// Pulley joint definition. This requires two ground anchors, -/// two dynamic body anchor points, and a pulley ratio. +/// two dynamic body anchor points, max lengths for each side, +/// and a pulley ratio. struct b2PulleyJointDef : public b2JointDef { b2PulleyJointDef() @@ -35,7 +36,9 @@ struct b2PulleyJointDef : public b2JointDef localAnchorA.Set(-1.0f, 0.0f); localAnchorB.Set(1.0f, 0.0f); lengthA = 0.0f; + maxLengthA = 0.0f; lengthB = 0.0f; + maxLengthB = 0.0f; ratio = 1.0f; collideConnected = true; } @@ -61,9 +64,15 @@ struct b2PulleyJointDef : public b2JointDef /// The a reference length for the segment attached to bodyA. float32 lengthA; + /// The maximum length of the segment attached to bodyA. + float32 maxLengthA; + /// The a reference length for the segment attached to bodyB. float32 lengthB; + /// The maximum length of the segment attached to bodyB. + float32 maxLengthB; + /// The pulley ratio, used to simulate a block-and-tackle. float32 ratio; }; @@ -72,10 +81,8 @@ struct b2PulleyJointDef : public b2JointDef /// The pulley supports a ratio such that: /// length1 + ratio * length2 <= constant /// Yes, the force transmitted is scaled by the ratio. -/// Warning: the pulley joint can get a bit squirrelly by itself. They often -/// work better when combined with prismatic joints. You should also cover the -/// the anchor points with static shapes to prevent one side from going to -/// zero length. +/// The pulley also enforces a maximum length limit on both sides. This is +/// useful to prevent one side of the pulley hitting the top. class b2PulleyJoint : public b2Joint { public: @@ -120,11 +127,22 @@ protected: float32 m_constant; float32 m_ratio; + float32 m_maxLength1; + float32 m_maxLength2; + // Effective masses float32 m_pulleyMass; + float32 m_limitMass1; + float32 m_limitMass2; // Impulses for accumulation/warm starting. float32 m_impulse; + float32 m_limitImpulse1; + float32 m_limitImpulse2; + + b2LimitState m_state; + b2LimitState m_limitState1; + b2LimitState m_limitState2; }; #endif diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp index 5807cb5..f984526 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -214,8 +214,7 @@ void b2RevoluteJoint::SolveVelocityConstraints(const b2TimeStep& step) float32 newImpulse = m_impulse.z + impulse.z; if (newImpulse < 0.0f) { - b2Vec2 rhs = -Cdot1 + m_impulse.z * b2Vec2(m_mass.col3.x, m_mass.col3.y); - b2Vec2 reduced = m_mass.Solve22(rhs); + b2Vec2 reduced = m_mass.Solve22(-Cdot1); impulse.x = reduced.x; impulse.y = reduced.y; impulse.z = -m_impulse.z; @@ -223,18 +222,13 @@ void b2RevoluteJoint::SolveVelocityConstraints(const b2TimeStep& step) m_impulse.y += reduced.y; m_impulse.z = 0.0f; } - else - { - m_impulse += impulse; - } } else if (m_limitState == e_atUpperLimit) { float32 newImpulse = m_impulse.z + impulse.z; if (newImpulse > 0.0f) { - b2Vec2 rhs = -Cdot1 + m_impulse.z * b2Vec2(m_mass.col3.x, m_mass.col3.y); - b2Vec2 reduced = m_mass.Solve22(rhs); + b2Vec2 reduced = m_mass.Solve22(-Cdot1); impulse.x = reduced.x; impulse.y = reduced.y; impulse.z = -m_impulse.z; @@ -242,10 +236,6 @@ void b2RevoluteJoint::SolveVelocityConstraints(const b2TimeStep& step) m_impulse.y += reduced.y; m_impulse.z = 0.0f; } - else - { - m_impulse += impulse; - } } b2Vec2 P(impulse.x, impulse.y); @@ -437,9 +427,9 @@ void b2RevoluteJoint::EnableMotor(bool flag) m_enableMotor = flag; } -float32 b2RevoluteJoint::GetMotorTorque(float32 inv_dt) const +float32 b2RevoluteJoint::GetMotorTorque() const { - return inv_dt * m_motorImpulse; + return m_motorImpulse; } void b2RevoluteJoint::SetMotorSpeed(float32 speed) @@ -463,13 +453,9 @@ bool b2RevoluteJoint::IsLimitEnabled() const void b2RevoluteJoint::EnableLimit(bool flag) { - if (flag != m_enableLimit) - { - m_bodyA->SetAwake(true); - m_bodyB->SetAwake(true); - m_enableLimit = flag; - m_impulse.z = 0.0f; - } + m_bodyA->SetAwake(true); + m_bodyB->SetAwake(true); + m_enableLimit = flag; } float32 b2RevoluteJoint::GetLowerLimit() const @@ -485,13 +471,8 @@ float32 b2RevoluteJoint::GetUpperLimit() const void b2RevoluteJoint::SetLimits(float32 lower, float32 upper) { b2Assert(lower <= upper); - - if (lower != m_lowerAngle || upper != m_upperAngle) - { - m_bodyA->SetAwake(true); - m_bodyB->SetAwake(true); - m_impulse.z = 0.0f; - m_lowerAngle = lower; - m_upperAngle = upper; - } + m_bodyA->SetAwake(true); + m_bodyB->SetAwake(true); + m_lowerAngle = lower; + m_upperAngle = upper; } diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2RevoluteJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2RevoluteJoint.h index 5214c83..c0180be 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2RevoluteJoint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2RevoluteJoint.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -93,6 +93,9 @@ public: b2Vec2 GetAnchorA() const; b2Vec2 GetAnchorB() const; + b2Vec2 GetReactionForce(float32 inv_dt) const; + float32 GetReactionTorque(float32 inv_dt) const; + /// Get the current joint angle in radians. float32 GetJointAngle() const; @@ -129,17 +132,8 @@ public: /// Set the maximum motor torque, usually in N-m. void SetMaxMotorTorque(float32 torque); - /// Get the reaction force given the inverse time step. - /// Unit is N. - b2Vec2 GetReactionForce(float32 inv_dt) const; - - /// Get the reaction torque due to the joint limit given the inverse time step. - /// Unit is N*m. - float32 GetReactionTorque(float32 inv_dt) const; - - /// Get the current motor torque given the inverse time step. - /// Unit is N*m. - float32 GetMotorTorque(float32 inv_dt) const; + /// Get the current motor torque, usually in N-m. + float32 GetMotorTorque() const; protected: diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2RopeJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2RopeJoint.cpp deleted file mode 100644 index 813b356..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2RopeJoint.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* -* Copyright (c) 2007-2010 Erin Catto http://www.box2d.org -* -* 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 -#include -#include - - -// Limit: -// C = norm(pB - pA) - L -// u = (pB - pA) / norm(pB - pA) -// Cdot = dot(u, vB + cross(wB, rB) - vA - cross(wA, rA)) -// J = [-u -cross(rA, u) u cross(rB, u)] -// K = J * invM * JT -// = invMassA + invIA * cross(rA, u)^2 + invMassB + invIB * cross(rB, u)^2 - -b2RopeJoint::b2RopeJoint(const b2RopeJointDef* def) -: b2Joint(def) -{ - m_localAnchorA = def->localAnchorA; - m_localAnchorB = def->localAnchorB; - - m_maxLength = def->maxLength; - - m_mass = 0.0f; - m_impulse = 0.0f; - m_state = e_inactiveLimit; - m_length = 0.0f; -} - -void b2RopeJoint::InitVelocityConstraints(const b2TimeStep& step) -{ - b2Body* bA = m_bodyA; - b2Body* bB = m_bodyB; - - m_rA = b2Mul(bA->GetTransform().R, m_localAnchorA - bA->GetLocalCenter()); - m_rB = b2Mul(bB->GetTransform().R, m_localAnchorB - bB->GetLocalCenter()); - - // Rope axis - m_u = bB->m_sweep.c + m_rB - bA->m_sweep.c - m_rA; - - m_length = m_u.Length(); - - float32 C = m_length - m_maxLength; - if (C > 0.0f) - { - m_state = e_atUpperLimit; - } - else - { - m_state = e_inactiveLimit; - } - - if (m_length > b2_linearSlop) - { - m_u *= 1.0f / m_length; - } - else - { - m_u.SetZero(); - m_mass = 0.0f; - m_impulse = 0.0f; - return; - } - - // Compute effective mass. - float32 crA = b2Cross(m_rA, m_u); - float32 crB = b2Cross(m_rB, m_u); - float32 invMass = bA->m_invMass + bA->m_invI * crA * crA + bB->m_invMass + bB->m_invI * crB * crB; - - m_mass = invMass != 0.0f ? 1.0f / invMass : 0.0f; - - if (step.warmStarting) - { - // Scale the impulse to support a variable time step. - m_impulse *= step.dtRatio; - - b2Vec2 P = m_impulse * m_u; - bA->m_linearVelocity -= bA->m_invMass * P; - bA->m_angularVelocity -= bA->m_invI * b2Cross(m_rA, P); - bB->m_linearVelocity += bB->m_invMass * P; - bB->m_angularVelocity += bB->m_invI * b2Cross(m_rB, P); - } - else - { - m_impulse = 0.0f; - } -} - -void b2RopeJoint::SolveVelocityConstraints(const b2TimeStep& step) -{ - B2_NOT_USED(step); - - b2Body* bA = m_bodyA; - b2Body* bB = m_bodyB; - - // Cdot = dot(u, v + cross(w, r)) - b2Vec2 vA = bA->m_linearVelocity + b2Cross(bA->m_angularVelocity, m_rA); - b2Vec2 vB = bB->m_linearVelocity + b2Cross(bB->m_angularVelocity, m_rB); - float32 C = m_length - m_maxLength; - float32 Cdot = b2Dot(m_u, vB - vA); - - // Predictive constraint. - if (C < 0.0f) - { - Cdot += step.inv_dt * C; - } - - float32 impulse = -m_mass * Cdot; - float32 oldImpulse = m_impulse; - m_impulse = b2Min(0.0f, m_impulse + impulse); - impulse = m_impulse - oldImpulse; - - b2Vec2 P = impulse * m_u; - bA->m_linearVelocity -= bA->m_invMass * P; - bA->m_angularVelocity -= bA->m_invI * b2Cross(m_rA, P); - bB->m_linearVelocity += bB->m_invMass * P; - bB->m_angularVelocity += bB->m_invI * b2Cross(m_rB, P); -} - -bool b2RopeJoint::SolvePositionConstraints(float32 baumgarte) -{ - B2_NOT_USED(baumgarte); - - b2Body* bA = m_bodyA; - b2Body* bB = m_bodyB; - - b2Vec2 rA = b2Mul(bA->GetTransform().R, m_localAnchorA - bA->GetLocalCenter()); - b2Vec2 rB = b2Mul(bB->GetTransform().R, m_localAnchorB - bB->GetLocalCenter()); - - b2Vec2 u = bB->m_sweep.c + rB - bA->m_sweep.c - rA; - - float32 length = u.Normalize(); - float32 C = length - m_maxLength; - - C = b2Clamp(C, 0.0f, b2_maxLinearCorrection); - - float32 impulse = -m_mass * C; - b2Vec2 P = impulse * u; - - bA->m_sweep.c -= bA->m_invMass * P; - bA->m_sweep.a -= bA->m_invI * b2Cross(rA, P); - bB->m_sweep.c += bB->m_invMass * P; - bB->m_sweep.a += bB->m_invI * b2Cross(rB, P); - - bA->SynchronizeTransform(); - bB->SynchronizeTransform(); - - return length - m_maxLength < b2_linearSlop; -} - -b2Vec2 b2RopeJoint::GetAnchorA() const -{ - return m_bodyA->GetWorldPoint(m_localAnchorA); -} - -b2Vec2 b2RopeJoint::GetAnchorB() const -{ - return m_bodyB->GetWorldPoint(m_localAnchorB); -} - -b2Vec2 b2RopeJoint::GetReactionForce(float32 inv_dt) const -{ - b2Vec2 F = (inv_dt * m_impulse) * m_u; - return F; -} - -float32 b2RopeJoint::GetReactionTorque(float32 inv_dt) const -{ - B2_NOT_USED(inv_dt); - return 0.0f; -} - -float32 b2RopeJoint::GetMaxLength() const -{ - return m_maxLength; -} - -b2LimitState b2RopeJoint::GetLimitState() const -{ - return m_state; -} diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2RopeJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2RopeJoint.h deleted file mode 100644 index b297ab3..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2RopeJoint.h +++ /dev/null @@ -1,99 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef B2_ROPE_JOINT_H -#define B2_ROPE_JOINT_H - -#include - -/// Rope joint definition. This requires two body anchor points and -/// a maximum lengths. -/// Note: by default the connected objects will not collide. -/// see collideConnected in b2JointDef. -struct b2RopeJointDef : public b2JointDef -{ - b2RopeJointDef() - { - type = e_ropeJoint; - localAnchorA.Set(-1.0f, 0.0f); - localAnchorB.Set(1.0f, 0.0f); - maxLength = 0.0f; - } - - /// The local anchor point relative to bodyA's origin. - b2Vec2 localAnchorA; - - /// The local anchor point relative to bodyB's origin. - b2Vec2 localAnchorB; - - /// The maximum length of the rope. - /// Warning: this must be larger than b2_linearSlop or - /// the joint will have no effect. - float32 maxLength; -}; - -/// A rope joint enforces a maximum distance between two points -/// on two bodies. It has no other effect. -/// Warning: if you attempt to change the maximum length during -/// the simulation you will get some non-physical behavior. -/// A model that would allow you to dynamically modify the length -/// would have some sponginess, so I chose not to implement it -/// that way. See b2DistanceJoint if you want to dynamically -/// control length. -class b2RopeJoint : public b2Joint -{ -public: - b2Vec2 GetAnchorA() const; - b2Vec2 GetAnchorB() const; - - b2Vec2 GetReactionForce(float32 inv_dt) const; - float32 GetReactionTorque(float32 inv_dt) const; - - /// Get the maximum length of the rope. - float32 GetMaxLength() const; - - b2LimitState GetLimitState() const; - -protected: - - friend class b2Joint; - b2RopeJoint(const b2RopeJointDef* data); - - void InitVelocityConstraints(const b2TimeStep& step); - void SolveVelocityConstraints(const b2TimeStep& step); - bool SolvePositionConstraints(float32 baumgarte); - - b2Vec2 m_localAnchorA; - b2Vec2 m_localAnchorB; - - float32 m_maxLength; - float32 m_length; - - // Jacobian info - b2Vec2 m_u, m_rA, m_rB; - - // Effective mass - float32 m_mass; - - // Impulses for accumulation/warm starting. - float32 m_impulse; - - b2LimitState m_state; -}; - -#endif diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2WeldJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2WeldJoint.cpp index f899d13..49b5513 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2WeldJoint.cpp +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2WeldJoint.cpp @@ -1,5 +1,5 @@ /* -* 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 diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2WeldJoint.h b/libs/box2d/src/Box2D/Dynamics/Joints/b2WeldJoint.h index 216b171..4e63b6a 100644 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2WeldJoint.h +++ b/libs/box2d/src/Box2D/Dynamics/Joints/b2WeldJoint.h @@ -1,5 +1,5 @@ /* -* 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 diff --git a/libs/box2d/src/Box2D/Dynamics/Joints/b2WheelJoint.cpp b/libs/box2d/src/Box2D/Dynamics/Joints/b2WheelJoint.cpp deleted file mode 100644 index 292a9dc..0000000 --- a/libs/box2d/src/Box2D/Dynamics/Joints/b2WheelJoint.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org -* -* 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 -#include -#include - -// Linear constraint (point-to-line) -// d = pB - pA = xB + rB - xA - rA -// C = dot(ay, d) -// Cdot = dot(d, cross(wA, ay)) + dot(ay, vB + cross(wB, rB) - vA - cross(wA, rA)) -// = -dot(ay, vA) - dot(cross(d + rA, ay), wA) + dot(ay, vB) + dot(cross(rB, ay), vB) -// J = [-ay, -cross(d + rA, ay), ay, cross(rB, ay)] - -// Spring linear constraint -// C = dot(ax, d) -// Cdot = = -dot(ax, vA) - dot(cross(d + rA, ax), wA) + dot(ax, vB) + dot(cross(rB, ax), vB) -// J = [-ax -cross(d+rA, ax) ax cross(rB, ax)] - -// Motor rotational constraint -// Cdot = wB - wA -// J = [0 0 -1 0 0 1] - -void b2WheelJointDef::Initialize(b2Body* bA, b2Body* bB, const b2Vec2& anchor, const b2Vec2& axis) -{ - bodyA = bA; - bodyB = bB; - localAnchorA = bodyA->GetLocalPoint(anchor); - localAnchorB = bodyB->GetLocalPoint(anchor); - localAxisA = bodyA->GetLocalVector(axis); -} - -b2WheelJoint::b2WheelJoint(const b2WheelJointDef* def) -: b2Joint(def) -{ - m_localAnchorA = def->localAnchorA; - m_localAnchorB = def->localAnchorB; - m_localXAxisA = def->localAxisA; - m_localYAxisA = b2Cross(1.0f, m_localXAxisA); - - m_mass = 0.0f; - m_impulse = 0.0f; - m_motorMass = 0.0; - m_motorImpulse = 0.0f; - m_springMass = 0.0f; - m_springImpulse = 0.0f; - - m_maxMotorTorque = def->maxMotorTorque; - m_motorSpeed = def->motorSpeed; - m_enableMotor = def->enableMotor; - - m_frequencyHz = def->frequencyHz; - m_dampingRatio = def->dampingRatio; - - m_bias = 0.0f; - m_gamma = 0.0f; - - m_ax.SetZero(); - m_ay.SetZero(); -} - -void b2WheelJoint::InitVelocityConstraints(const b2TimeStep& step) -{ - b2Body* bA = m_bodyA; - b2Body* bB = m_bodyB; - - m_localCenterA = bA->GetLocalCenter(); - m_localCenterB = bB->GetLocalCenter(); - - b2Transform xfA = bA->GetTransform(); - b2Transform xfB = bB->GetTransform(); - - // Compute the effective masses. - b2Vec2 rA = b2Mul(xfA.R, m_localAnchorA - m_localCenterA); - b2Vec2 rB = b2Mul(xfB.R, m_localAnchorB - m_localCenterB); - b2Vec2 d = bB->m_sweep.c + rB - bA->m_sweep.c - rA; - - m_invMassA = bA->m_invMass; - m_invIA = bA->m_invI; - m_invMassB = bB->m_invMass; - m_invIB = bB->m_invI; - - // Point to line constraint - { - m_ay = b2Mul(xfA.R, m_localYAxisA); - m_sAy = b2Cross(d + rA, m_ay); - m_sBy = b2Cross(rB, m_ay); - - m_mass = m_invMassA + m_invMassB + m_invIA * m_sAy * m_sAy + m_invIB * m_sBy * m_sBy; - - if (m_mass > 0.0f) - { - m_mass = 1.0f / m_mass; - } - } - - // Spring constraint - m_springMass = 0.0f; - if (m_frequencyHz > 0.0f) - { - m_ax = b2Mul(xfA.R, m_localXAxisA); - m_sAx = b2Cross(d + rA, m_ax); - m_sBx = b2Cross(rB, m_ax); - - float32 invMass = m_invMassA + m_invMassB + m_invIA * m_sAx * m_sAx + m_invIB * m_sBx * m_sBx; - - if (invMass > 0.0f) - { - m_springMass = 1.0f / invMass; - - float32 C = b2Dot(d, m_ax); - - // Frequency - float32 omega = 2.0f * b2_pi * m_frequencyHz; - - // Damping coefficient - float32 d = 2.0f * m_springMass * m_dampingRatio * omega; - - // Spring stiffness - float32 k = m_springMass * omega * omega; - - // magic formulas - m_gamma = step.dt * (d + step.dt * k); - if (m_gamma > 0.0f) - { - m_gamma = 1.0f / m_gamma; - } - - m_bias = C * step.dt * k * m_gamma; - - m_springMass = invMass + m_gamma; - if (m_springMass > 0.0f) - { - m_springMass = 1.0f / m_springMass; - } - } - } - else - { - m_springImpulse = 0.0f; - m_springMass = 0.0f; - } - - // Rotational motor - if (m_enableMotor) - { - m_motorMass = m_invIA + m_invIB; - if (m_motorMass > 0.0f) - { - m_motorMass = 1.0f / m_motorMass; - } - } - else - { - m_motorMass = 0.0f; - m_motorImpulse = 0.0f; - } - - if (step.warmStarting) - { - // Account for variable time step. - m_impulse *= step.dtRatio; - m_springImpulse *= step.dtRatio; - m_motorImpulse *= step.dtRatio; - - b2Vec2 P = m_impulse * m_ay + m_springImpulse * m_ax; - float32 LA = m_impulse * m_sAy + m_springImpulse * m_sAx + m_motorImpulse; - float32 LB = m_impulse * m_sBy + m_springImpulse * m_sBx + m_motorImpulse; - - bA->m_linearVelocity -= m_invMassA * P; - bA->m_angularVelocity -= m_invIA * LA; - - bB->m_linearVelocity += m_invMassB * P; - bB->m_angularVelocity += m_invIB * LB; - } - else - { - m_impulse = 0.0f; - m_springImpulse = 0.0f; - m_motorImpulse = 0.0f; - } -} - -void b2WheelJoint::SolveVelocityConstraints(const b2TimeStep& step) -{ - b2Body* bA = m_bodyA; - b2Body* bB = m_bodyB; - - b2Vec2 vA = bA->m_linearVelocity; - float32 wA = bA->m_angularVelocity; - b2Vec2 vB = bB->m_linearVelocity; - float32 wB = bB->m_angularVelocity; - - // Solve spring constraint - { - float32 Cdot = b2Dot(m_ax, vB - vA) + m_sBx * wB - m_sAx * wA; - float32 impulse = -m_springMass * (Cdot + m_bias + m_gamma * m_springImpulse); - m_springImpulse += impulse; - - b2Vec2 P = impulse * m_ax; - float32 LA = impulse * m_sAx; - float32 LB = impulse * m_sBx; - - vA -= m_invMassA * P; - wA -= m_invIA * LA; - - vB += m_invMassB * P; - wB += m_invIB * LB; - } - - // Solve rotational motor constraint - { - float32 Cdot = wB - wA - m_motorSpeed; - float32 impulse = -m_motorMass * Cdot; - - float32 oldImpulse = m_motorImpulse; - float32 maxImpulse = step.dt * m_maxMotorTorque; - m_motorImpulse = b2Clamp(m_motorImpulse + impulse, -maxImpulse, maxImpulse); - impulse = m_motorImpulse - oldImpulse; - - wA -= m_invIA * impulse; - wB += m_invIB * impulse; - } - - // Solve point to line constraint - { - float32 Cdot = b2Dot(m_ay, vB - vA) + m_sBy * wB - m_sAy * wA; - float32 impulse = m_mass * (-Cdot); - m_impulse += impulse; - - b2Vec2 P = impulse * m_ay; - float32 LA = impulse * m_sAy; - float32 LB = impulse * m_sBy; - - vA -= m_invMassA * P; - wA -= m_invIA * LA; - - vB += m_invMassB * P; - wB += m_invIB * LB; - } - - bA->m_linearVelocity = vA; - bA->m_angularVelocity = wA; - bB->m_linearVelocity = vB; - bB->m_angularVelocity = wB; -} - -bool b2WheelJoint::SolvePositionConstraints(float32 baumgarte) -{ - B2_NOT_USED(baumgarte); - - b2Body* bA = m_bodyA; - b2Body* bB = m_bodyB; - - b2Vec2 xA = bA->m_sweep.c; - float32 angleA = bA->m_sweep.a; - - b2Vec2 xB = bB->m_sweep.c; - float32 angleB = bB->m_sweep.a; - - b2Mat22 RA(angleA), RB(angleB); - - b2Vec2 rA = b2Mul(RA, m_localAnchorA - m_localCenterA); - b2Vec2 rB = b2Mul(RB, m_localAnchorB - m_localCenterB); - b2Vec2 d = xB + rB - xA - rA; - - b2Vec2 ay = b2Mul(RA, m_localYAxisA); - - float32 sAy = b2Cross(d + rA, ay); - float32 sBy = b2Cross(rB, ay); - - float32 C = b2Dot(d, ay); - - float32 k = m_invMassA + m_invMassB + m_invIA * m_sAy * m_sAy + m_invIB * m_sBy * m_sBy; - - float32 impulse; - if (k != 0.0f) - { - impulse = - C / k; - } - else - { - impulse = 0.0f; - } - - b2Vec2 P = impulse * ay; - float32 LA = impulse * sAy; - float32 LB = impulse * sBy; - - xA -= m_invMassA * P; - angleA -= m_invIA * LA; - xB += m_invMassB * P; - angleB += m_invIB * LB; - - // TODO_ERIN remove need for this. - bA->m_sweep.c = xA; - bA->m_sweep.a = angleA; - bB->m_sweep.c = xB; - bB->m_sweep.a = angleB; - bA->SynchronizeTransform(); - bB->SynchronizeTransform(); - - return b2Abs(C) <= b2_linearSlop; -} - -b2Vec2 b2WheelJoint::GetAnchorA() const -{ - return m_bodyA->GetWorldPoint(m_localAnchorA); -} - -b2Vec2 b2WheelJoint::GetAnchorB() const -{ - return m_bodyB->GetWorldPoint(m_localAnchorB); -} - -b2Vec2 b2WheelJoint::GetReactionForce(float32 inv_dt) const -{ - return inv_dt * (m_impulse * m_ay + m_springImpulse * m_ax); -} - -float32 b2WheelJoint::GetReactionTorque(float32 inv_dt) const -{ - return inv_dt * m_motorImpulse; -} - -float32 b2WheelJoint::GetJointTranslation() const -{ - b2Body* bA = m_bodyA; - b2Body* bB = m_bodyB; - - b2Vec2 pA = bA->GetWorldPoint(m_localAnchorA); - b2Vec2 pB = bB->GetWorldPoint(m_localAnchorB); - b2Vec2 d = pB - pA; - b2Vec2 axis = bA->GetWorldVector(m_localXAxisA); - - float32 translation = b2Dot(d, axis); - return translation; -} - -float32 b2WheelJoint::GetJointSpeed() const -{ - float32 wA = m_bodyA->m_angularVelocity; - float32 wB = m_bodyB->m_angularVelocity; - return wB - wA; -} - -bool b2WheelJoint::IsMotorEnabled() const -{ - return m_enableMotor; -} - -void b2WheelJoint::EnableMotor(bool flag) -{ - m_bodyA->SetAwake(true); - m_bodyB->SetAwake(true); - m_enableMotor = flag; -} - -void b2WheelJoint::SetMotorSpeed(float32 speed) -{ - m_bodyA->SetAwake(true); - m_bodyB->SetAwake(true); - m_motorSpeed = speed; -} - -void b2WheelJoint::SetMaxMotorTorque(float32 torque) -{ - m_bodyA->SetAwake(true); - m_bodyB->SetAwake(true); - m_maxMotorTorque = torque; -} - -float32 b2WheelJoint::GetMotorTorque(float32 inv_dt) const -{ - return inv_dt * m_motorImpulse; -} - - - - - diff --git a/libs/box2d/src/Box2D/Dynamics/b2Body.cpp b/libs/box2d/src/Box2D/Dynamics/b2Body.cpp index da44e3b..4b88651 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2Body.cpp +++ b/libs/box2d/src/Box2D/Dynamics/b2Body.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2007 Erin Catto http://www.box2d.org +* 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 @@ -28,6 +28,7 @@ b2Body::b2Body(const b2BodyDef* bd, b2World* world) b2Assert(bd->linearVelocity.IsValid()); b2Assert(b2IsValid(bd->angle)); b2Assert(b2IsValid(bd->angularVelocity)); + b2Assert(b2IsValid(bd->inertiaScale) && bd->inertiaScale >= 0.0f); b2Assert(b2IsValid(bd->angularDamping) && bd->angularDamping >= 0.0f); b2Assert(b2IsValid(bd->linearDamping) && bd->linearDamping >= 0.0f); @@ -73,7 +74,6 @@ b2Body::b2Body(const b2BodyDef* bd, b2World* world) m_linearDamping = bd->linearDamping; m_angularDamping = bd->angularDamping; - m_gravityScale = bd->gravityScale; m_force.SetZero(); m_torque = 0.0f; @@ -130,9 +130,9 @@ void b2Body::SetType(b2BodyType type) m_torque = 0.0f; // Since the body type changed, we need to flag contacts for filtering. - for (b2Fixture* f = m_fixtureList; f; f = f->m_next) + for (b2ContactEdge* ce = m_contactList; ce; ce = ce->next) { - f->Refilter(); + ce->contact->FlagForFiltering(); } } @@ -153,7 +153,7 @@ b2Fixture* b2Body::CreateFixture(const b2FixtureDef* def) if (m_flags & e_activeFlag) { b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase; - fixture->CreateProxies(broadPhase, m_xf); + fixture->CreateProxy(broadPhase, m_xf); } fixture->m_next = m_fixtureList; @@ -235,8 +235,13 @@ void b2Body::DestroyFixture(b2Fixture* fixture) if (m_flags & e_activeFlag) { + b2Assert(fixture->m_proxyId != b2BroadPhase::e_nullProxy); b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase; - fixture->DestroyProxies(broadPhase); + fixture->DestroyProxy(broadPhase); + } + else + { + b2Assert(fixture->m_proxyId == b2BroadPhase::e_nullProxy); } fixture->Destroy(allocator); @@ -423,8 +428,6 @@ void b2Body::SynchronizeFixtures() void b2Body::SetActive(bool flag) { - b2Assert(m_world->IsLocked() == false); - if (flag == IsActive()) { return; @@ -438,7 +441,7 @@ void b2Body::SetActive(bool flag) b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase; for (b2Fixture* f = m_fixtureList; f; f = f->m_next) { - f->CreateProxies(broadPhase, m_xf); + f->CreateProxy(broadPhase, m_xf); } // Contacts are created the next time step. @@ -451,7 +454,7 @@ void b2Body::SetActive(bool flag) b2BroadPhase* broadPhase = &m_world->m_contactManager.m_broadPhase; for (b2Fixture* f = m_fixtureList; f; f = f->m_next) { - f->DestroyProxies(broadPhase); + f->DestroyProxy(broadPhase); } // Destroy the attached contacts. diff --git a/libs/box2d/src/Box2D/Dynamics/b2Body.h b/libs/box2d/src/Box2D/Dynamics/b2Body.h index 48a458d..f2f915f 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2Body.h +++ b/libs/box2d/src/Box2D/Dynamics/b2Body.h @@ -1,5 +1,5 @@ /* -* 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 @@ -40,10 +40,7 @@ enum b2BodyType { b2_staticBody = 0, b2_kinematicBody, - b2_dynamicBody - - // TODO_ERIN - //b2_bulletBody, + b2_dynamicBody, }; /// A body definition holds all the data needed to construct a rigid body. @@ -66,7 +63,7 @@ struct b2BodyDef bullet = false; type = b2_staticBody; active = true; - gravityScale = 1.0f; + inertiaScale = 1.0f; } /// The body type: static, kinematic, or dynamic. @@ -118,8 +115,8 @@ struct b2BodyDef /// Use this to store application specific body data. void* userData; - /// Scale the gravity applied to this body. - float32 gravityScale; + /// Experimental: scales the inertia tensor. + float32 inertiaScale; }; /// A rigid body. These are created via b2World::CreateBody. @@ -284,12 +281,6 @@ public: /// Set the angular damping of the body. void SetAngularDamping(float32 angularDamping); - /// Get the gravity scale of the body. - float32 GetGravityScale() const; - - /// Set the angular damping of the body. - void SetGravityScale(float32 scale); - /// Set the type of this body. This may alter the mass and velocity. void SetType(b2BodyType type); @@ -377,17 +368,17 @@ private: friend class b2Island; friend class b2ContactManager; friend class b2ContactSolver; + friend class b2TOISolver; friend class b2DistanceJoint; friend class b2GearJoint; - friend class b2WheelJoint; + friend class b2LineJoint; friend class b2MouseJoint; friend class b2PrismaticJoint; friend class b2PulleyJoint; friend class b2RevoluteJoint; friend class b2WeldJoint; friend class b2FrictionJoint; - friend class b2RopeJoint; // m_flags enum @@ -398,7 +389,7 @@ private: e_bulletFlag = 0x0008, e_fixedRotationFlag = 0x0010, e_activeFlag = 0x0020, - e_toiFlag = 0x0040 + e_toiFlag = 0x0040, }; b2Body(const b2BodyDef* bd, b2World* world); @@ -445,7 +436,6 @@ private: float32 m_linearDamping; float32 m_angularDamping; - float32 m_gravityScale; float32 m_sleepTime; @@ -589,16 +579,6 @@ inline void b2Body::SetAngularDamping(float32 angularDamping) m_angularDamping = angularDamping; } -inline float32 b2Body::GetGravityScale() const -{ - return m_gravityScale; -} - -inline void b2Body::SetGravityScale(float32 scale) -{ - m_gravityScale = scale; -} - inline void b2Body::SetBullet(bool flag) { if (flag) @@ -800,10 +780,10 @@ inline void b2Body::SynchronizeTransform() m_xf.position = m_sweep.c - b2Mul(m_xf.R, m_sweep.localCenter); } -inline void b2Body::Advance(float32 alpha) +inline void b2Body::Advance(float32 t) { // Advance to the new safe time. - m_sweep.Advance(alpha); + m_sweep.Advance(t); m_sweep.c = m_sweep.c0; m_sweep.a = m_sweep.a0; SynchronizeTransform(); diff --git a/libs/box2d/src/Box2D/Dynamics/b2ContactManager.cpp b/libs/box2d/src/Box2D/Dynamics/b2ContactManager.cpp index cde07a3..d8d96dd 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2ContactManager.cpp +++ b/libs/box2d/src/Box2D/Dynamics/b2ContactManager.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -110,8 +110,6 @@ void b2ContactManager::Collide() { b2Fixture* fixtureA = c->GetFixtureA(); b2Fixture* fixtureB = c->GetFixtureB(); - int32 indexA = c->GetChildIndexA(); - int32 indexB = c->GetChildIndexB(); b2Body* bodyA = fixtureA->GetBody(); b2Body* bodyB = fixtureB->GetBody(); @@ -146,8 +144,8 @@ void b2ContactManager::Collide() c->m_flags &= ~b2Contact::e_filterFlag; } - int32 proxyIdA = fixtureA->m_proxies[indexA].proxyId; - int32 proxyIdB = fixtureB->m_proxies[indexB].proxyId; + int32 proxyIdA = fixtureA->m_proxyId; + int32 proxyIdB = fixtureB->m_proxyId; bool overlap = m_broadPhase.TestOverlap(proxyIdA, proxyIdB); // Here we destroy contacts that cease to overlap in the broad-phase. @@ -172,14 +170,8 @@ void b2ContactManager::FindNewContacts() void b2ContactManager::AddPair(void* proxyUserDataA, void* proxyUserDataB) { - b2FixtureProxy* proxyA = (b2FixtureProxy*)proxyUserDataA; - b2FixtureProxy* proxyB = (b2FixtureProxy*)proxyUserDataB; - - b2Fixture* fixtureA = proxyA->fixture; - b2Fixture* fixtureB = proxyB->fixture; - - int32 indexA = proxyA->childIndex; - int32 indexB = proxyB->childIndex; + b2Fixture* fixtureA = (b2Fixture*)proxyUserDataA; + b2Fixture* fixtureB = (b2Fixture*)proxyUserDataB; b2Body* bodyA = fixtureA->GetBody(); b2Body* bodyB = fixtureB->GetBody(); @@ -198,16 +190,13 @@ void b2ContactManager::AddPair(void* proxyUserDataA, void* proxyUserDataB) { b2Fixture* fA = edge->contact->GetFixtureA(); b2Fixture* fB = edge->contact->GetFixtureB(); - int32 iA = edge->contact->GetChildIndexA(); - int32 iB = edge->contact->GetChildIndexB(); - - if (fA == fixtureA && fB == fixtureB && iA == indexA && iB == indexB) + if (fA == fixtureA && fB == fixtureB) { // A contact already exists. return; } - if (fA == fixtureB && fB == fixtureA && iA == indexB && iB == indexA) + if (fA == fixtureB && fB == fixtureA) { // A contact already exists. return; @@ -230,13 +219,11 @@ void b2ContactManager::AddPair(void* proxyUserDataA, void* proxyUserDataB) } // Call the factory. - b2Contact* c = b2Contact::Create(fixtureA, indexA, fixtureB, indexB, m_allocator); + b2Contact* c = b2Contact::Create(fixtureA, fixtureB, m_allocator); // Contact creation may swap fixtures. fixtureA = c->GetFixtureA(); fixtureB = c->GetFixtureB(); - indexA = c->GetChildIndexA(); - indexB = c->GetChildIndexB(); bodyA = fixtureA->GetBody(); bodyB = fixtureB->GetBody(); diff --git a/libs/box2d/src/Box2D/Dynamics/b2ContactManager.h b/libs/box2d/src/Box2D/Dynamics/b2ContactManager.h index dc1f77f..fcba54a 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2ContactManager.h +++ b/libs/box2d/src/Box2D/Dynamics/b2ContactManager.h @@ -1,5 +1,5 @@ /* -* 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 diff --git a/libs/box2d/src/Box2D/Dynamics/b2Fixture.cpp b/libs/box2d/src/Box2D/Dynamics/b2Fixture.cpp index e70606d..31355b5 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2Fixture.cpp +++ b/libs/box2d/src/Box2D/Dynamics/b2Fixture.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -18,26 +18,29 @@ #include #include -#include #include -#include #include -#include #include #include #include + b2Fixture::b2Fixture() { m_userData = NULL; m_body = NULL; m_next = NULL; - m_proxies = NULL; - m_proxyCount = 0; + m_proxyId = b2BroadPhase::e_nullProxy; m_shape = NULL; m_density = 0.0f; } +b2Fixture::~b2Fixture() +{ + b2Assert(m_shape == NULL); + b2Assert(m_proxyId == b2BroadPhase::e_nullProxy); +} + void b2Fixture::Create(b2BlockAllocator* allocator, b2Body* body, const b2FixtureDef* def) { m_userData = def->userData; @@ -53,28 +56,13 @@ void b2Fixture::Create(b2BlockAllocator* allocator, b2Body* body, const b2Fixtur m_shape = def->shape->Clone(allocator); - // Reserve proxy space - int32 childCount = m_shape->GetChildCount(); - m_proxies = (b2FixtureProxy*)allocator->Allocate(childCount * sizeof(b2FixtureProxy)); - for (int32 i = 0; i < childCount; ++i) - { - m_proxies[i].fixture = NULL; - m_proxies[i].proxyId = b2BroadPhase::e_nullProxy; - } - m_proxyCount = 0; - m_density = def->density; } void b2Fixture::Destroy(b2BlockAllocator* allocator) { - // The proxies must be destroyed before calling this. - b2Assert(m_proxyCount == 0); - - // Free the proxy array. - int32 childCount = m_shape->GetChildCount(); - allocator->Free(m_proxies, childCount * sizeof(b2FixtureProxy)); - m_proxies = NULL; + // The proxy must be destroyed before calling this. + b2Assert(m_proxyId == b2BroadPhase::e_nullProxy); // Free the child shape. switch (m_shape->m_type) @@ -87,14 +75,6 @@ void b2Fixture::Destroy(b2BlockAllocator* allocator) } break; - case b2Shape::e_edge: - { - b2EdgeShape* s = (b2EdgeShape*)m_shape; - s->~b2EdgeShape(); - allocator->Free(s, sizeof(b2EdgeShape)); - } - break; - case b2Shape::e_polygon: { b2PolygonShape* s = (b2PolygonShape*)m_shape; @@ -103,14 +83,6 @@ void b2Fixture::Destroy(b2BlockAllocator* allocator) } break; - case b2Shape::e_loop: - { - b2LoopShape* s = (b2LoopShape*)m_shape; - s->~b2LoopShape(); - allocator->Free(s, sizeof(b2LoopShape)); - } - break; - default: b2Assert(false); break; @@ -119,69 +91,50 @@ void b2Fixture::Destroy(b2BlockAllocator* allocator) m_shape = NULL; } -void b2Fixture::CreateProxies(b2BroadPhase* broadPhase, const b2Transform& xf) +void b2Fixture::CreateProxy(b2BroadPhase* broadPhase, const b2Transform& xf) { - b2Assert(m_proxyCount == 0); - - // Create proxies in the broad-phase. - m_proxyCount = m_shape->GetChildCount(); + b2Assert(m_proxyId == b2BroadPhase::e_nullProxy); - for (int32 i = 0; i < m_proxyCount; ++i) - { - b2FixtureProxy* proxy = m_proxies + i; - m_shape->ComputeAABB(&proxy->aabb, xf, i); - proxy->proxyId = broadPhase->CreateProxy(proxy->aabb, proxy); - proxy->fixture = this; - proxy->childIndex = i; - } + // Create proxy in the broad-phase. + m_shape->ComputeAABB(&m_aabb, xf); + m_proxyId = broadPhase->CreateProxy(m_aabb, this); } -void b2Fixture::DestroyProxies(b2BroadPhase* broadPhase) +void b2Fixture::DestroyProxy(b2BroadPhase* broadPhase) { - // Destroy proxies in the broad-phase. - for (int32 i = 0; i < m_proxyCount; ++i) + if (m_proxyId == b2BroadPhase::e_nullProxy) { - b2FixtureProxy* proxy = m_proxies + i; - broadPhase->DestroyProxy(proxy->proxyId); - proxy->proxyId = b2BroadPhase::e_nullProxy; + return; } - m_proxyCount = 0; + // Destroy proxy in the broad-phase. + broadPhase->DestroyProxy(m_proxyId); + m_proxyId = b2BroadPhase::e_nullProxy; } void b2Fixture::Synchronize(b2BroadPhase* broadPhase, const b2Transform& transform1, const b2Transform& transform2) { - if (m_proxyCount == 0) + if (m_proxyId == b2BroadPhase::e_nullProxy) { return; } - for (int32 i = 0; i < m_proxyCount; ++i) - { - b2FixtureProxy* proxy = m_proxies + i; - - // Compute an AABB that covers the swept shape (may miss some rotation effect). - b2AABB aabb1, aabb2; - m_shape->ComputeAABB(&aabb1, transform1, proxy->childIndex); - m_shape->ComputeAABB(&aabb2, transform2, proxy->childIndex); + // Compute an AABB that covers the swept shape (may miss some rotation effect). + b2AABB aabb1, aabb2; + m_shape->ComputeAABB(&aabb1, transform1); + m_shape->ComputeAABB(&aabb2, transform2); - proxy->aabb.Combine(aabb1, aabb2); + m_aabb.Combine(aabb1, aabb2); - b2Vec2 displacement = transform2.position - transform1.position; + b2Vec2 displacement = transform2.position - transform1.position; - broadPhase->MoveProxy(proxy->proxyId, proxy->aabb, displacement); - } + broadPhase->MoveProxy(m_proxyId, m_aabb, displacement); } void b2Fixture::SetFilterData(const b2Filter& filter) { m_filter = filter; - Refilter(); -} - -void b2Fixture::Refilter() -{ if (m_body == NULL) { return; @@ -201,20 +154,6 @@ void b2Fixture::Refilter() edge = edge->next; } - - b2World* world = m_body->GetWorld(); - - if (world == NULL) - { - return; - } - - // Touch each proxy so that new pairs may be created - b2BroadPhase* broadPhase = &world->m_contactManager.m_broadPhase; - for (int32 i = 0; i < m_proxyCount; ++i) - { - broadPhase->TouchProxy(m_proxies[i].proxyId); - } } void b2Fixture::SetSensor(bool sensor) diff --git a/libs/box2d/src/Box2D/Dynamics/b2Fixture.h b/libs/box2d/src/Box2D/Dynamics/b2Fixture.h index a7b5c34..d9d3255 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2Fixture.h +++ b/libs/box2d/src/Box2D/Dynamics/b2Fixture.h @@ -1,5 +1,5 @@ /* -* 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 @@ -26,7 +26,6 @@ class b2BlockAllocator; class b2Body; class b2BroadPhase; -class b2Fixture; /// This holds contact filtering data. struct b2Filter @@ -62,6 +61,8 @@ struct b2FixtureDef isSensor = false; } + virtual ~b2FixtureDef() {} + /// The shape, this must be set. The shape will be cloned, so you /// can create the shape on the stack. const b2Shape* shape; @@ -86,14 +87,6 @@ struct b2FixtureDef b2Filter filter; }; -/// This proxy is used internally to connect fixtures to the broad-phase. -struct b2FixtureProxy -{ - b2AABB aabb; - b2Fixture* fixture; - int32 childIndex; - int32 proxyId; -}; /// A fixture is used to attach a shape to a body for collision detection. A fixture /// inherits its transform from its parent. Fixtures hold additional non-geometric data @@ -122,15 +115,11 @@ public: /// Set the contact filtering data. This will not update contacts until the next time /// step when either parent body is active and awake. - /// This automatically calls Refilter. void SetFilterData(const b2Filter& filter); /// Get the contact filtering data. const b2Filter& GetFilterData() const; - /// Call this if you want to establish collision that was previously disabled by b2ContactFilter::ShouldCollide. - void Refilter(); - /// Get the parent body of this fixture. This is NULL if the fixture is not attached. /// @return the parent body. b2Body* GetBody(); @@ -149,13 +138,14 @@ public: void SetUserData(void* data); /// Test a point for containment in this fixture. + /// @param xf the shape world transform. /// @param p a point in world coordinates. bool TestPoint(const b2Vec2& p) const; /// Cast a ray against this shape. /// @param output the ray-cast results. /// @param input the ray-cast input parameters. - bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const; + bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const; /// Get the mass data for this fixture. The mass data is based on the density and /// the shape. The rotational inertia is about the shape's origin. This operation @@ -172,21 +162,19 @@ public: /// Get the coefficient of friction. float32 GetFriction() const; - /// Set the coefficient of friction. This will _not_ change the friction of - /// existing contacts. + /// Set the coefficient of friction. void SetFriction(float32 friction); /// Get the coefficient of restitution. float32 GetRestitution() const; - /// Set the coefficient of restitution. This will _not_ change the restitution of - /// existing contacts. + /// Set the coefficient of restitution. void SetRestitution(float32 restitution); /// Get the fixture's AABB. This AABB may be enlarge and/or stale. /// If you need a more accurate AABB, compute it using the shape and /// the body transform. - const b2AABB& GetAABB(int32 childIndex) const; + const b2AABB& GetAABB() const; protected: @@ -196,6 +184,7 @@ protected: friend class b2ContactManager; b2Fixture(); + ~b2Fixture(); // We need separation create/destroy functions from the constructor/destructor because // the destructor cannot access the allocator (no destructor arguments allowed by C++). @@ -203,11 +192,13 @@ protected: void Destroy(b2BlockAllocator* allocator); // These support body activation/deactivation. - void CreateProxies(b2BroadPhase* broadPhase, const b2Transform& xf); - void DestroyProxies(b2BroadPhase* broadPhase); + void CreateProxy(b2BroadPhase* broadPhase, const b2Transform& xf); + void DestroyProxy(b2BroadPhase* broadPhase); void Synchronize(b2BroadPhase* broadPhase, const b2Transform& xf1, const b2Transform& xf2); + b2AABB m_aabb; + float32 m_density; b2Fixture* m_next; @@ -218,9 +209,7 @@ protected: float32 m_friction; float32 m_restitution; - b2FixtureProxy* m_proxies; - int32 m_proxyCount; - + int32 m_proxyId; b2Filter m_filter; bool m_isSensor; @@ -319,9 +308,9 @@ inline bool b2Fixture::TestPoint(const b2Vec2& p) const return m_shape->TestPoint(m_body->GetTransform(), p); } -inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input, int32 childIndex) const +inline bool b2Fixture::RayCast(b2RayCastOutput* output, const b2RayCastInput& input) const { - return m_shape->RayCast(output, input, m_body->GetTransform(), childIndex); + return m_shape->RayCast(output, input, m_body->GetTransform()); } inline void b2Fixture::GetMassData(b2MassData* massData) const @@ -329,10 +318,9 @@ inline void b2Fixture::GetMassData(b2MassData* massData) const m_shape->ComputeMass(massData, m_density); } -inline const b2AABB& b2Fixture::GetAABB(int32 childIndex) const +inline const b2AABB& b2Fixture::GetAABB() const { - b2Assert(0 <= childIndex && childIndex < m_proxyCount); - return m_proxies[childIndex].aabb; + return m_aabb; } #endif diff --git a/libs/box2d/src/Box2D/Dynamics/b2Island.cpp b/libs/box2d/src/Box2D/Dynamics/b2Island.cpp index 671b78f..0092499 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2Island.cpp +++ b/libs/box2d/src/Box2D/Dynamics/b2Island.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -16,7 +16,6 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include #include #include #include @@ -192,7 +191,7 @@ void b2Island::Solve(const b2TimeStep& step, const b2Vec2& gravity, bool allowSl } // Integrate velocities. - b->m_linearVelocity += step.dt * (b->m_gravityScale * gravity + b->m_invMass * b->m_force); + b->m_linearVelocity += step.dt * (gravity + b->m_invMass * b->m_force); b->m_angularVelocity += step.dt * b->m_invI * b->m_torque; // Apply damping. @@ -223,22 +222,8 @@ void b2Island::Solve(const b2TimeStep& step, const b2Vec2& gravity, bool allowSl } // Initialize velocity constraints. - b2ContactSolverDef solverDef; - solverDef.contacts = m_contacts; - solverDef.count = m_contactCount; - solverDef.allocator = m_allocator; - solverDef.impulseRatio = step.dtRatio; - solverDef.warmStarting = step.warmStarting; - - b2ContactSolver contactSolver(&solverDef); - - contactSolver.InitializeVelocityConstraints(); - - if (step.warmStarting) - { - contactSolver.WarmStart(); - } - + b2ContactSolver contactSolver(m_contacts, m_contactCount, m_allocator, step.dtRatio); + contactSolver.WarmStart(); for (int32 i = 0; i < m_jointCount; ++i) { m_joints[i]->InitVelocityConstraints(step); @@ -364,129 +349,6 @@ void b2Island::Solve(const b2TimeStep& step, const b2Vec2& gravity, bool allowSl } } -void b2Island::SolveTOI(const b2TimeStep& subStep, const b2Body* bodyA, const b2Body* bodyB) -{ - b2ContactSolverDef solverDef; - solverDef.contacts = m_contacts; - solverDef.count = m_contactCount; - solverDef.allocator = m_allocator; - solverDef.impulseRatio = subStep.dtRatio; - solverDef.warmStarting = subStep.warmStarting; - b2ContactSolver contactSolver(&solverDef); - - // Solve position constraints. - const float32 k_toiBaumgarte = 0.75f; - for (int32 i = 0; i < subStep.positionIterations; ++i) - { - bool contactsOkay = contactSolver.SolveTOIPositionConstraints(k_toiBaumgarte, bodyA, bodyB); - if (contactsOkay) - { - break; - } - - if (i == subStep.positionIterations - 1) - { - i += 0; - } - } - -#if 0 - // Is the new position really safe? - for (int32 i = 0; i < m_contactCount; ++i) - { - b2Contact* c = m_contacts[i]; - b2Fixture* fA = c->GetFixtureA(); - b2Fixture* fB = c->GetFixtureB(); - - b2Body* bA = fA->GetBody(); - b2Body* bB = fB->GetBody(); - - int32 indexA = c->GetChildIndexA(); - int32 indexB = c->GetChildIndexB(); - - b2DistanceInput input; - input.proxyA.Set(fA->GetShape(), indexA); - input.proxyB.Set(fB->GetShape(), indexB); - input.transformA = bA->GetTransform(); - input.transformB = bB->GetTransform(); - input.useRadii = false; - - b2DistanceOutput output; - b2SimplexCache cache; - cache.count = 0; - b2Distance(&output, &cache, &input); - - if (output.distance == 0 || cache.count == 3) - { - cache.count += 0; - } - } -#endif - - // Leap of faith to new safe state. - for (int32 i = 0; i < m_bodyCount; ++i) - { - m_bodies[i]->m_sweep.a0 = m_bodies[i]->m_sweep.a; - m_bodies[i]->m_sweep.c0 = m_bodies[i]->m_sweep.c; - } - - // No warm starting is needed for TOI events because warm - // starting impulses were applied in the discrete solver. - contactSolver.InitializeVelocityConstraints(); - - // Solve velocity constraints. - for (int32 i = 0; i < subStep.velocityIterations; ++i) - { - contactSolver.SolveVelocityConstraints(); - } - - // Don't store the TOI contact forces for warm starting - // because they can be quite large. - - // Integrate positions. - for (int32 i = 0; i < m_bodyCount; ++i) - { - b2Body* b = m_bodies[i]; - - if (b->GetType() == b2_staticBody) - { - continue; - } - - // Check for large velocities. - b2Vec2 translation = subStep.dt * b->m_linearVelocity; - if (b2Dot(translation, translation) > b2_maxTranslationSquared) - { - translation.Normalize(); - b->m_linearVelocity = (b2_maxTranslation * subStep.inv_dt) * translation; - } - - float32 rotation = subStep.dt * b->m_angularVelocity; - if (rotation * rotation > b2_maxRotationSquared) - { - if (rotation < 0.0) - { - b->m_angularVelocity = -subStep.inv_dt * b2_maxRotation; - } - else - { - b->m_angularVelocity = subStep.inv_dt * b2_maxRotation; - } - } - - // Integrate - b->m_sweep.c += subStep.dt * b->m_linearVelocity; - b->m_sweep.a += subStep.dt * b->m_angularVelocity; - - // Compute new transform - b->SynchronizeTransform(); - - // Note: shapes are synchronized later. - } - - Report(contactSolver.m_constraints); -} - void b2Island::Report(const b2ContactConstraint* constraints) { if (m_listener == NULL) diff --git a/libs/box2d/src/Box2D/Dynamics/b2Island.h b/libs/box2d/src/Box2D/Dynamics/b2Island.h index 8572081..3a5fd11 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2Island.h +++ b/libs/box2d/src/Box2D/Dynamics/b2Island.h @@ -1,5 +1,5 @@ /* -* 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 @@ -60,8 +60,6 @@ public: void Solve(const b2TimeStep& step, const b2Vec2& gravity, bool allowSleep); - void SolveTOI(const b2TimeStep& subStep, const b2Body* bodyA, const b2Body* bodyB); - void Add(b2Body* body) { b2Assert(m_bodyCount < m_bodyCapacity); @@ -100,6 +98,8 @@ public: int32 m_bodyCapacity; int32 m_contactCapacity; int32 m_jointCapacity; + + int32 m_positionIterationCount; }; #endif diff --git a/libs/box2d/src/Box2D/Dynamics/b2TimeStep.h b/libs/box2d/src/Box2D/Dynamics/b2TimeStep.h index 74afb9c..f59245d 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2TimeStep.h +++ b/libs/box2d/src/Box2D/Dynamics/b2TimeStep.h @@ -1,5 +1,5 @@ /* -* 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 @@ -21,15 +21,15 @@ #include -/// 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; -}; +/// 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; +}; #endif diff --git a/libs/box2d/src/Box2D/Dynamics/b2World.cpp b/libs/box2d/src/Box2D/Dynamics/b2World.cpp index dffda12..d3b9e00 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2World.cpp +++ b/libs/box2d/src/Box2D/Dynamics/b2World.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -23,15 +23,12 @@ #include #include #include +#include #include #include #include -#include -#include #include #include -#include -#include #include b2World::b2World(const b2Vec2& gravity, bool doSleep) @@ -47,9 +44,6 @@ b2World::b2World(const b2Vec2& gravity, bool doSleep) m_warmStarting = true; m_continuousPhysics = true; - m_subStepping = false; - - m_stepComplete = true; m_allowSleep = doSleep; m_gravity = gravity; @@ -59,29 +53,10 @@ b2World::b2World(const b2Vec2& gravity, bool doSleep) m_inv_dt0 = 0.0f; m_contactManager.m_allocator = &m_blockAllocator; - - memset(&m_profile, 0, sizeof(b2Profile)); } b2World::~b2World() { - // Some shapes allocate using b2Alloc. - b2Body* b = m_bodyList; - while (b) - { - b2Body* bNext = b->m_next; - - b2Fixture* f = b->m_fixtureList; - while (f) - { - b2Fixture* fNext = f->m_next; - f->m_proxyCount = 0; - f->Destroy(&m_blockAllocator); - f = fNext; - } - - b = bNext; - } } void b2World::SetDestructionListener(b2DestructionListener* listener) @@ -99,7 +74,7 @@ void b2World::SetContactListener(b2ContactListener* listener) m_contactManager.m_contactListener = listener; } -void b2World::SetDebugDraw(b2Draw* debugDraw) +void b2World::SetDebugDraw(b2DebugDraw* debugDraw) { m_debugDraw = debugDraw; } @@ -150,8 +125,6 @@ void b2World::DestroyBody(b2Body* b) } DestroyJoint(je0->joint); - - b->m_jointList = je; } b->m_jointList = NULL; @@ -177,13 +150,10 @@ void b2World::DestroyBody(b2Body* b) m_destructionListener->SayGoodbye(f0); } - f0->DestroyProxies(&m_contactManager.m_broadPhase); + f0->DestroyProxy(&m_contactManager.m_broadPhase); f0->Destroy(&m_blockAllocator); f0->~b2Fixture(); m_blockAllocator.Free(f0, sizeof(b2Fixture)); - - b->m_fixtureList = f; - b->m_fixtureCount -= 1; } b->m_fixtureList = NULL; b->m_fixtureCount = 0; @@ -543,331 +513,270 @@ void b2World::Solve(const b2TimeStep& step) m_contactManager.FindNewContacts(); } -// Find TOI contacts and solve them. -void b2World::SolveTOI(const b2TimeStep& step) +// Advance a dynamic body to its first time of contact +// and adjust the position to ensure clearance. +void b2World::SolveTOI(b2Body* body) { - b2Island island(2 * b2_maxTOIContacts, b2_maxTOIContacts, 0, &m_stackAllocator, m_contactManager.m_contactListener); - - if (m_stepComplete) + // Find the minimum contact. + b2Contact* toiContact = NULL; + float32 toi = 1.0f; + b2Body* toiOther = NULL; + bool found; + int32 count; + int32 iter = 0; + + bool bullet = body->IsBullet(); + + // Iterate until all contacts agree on the minimum TOI. We have + // to iterate because the TOI algorithm may skip some intermediate + // collisions when objects rotate through each other. + do { - for (b2Body* b = m_bodyList; b; b = b->m_next) + count = 0; + found = false; + for (b2ContactEdge* ce = body->m_contactList; ce; ce = ce->next) { - b->m_flags &= ~b2Body::e_islandFlag; - b->m_sweep.alpha0 = 0.0f; - } - - for (b2Contact* c = m_contactManager.m_contactList; c; c = c->m_next) - { - // Invalidate TOI - c->m_flags &= ~(b2Contact::e_toiFlag | b2Contact::e_islandFlag); - c->m_toiCount = 0; - c->m_toi = 1.0f; - } - } - - // Find TOI events and solve them. - for (;;) - { - // Find the first TOI. - b2Contact* minContact = NULL; - float32 minAlpha = 1.0f; - - for (b2Contact* c = m_contactManager.m_contactList; c; c = c->m_next) - { - // Is this contact disabled? - if (c->IsEnabled() == false) + if (ce->contact == toiContact) { continue; } - // Prevent excessive sub-stepping. - if (c->m_toiCount > b2_maxSubSteps) - { - continue; - } + b2Body* other = ce->other; + b2BodyType type = other->GetType(); - float32 alpha = 1.0f; - if (c->m_flags & b2Contact::e_toiFlag) + // Only bullets perform TOI with dynamic bodies. + if (bullet == true) { - // This contact has a valid cached TOI. - alpha = c->m_toi; - } - else - { - b2Fixture* fA = c->GetFixtureA(); - b2Fixture* fB = c->GetFixtureB(); - - // Is there a sensor? - if (fA->IsSensor() || fB->IsSensor()) - { - continue; - } - - b2Body* bA = fA->GetBody(); - b2Body* bB = fB->GetBody(); - - b2BodyType typeA = bA->GetType(); - b2BodyType typeB = bB->GetType(); - b2Assert(typeA == b2_dynamicBody || typeB == b2_dynamicBody); - - bool awakeA = bA->IsAwake() && typeA != b2_staticBody; - bool awakeB = bB->IsAwake() && typeB != b2_staticBody; - - // Is at least one body awake? - if (awakeA == false && awakeB == false) + // Bullets only perform TOI with bodies that have their TOI resolved. + if ((other->m_flags & b2Body::e_toiFlag) == 0) { continue; } - bool collideA = bA->IsBullet() || typeA != b2_dynamicBody; - bool collideB = bB->IsBullet() || typeB != b2_dynamicBody; - - // Are these two non-bullet dynamic bodies? - if (collideA == false && collideB == false) + // No repeated hits on non-static bodies + if (type != b2_staticBody && (ce->contact->m_flags & b2Contact::e_bulletHitFlag) != 0) { - continue; + continue; } + } + else if (type == b2_dynamicBody) + { + continue; + } - // Compute the TOI for this contact. - // Put the sweeps onto the same time interval. - float32 alpha0 = bA->m_sweep.alpha0; - - if (bA->m_sweep.alpha0 < bB->m_sweep.alpha0) - { - alpha0 = bB->m_sweep.alpha0; - bA->m_sweep.Advance(alpha0); - } - else if (bB->m_sweep.alpha0 < bA->m_sweep.alpha0) - { - alpha0 = bA->m_sweep.alpha0; - bB->m_sweep.Advance(alpha0); - } + // Check for a disabled contact. + b2Contact* contact = ce->contact; + if (contact->IsEnabled() == false) + { + continue; + } - b2Assert(alpha0 < 1.0f); + // Prevent infinite looping. + if (contact->m_toiCount > 10) + { + continue; + } - int32 indexA = c->GetChildIndexA(); - int32 indexB = c->GetChildIndexB(); + b2Fixture* fixtureA = contact->m_fixtureA; + b2Fixture* fixtureB = contact->m_fixtureB; - // Compute the time of impact in interval [0, minTOI] - b2TOIInput input; - input.proxyA.Set(fA->GetShape(), indexA); - input.proxyB.Set(fB->GetShape(), indexB); - input.sweepA = bA->m_sweep; - input.sweepB = bB->m_sweep; - input.tMax = 1.0f; + // Cull sensors. + if (fixtureA->IsSensor() || fixtureB->IsSensor()) + { + continue; + } - b2TOIOutput output; - b2TimeOfImpact(&output, &input); + b2Body* bodyA = fixtureA->m_body; + b2Body* bodyB = fixtureB->m_body; - // Beta is the fraction of the remaining portion of the . - float32 beta = output.t; - if (output.state == b2TOIOutput::e_touching) - { - alpha = b2Min(alpha0 + (1.0f - alpha0) * beta, 1.0f); - } - else - { - alpha = 1.0f; - } + // Compute the time of impact in interval [0, minTOI] + b2TOIInput input; + input.proxyA.Set(fixtureA->GetShape()); + input.proxyB.Set(fixtureB->GetShape()); + input.sweepA = bodyA->m_sweep; + input.sweepB = bodyB->m_sweep; + input.tMax = toi; - c->m_toi = alpha; - c->m_flags |= b2Contact::e_toiFlag; - } + b2TOIOutput output; + b2TimeOfImpact(&output, &input); - if (alpha < minAlpha) + if (output.state == b2TOIOutput::e_touching && output.t < toi) { - // This is the minimum TOI found so far. - minContact = c; - minAlpha = alpha; + toiContact = contact; + toi = output.t; + toiOther = other; + found = true; } - } - if (minContact == NULL || 1.0f - 10.0f * b2_epsilon < minAlpha) - { - // No more TOI events. Done! - m_stepComplete = true; - break; + ++count; } - // Advance the bodies to the TOI. - b2Fixture* fA = minContact->GetFixtureA(); - b2Fixture* fB = minContact->GetFixtureB(); - b2Body* bA = fA->GetBody(); - b2Body* bB = fB->GetBody(); + ++iter; + } while (found && count > 1 && iter < 50); + + if (toiContact == NULL) + { + body->Advance(1.0f); + return; + } - b2Sweep backup1 = bA->m_sweep; - b2Sweep backup2 = bB->m_sweep; + b2Sweep backup = body->m_sweep; + body->Advance(toi); + toiContact->Update(m_contactManager.m_contactListener); + if (toiContact->IsEnabled() == false) + { + // Contact disabled. Backup and recurse. + body->m_sweep = backup; + SolveTOI(body); + } - bA->Advance(minAlpha); - bB->Advance(minAlpha); + ++toiContact->m_toiCount; - // The TOI contact likely has some new contact points. - minContact->Update(m_contactManager.m_contactListener); - minContact->m_flags &= ~b2Contact::e_toiFlag; - ++minContact->m_toiCount; + // Update all the valid contacts on this body and build a contact island. + b2Contact* contacts[b2_maxTOIContacts]; + count = 0; + for (b2ContactEdge* ce = body->m_contactList; ce && count < b2_maxTOIContacts; ce = ce->next) + { + b2Body* other = ce->other; + b2BodyType type = other->GetType(); - // Is the contact solid? - if (minContact->IsEnabled() == false || minContact->IsTouching() == false) + // Only perform correction with static bodies, so the + // body won't get pushed out of the world. + if (type == b2_dynamicBody) { - // Restore the sweeps. - minContact->SetEnabled(false); - bA->m_sweep = backup1; - bB->m_sweep = backup2; - bA->SynchronizeTransform(); - bB->SynchronizeTransform(); continue; } - bA->SetAwake(true); - bB->SetAwake(true); - - // Build the island - island.Clear(); - island.Add(bA); - island.Add(bB); - island.Add(minContact); + // Check for a disabled contact. + b2Contact* contact = ce->contact; + if (contact->IsEnabled() == false) + { + continue; + } - bA->m_flags |= b2Body::e_islandFlag; - bB->m_flags |= b2Body::e_islandFlag; - minContact->m_flags |= b2Contact::e_islandFlag; + b2Fixture* fixtureA = contact->m_fixtureA; + b2Fixture* fixtureB = contact->m_fixtureB; - // Get contacts on bodyA and bodyB. - b2Body* bodies[2] = {bA, bB}; - for (int32 i = 0; i < 2; ++i) + // Cull sensors. + if (fixtureA->IsSensor() || fixtureB->IsSensor()) { - b2Body* body = bodies[i]; - if (body->m_type == b2_dynamicBody) - { - for (b2ContactEdge* ce = body->m_contactList; ce; ce = ce->next) - { - if (island.m_bodyCount == island.m_bodyCapacity) - { - break; - } + continue; + } - if (island.m_contactCount == island.m_contactCapacity) - { - break; - } + // The contact likely has some new contact points. The listener + // gives the user a chance to disable the contact. + if (contact != toiContact) + { + contact->Update(m_contactManager.m_contactListener); + } - b2Contact* contact = ce->contact; + // Did the user disable the contact? + if (contact->IsEnabled() == false) + { + // Skip this contact. + continue; + } - // Has this contact already been added to the island? - if (contact->m_flags & b2Contact::e_islandFlag) - { - continue; - } + if (contact->IsTouching() == false) + { + continue; + } - // Only add static, kinematic, or bullet bodies. - b2Body* other = ce->other; - if (other->m_type == b2_dynamicBody && - body->IsBullet() == false && other->IsBullet() == false) - { - continue; - } + contacts[count] = contact; + ++count; + } - // Skip sensors. - bool sensorA = contact->m_fixtureA->m_isSensor; - bool sensorB = contact->m_fixtureB->m_isSensor; - if (sensorA || sensorB) - { - continue; - } - - // Tentatively advance the body to the TOI. - b2Sweep backup = other->m_sweep; - if ((other->m_flags & b2Body::e_islandFlag) == 0) - { - other->Advance(minAlpha); - } - - // Update the contact points - contact->Update(m_contactManager.m_contactListener); - - // Was the contact disabled by the user? - if (contact->IsEnabled() == false) - { - other->m_sweep = backup; - other->SynchronizeTransform(); - continue; - } + // Reduce the TOI body's overlap with the contact island. + b2TOISolver solver(&m_stackAllocator); + solver.Initialize(contacts, count, body); - // Are there contact points? - if (contact->IsTouching() == false) - { - other->m_sweep = backup; - other->SynchronizeTransform(); - continue; - } + const float32 k_toiBaumgarte = 0.75f; + bool solved = false; + for (int32 i = 0; i < 20; ++i) + { + bool contactsOkay = solver.Solve(k_toiBaumgarte); + if (contactsOkay) + { + solved = true; + break; + } + } - // Add the contact to the island - contact->m_flags |= b2Contact::e_islandFlag; - island.Add(contact); + if (toiOther->GetType() != b2_staticBody) + { + toiContact->m_flags |= b2Contact::e_bulletHitFlag; + } +} - // Has the other body already been added to the island? - if (other->m_flags & b2Body::e_islandFlag) - { - continue; - } - - // Add the other body to the island. - other->m_flags |= b2Body::e_islandFlag; +// Sequentially solve TOIs for each body. We bring each +// body to the time of contact and perform some position correction. +// Time is not conserved. +void b2World::SolveTOI() +{ + // Prepare all contacts. + for (b2Contact* c = m_contactManager.m_contactList; c; c = c->m_next) + { + // Enable the contact + c->m_flags |= b2Contact::e_enabledFlag; - if (other->m_type != b2_staticBody) - { - other->SetAwake(true); - } + // Set the number of TOI events for this contact to zero. + c->m_toiCount = 0; + } - island.Add(other); - } - } + // Initialize the TOI flag. + for (b2Body* body = m_bodyList; body; body = body->m_next) + { + // Kinematic, and static bodies will not be affected by the TOI event. + // If a body was not in an island then it did not move. + if ((body->m_flags & b2Body::e_islandFlag) == 0 || body->GetType() == b2_kinematicBody || body->GetType() == b2_staticBody) + { + body->m_flags |= b2Body::e_toiFlag; + } + else + { + body->m_flags &= ~b2Body::e_toiFlag; } + } - b2TimeStep subStep; - subStep.dt = (1.0f - minAlpha) * step.dt; - subStep.inv_dt = 1.0f / subStep.dt; - subStep.dtRatio = 1.0f; - subStep.positionIterations = 20; - subStep.velocityIterations = step.velocityIterations; - subStep.warmStarting = false; - island.SolveTOI(subStep, bA, bB); + // Collide non-bullets. + for (b2Body* body = m_bodyList; body; body = body->m_next) + { + if (body->m_flags & b2Body::e_toiFlag) + { + continue; + } - // Reset island flags and synchronize broad-phase proxies. - for (int32 i = 0; i < island.m_bodyCount; ++i) + if (body->IsBullet() == true) { - b2Body* body = island.m_bodies[i]; - body->m_flags &= ~b2Body::e_islandFlag; + continue; + } - if (body->m_type != b2_dynamicBody) - { - continue; - } + SolveTOI(body); - body->SynchronizeFixtures(); + body->m_flags |= b2Body::e_toiFlag; + } - // Invalidate all contact TOIs on this displaced body. - for (b2ContactEdge* ce = body->m_contactList; ce; ce = ce->next) - { - ce->contact->m_flags &= ~(b2Contact::e_toiFlag | b2Contact::e_islandFlag); - } + // Collide bullets. + for (b2Body* body = m_bodyList; body; body = body->m_next) + { + if (body->m_flags & b2Body::e_toiFlag) + { + continue; } - // Commit fixture proxy movements to the broad-phase so that new contacts are created. - // Also, some contacts can be destroyed. - m_contactManager.FindNewContacts(); - - if (m_subStepping) + if (body->IsBullet() == false) { - m_stepComplete = false; - break; + continue; } + + SolveTOI(body); + + body->m_flags |= b2Body::e_toiFlag; } } void b2World::Step(float32 dt, int32 velocityIterations, int32 positionIterations) { - b2Timer stepTimer; - // If new fixtures were added, we need to find the new contacts. if (m_flags & e_newFixture) { @@ -893,28 +802,20 @@ void b2World::Step(float32 dt, int32 velocityIterations, int32 positionIteration step.dtRatio = m_inv_dt0 * dt; step.warmStarting = m_warmStarting; - + // Update contacts. This is where some contacts are destroyed. - { - b2Timer timer; - m_contactManager.Collide(); - m_profile.collide = timer.GetMilliseconds(); - } + m_contactManager.Collide(); // Integrate velocities, solve velocity constraints, and integrate positions. - if (m_stepComplete && step.dt > 0.0f) + if (step.dt > 0.0f) { - b2Timer timer; Solve(step); - m_profile.solve = timer.GetMilliseconds(); } // Handle TOI events. if (m_continuousPhysics && step.dt > 0.0f) { - b2Timer timer; - SolveTOI(step); - m_profile.solveTOI = timer.GetMilliseconds(); + SolveTOI(); } if (step.dt > 0.0f) @@ -928,8 +829,6 @@ void b2World::Step(float32 dt, int32 velocityIterations, int32 positionIteration } m_flags &= ~e_locked; - - m_profile.step = stepTimer.GetMilliseconds(); } void b2World::ClearForces() @@ -945,8 +844,8 @@ struct b2WorldQueryWrapper { bool QueryCallback(int32 proxyId) { - b2FixtureProxy* proxy = (b2FixtureProxy*)broadPhase->GetUserData(proxyId); - return callback->ReportFixture(proxy->fixture); + b2Fixture* fixture = (b2Fixture*)broadPhase->GetUserData(proxyId); + return callback->ReportFixture(fixture); } const b2BroadPhase* broadPhase; @@ -966,11 +865,9 @@ struct b2WorldRayCastWrapper float32 RayCastCallback(const b2RayCastInput& input, int32 proxyId) { void* userData = broadPhase->GetUserData(proxyId); - b2FixtureProxy* proxy = (b2FixtureProxy*)userData; - b2Fixture* fixture = proxy->fixture; - int32 index = proxy->childIndex; + b2Fixture* fixture = (b2Fixture*)userData; b2RayCastOutput output; - bool hit = fixture->RayCast(&output, input, index); + bool hit = fixture->RayCast(&output, input); if (hit) { @@ -1014,32 +911,6 @@ void b2World::DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color } break; - case b2Shape::e_edge: - { - b2EdgeShape* edge = (b2EdgeShape*)fixture->GetShape(); - b2Vec2 v1 = b2Mul(xf, edge->m_vertex1); - b2Vec2 v2 = b2Mul(xf, edge->m_vertex2); - m_debugDraw->DrawSegment(v1, v2, color); - } - break; - - case b2Shape::e_loop: - { - b2LoopShape* loop = (b2LoopShape*)fixture->GetShape(); - int32 count = loop->GetCount(); - const b2Vec2* vertices = loop->GetVertices(); - - b2Vec2 v1 = b2Mul(xf, vertices[count - 1]); - for (int32 i = 0; i < count; ++i) - { - b2Vec2 v2 = b2Mul(xf, vertices[i]); - m_debugDraw->DrawSegment(v1, v2, color); - m_debugDraw->DrawCircle(v1, 0.05f, color); - v1 = v2; - } - } - break; - case b2Shape::e_polygon: { b2PolygonShape* poly = (b2PolygonShape*)fixture->GetShape(); @@ -1108,7 +979,7 @@ void b2World::DrawDebugData() uint32 flags = m_debugDraw->GetFlags(); - if (flags & b2Draw::e_shapeBit) + if (flags & b2DebugDraw::e_shapeBit) { for (b2Body* b = m_bodyList; b; b = b->GetNext()) { @@ -1139,7 +1010,7 @@ void b2World::DrawDebugData() } } - if (flags & b2Draw::e_jointBit) + if (flags & b2DebugDraw::e_jointBit) { for (b2Joint* j = m_jointList; j; j = j->GetNext()) { @@ -1147,22 +1018,22 @@ void b2World::DrawDebugData() } } - if (flags & b2Draw::e_pairBit) + if (flags & b2DebugDraw::e_pairBit) { b2Color color(0.3f, 0.9f, 0.9f); for (b2Contact* c = m_contactManager.m_contactList; c; c = c->GetNext()) { - //b2Fixture* fixtureA = c->GetFixtureA(); - //b2Fixture* fixtureB = c->GetFixtureB(); + b2Fixture* fixtureA = c->GetFixtureA(); + b2Fixture* fixtureB = c->GetFixtureB(); - //b2Vec2 cA = fixtureA->GetAABB().GetCenter(); - //b2Vec2 cB = fixtureB->GetAABB().GetCenter(); + b2Vec2 cA = fixtureA->GetAABB().GetCenter(); + b2Vec2 cB = fixtureB->GetAABB().GetCenter(); - //m_debugDraw->DrawSegment(cA, cB, color); + m_debugDraw->DrawSegment(cA, cB, color); } } - if (flags & b2Draw::e_aabbBit) + if (flags & b2DebugDraw::e_aabbBit) { b2Color color(0.9f, 0.3f, 0.9f); b2BroadPhase* bp = &m_contactManager.m_broadPhase; @@ -1176,23 +1047,19 @@ void b2World::DrawDebugData() for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) { - for (int32 i = 0; i < f->m_proxyCount; ++i) - { - b2FixtureProxy* proxy = f->m_proxies + i; - b2AABB aabb = bp->GetFatAABB(proxy->proxyId); - b2Vec2 vs[4]; - vs[0].Set(aabb.lowerBound.x, aabb.lowerBound.y); - vs[1].Set(aabb.upperBound.x, aabb.lowerBound.y); - vs[2].Set(aabb.upperBound.x, aabb.upperBound.y); - vs[3].Set(aabb.lowerBound.x, aabb.upperBound.y); - - m_debugDraw->DrawPolygon(vs, 4, color); - } + b2AABB aabb = bp->GetFatAABB(f->m_proxyId); + b2Vec2 vs[4]; + vs[0].Set(aabb.lowerBound.x, aabb.lowerBound.y); + vs[1].Set(aabb.upperBound.x, aabb.lowerBound.y); + vs[2].Set(aabb.upperBound.x, aabb.upperBound.y); + vs[3].Set(aabb.lowerBound.x, aabb.upperBound.y); + + m_debugDraw->DrawPolygon(vs, 4, color); } } } - if (flags & b2Draw::e_centerOfMassBit) + if (flags & b2DebugDraw::e_centerOfMassBit) { for (b2Body* b = m_bodyList; b; b = b->GetNext()) { @@ -1207,18 +1074,3 @@ int32 b2World::GetProxyCount() const { return m_contactManager.m_broadPhase.GetProxyCount(); } - -int32 b2World::GetTreeHeight() const -{ - return m_contactManager.m_broadPhase.GetTreeHeight(); -} - -int32 b2World::GetTreeBalance() const -{ - return m_contactManager.m_broadPhase.GetTreeBalance(); -} - -float32 b2World::GetTreeQuality() const -{ - return m_contactManager.m_broadPhase.GetTreeQuality(); -} diff --git a/libs/box2d/src/Box2D/Dynamics/b2World.h b/libs/box2d/src/Box2D/Dynamics/b2World.h index 169d106..bff1427 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2World.h +++ b/libs/box2d/src/Box2D/Dynamics/b2World.h @@ -1,5 +1,5 @@ /* -* 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 @@ -27,23 +27,12 @@ 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. @@ -74,7 +63,7 @@ public: /// 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. @@ -105,12 +94,9 @@ public: 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(); @@ -135,20 +121,17 @@ public: /// 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; } @@ -156,9 +139,6 @@ public: /// 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; @@ -171,16 +151,6 @@ public: /// 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); @@ -196,12 +166,6 @@ public: /// 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 @@ -209,16 +173,16 @@ private: { 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); @@ -239,21 +203,20 @@ private: 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() @@ -261,31 +224,16 @@ 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; @@ -334,14 +282,4 @@ inline bool b2World::GetAutoClearForces() const 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 diff --git a/libs/box2d/src/Box2D/Dynamics/b2WorldCallbacks.cpp b/libs/box2d/src/Box2D/Dynamics/b2WorldCallbacks.cpp index 82b28cc..bc5fefb 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2WorldCallbacks.cpp +++ b/libs/box2d/src/Box2D/Dynamics/b2WorldCallbacks.cpp @@ -1,5 +1,5 @@ /* -* 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 @@ -34,3 +34,28 @@ bool b2ContactFilter::ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB) bool collide = (filterA.maskBits & filterB.categoryBits) != 0 && (filterA.categoryBits & filterB.maskBits) != 0; return collide; } + +b2DebugDraw::b2DebugDraw() +{ + m_drawFlags = 0; +} + +void b2DebugDraw::SetFlags(uint32 flags) +{ + m_drawFlags = flags; +} + +uint32 b2DebugDraw::GetFlags() const +{ + return m_drawFlags; +} + +void b2DebugDraw::AppendFlags(uint32 flags) +{ + m_drawFlags |= flags; +} + +void b2DebugDraw::ClearFlags(uint32 flags) +{ + m_drawFlags &= ~flags; +} diff --git a/libs/box2d/src/Box2D/Dynamics/b2WorldCallbacks.h b/libs/box2d/src/Box2D/Dynamics/b2WorldCallbacks.h index 33393f8..82ee67e 100644 --- a/libs/box2d/src/Box2D/Dynamics/b2WorldCallbacks.h +++ b/libs/box2d/src/Box2D/Dynamics/b2WorldCallbacks.h @@ -1,5 +1,5 @@ /* -* 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 @@ -27,6 +27,7 @@ class b2Fixture; class b2Body; class b2Joint; class b2Contact; +struct b2ContactPoint; struct b2ContactResult; struct b2Manifold; @@ -151,4 +152,66 @@ public: const b2Vec2& normal, float32 fraction) = 0; }; +/// Color for debug drawing. Each value has the range [0,1]. +struct b2Color +{ + b2Color() {} + b2Color(float32 r, float32 g, float32 b) : r(r), g(g), b(b) {} + void Set(float32 ri, float32 gi, float32 bi) { r = ri; g = gi; b = bi; } + float32 r, g, b; +}; + +/// Implement and register this class with a b2World to provide debug drawing of physics +/// entities in your game. +class b2DebugDraw +{ +public: + b2DebugDraw(); + + virtual ~b2DebugDraw() {} + + enum + { + e_shapeBit = 0x0001, ///< draw shapes + e_jointBit = 0x0002, ///< draw joint connections + e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes + e_pairBit = 0x0008, ///< draw broad-phase pairs + e_centerOfMassBit = 0x0010, ///< draw center of mass frame + }; + + /// Set the drawing flags. + void SetFlags(uint32 flags); + + /// Get the drawing flags. + uint32 GetFlags() const; + + /// Append flags to the current flags. + void AppendFlags(uint32 flags); + + /// Clear flags from the current flags. + void ClearFlags(uint32 flags); + + /// Draw a closed polygon provided in CCW order. + virtual void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0; + + /// Draw a solid closed polygon provided in CCW order. + virtual void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color) = 0; + + /// Draw a circle. + virtual void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color) = 0; + + /// Draw a solid circle. + virtual void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color) = 0; + + /// Draw a line segment. + virtual void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color) = 0; + + /// Draw a transform. Choose your own length scale. + /// @param xf a transform. + virtual void DrawTransform(const b2Transform& xf) = 0; + +protected: + uint32 m_drawFlags; +}; + #endif diff --git a/libs/box2d/src/Box2D/Rope/b2Rope.cpp b/libs/box2d/src/Box2D/Rope/b2Rope.cpp deleted file mode 100644 index 97578b2..0000000 --- a/libs/box2d/src/Box2D/Rope/b2Rope.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* -* Copyright (c) 2011 Erin Catto http://box2d.org -* -* 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 -#include - -b2Rope::b2Rope() -{ - m_count = 0; - m_ps = NULL; - m_p0s = NULL; - m_vs = NULL; - m_ims = NULL; - m_Ls = NULL; - m_as = NULL; - m_gravity.SetZero(); - m_k2 = 1.0f; - m_k3 = 0.1f; -} - -b2Rope::~b2Rope() -{ - b2Free(m_ps); - b2Free(m_p0s); - b2Free(m_vs); - b2Free(m_ims); - b2Free(m_Ls); - b2Free(m_as); -} - -void b2Rope::Initialize(const b2RopeDef* def) -{ - b2Assert(def->count >= 3); - m_count = def->count; - m_ps = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2)); - m_p0s = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2)); - m_vs = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2)); - m_ims = (float32*)b2Alloc(m_count * sizeof(float32)); - - for (int32 i = 0; i < m_count; ++i) - { - m_ps[i] = def->vertices[i]; - m_p0s[i] = def->vertices[i]; - m_vs[i].SetZero(); - - float32 m = def->masses[i]; - if (m > 0.0f) - { - m_ims[i] = 1.0f / m; - } - else - { - m_ims[i] = 0.0f; - } - } - - int32 count2 = m_count - 1; - int32 count3 = m_count - 2; - m_Ls = (float32*)b2Alloc(count2 * sizeof(float32)); - m_as = (float32*)b2Alloc(count3 * sizeof(float32)); - - for (int32 i = 0; i < count2; ++i) - { - b2Vec2 p1 = m_ps[i]; - b2Vec2 p2 = m_ps[i+1]; - m_Ls[i] = b2Distance(p1, p2); - } - - for (int32 i = 0; i < count3; ++i) - { - b2Vec2 p1 = m_ps[i]; - b2Vec2 p2 = m_ps[i + 1]; - b2Vec2 p3 = m_ps[i + 2]; - - b2Vec2 d1 = p2 - p1; - b2Vec2 d2 = p3 - p2; - - float32 a = b2Cross(d1, d2); - float32 b = b2Dot(d1, d2); - - m_as[i] = b2Atan2(a, b); - } - - m_gravity = def->gravity; - m_damping = def->damping; - m_k2 = def->k2; - m_k3 = def->k3; -} - -void b2Rope::Step(float32 h, int32 iterations) -{ - if (h == 0.0) - { - return; - } - - float32 d = expf(- h * m_damping); - - for (int32 i = 0; i < m_count; ++i) - { - m_p0s[i] = m_ps[i]; - if (m_ims[i] > 0.0f) - { - m_vs[i] += h * m_gravity; - } - m_vs[i] *= d; - m_ps[i] += h * m_vs[i]; - - } - - for (int32 i = 0; i < iterations; ++i) - { - SolveC2(); - SolveC3(); - SolveC2(); - } - - float32 inv_h = 1.0f / h; - for (int32 i = 0; i < m_count; ++i) - { - m_vs[i] = inv_h * (m_ps[i] - m_p0s[i]); - } -} - -void b2Rope::SolveC2() -{ - int32 count2 = m_count - 1; - - for (int32 i = 0; i < count2; ++i) - { - b2Vec2 p1 = m_ps[i]; - b2Vec2 p2 = m_ps[i + 1]; - - b2Vec2 d = p2 - p1; - float32 L = d.Normalize(); - - float32 im1 = m_ims[i]; - float32 im2 = m_ims[i + 1]; - - if (im1 + im2 == 0.0f) - { - continue; - } - - float32 s1 = im1 / (im1 + im2); - float32 s2 = im2 / (im1 + im2); - - p1 -= m_k2 * s1 * (m_Ls[i] - L) * d; - p2 += m_k2 * s2 * (m_Ls[i] - L) * d; - - m_ps[i] = p1; - m_ps[i + 1] = p2; - } -} - -void b2Rope::SetAngle(float32 angle) -{ - int32 count3 = m_count - 2; - for (int32 i = 0; i < count3; ++i) - { - m_as[i] = angle; - } -} - -void b2Rope::SolveC3() -{ - int32 count3 = m_count - 2; - - for (int32 i = 0; i < count3; ++i) - { - b2Vec2 p1 = m_ps[i]; - b2Vec2 p2 = m_ps[i + 1]; - b2Vec2 p3 = m_ps[i + 2]; - - float32 m1 = m_ims[i]; - float32 m2 = m_ims[i + 1]; - float32 m3 = m_ims[i + 2]; - - b2Vec2 d1 = p2 - p1; - b2Vec2 d2 = p3 - p2; - - float32 L1sqr = d1.LengthSquared(); - float32 L2sqr = d2.LengthSquared(); - - if (L1sqr * L2sqr == 0.0f) - { - continue; - } - - float32 a = b2Cross(d1, d2); - float32 b = b2Dot(d1, d2); - - float32 angle = b2Atan2(a, b); - - b2Vec2 Jd1 = (-1.0f / L1sqr) * d1.Skew(); - b2Vec2 Jd2 = (1.0f / L2sqr) * d2.Skew(); - - b2Vec2 J1 = -Jd1; - b2Vec2 J2 = Jd1 - Jd2; - b2Vec2 J3 = Jd2; - - float32 mass = m1 * b2Dot(J1, J1) + m2 * b2Dot(J2, J2) + m3 * b2Dot(J3, J3); - if (mass == 0.0f) - { - continue; - } - - mass = 1.0f / mass; - - float32 C = angle - m_as[i]; - - while (C > b2_pi) - { - angle -= 2 * b2_pi; - C = angle - m_as[i]; - } - - while (C < -b2_pi) - { - angle += 2.0f * b2_pi; - C = angle - m_as[i]; - } - - float32 impulse = - m_k3 * mass * C; - - p1 += (m1 * impulse) * J1; - p2 += (m2 * impulse) * J2; - p3 += (m3 * impulse) * J3; - - m_ps[i] = p1; - m_ps[i + 1] = p2; - m_ps[i + 2] = p3; - } -} - -void b2Rope::Draw(b2Draw* draw) const -{ - b2Color c(0.4f, 0.5f, 0.7f); - - for (int32 i = 0; i < m_count - 1; ++i) - { - draw->DrawSegment(m_ps[i], m_ps[i+1], c); - } -} diff --git a/libs/box2d/src/Box2D/Rope/b2Rope.h b/libs/box2d/src/Box2D/Rope/b2Rope.h deleted file mode 100644 index bc5375d..0000000 --- a/libs/box2d/src/Box2D/Rope/b2Rope.h +++ /dev/null @@ -1,115 +0,0 @@ -/* -* Copyright (c) 2011 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef B2_ROPE_H -#define B2_ROPE_H - -#include - -class b2Draw; - -/// -struct b2RopeDef -{ - b2RopeDef() - { - vertices = NULL; - count = 0; - masses = NULL; - gravity.SetZero(); - damping = 0.1f; - k2 = 0.9f; - k3 = 0.1f; - } - - /// - b2Vec2* vertices; - - /// - int32 count; - - /// - float32* masses; - - /// - b2Vec2 gravity; - - /// - float32 damping; - - /// Stretching stiffness - float32 k2; - - /// Bending stiffness. Values above 0.5 can make the simulation blow up. - float32 k3; -}; - -/// -class b2Rope -{ -public: - b2Rope(); - ~b2Rope(); - - /// - void Initialize(const b2RopeDef* def); - - /// - void Step(float32 timeStep, int32 iterations); - - /// - int32 GetVertexCount() const - { - return m_count; - } - - /// - const b2Vec2* GetVertices() const - { - return m_ps; - } - - /// - void Draw(b2Draw* draw) const; - - /// - void SetAngle(float32 angle); - -private: - - void SolveC2(); - void SolveC3(); - - int32 m_count; - b2Vec2* m_ps; - b2Vec2* m_p0s; - b2Vec2* m_vs; - - float32* m_ims; - - float32* m_Ls; - float32* m_as; - - b2Vec2 m_gravity; - float32 m_damping; - - float32 m_k2; - float32 m_k3; -}; - -#endif diff --git a/libs/box2d/src/Tests/ApplyForce.h b/libs/box2d/src/Tests/ApplyForce.h index b13ea7d..766a56b 100644 --- a/libs/box2d/src/Tests/ApplyForce.h +++ b/libs/box2d/src/Tests/ApplyForce.h @@ -1,5 +1,5 @@ /* -* 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 @@ -34,7 +34,7 @@ public: bd.position.Set(0.0f, 20.0f); ground = m_world->CreateBody(&bd); - b2EdgeShape shape; + b2PolygonShape shape; b2FixtureDef sd; sd.shape = &shape; @@ -42,19 +42,19 @@ public: sd.restitution = k_restitution; // Left vertical - shape.Set(b2Vec2(-20.0f, -20.0f), b2Vec2(-20.0f, 20.0f)); + shape.SetAsEdge(b2Vec2(-20.0f, -20.0f), b2Vec2(-20.0f, 20.0f)); ground->CreateFixture(&sd); // Right vertical - shape.Set(b2Vec2(20.0f, -20.0f), b2Vec2(20.0f, 20.0f)); + shape.SetAsEdge(b2Vec2(20.0f, -20.0f), b2Vec2(20.0f, 20.0f)); ground->CreateFixture(&sd); // Top horizontal - shape.Set(b2Vec2(-20.0f, 20.0f), b2Vec2(20.0f, 20.0f)); + shape.SetAsEdge(b2Vec2(-20.0f, 20.0f), b2Vec2(20.0f, 20.0f)); ground->CreateFixture(&sd); // Bottom horizontal - shape.Set(b2Vec2(-20.0f, -20.0f), b2Vec2(20.0f, -20.0f)); + shape.SetAsEdge(b2Vec2(-20.0f, -20.0f), b2Vec2(20.0f, -20.0f)); ground->CreateFixture(&sd); } diff --git a/libs/box2d/src/Tests/BodyTypes.h b/libs/box2d/src/Tests/BodyTypes.h index 4b4b055..94bedac 100644 --- a/libs/box2d/src/Tests/BodyTypes.h +++ b/libs/box2d/src/Tests/BodyTypes.h @@ -1,5 +1,5 @@ /* -* 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 @@ -29,8 +29,8 @@ public: b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f)); b2FixtureDef fd; fd.shape = &shape; diff --git a/libs/box2d/src/Tests/Breakable.h b/libs/box2d/src/Tests/Breakable.h index 3fbdd47..ae46c0f 100644 --- a/libs/box2d/src/Tests/Breakable.h +++ b/libs/box2d/src/Tests/Breakable.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2008-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2008-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 @@ -36,8 +36,8 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/Bridge.h b/libs/box2d/src/Tests/Bridge.h index ef83649..4d79d05 100644 --- a/libs/box2d/src/Tests/Bridge.h +++ b/libs/box2d/src/Tests/Bridge.h @@ -1,5 +1,5 @@ /* -* 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 @@ -25,7 +25,7 @@ public: enum { - e_count = 30 + e_count = 30, }; Bridge() @@ -35,8 +35,8 @@ public: b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/BulletTest.h b/libs/box2d/src/Tests/BulletTest.h deleted file mode 100644 index 54dc0e6..0000000 --- a/libs/box2d/src/Tests/BulletTest.h +++ /dev/null @@ -1,136 +0,0 @@ -/* -* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef BULLET_TEST_H -#define BULLET_TEST_H - -class BulletTest : public Test -{ -public: - - BulletTest() - { - { - b2BodyDef bd; - bd.position.Set(0.0f, 0.0f); - b2Body* body = m_world->CreateBody(&bd); - - b2EdgeShape edge; - - edge.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f)); - body->CreateFixture(&edge, 0.0f); - - b2PolygonShape shape; - shape.SetAsBox(0.2f, 1.0f, b2Vec2(0.5f, 1.0f), 0.0f); - body->CreateFixture(&shape, 0.0f); - } - - { - b2BodyDef bd; - bd.type = b2_dynamicBody; - bd.position.Set(0.0f, 4.0f); - - b2PolygonShape box; - box.SetAsBox(2.0f, 0.1f); - - m_body = m_world->CreateBody(&bd); - m_body->CreateFixture(&box, 1.0f); - - box.SetAsBox(0.25f, 0.25f); - - //m_x = RandomFloat(-1.0f, 1.0f); - m_x = 0.20352793f; - bd.position.Set(m_x, 10.0f); - bd.bullet = true; - - m_bullet = m_world->CreateBody(&bd); - m_bullet->CreateFixture(&box, 100.0f); - - m_bullet->SetLinearVelocity(b2Vec2(0.0f, -50.0f)); - } - } - - void Launch() - { - m_body->SetTransform(b2Vec2(0.0f, 4.0f), 0.0f); - m_body->SetLinearVelocity(b2Vec2_zero); - m_body->SetAngularVelocity(0.0f); - - m_x = RandomFloat(-1.0f, 1.0f); - m_bullet->SetTransform(b2Vec2(m_x, 10.0f), 0.0f); - m_bullet->SetLinearVelocity(b2Vec2(0.0f, -50.0f)); - m_bullet->SetAngularVelocity(0.0f); - - extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters; - extern int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters; - extern int32 b2_toiRootIters, b2_toiMaxRootIters; - - b2_gjkCalls = 0; - b2_gjkIters = 0; - b2_gjkMaxIters = 0; - - b2_toiCalls = 0; - b2_toiIters = 0; - b2_toiMaxIters = 0; - b2_toiRootIters = 0; - b2_toiMaxRootIters = 0; - } - - void Step(Settings* settings) - { - Test::Step(settings); - - extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters; - extern int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters; - extern int32 b2_toiRootIters, b2_toiMaxRootIters; - - if (b2_gjkCalls > 0) - { - m_debugDraw.DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d", - b2_gjkCalls, b2_gjkIters / float32(b2_gjkCalls), b2_gjkMaxIters); - m_textLine += 15; - } - - if (b2_toiCalls > 0) - { - m_debugDraw.DrawString(5, m_textLine, "toi calls = %d, ave toi iters = %3.1f, max toi iters = %d", - b2_toiCalls, b2_toiIters / float32(b2_toiCalls), b2_toiMaxRootIters); - m_textLine += 15; - - m_debugDraw.DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d", - b2_toiRootIters / float32(b2_toiCalls), b2_toiMaxRootIters); - m_textLine += 15; - } - - if (m_stepCount % 60 == 0) - { - Launch(); - } - } - - static Test* Create() - { - return new BulletTest; - } - - b2Body* m_body; - b2Body* m_bullet; - float32 m_x; -}; - -#endif diff --git a/libs/box2d/src/Tests/Cantilever.h b/libs/box2d/src/Tests/Cantilever.h index 28084da..d9fb622 100644 --- a/libs/box2d/src/Tests/Cantilever.h +++ b/libs/box2d/src/Tests/Cantilever.h @@ -1,5 +1,5 @@ /* -* 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 @@ -25,7 +25,7 @@ public: enum { - e_count = 8 + e_count = 8, }; Cantilever() @@ -35,8 +35,8 @@ public: b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } @@ -83,6 +83,7 @@ public: b2BodyDef bd; bd.type = b2_dynamicBody; bd.position.Set(-14.5f + 1.0f * i, 15.0f); + bd.inertiaScale = 10.0f; b2Body* body = m_world->CreateBody(&bd); body->CreateFixture(&fd); @@ -140,6 +141,7 @@ public: b2BodyDef bd; bd.type = b2_dynamicBody; bd.position.Set(5.5f + 1.0f * i, 10.0f); + bd.inertiaScale = 10.0f; b2Body* body = m_world->CreateBody(&bd); body->CreateFixture(&fd); diff --git a/libs/box2d/src/Tests/Car.h b/libs/box2d/src/Tests/Car.h deleted file mode 100644 index d86201e..0000000 --- a/libs/box2d/src/Tests/Car.h +++ /dev/null @@ -1,286 +0,0 @@ -/* -* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef CAR_H -#define CAR_H - -// This is a fun demo that shows off the wheel joint -class Car : public Test -{ -public: - Car() - { - m_hz = 4.0f; - m_zeta = 0.7f; - m_speed = 50.0f; - - b2Body* ground = NULL; - { - b2BodyDef bd; - ground = m_world->CreateBody(&bd); - - b2EdgeShape shape; - - b2FixtureDef fd; - fd.shape = &shape; - fd.density = 0.0f; - fd.friction = 0.6f; - - shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f)); - ground->CreateFixture(&fd); - - float32 hs[10] = {0.25f, 1.0f, 4.0f, 0.0f, 0.0f, -1.0f, -2.0f, -2.0f, -1.25f, 0.0f}; - - float32 x = 20.0f, y1 = 0.0f, dx = 5.0f; - - for (int32 i = 0; i < 10; ++i) - { - float32 y2 = hs[i]; - shape.Set(b2Vec2(x, y1), b2Vec2(x + dx, y2)); - ground->CreateFixture(&fd); - y1 = y2; - x += dx; - } - - for (int32 i = 0; i < 10; ++i) - { - float32 y2 = hs[i]; - shape.Set(b2Vec2(x, y1), b2Vec2(x + dx, y2)); - ground->CreateFixture(&fd); - y1 = y2; - x += dx; - } - - shape.Set(b2Vec2(x, 0.0f), b2Vec2(x + 40.0f, 0.0f)); - ground->CreateFixture(&fd); - - x += 80.0f; - shape.Set(b2Vec2(x, 0.0f), b2Vec2(x + 40.0f, 0.0f)); - ground->CreateFixture(&fd); - - x += 40.0f; - shape.Set(b2Vec2(x, 0.0f), b2Vec2(x + 10.0f, 5.0f)); - ground->CreateFixture(&fd); - - x += 20.0f; - shape.Set(b2Vec2(x, 0.0f), b2Vec2(x + 40.0f, 0.0f)); - ground->CreateFixture(&fd); - - x += 40.0f; - shape.Set(b2Vec2(x, 0.0f), b2Vec2(x, 20.0f)); - ground->CreateFixture(&fd); - } - - // Teeter - { - b2BodyDef bd; - bd.position.Set(140.0f, 1.0f); - bd.type = b2_dynamicBody; - b2Body* body = m_world->CreateBody(&bd); - - b2PolygonShape box; - box.SetAsBox(10.0f, 0.25f); - body->CreateFixture(&box, 1.0f); - - b2RevoluteJointDef jd; - jd.Initialize(ground, body, body->GetPosition()); - jd.lowerAngle = -8.0f * b2_pi / 180.0f; - jd.upperAngle = 8.0f * b2_pi / 180.0f; - jd.enableLimit = true; - m_world->CreateJoint(&jd); - - body->ApplyAngularImpulse(100.0f); - } - - // Bridge - { - int32 N = 20; - b2PolygonShape shape; - shape.SetAsBox(1.0f, 0.125f); - - b2FixtureDef fd; - fd.shape = &shape; - fd.density = 1.0f; - fd.friction = 0.6f; - - b2RevoluteJointDef jd; - - b2Body* prevBody = ground; - for (int32 i = 0; i < N; ++i) - { - b2BodyDef bd; - bd.type = b2_dynamicBody; - bd.position.Set(161.0f + 2.0f * i, -0.125f); - b2Body* body = m_world->CreateBody(&bd); - body->CreateFixture(&fd); - - b2Vec2 anchor(160.0f + 2.0f * i, -0.125f); - jd.Initialize(prevBody, body, anchor); - m_world->CreateJoint(&jd); - - prevBody = body; - } - - b2Vec2 anchor(160.0f + 2.0f * N, -0.125f); - jd.Initialize(prevBody, ground, anchor); - m_world->CreateJoint(&jd); - } - - // Boxes - { - b2PolygonShape box; - box.SetAsBox(0.5f, 0.5f); - - b2Body* body = NULL; - b2BodyDef bd; - bd.type = b2_dynamicBody; - - bd.position.Set(230.0f, 0.5f); - body = m_world->CreateBody(&bd); - body->CreateFixture(&box, 0.5f); - - bd.position.Set(230.0f, 1.5f); - body = m_world->CreateBody(&bd); - body->CreateFixture(&box, 0.5f); - - bd.position.Set(230.0f, 2.5f); - body = m_world->CreateBody(&bd); - body->CreateFixture(&box, 0.5f); - - bd.position.Set(230.0f, 3.5f); - body = m_world->CreateBody(&bd); - body->CreateFixture(&box, 0.5f); - - bd.position.Set(230.0f, 4.5f); - body = m_world->CreateBody(&bd); - body->CreateFixture(&box, 0.5f); - } - - // Car - { - b2PolygonShape chassis; - b2Vec2 vertices[8]; - vertices[0].Set(-1.5f, -0.5f); - vertices[1].Set(1.5f, -0.5f); - vertices[2].Set(1.5f, 0.0f); - vertices[3].Set(0.0f, 0.9f); - vertices[4].Set(-1.15f, 0.9f); - vertices[5].Set(-1.5f, 0.2f); - chassis.Set(vertices, 6); - - b2CircleShape circle; - circle.m_radius = 0.4f; - - b2BodyDef bd; - bd.type = b2_dynamicBody; - bd.position.Set(0.0f, 1.0f); - m_car = m_world->CreateBody(&bd); - m_car->CreateFixture(&chassis, 1.0f); - - b2FixtureDef fd; - fd.shape = &circle; - fd.density = 1.0f; - fd.friction = 0.9f; - - bd.position.Set(-1.0f, 0.35f); - m_wheel1 = m_world->CreateBody(&bd); - m_wheel1->CreateFixture(&fd); - - bd.position.Set(1.0f, 0.4f); - m_wheel2 = m_world->CreateBody(&bd); - m_wheel2->CreateFixture(&fd); - - b2WheelJointDef jd; - b2Vec2 axis(0.0f, 1.0f); - - jd.Initialize(m_car, m_wheel1, m_wheel1->GetPosition(), axis); - jd.motorSpeed = 0.0f; - jd.maxMotorTorque = 20.0f; - jd.enableMotor = true; - jd.frequencyHz = m_hz; - jd.dampingRatio = m_zeta; - m_spring1 = (b2WheelJoint*)m_world->CreateJoint(&jd); - - jd.Initialize(m_car, m_wheel2, m_wheel2->GetPosition(), axis); - jd.motorSpeed = 0.0f; - jd.maxMotorTorque = 10.0f; - jd.enableMotor = false; - jd.frequencyHz = m_hz; - jd.dampingRatio = m_zeta; - m_spring2 = (b2WheelJoint*)m_world->CreateJoint(&jd); - } - } - - void Keyboard(unsigned char key) - { - switch (key) - { - case 'a': - m_spring1->SetMotorSpeed(m_speed); - break; - - case 's': - m_spring1->SetMotorSpeed(0.0f); - break; - - case 'd': - m_spring1->SetMotorSpeed(-m_speed); - break; - - case 'q': - m_hz = b2Max(0.0f, m_hz - 1.0f); - m_spring1->SetSpringFrequencyHz(m_hz); - m_spring2->SetSpringFrequencyHz(m_hz); - break; - - case 'e': - m_hz += 1.0f; - m_spring1->SetSpringFrequencyHz(m_hz); - m_spring2->SetSpringFrequencyHz(m_hz); - break; - } - } - - void Step(Settings* settings) - { - m_debugDraw.DrawString(5, m_textLine, "Keys: left = a, brake = s, right = d, hz down = q, hz up = e"); - m_textLine += 15; - m_debugDraw.DrawString(5, m_textLine, "frequency = %g hz, damping ratio = %g", m_hz, m_zeta); - m_textLine += 15; - - settings->viewCenter.x = m_car->GetPosition().x; - Test::Step(settings); - } - - static Test* Create() - { - return new Car; - } - - b2Body* m_car; - b2Body* m_wheel1; - b2Body* m_wheel2; - - float32 m_hz; - float32 m_zeta; - float32 m_speed; - b2WheelJoint* m_spring1; - b2WheelJoint* m_spring2; -}; - -#endif diff --git a/libs/box2d/src/Tests/Chain.h b/libs/box2d/src/Tests/Chain.h index 33b8de9..ac21a7e 100644 --- a/libs/box2d/src/Tests/Chain.h +++ b/libs/box2d/src/Tests/Chain.h @@ -1,5 +1,5 @@ /* -* 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 @@ -29,8 +29,8 @@ public: b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/CharacterCollision.h b/libs/box2d/src/Tests/CharacterCollision.h index 389e930..79f603c 100644 --- a/libs/box2d/src/Tests/CharacterCollision.h +++ b/libs/box2d/src/Tests/CharacterCollision.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org +* Copyright (c) 2006-2010 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 @@ -32,30 +32,27 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } - // Collinear edges with no adjacency information. - // This shows the problematic case where a box shape can hit - // an internal vertex. + // Collinear edges { b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-8.0f, 1.0f), b2Vec2(-6.0f, 1.0f)); + b2PolygonShape shape; + shape.m_radius = 0.0f; + shape.SetAsEdge(b2Vec2(-8.0f, 1.0f), b2Vec2(-6.0f, 1.0f)); ground->CreateFixture(&shape, 0.0f); - shape.Set(b2Vec2(-6.0f, 1.0f), b2Vec2(-4.0f, 1.0f)); + shape.SetAsEdge(b2Vec2(-6.0f, 1.0f), b2Vec2(-4.0f, 1.0f)); ground->CreateFixture(&shape, 0.0f); - shape.Set(b2Vec2(-4.0f, 1.0f), b2Vec2(-2.0f, 1.0f)); + shape.SetAsEdge(b2Vec2(-4.0f, 1.0f), b2Vec2(-2.0f, 1.0f)); ground->CreateFixture(&shape, 0.0f); } - // Square tiles. This shows that adjacency shapes may - // have non-smooth collision. There is no solution - // to this problem. + // Square tiles { b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); @@ -69,47 +66,29 @@ public: ground->CreateFixture(&shape, 0.0f); } - // Square made from an edge loop. Collision should be smooth. + // Square made from edges notice how the edges are shrunk to account + // for the polygon radius. This makes it so the square character does + // not get snagged. However, ray casts can now go through the cracks. { b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2Vec2 vs[4]; - vs[0].Set(-1.0f, 3.0f); - vs[1].Set(1.0f, 3.0f); - vs[2].Set(1.0f, 5.0f); - vs[3].Set(-1.0f, 5.0f); - b2LoopShape shape; - shape.Create(vs, 4); + b2PolygonShape shape; + float32 d = 2.0f * b2_polygonRadius; + shape.SetAsEdge(b2Vec2(-1.0f + d, 3.0f), b2Vec2(1.0f - d, 3.0f)); ground->CreateFixture(&shape, 0.0f); - } - - // Edge loop. Collision should be smooth. - { - b2BodyDef bd; - bd.position.Set(-10.0f, 4.0f); - b2Body* ground = m_world->CreateBody(&bd); - - b2Vec2 vs[10]; - vs[0].Set(0.0f, 0.0f); - vs[1].Set(6.0f, 0.0f); - vs[2].Set(6.0f, 2.0f); - vs[3].Set(4.0f, 1.0f); - vs[4].Set(2.0f, 2.0f); - vs[5].Set(0.0f, 2.0f); - vs[6].Set(-2.0f, 2.0f); - vs[7].Set(-4.0f, 3.0f); - vs[8].Set(-6.0f, 2.0f); - vs[9].Set(-6.0f, 0.0f); - b2LoopShape shape; - shape.Create(vs, 10); + shape.SetAsEdge(b2Vec2(1.0f, 3.0f + d), b2Vec2(1.0f, 5.0f - d)); + ground->CreateFixture(&shape, 0.0f); + shape.SetAsEdge(b2Vec2(1.0f - d, 5.0f), b2Vec2(-1.0f + d, 5.0f)); + ground->CreateFixture(&shape, 0.0f); + shape.SetAsEdge(b2Vec2(-1.0f, 5.0f - d), b2Vec2(-1.0f, 3.0f + d)); ground->CreateFixture(&shape, 0.0f); } - // Square character 1 + // Square character { b2BodyDef bd; - bd.position.Set(-3.0f, 8.0f); + bd.position.Set(-3.0f, 5.0f); bd.type = b2_dynamicBody; bd.fixedRotation = true; bd.allowSleep = false; @@ -125,29 +104,10 @@ public: body->CreateFixture(&fd); } - // Square character 2 - { - b2BodyDef bd; - bd.position.Set(-5.0f, 5.0f); - bd.type = b2_dynamicBody; - bd.fixedRotation = true; - bd.allowSleep = false; - - b2Body* body = m_world->CreateBody(&bd); - - b2PolygonShape shape; - shape.SetAsBox(0.25f, 0.25f); - - b2FixtureDef fd; - fd.shape = &shape; - fd.density = 20.0f; - body->CreateFixture(&fd); - } - // Hexagon character { b2BodyDef bd; - bd.position.Set(-5.0f, 8.0f); + bd.position.Set(-5.0f, 5.0f); bd.type = b2_dynamicBody; bd.fixedRotation = true; bd.allowSleep = false; @@ -195,11 +155,7 @@ public: void Step(Settings* settings) { Test::Step(settings); - m_debugDraw.DrawString(5, m_textLine, "This tests various character collision shapes."); - m_textLine += 15; - m_debugDraw.DrawString(5, m_textLine, "Limitation: square and hexagon can snag on aligned boxes."); - m_textLine += 15; - m_debugDraw.DrawString(5, m_textLine, "Feature: loops have smooth collision inside and out."); + m_debugDraw.DrawString(5, m_textLine, "This tests various character collision shapes"); m_textLine += 15; } diff --git a/libs/box2d/src/Tests/CollisionFiltering.h b/libs/box2d/src/Tests/CollisionFiltering.h index 8f42a5f..8b90344 100644 --- a/libs/box2d/src/Tests/CollisionFiltering.h +++ b/libs/box2d/src/Tests/CollisionFiltering.h @@ -1,5 +1,5 @@ /* -* 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 @@ -44,8 +44,8 @@ public: { // Ground body { - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); b2FixtureDef sd; sd.shape = &shape; diff --git a/libs/box2d/src/Tests/CollisionProcessing.h b/libs/box2d/src/Tests/CollisionProcessing.h index c8cc328..23ee6c5 100644 --- a/libs/box2d/src/Tests/CollisionProcessing.h +++ b/libs/box2d/src/Tests/CollisionProcessing.h @@ -1,5 +1,5 @@ /* -* 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 @@ -30,8 +30,8 @@ public: { // Ground body { - b2EdgeShape shape; - shape.Set(b2Vec2(-50.0f, 0.0f), b2Vec2(50.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-50.0f, 0.0f), b2Vec2(50.0f, 0.0f)); b2FixtureDef sd; sd.shape = &shape;; diff --git a/libs/box2d/src/Tests/CompoundShapes.h b/libs/box2d/src/Tests/CompoundShapes.h index a5ca30e..375296e 100644 --- a/libs/box2d/src/Tests/CompoundShapes.h +++ b/libs/box2d/src/Tests/CompoundShapes.h @@ -1,5 +1,5 @@ /* -* 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 @@ -30,8 +30,8 @@ public: bd.position.Set(0.0f, 0.0f); b2Body* body = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(50.0f, 0.0f), b2Vec2(-50.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(50.0f, 0.0f), b2Vec2(-50.0f, 0.0f)); body->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/Confined.h b/libs/box2d/src/Tests/Confined.h index f2d205e..47d43f7 100644 --- a/libs/box2d/src/Tests/Confined.h +++ b/libs/box2d/src/Tests/Confined.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2009 Erin Catto http://www.box2d.org +* Copyright (c) 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 @@ -35,22 +35,22 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; + b2PolygonShape shape; // Floor - shape.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f)); + shape.SetAsEdge(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); // Left wall - shape.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(-10.0f, 20.0f)); + shape.SetAsEdge(b2Vec2(-10.0f, 0.0f), b2Vec2(-10.0f, 20.0f)); ground->CreateFixture(&shape, 0.0f); // Right wall - shape.Set(b2Vec2(10.0f, 0.0f), b2Vec2(10.0f, 20.0f)); + shape.SetAsEdge(b2Vec2(10.0f, 0.0f), b2Vec2(10.0f, 20.0f)); ground->CreateFixture(&shape, 0.0f); // Roof - shape.Set(b2Vec2(-10.0f, 20.0f), b2Vec2(10.0f, 20.0f)); + shape.SetAsEdge(b2Vec2(-10.0f, 20.0f), b2Vec2(10.0f, 20.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/ContinuousTest.h b/libs/box2d/src/Tests/ContinuousTest.h index c56b211..566ed7a 100644 --- a/libs/box2d/src/Tests/ContinuousTest.h +++ b/libs/box2d/src/Tests/ContinuousTest.h @@ -1,5 +1,5 @@ /* -* 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 @@ -30,12 +30,11 @@ public: bd.position.Set(0.0f, 0.0f); b2Body* body = m_world->CreateBody(&bd); - b2EdgeShape edge; + b2PolygonShape shape; - edge.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f)); - body->CreateFixture(&edge, 0.0f); + shape.SetAsEdge(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f)); + body->CreateFixture(&shape, 0.0f); - b2PolygonShape shape; shape.SetAsBox(0.2f, 1.0f, b2Vec2(0.5f, 1.0f), 0.0f); body->CreateFixture(&shape, 0.0f); } @@ -54,7 +53,7 @@ public: m_body->CreateFixture(&shape, 1.0f); m_angularVelocity = RandomFloat(-50.0f, 50.0f); - //m_angularVelocity = 46.661274f; + m_angularVelocity = 33.468121f; m_body->SetLinearVelocity(b2Vec2(0.0f, -100.0f)); m_body->SetAngularVelocity(m_angularVelocity); } @@ -62,7 +61,7 @@ public: { b2BodyDef bd; bd.type = b2_dynamicBody; - bd.position.Set(0.0f, 2.0f); + bd.position.Set(0.0f, 0.5f); b2Body* body = m_world->CreateBody(&bd); b2CircleShape shape; @@ -70,7 +69,7 @@ public: shape.m_radius = 0.5f; body->CreateFixture(&shape, 1.0f); - bd.bullet = true; + //bd.bullet = true; bd.position.Set(0.0f, 10.0f); body = m_world->CreateBody(&bd); body->CreateFixture(&shape, 1.0f); @@ -107,6 +106,7 @@ public: extern int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters; extern int32 b2_toiRootIters, b2_toiMaxRootIters; + extern int32 b2_toiMaxOptIters; if (b2_toiCalls > 0) { @@ -117,11 +117,14 @@ public: m_debugDraw.DrawString(5, m_textLine, "ave toi root iters = %3.1f, max toi root iters = %d", b2_toiRootIters / float32(b2_toiCalls), b2_toiMaxRootIters); m_textLine += 15; + + m_debugDraw.DrawString(5, m_textLine, "max toi opt iters = %d", b2_toiMaxOptIters); + m_textLine += 15; } if (m_stepCount % 60 == 0) { - //Launch(); + Launch(); } } diff --git a/libs/box2d/src/Tests/DistanceTest.h b/libs/box2d/src/Tests/DistanceTest.h index 795c023..1170312 100644 --- a/libs/box2d/src/Tests/DistanceTest.h +++ b/libs/box2d/src/Tests/DistanceTest.h @@ -1,5 +1,5 @@ /* -* 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 @@ -49,8 +49,8 @@ public: 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; diff --git a/libs/box2d/src/Tests/Dominos.h b/libs/box2d/src/Tests/Dominos.h index 01e8bbd..9dc22ce 100644 --- a/libs/box2d/src/Tests/Dominos.h +++ b/libs/box2d/src/Tests/Dominos.h @@ -1,5 +1,5 @@ /* -* 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 @@ -27,8 +27,8 @@ public: { b2Body* b1; { - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); b2BodyDef bd; b1 = m_world->CreateBody(&bd); diff --git a/libs/box2d/src/Tests/DynamicTreeTest.h b/libs/box2d/src/Tests/DynamicTreeTest.h index 4456a39..0402859 100644 --- a/libs/box2d/src/Tests/DynamicTreeTest.h +++ b/libs/box2d/src/Tests/DynamicTreeTest.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2009 Erin Catto http://www.box2d.org +* Copyright (c) 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 @@ -25,7 +25,7 @@ public: enum { - e_actorCount = 128 + e_actorCount = 128, }; DynamicTreeTest() @@ -126,12 +126,6 @@ public: m_debugDraw.DrawPoint(p, 6.0f, cr); } - { - int32 height = m_tree.GetHeight(); - m_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d", height); - m_textLine += 15; - } - ++m_stepCount; } diff --git a/libs/box2d/src/Tests/EdgeShapes.h b/libs/box2d/src/Tests/EdgeShapes.h index 56a6d62..01d3b53 100644 --- a/libs/box2d/src/Tests/EdgeShapes.h +++ b/libs/box2d/src/Tests/EdgeShapes.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org +* Copyright (c) 2006-2010 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 @@ -48,7 +48,7 @@ public: enum { - e_maxBodies = 256 + e_maxBodies = 256, }; EdgeShapes() @@ -65,8 +65,8 @@ public: float32 x2 = x1 + 0.5f; float32 y2 = 2.0f * cosf(x2 / 10.0f * b2_pi); - b2EdgeShape shape; - shape.Set(b2Vec2(x1, y1), b2Vec2(x2, y2)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(x1, y1), b2Vec2(x2, y2)); ground->CreateFixture(&shape, 0.0f); x1 = x2; @@ -92,8 +92,8 @@ public: { float32 w = 1.0f; - float32 b = w / (2.0f + b2Sqrt(2.0f)); - float32 s = b2Sqrt(2.0f) * b; + float32 b = w / (2.0f + sqrtf(2.0f)); + float32 s = sqrtf(2.0f) * b; b2Vec2 vertices[8]; vertices[0].Set(0.5f * s, 0.0f); diff --git a/libs/box2d/src/Tests/EdgeTest.h b/libs/box2d/src/Tests/EdgeTest.h deleted file mode 100644 index 2cabf2e..0000000 --- a/libs/box2d/src/Tests/EdgeTest.h +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef EDGE_TEST_H -#define EDGE_TEST_H - -class EdgeTest : public Test -{ -public: - - EdgeTest() - { - { - b2BodyDef bd; - b2Body* ground = m_world->CreateBody(&bd); - - b2Vec2 v1(-10.0f, 0.0f), v2(-7.0f, -2.0f), v3(-4.0f, 0.0f); - b2Vec2 v4(0.0f, 0.0f), v5(4.0f, 0.0f), v6(7.0f, 2.0f), v7(10.0f, 0.0f); - - b2EdgeShape shape; - - shape.Set(v1, v2); - shape.m_hasVertex3 = true; - shape.m_vertex3 = v3; - ground->CreateFixture(&shape, 0.0f); - - shape.Set(v2, v3); - shape.m_hasVertex0 = true; - shape.m_hasVertex3 = true; - shape.m_vertex0 = v1; - shape.m_vertex3 = v4; - ground->CreateFixture(&shape, 0.0f); - - shape.Set(v3, v4); - shape.m_hasVertex0 = true; - shape.m_hasVertex3 = true; - shape.m_vertex0 = v2; - shape.m_vertex3 = v5; - ground->CreateFixture(&shape, 0.0f); - - shape.Set(v4, v5); - shape.m_hasVertex0 = true; - shape.m_hasVertex3 = true; - shape.m_vertex0 = v3; - shape.m_vertex3 = v6; - ground->CreateFixture(&shape, 0.0f); - - shape.Set(v5, v6); - shape.m_hasVertex0 = true; - shape.m_hasVertex3 = true; - shape.m_vertex0 = v4; - shape.m_vertex3 = v7; - ground->CreateFixture(&shape, 0.0f); - - shape.Set(v6, v7); - shape.m_hasVertex0 = true; - shape.m_vertex0 = v5; - ground->CreateFixture(&shape, 0.0f); - } - - { - b2BodyDef bd; - bd.type = b2_dynamicBody; - bd.position.Set(-0.5f, 0.6f); - bd.allowSleep = false; - b2Body* body = m_world->CreateBody(&bd); - - b2CircleShape shape; - shape.m_radius = 0.5f; - - body->CreateFixture(&shape, 1.0f); - } - - { - b2BodyDef bd; - bd.type = b2_dynamicBody; - bd.position.Set(1.0f, 0.6f); - bd.allowSleep = false; - b2Body* body = m_world->CreateBody(&bd); - - b2PolygonShape shape; - shape.SetAsBox(0.5f, 0.5f); - - body->CreateFixture(&shape, 1.0f); - } - } - - static Test* Create() - { - return new EdgeTest; - } -}; - -#endif diff --git a/libs/box2d/src/Tests/Gears.h b/libs/box2d/src/Tests/Gears.h index 6d6ff99..e6bd627 100644 --- a/libs/box2d/src/Tests/Gears.h +++ b/libs/box2d/src/Tests/Gears.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2007-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 @@ -29,8 +29,8 @@ public: b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(50.0f, 0.0f), b2Vec2(-50.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(50.0f, 0.0f), b2Vec2(-50.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/OneSidedPlatform.h b/libs/box2d/src/Tests/OneSidedPlatform.h index 9d3c84e..ae7403d 100644 --- a/libs/box2d/src/Tests/OneSidedPlatform.h +++ b/libs/box2d/src/Tests/OneSidedPlatform.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2008-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2008-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 @@ -27,7 +27,7 @@ public: { e_unknown, e_above, - e_below + e_below, }; OneSidedPlatform() @@ -37,8 +37,8 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-20.0f, 0.0f), b2Vec2(20.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } @@ -86,7 +86,7 @@ public: return; } - if (fixtureB != m_platform && fixtureB != m_character) + if (fixtureB != m_character && fixtureB != m_character) { return; } diff --git a/libs/box2d/src/Tests/Pinball.h b/libs/box2d/src/Tests/Pinball.h deleted file mode 100644 index 76fadc7..0000000 --- a/libs/box2d/src/Tests/Pinball.h +++ /dev/null @@ -1,169 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef PINBALL_H -#define PINBALL_H - -/// This tests bullet collision and provides an example of a gameplay scenario. -/// This also uses a loop shape. -class Pinball : public Test -{ -public: - Pinball() - { - // Ground body - b2Body* ground = NULL; - { - b2BodyDef bd; - ground = m_world->CreateBody(&bd); - - b2Vec2 vs[5]; - vs[0].Set(0.0f, -2.0f); - vs[1].Set(8.0f, 6.0f); - vs[2].Set(8.0f, 20.0f); - vs[3].Set(-8.0f, 20.0f); - vs[4].Set(-8.0f, 6.0f); - - b2LoopShape loop; - loop.Create(vs, 5); - b2FixtureDef fd; - fd.shape = &loop; - fd.density = 0.0f; - ground->CreateFixture(&fd); - } - - // Flippers - { - b2Vec2 p1(-2.0f, 0.0f), p2(2.0f, 0.0f); - - b2BodyDef bd; - bd.type = b2_dynamicBody; - - bd.position = p1; - b2Body* leftFlipper = m_world->CreateBody(&bd); - - bd.position = p2; - b2Body* rightFlipper = m_world->CreateBody(&bd); - - b2PolygonShape box; - box.SetAsBox(1.75f, 0.1f); - - b2FixtureDef fd; - fd.shape = &box; - fd.density = 1.0f; - - leftFlipper->CreateFixture(&fd); - rightFlipper->CreateFixture(&fd); - - b2RevoluteJointDef jd; - jd.bodyA = ground; - jd.localAnchorB.SetZero(); - jd.enableMotor = true; - jd.maxMotorTorque = 1000.0f; - jd.enableLimit = true; - - jd.motorSpeed = 0.0f; - jd.localAnchorA = p1; - jd.bodyB = leftFlipper; - jd.lowerAngle = -30.0f * b2_pi / 180.0f; - jd.upperAngle = 5.0f * b2_pi / 180.0f; - m_leftJoint = (b2RevoluteJoint*)m_world->CreateJoint(&jd); - - jd.motorSpeed = 0.0f; - jd.localAnchorA = p2; - jd.bodyB = rightFlipper; - jd.lowerAngle = -5.0f * b2_pi / 180.0f; - jd.upperAngle = 30.0f * b2_pi / 180.0f; - m_rightJoint = (b2RevoluteJoint*)m_world->CreateJoint(&jd); - } - - // Circle character - { - b2BodyDef bd; - bd.position.Set(1.0f, 15.0f); - bd.type = b2_dynamicBody; - bd.bullet = true; - - m_ball = m_world->CreateBody(&bd); - - b2CircleShape shape; - shape.m_radius = 0.2f; - - b2FixtureDef fd; - fd.shape = &shape; - fd.density = 1.0f; - m_ball->CreateFixture(&fd); - } - - m_button = false; - } - - void Step(Settings* settings) - { - if (m_button) - { - m_leftJoint->SetMotorSpeed(20.0f); - m_rightJoint->SetMotorSpeed(-20.0f); - } - else - { - m_leftJoint->SetMotorSpeed(-10.0f); - m_rightJoint->SetMotorSpeed(10.0f); - } - - Test::Step(settings); - - m_debugDraw.DrawString(5, m_textLine, "Press 'a' to control the flippers"); - m_textLine += 15; - - } - - void Keyboard(unsigned char key) - { - switch (key) - { - case 'a': - case 'A': - m_button = true; - break; - } - } - - void KeyboardUp(unsigned char key) - { - switch (key) - { - case 'a': - case 'A': - m_button = false; - break; - } - } - - static Test* Create() - { - return new Pinball; - } - - b2RevoluteJoint* m_leftJoint; - b2RevoluteJoint* m_rightJoint; - b2Body* m_ball; - bool m_button; -}; - -#endif diff --git a/libs/box2d/src/Tests/PolyCollision.h b/libs/box2d/src/Tests/PolyCollision.h index 43ede33..70daf51 100644 --- a/libs/box2d/src/Tests/PolyCollision.h +++ b/libs/box2d/src/Tests/PolyCollision.h @@ -1,5 +1,5 @@ /* -* 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 @@ -25,7 +25,7 @@ public: PolyCollision() { { - m_polygonA.SetAsBox(0.2f, 0.4f); + m_polygonA.SetAsEdge(b2Vec2(20.0f, 0.0f), b2Vec2(20.0f, 20.0f)); m_transformA.Set(b2Vec2(0.0f, 0.0f), 0.0f); } diff --git a/libs/box2d/src/Tests/PolyShapes.h b/libs/box2d/src/Tests/PolyShapes.h index a586a79..fbc84db 100644 --- a/libs/box2d/src/Tests/PolyShapes.h +++ b/libs/box2d/src/Tests/PolyShapes.h @@ -1,5 +1,5 @@ /* -* 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 @@ -89,7 +89,7 @@ public: b2Body* body = fixture->GetBody(); b2Shape* shape = fixture->GetShape(); - bool overlap = b2TestOverlap(shape, 0, &m_circle, 0, body->GetTransform(), m_transform); + bool overlap = b2TestOverlap(shape, &m_circle, body->GetTransform(), m_transform); if (overlap) { @@ -102,7 +102,7 @@ public: b2CircleShape m_circle; b2Transform m_transform; - b2Draw* m_debugDraw; + b2DebugDraw* m_debugDraw; int32 m_count; }; @@ -116,8 +116,8 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } @@ -139,8 +139,8 @@ public: { float32 w = 1.0f; - float32 b = w / (2.0f + b2Sqrt(2.0f)); - float32 s = b2Sqrt(2.0f) * b; + float32 b = w / (2.0f + sqrtf(2.0f)); + float32 s = sqrtf(2.0f) * b; b2Vec2 vertices[8]; vertices[0].Set(0.5f * s, 0.0f); @@ -263,7 +263,7 @@ public: callback.m_debugDraw = &m_debugDraw; b2AABB aabb; - callback.m_circle.ComputeAABB(&aabb, callback.m_transform, 0); + callback.m_circle.ComputeAABB(&aabb, callback.m_transform); m_world->QueryAABB(&callback, aabb); diff --git a/libs/box2d/src/Tests/Prismatic.h b/libs/box2d/src/Tests/Prismatic.h index 468ba08..1d01000 100644 --- a/libs/box2d/src/Tests/Prismatic.h +++ b/libs/box2d/src/Tests/Prismatic.h @@ -1,5 +1,5 @@ /* -* 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 @@ -29,8 +29,8 @@ public: b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } @@ -90,7 +90,7 @@ public: Test::Step(settings); m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (m) motors, (s) speed"); m_textLine += 15; - float32 force = m_joint->GetMotorForce(settings->hz); + float32 force = m_joint->GetMotorForce(); m_debugDraw.DrawString(5, m_textLine, "Motor Force = %4.0f", (float) force); m_textLine += 15; } diff --git a/libs/box2d/src/Tests/Pulleys.h b/libs/box2d/src/Tests/Pulleys.h index 1f63810..0e2a41c 100644 --- a/libs/box2d/src/Tests/Pulleys.h +++ b/libs/box2d/src/Tests/Pulleys.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2007-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 @@ -24,31 +24,21 @@ class Pulleys : public Test public: Pulleys() { - float32 y = 16.0f; - float32 L = 12.0f; - float32 a = 1.0f; - float32 b = 2.0f; - b2Body* ground = NULL; { b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape edge; - edge.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); - //ground->CreateFixture(&shape, 0.0f); - - b2CircleShape circle; - circle.m_radius = 2.0f; - - circle.m_p.Set(-10.0f, y + b + L); - ground->CreateFixture(&circle, 0.0f); - - circle.m_p.Set(10.0f, y + b + L); - ground->CreateFixture(&circle, 0.0f); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + ground->CreateFixture(&shape, 0.0f); } { + float32 a = 2.0f; + float32 b = 4.0f; + float32 y = 16.0f; + float32 L = 12.0f; b2PolygonShape shape; shape.SetAsBox(a, b); @@ -56,7 +46,6 @@ public: b2BodyDef bd; bd.type = b2_dynamicBody; - //bd.fixedRotation = true; bd.position.Set(-10.0f, y); b2Body* body1 = m_world->CreateBody(&bd); body1->CreateFixture(&shape, 5.0f); @@ -70,7 +59,7 @@ public: b2Vec2 anchor2(10.0f, y + b); b2Vec2 groundAnchor1(-10.0f, y + b + L); b2Vec2 groundAnchor2(10.0f, y + b + L); - pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 1.5f); + pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 2.0f); m_joint1 = (b2PulleyJoint*)m_world->CreateJoint(&pulleyDef); } diff --git a/libs/box2d/src/Tests/Pyramid.h b/libs/box2d/src/Tests/Pyramid.h index ac3cd46..7c1cdd3 100644 --- a/libs/box2d/src/Tests/Pyramid.h +++ b/libs/box2d/src/Tests/Pyramid.h @@ -1,5 +1,5 @@ /* -* 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 @@ -24,7 +24,7 @@ class Pyramid : public Test public: enum { - e_count = 20 + e_count = 20, }; Pyramid() @@ -33,8 +33,8 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } @@ -68,17 +68,17 @@ public: } } - void Step(Settings* settings) - { - Test::Step(settings); - - //b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree; - - //if (m_stepCount == 400) - //{ - // tree->RebuildBottomUp(); - //} - } + //void Step(Settings* settings) + //{ + // // We need higher accuracy for the pyramid. + // int32 velocityIterations = settings->velocityIterations; + // int32 positionIterations = settings->positionIterations; + // settings->velocityIterations = b2Max(8, velocityIterations); + // settings->positionIterations = b2Max(1, positionIterations); + // Test::Step(settings); + // settings->velocityIterations = velocityIterations; + // settings->positionIterations = positionIterations; + //} static Test* Create() { diff --git a/libs/box2d/src/Tests/RayCast.h b/libs/box2d/src/Tests/RayCast.h index 7c0c788..e3ff624 100644 --- a/libs/box2d/src/Tests/RayCast.h +++ b/libs/box2d/src/Tests/RayCast.h @@ -1,5 +1,5 @@ /* -* 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 @@ -149,7 +149,7 @@ public: enum { - e_maxBodies = 256 + e_maxBodies = 256, }; enum Mode @@ -166,8 +166,8 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } @@ -189,8 +189,8 @@ public: { float32 w = 1.0f; - float32 b = w / (2.0f + b2Sqrt(2.0f)); - float32 s = b2Sqrt(2.0f) * b; + float32 b = w / (2.0f + sqrtf(2.0f)); + float32 s = sqrtf(2.0f) * b; b2Vec2 vertices[8]; vertices[0].Set(0.5f * s, 0.0f); diff --git a/libs/box2d/src/Tests/Revolute.h b/libs/box2d/src/Tests/Revolute.h index 86ac28a..050b6f7 100644 --- a/libs/box2d/src/Tests/Revolute.h +++ b/libs/box2d/src/Tests/Revolute.h @@ -1,5 +1,5 @@ /* -* 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 @@ -29,14 +29,9 @@ public: b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); - - b2FixtureDef fd; - fd.shape = &shape; - //fd.filter.categoryBits = 2; - - ground->CreateFixture(&fd); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + ground->CreateFixture(&shape, 0.0f); } { @@ -48,7 +43,7 @@ public: b2RevoluteJointDef rjd; - bd.position.Set(-10.0f, 20.0f); + bd.position.Set(0.0f, 20.0f); b2Body* body = m_world->CreateBody(&bd); body->CreateFixture(&shape, 5.0f); @@ -56,7 +51,7 @@ public: body->SetAngularVelocity(w); body->SetLinearVelocity(b2Vec2(-8.0f * w, 0.0f)); - rjd.Initialize(ground, body, b2Vec2(-10.0f, 12.0f)); + rjd.Initialize(ground, body, b2Vec2(0.0f, 12.0f)); rjd.motorSpeed = 1.0f * b2_pi; rjd.maxMotorTorque = 10000.0f; rjd.enableMotor = false; @@ -67,61 +62,6 @@ public: m_joint = (b2RevoluteJoint*)m_world->CreateJoint(&rjd); } - - { - b2CircleShape circle_shape; - circle_shape.m_radius = 3.0f; - - b2BodyDef circle_bd; - circle_bd.type = b2_dynamicBody; - circle_bd.position.Set(5.0f, 30.0f); - - b2FixtureDef fd; - fd.density = 5.0f; - fd.filter.maskBits = 1; - fd.shape = &circle_shape; - - m_ball = m_world->CreateBody(&circle_bd); - m_ball->CreateFixture(&fd); - - b2PolygonShape polygon_shape; - polygon_shape.SetAsBox(10.0f, 0.2f, b2Vec2 (-10.0f, 0.0f), 0.0f); - - b2BodyDef polygon_bd; - polygon_bd.position.Set(20.0f, 10.0f); - polygon_bd.type = b2_dynamicBody; - polygon_bd.bullet = true; - b2Body* polygon_body = m_world->CreateBody(&polygon_bd); - polygon_body->CreateFixture(&polygon_shape, 2.0f); - - b2RevoluteJointDef rjd; - rjd.Initialize(ground, polygon_body, b2Vec2(20.0f, 10.0f)); - rjd.lowerAngle = -0.25f * b2_pi; - rjd.upperAngle = 0.0f * b2_pi; - rjd.enableLimit = true; - m_world->CreateJoint(&rjd); - } - - // Tests mass computation of a small object far from the origin - { - b2BodyDef bodyDef; - bodyDef.type = b2_dynamicBody; - b2Body* body = m_world->CreateBody(&bodyDef); - - b2PolygonShape polyShape; - b2Vec2 verts[3]; - verts[0].Set( 17.63f, 36.31f ); - verts[1].Set( 17.52f, 36.69f ); - verts[2].Set( 17.19f, 36.36f ); - polyShape.Set(verts, 3); - - b2FixtureDef polyFixtureDef; - polyFixtureDef.shape = &polyShape; - polyFixtureDef.density = 1; - - body->CreateFixture(&polyFixtureDef); //assertion hits inside here - } - } void Keyboard(unsigned char key) @@ -129,11 +69,11 @@ public: switch (key) { case 'l': - m_joint->EnableLimit(!m_joint->IsLimitEnabled()); + m_joint->EnableLimit(m_joint->IsLimitEnabled()); break; - case 'm': - m_joint->EnableMotor(!m_joint->IsMotorEnabled()); + case 's': + m_joint->EnableMotor(false); break; } } @@ -141,14 +81,8 @@ public: void Step(Settings* settings) { Test::Step(settings); - m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (m) motor"); + m_debugDraw.DrawString(5, m_textLine, "Keys: (l) limits, (a) left, (s) off, (d) right"); m_textLine += 15; - - //if (m_stepCount == 360) - //{ - // m_ball->SetTransform(b2Vec2(0.0f, 0.5f), 0.0f); - //} - //float32 torque1 = m_joint1->GetMotorTorque(); //m_debugDraw.DrawString(5, m_textLine, "Motor Torque = %4.0f, %4.0f : Motor Force = %4.0f", (float) torque1, (float) torque2, (float) force3); //m_textLine += 15; @@ -159,7 +93,6 @@ public: return new Revolute; } - b2Body* m_ball; b2RevoluteJoint* m_joint; }; diff --git a/libs/box2d/src/Tests/Rope.h b/libs/box2d/src/Tests/Rope.h deleted file mode 100644 index 38ff81d..0000000 --- a/libs/box2d/src/Tests/Rope.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -* Copyright (c) 2011 Erin Catto http://box2d.org -* -* 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. -*/ - -#ifndef ROPE_H -#define ROPE_H - -/// -class Rope : public Test -{ -public: - Rope() - { - const int32 N = 40; - b2Vec2 vertices[N]; - float32 masses[N]; - - for (int32 i = 0; i < N; ++i) - { - vertices[i].Set(0.0f, 20.0f - 0.25f * i); - masses[i] = 1.0f; - } - masses[0] = 0.0f; - masses[1] = 0.0f; - - b2RopeDef def; - def.vertices = vertices; - def.count = N; - def.gravity.Set(0.0f, -10.0f); - def.masses = masses; - def.damping = 0.1f; - def.k2 = 1.0f; - def.k3 = 0.5f; - - m_rope.Initialize(&def); - - m_angle = 0.0f; - m_rope.SetAngle(m_angle); - } - - void Keyboard(unsigned char key) - { - switch (key) - { - case 'q': - m_angle = b2Max(-b2_pi, m_angle - 0.05f * b2_pi); - m_rope.SetAngle(m_angle); - break; - - case 'e': - m_angle = b2Min(b2_pi, m_angle + 0.05f * b2_pi); - m_rope.SetAngle(m_angle); - break; - } - } - - void Step(Settings* settings) - { - float32 dt = settings->hz > 0.0f ? 1.0f / settings->hz : 0.0f; - - if (settings->pause == 1 && settings->singleStep == 0) - { - dt = 0.0f; - } - - m_rope.Step(dt, 1); - - Test::Step(settings); - - m_rope.Draw(&m_debugDraw); - - m_debugDraw.DrawString(5, m_textLine, "Press (q,e) to adjust target angle"); - m_textLine += 15; - m_debugDraw.DrawString(5, m_textLine, "Target angle = %g degrees", m_angle * 180.0f / b2_pi); - m_textLine += 15; - } - - static Test* Create() - { - return new Rope; - } - - b2Rope m_rope; - float32 m_angle; -}; - -#endif diff --git a/libs/box2d/src/Tests/RopeJoint.h b/libs/box2d/src/Tests/RopeJoint.h deleted file mode 100644 index 038dede..0000000 --- a/libs/box2d/src/Tests/RopeJoint.h +++ /dev/null @@ -1,145 +0,0 @@ -/* -* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef ROPE_JOINT_H -#define ROPE_JOINT_H - -/// This test shows how a rope joint can be used to stabilize a chain of -/// bodies with a heavy payload. Notice that the rope joint just prevents -/// excessive stretching and has no other effect. -/// By disabling the rope joint you can see that the Box2D solver has trouble -/// supporting heavy bodies with light bodies. Try playing around with the -/// densities, time step, and iterations to see how they affect stability. -/// This test also shows how to use contact filtering. Filtering is configured -/// so that the payload does not collide with the chain. -class RopeJoint : public Test -{ -public: - RopeJoint() - { - b2Body* ground = NULL; - { - b2BodyDef bd; - ground = m_world->CreateBody(&bd); - - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); - ground->CreateFixture(&shape, 0.0f); - } - - { - b2PolygonShape shape; - shape.SetAsBox(0.5f, 0.125f); - - b2FixtureDef fd; - fd.shape = &shape; - fd.density = 20.0f; - fd.friction = 0.2f; - fd.filter.categoryBits = 0x0001; - fd.filter.maskBits = 0xFFFF & ~0x0002; - - b2RevoluteJointDef jd; - jd.collideConnected = false; - - const int32 N = 10; - const float32 y = 15.0f; - m_ropeDef.localAnchorA.Set(0.0f, y); - - b2Body* prevBody = ground; - for (int32 i = 0; i < N; ++i) - { - b2BodyDef bd; - bd.type = b2_dynamicBody; - bd.position.Set(0.5f + 1.0f * i, y); - if (i == N - 1) - { - shape.SetAsBox(1.5f, 1.5f); - fd.density = 100.0f; - fd.filter.categoryBits = 0x0002; - bd.position.Set(1.0f * i, y); - bd.angularDamping = 0.4f; - } - - b2Body* body = m_world->CreateBody(&bd); - - body->CreateFixture(&fd); - - b2Vec2 anchor(float32(i), y); - jd.Initialize(prevBody, body, anchor); - m_world->CreateJoint(&jd); - - prevBody = body; - } - - m_ropeDef.localAnchorB.SetZero(); - - float32 extraLength = 0.01f; - m_ropeDef.maxLength = N - 1.0f + extraLength; - m_ropeDef.bodyB = prevBody; - } - - { - m_ropeDef.bodyA = ground; - m_rope = m_world->CreateJoint(&m_ropeDef); - } - } - - void Keyboard(unsigned char key) - { - switch (key) - { - case 'j': - if (m_rope) - { - m_world->DestroyJoint(m_rope); - m_rope = NULL; - } - else - { - m_rope = m_world->CreateJoint(&m_ropeDef); - } - break; - } - } - - void Step(Settings* settings) - { - Test::Step(settings); - m_debugDraw.DrawString(5, m_textLine, "Press (j) to toggle the rope joint."); - m_textLine += 15; - if (m_rope) - { - m_debugDraw.DrawString(5, m_textLine, "Rope ON"); - } - else - { - m_debugDraw.DrawString(5, m_textLine, "Rope OFF"); - } - m_textLine += 15; - } - - static Test* Create() - { - return new RopeJoint; - } - - b2RopeJointDef m_ropeDef; - b2Joint* m_rope; -}; - -#endif diff --git a/libs/box2d/src/Tests/SensorTest.h b/libs/box2d/src/Tests/SensorTest.h index a268041..787a25d 100644 --- a/libs/box2d/src/Tests/SensorTest.h +++ b/libs/box2d/src/Tests/SensorTest.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2008-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2008-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 @@ -36,8 +36,8 @@ public: b2Body* ground = m_world->CreateBody(&bd); { - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/ShapeEditing.h b/libs/box2d/src/Tests/ShapeEditing.h index 94cbcc5..2e6cbe1 100644 --- a/libs/box2d/src/Tests/ShapeEditing.h +++ b/libs/box2d/src/Tests/ShapeEditing.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2008-2009 Erin Catto http://www.box2d.org +* Copyright (c) 2008-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 @@ -29,8 +29,8 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/SliderCrank.h b/libs/box2d/src/Tests/SliderCrank.h index 52e6e9c..883bd83 100644 --- a/libs/box2d/src/Tests/SliderCrank.h +++ b/libs/box2d/src/Tests/SliderCrank.h @@ -1,5 +1,5 @@ /* -* 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 @@ -31,8 +31,8 @@ public: b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } @@ -86,7 +86,6 @@ public: b2BodyDef bd; bd.type = b2_dynamicBody; - bd.fixedRotation = true; bd.position.Set(0.0f, 17.0f); b2Body* body = m_world->CreateBody(&bd); body->CreateFixture(&shape, 2.0f); @@ -139,7 +138,7 @@ public: Test::Step(settings); m_debugDraw.DrawString(5, m_textLine, "Keys: (f) toggle friction, (m) toggle motor"); m_textLine += 15; - float32 torque = m_joint1->GetMotorTorque(settings->hz); + float32 torque = m_joint1->GetMotorTorque(); m_debugDraw.DrawString(5, m_textLine, "Motor Torque = %5.0f", (float) torque); m_textLine += 15; } diff --git a/libs/box2d/src/Tests/SphereStack.h b/libs/box2d/src/Tests/SphereStack.h index 22485c6..fed7ba9 100644 --- a/libs/box2d/src/Tests/SphereStack.h +++ b/libs/box2d/src/Tests/SphereStack.h @@ -1,5 +1,5 @@ /* -* 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 @@ -34,8 +34,8 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } @@ -53,7 +53,7 @@ public: m_bodies[i]->CreateFixture(&shape, 1.0f); - m_bodies[i]->SetLinearVelocity(b2Vec2(0.0f, -50.0f)); + //m_bodies[i]->SetLinearVelocity(b2Vec2(0.0f, -100.0f)); } } } diff --git a/libs/box2d/src/Tests/TheoJansen.h b/libs/box2d/src/Tests/TheoJansen.h index 6fb808b..fec1429 100644 --- a/libs/box2d/src/Tests/TheoJansen.h +++ b/libs/box2d/src/Tests/TheoJansen.h @@ -1,5 +1,5 @@ /* -* 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 @@ -128,14 +128,14 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-50.0f, 0.0f), b2Vec2(50.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-50.0f, 0.0f), b2Vec2(50.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); - shape.Set(b2Vec2(-50.0f, 0.0f), b2Vec2(-50.0f, 10.0f)); + shape.SetAsEdge(b2Vec2(-50.0f, 0.0f), b2Vec2(-50.0f, 10.0f)); ground->CreateFixture(&shape, 0.0f); - shape.Set(b2Vec2(50.0f, 0.0f), b2Vec2(50.0f, 10.0f)); + shape.SetAsEdge(b2Vec2(50.0f, 0.0f), b2Vec2(50.0f, 10.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/Tiles.h b/libs/box2d/src/Tests/Tiles.h deleted file mode 100644 index 05b9e11..0000000 --- a/libs/box2d/src/Tests/Tiles.h +++ /dev/null @@ -1,146 +0,0 @@ -/* -* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org -* -* 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. -*/ - -#ifndef TILES_H -#define TILES_H - -/// This stress tests the dynamic tree broad-phase. This also shows that tile -/// based collision is _not_ smooth due to Box2D not knowing about adjacency. -class Tiles : public Test -{ -public: - enum - { - e_count = 20 - }; - - Tiles() - { - m_fixtureCount = 0; - b2Timer timer; - - { - float32 a = 0.5f; - b2BodyDef bd; - bd.position.y = -a; - b2Body* ground = m_world->CreateBody(&bd); - -#if 1 - int32 N = 200; - int32 M = 10; - b2Vec2 position; - position.y = 0.0f; - for (int32 j = 0; j < M; ++j) - { - position.x = -N * a; - for (int32 i = 0; i < N; ++i) - { - b2PolygonShape shape; - shape.SetAsBox(a, a, position, 0.0f); - ground->CreateFixture(&shape, 0.0f); - ++m_fixtureCount; - position.x += 2.0f * a; - } - position.y -= 2.0f * a; - } -#else - int32 N = 200; - int32 M = 10; - b2Vec2 position; - position.x = -N * a; - for (int32 i = 0; i < N; ++i) - { - position.y = 0.0f; - for (int32 j = 0; j < M; ++j) - { - b2PolygonShape shape; - shape.SetAsBox(a, a, position, 0.0f); - ground->CreateFixture(&shape, 0.0f); - position.y -= 2.0f * a; - } - position.x += 2.0f * a; - } -#endif - } - - { - float32 a = 0.5f; - b2PolygonShape shape; - shape.SetAsBox(a, a); - - b2Vec2 x(-7.0f, 0.75f); - b2Vec2 y; - b2Vec2 deltaX(0.5625f, 1.25f); - b2Vec2 deltaY(1.125f, 0.0f); - - for (int32 i = 0; i < e_count; ++i) - { - y = x; - - for (int32 j = i; j < e_count; ++j) - { - b2BodyDef bd; - bd.type = b2_dynamicBody; - bd.position = y; - b2Body* body = m_world->CreateBody(&bd); - body->CreateFixture(&shape, 5.0f); - ++m_fixtureCount; - y += deltaY; - } - - x += deltaX; - } - } - - m_createTime = timer.GetMilliseconds(); - } - - void Step(Settings* settings) - { - const b2ContactManager& cm = m_world->GetContactManager(); - int32 height = cm.m_broadPhase.GetTreeHeight(); - int32 leafCount = cm.m_broadPhase.GetProxyCount(); - int32 minimumNodeCount = 2 * leafCount - 1; - float32 minimumHeight = ceilf(logf(float32(minimumNodeCount)) / logf(2.0f)); - m_debugDraw.DrawString(5, m_textLine, "dynamic tree height = %d, min = %d", height, int32(minimumHeight)); - m_textLine += 15; - - Test::Step(settings); - - m_debugDraw.DrawString(5, m_textLine, "create time = %6.2f ms, fixture count = %d", - m_createTime, m_fixtureCount); - m_textLine += 15; - - //b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree; - - //if (m_stepCount == 400) - //{ - // tree->RebuildBottomUp(); - //} - } - - static Test* Create() - { - return new Tiles; - } - - int32 m_fixtureCount; - float32 m_createTime; -}; - -#endif diff --git a/libs/box2d/src/Tests/TimeOfImpact.h b/libs/box2d/src/Tests/TimeOfImpact.h index f836e0e..957d5ed 100644 --- a/libs/box2d/src/Tests/TimeOfImpact.h +++ b/libs/box2d/src/Tests/TimeOfImpact.h @@ -1,5 +1,5 @@ /* -* 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 @@ -55,8 +55,8 @@ public: //sweepB.a -= 300.0f * b2_pi; b2TOIInput input; - input.proxyA.Set(&m_shapeA, 0); - input.proxyB.Set(&m_shapeB, 0); + input.proxyA.Set(&m_shapeA); + input.proxyB.Set(&m_shapeB); input.sweepA = sweepA; input.sweepB = sweepB; input.tMax = 1.0f; diff --git a/libs/box2d/src/Tests/VaryingFriction.h b/libs/box2d/src/Tests/VaryingFriction.h index a28354a..2ca215d 100644 --- a/libs/box2d/src/Tests/VaryingFriction.h +++ b/libs/box2d/src/Tests/VaryingFriction.h @@ -1,5 +1,5 @@ /* -* 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 @@ -29,8 +29,8 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/VaryingRestitution.h b/libs/box2d/src/Tests/VaryingRestitution.h index 8a1bed6..cb92965 100644 --- a/libs/box2d/src/Tests/VaryingRestitution.h +++ b/libs/box2d/src/Tests/VaryingRestitution.h @@ -1,5 +1,5 @@ /* -* 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 @@ -19,8 +19,6 @@ #ifndef VARYING_RESTITUTION_H #define VARYING_RESTITUTION_H -// Note: even with a restitution of 1.0, there is some energy change -// due to position correction. class VaryingRestitution : public Test { public: @@ -31,8 +29,8 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/VerticalStack.h b/libs/box2d/src/Tests/VerticalStack.h index 7d545e2..45d8738 100644 --- a/libs/box2d/src/Tests/VerticalStack.h +++ b/libs/box2d/src/Tests/VerticalStack.h @@ -1,5 +1,5 @@ /* -* 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 @@ -37,11 +37,11 @@ public: b2BodyDef bd; b2Body* ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); - shape.Set(b2Vec2(20.0f, 0.0f), b2Vec2(20.0f, 20.0f)); + shape.SetAsEdge(b2Vec2(20.0f, 0.0f), b2Vec2(20.0f, 20.0f)); ground->CreateFixture(&shape, 0.0f); } diff --git a/libs/box2d/src/Tests/Web.h b/libs/box2d/src/Tests/Web.h index 9ed279e..6af3b74 100644 --- a/libs/box2d/src/Tests/Web.h +++ b/libs/box2d/src/Tests/Web.h @@ -1,5 +1,5 @@ /* -* 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 @@ -30,8 +30,8 @@ public: b2BodyDef bd; ground = m_world->CreateBody(&bd); - b2EdgeShape shape; - shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); + b2PolygonShape shape; + shape.SetAsEdge(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); ground->CreateFixture(&shape, 0.0f); } @@ -61,8 +61,8 @@ public: b2DistanceJointDef jd; b2Vec2 p1, p2, d; - jd.frequencyHz = 2.0f; - jd.dampingRatio = 0.0f; + jd.frequencyHz = 4.0f; + jd.dampingRatio = 0.5f; jd.bodyA = ground; jd.bodyB = m_bodies[0];