├── .gitattributes
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ ├── generic-build.yml
│ └── nuget-release.yml
├── .gitignore
├── LICENSE.txt
├── MONOGAME LICENSE.txt
├── README.md
└── src
├── Directory.Build.props
├── Global.ruleset
├── VelcroPhysics.All.sln
├── VelcroPhysics.Benchmarks
├── Code
│ ├── DummyStopWatch.cs
│ ├── MeasuredBenchmark.cs
│ ├── TestClasses
│ │ ├── Class32.cs
│ │ ├── Class64.cs
│ │ ├── Class8.cs
│ │ ├── Dummy.cs
│ │ ├── PoolObject.cs
│ │ ├── Struct32.cs
│ │ ├── Struct64.cs
│ │ └── Struct8.cs
│ └── UnmeasuredBenchmark.cs
├── Program.cs
├── Tests
│ ├── CLR
│ │ ├── ClassBenchmarks.cs
│ │ ├── FieldPropertyBenchmarks.cs
│ │ └── StopWatchBenchmark.cs
│ ├── Collision
│ │ ├── BroadphaseBenchmark.cs
│ │ ├── DistanceBenchmark.cs
│ │ └── TOIBenchmark.cs
│ ├── Primitives
│ │ ├── AabbBenchmark.cs
│ │ └── Vector2Benchmark.cs
│ └── Shared
│ │ ├── GraphBenchmark.cs
│ │ └── PoolBenchmarks.cs
├── Utilities
│ └── RandomExtensions.cs
└── VelcroPhysics.Benchmarks.csproj
├── VelcroPhysics.MonoGame.ContentPipelines.SVGImport
├── Objects
│ ├── PathDefinition.cs
│ ├── VerticesContainer.cs
│ └── VerticesExt.cs
├── PathContainerProcessor.cs
├── SVGImporter.cs
├── SVGPathParser.cs
├── VelcroPhysics.MonoGame.Content.SVGImport.csproj
├── VerticesContainerReader.cs
└── VerticesContainerWriter.cs
├── VelcroPhysics.MonoGame.ContentPipelines.TextureToVertices
├── TextureToVerticesProcessor.cs
└── VelcroPhysics.MonoGame.Content.TextureToVertices.csproj
├── VelcroPhysics.MonoGame.DebugView
├── Content
│ └── Font.xnb
├── DebugView.cs
├── PrimitiveBatch.cs
└── VelcroPhysics.MonoGame.DebugView.csproj
├── VelcroPhysics.MonoGame.Samples.Demo
├── Content
│ ├── Common
│ │ ├── Buttons.png
│ │ ├── Checkmark.png
│ │ ├── Cursor.png
│ │ └── SamplesLogo.png
│ ├── Content.mgcb
│ ├── DemoGFX
│ │ ├── Car.png
│ │ ├── Club.png
│ │ ├── Cookie.png
│ │ ├── Diamond.png
│ │ ├── Goo.png
│ │ ├── Heart.png
│ │ ├── Link.png
│ │ ├── Spade.png
│ │ ├── Wheel.png
│ │ └── cookie_orig.png
│ ├── DemoSFX
│ │ └── Click.wav
│ ├── Fonts
│ │ ├── DetailsFont.spritefont
│ │ ├── MenuFont.spritefont
│ │ └── Roboto-Regular.ttf
│ ├── Materials
│ │ ├── Square.png
│ │ └── Stripe.png
│ └── Pipeline
│ │ ├── Body.svg
│ │ └── BreakableBody.svg
├── Demos
│ ├── D01_SingleFixture.cs
│ ├── D02_MultipleFixtures.cs
│ ├── D03_StaticBodies.cs
│ ├── D04_StackedBodies.cs
│ ├── D05_CollisionCategories.cs
│ ├── D06_Restitution.cs
│ ├── D07_Friction.cs
│ ├── D08_DistanceAngleJoint.cs
│ ├── D09_DynamicJoints.cs
│ ├── D10_Ragdoll.cs
│ ├── D11_SoftBody.cs
│ ├── D12_WebOfGoo.cs
│ ├── D13_TheoJansenWalker.cs
│ ├── D14_RacingCar.cs
│ ├── D15_SVGtoBody.cs
│ ├── D16_BreakableBody.cs
│ └── Prefabs
│ │ ├── Agent.cs
│ │ ├── Border.cs
│ │ ├── JumpySpider.cs
│ │ ├── ObjectType.cs
│ │ ├── Objects.cs
│ │ ├── Pyramid.cs
│ │ ├── Ragdoll.cs
│ │ ├── TheoJansenWalker.cs
│ │ └── WebOfGoo.cs
├── Game1.cs
├── Managers.cs
├── MediaSystem
│ ├── Colors.cs
│ ├── FontManager.cs
│ ├── Graphics
│ │ ├── LineBatch.cs
│ │ ├── QuadRenderer.cs
│ │ └── Sprite.cs
│ ├── SoundManager.cs
│ └── TextureManager.cs
├── Program.cs
├── ScreenSystem
│ ├── Camera2D.cs
│ ├── FrameRateCounter.cs
│ ├── InputHelper.cs
│ ├── MouseButtons.cs
│ ├── ScreenManager.cs
│ └── ScreenState.cs
├── Screens
│ ├── BackgroundScreen.cs
│ ├── DescriptionBoxScreen.cs
│ ├── GameScreen.cs
│ ├── MenuEntry.cs
│ ├── MenuScreen.cs
│ ├── MenuSlider.cs
│ ├── OptionEntry.cs
│ ├── OptionsScreen.cs
│ └── PhysicsDemoScreen.cs
└── VelcroPhysics.MonoGame.Samples.Demo.csproj
├── VelcroPhysics.MonoGame.Samples.HelloWorld
├── Content
│ ├── CircleSprite.png
│ ├── Content.mgcb
│ ├── Font.spritefont
│ ├── GroundSprite.png
│ └── Roboto-Regular.ttf
├── Game1.cs
├── Program.cs
└── VelcroPhysics.MonoGame.Samples.HelloWorld.csproj
├── VelcroPhysics.MonoGame.Samples.Testbed
├── Content
│ ├── Content.mgcb
│ ├── Font.spritefont
│ ├── Roboto-Regular.ttf
│ ├── Rock.png
│ ├── Terrain.png
│ └── Texture.png
├── Data
│ ├── 2.dat
│ ├── bird.dat
│ ├── debug.dat
│ ├── diamond.dat
│ ├── dude.dat
│ ├── funny.dat
│ ├── kzer-za.dat
│ ├── nazca_monkey.dat
│ ├── star.dat
│ └── strange.dat
├── Framework
│ ├── GameSettings.cs
│ ├── Input
│ │ ├── GamePadManager.cs
│ │ ├── KeyboardManager.cs
│ │ ├── MouseButton.cs
│ │ └── MouseManager.cs
│ ├── Rand.cs
│ └── Test.cs
├── Game1.cs
├── Program.cs
├── TestEntries.cs
├── Tests
│ ├── AddPairTest.cs
│ ├── ApplyForceTest.cs
│ ├── BodyTypesTest.cs
│ ├── BoxStackTest.cs
│ ├── BreakableTest.cs
│ ├── BridgeTest.cs
│ ├── BulletTest.cs
│ ├── CantileverTest.cs
│ ├── CarTest.cs
│ ├── ChainProblemTest.cs
│ ├── ChainTest.cs
│ ├── CharacterCollisionTest.cs
│ ├── CircleStackTest.cs
│ ├── CollisionFilteringTest.cs
│ ├── CollisionProcessingTest.cs
│ ├── CompoundShapesTest.cs
│ ├── ConfinedTest.cs
│ ├── ContinuousTest.cs
│ ├── ConvexHullTest.cs
│ ├── ConveyorBeltTest.cs
│ ├── DistanceJointTest.cs
│ ├── DistanceTest.cs
│ ├── DominosTest.cs
│ ├── DumpLoaderTest.cs
│ ├── DynamicTreeTest.cs
│ ├── EdgeShapesTest.cs
│ ├── EdgeTest.cs
│ ├── FrictionTest.cs
│ ├── GearJointTest.cs
│ ├── Heavy1Test.cs
│ ├── Heavy2Test.cs
│ ├── MobileBalancedTest.cs
│ ├── MobileUnbalancedTest.cs
│ ├── MotorJointTest.cs
│ ├── New
│ │ └── RopeTest.cs
│ ├── PinballTest.cs
│ ├── PlatformerTest.cs
│ ├── PolygonCollisionTest.cs
│ ├── PolygonShapesTest.cs
│ ├── PrismaticJointTest.cs
│ ├── PulleyJointTest.cs
│ ├── PyramidTest.cs
│ ├── RaycastTest.cs
│ ├── RestitutionTest.cs
│ ├── RevoluteJointTest.cs
│ ├── SensorsTest.cs
│ ├── ShapeCastTest.cs
│ ├── ShapeEditingTest.cs
│ ├── SkierTest.cs
│ ├── SliderCrank1Test.cs
│ ├── SliderCrank2Test.cs
│ ├── TheoJansenTest.cs
│ ├── TilesTest.cs
│ ├── TimeOfImpactTest.cs
│ ├── TumblerTest.cs
│ ├── Velcro
│ │ ├── AngleJointTest.cs
│ │ ├── BuoyancyTest.cs
│ │ ├── CheckPolygonTest.cs
│ │ ├── CircleBenchmarkTest.cs
│ │ ├── CirclePenetrationTest.cs
│ │ ├── CloneTest.cs
│ │ ├── CollisionCallbackTest.cs
│ │ ├── ConvexHull2Test.cs
│ │ ├── CuttingTest.cs
│ │ ├── DeletionTest.cs
│ │ ├── DestructibleTerrainTest.cs
│ │ ├── ExplosionTest.cs
│ │ ├── GravityControllerTest.cs
│ │ ├── LockTest.cs
│ │ ├── PathTest.cs
│ │ ├── RockBreakTest.cs
│ │ ├── RoundedRectangleTest.cs
│ │ ├── SerializationTest.cs
│ │ ├── SimpleWindForceTest.cs
│ │ ├── SimplificationTest.cs
│ │ ├── TextureVerticesTest.cs
│ │ ├── TriangulationTest.cs
│ │ └── YuPengPolygonTest.cs
│ ├── WebTest.cs
│ ├── WheelJointTest.cs
│ └── WreckingBallTest.cs
├── VelcroPhysics.MonoGame.Samples.Testbed.csproj
└── app.manifest
├── VelcroPhysics.MonoGame.sln
├── VelcroPhysics.Tests
├── Code
│ ├── Dummy.cs
│ └── PoolObject.cs
├── Tests
│ ├── CollisionTest.cs
│ ├── MathTest.cs
│ └── Shared
│ │ ├── AABBTests.cs
│ │ ├── GraphTests.cs
│ │ └── PoolTests.cs
└── VelcroPhysics.Tests.csproj
├── VelcroPhysics.sln
└── VelcroPhysics
├── Collision
├── AABBHelper.cs
├── Broadphase
│ ├── DynamicTree.cs
│ ├── DynamicTreeBroadPhase.cs
│ ├── IBroadPhase.cs
│ ├── Pair.cs
│ └── TreeNode.cs
├── ContactSystem
│ ├── Contact.cs
│ ├── ContactEdge.cs
│ ├── ContactFeature.cs
│ ├── ContactFeatureType.cs
│ ├── ContactFlags.cs
│ ├── ContactId.cs
│ ├── ContactManager.cs
│ └── ContactType.cs
├── Distance
│ ├── DistanceGJK.cs
│ ├── DistanceInput.cs
│ ├── DistanceOutput.cs
│ ├── DistanceProxy.cs
│ ├── ShapeCastInput.cs
│ └── ShapeCastOutput.cs
├── Filtering
│ ├── Category.cs
│ └── Filter.cs
├── Handlers
│ ├── AfterCollisionHandler.cs
│ ├── BeforeCollisionHandler.cs
│ ├── BeginContactHandler.cs
│ ├── BroadphaseHandler.cs
│ ├── CollisionFilterHandler.cs
│ ├── EndContactHandler.cs
│ ├── OnCollisionHandler.cs
│ └── OnSeparationHandler.cs
├── Narrowphase
│ ├── ClipVertex.cs
│ ├── CollideCircle.cs
│ ├── CollideEdge.cs
│ ├── CollidePolygon.cs
│ ├── Collision.cs
│ ├── EPAxis.cs
│ ├── EPAxisType.cs
│ ├── Manifold.cs
│ ├── ManifoldPoint.cs
│ ├── ManifoldType.cs
│ ├── PointState.cs
│ ├── ReferenceFace.cs
│ ├── Simplex.cs
│ ├── SimplexCache.cs
│ ├── SimplexVertex.cs
│ └── WorldManifold.cs
├── RayCast
│ ├── RayCastInput.cs
│ └── RayCastOutput.cs
├── RayCastHelper.cs
├── Shapes
│ ├── ChainShape.cs
│ ├── CircleShape.cs
│ ├── EdgeShape.cs
│ ├── MassData.cs
│ ├── PolygonShape.cs
│ ├── Shape.cs
│ └── ShapeType.cs
├── TOI
│ ├── SeparationFunction.cs
│ ├── SeparationFunctionType.cs
│ ├── Sweep.cs
│ ├── TOIInput.cs
│ ├── TOIOutput.cs
│ ├── TOIOutputState.cs
│ └── TimeOfImpact.cs
└── TestPointHelper.cs
├── Definitions
├── BodyDef.cs
├── FixtureDef.cs
├── IDef.cs
├── Joints
│ ├── DistanceJointDef.cs
│ ├── FixedMouseJointDef.cs
│ ├── FrictionJointDef.cs
│ ├── GearJointDef.cs
│ ├── JointDef.cs
│ ├── MotorJointDef.cs
│ ├── PrismaticJointDef.cs
│ ├── PulleyJointDef.cs
│ ├── RevoluteJointDef.cs
│ ├── WeldJointDef.cs
│ └── WheelJointDef.cs
└── Shapes
│ ├── ChainShapeDef.cs
│ ├── CircleShapeDef.cs
│ ├── EdgeShapeDef.cs
│ ├── PolygonShapeDef.cs
│ └── ShapeDef.cs
├── Dynamics
├── Body.cs
├── BodyFlags.cs
├── BodyType.cs
├── BreakableBody.cs
├── Fixture.cs
├── FixtureProxy.cs
├── Handlers
│ ├── BodyHandler.cs
│ ├── ControllerHandler.cs
│ ├── FixtureHandler.cs
│ ├── JointHandler.cs
│ ├── PostSolveHandler.cs
│ └── PreSolveHandler.cs
├── Joints
│ ├── AngleJoint.cs
│ ├── DistanceJoint.cs
│ ├── FixedMouseJoint.cs
│ ├── FrictionJoint.cs
│ ├── GearJoint.cs
│ ├── Joint.cs
│ ├── Misc
│ │ ├── JointEdge.cs
│ │ ├── JointType.cs
│ │ └── LimitState.cs
│ ├── MotorJoint.cs
│ ├── PrismaticJoint.cs
│ ├── PulleyJoint.cs
│ ├── RevoluteJoint.cs
│ ├── WeldJoint.cs
│ └── WheelJoint.cs
├── Profile.cs
├── Solver
│ ├── ContactPositionConstraint.cs
│ ├── ContactSolver.cs
│ ├── ContactVelocityConstraint.cs
│ ├── Island.cs
│ ├── Position.cs
│ ├── PositionSolverManifold.cs
│ ├── SolverData.cs
│ ├── Velocity.cs
│ └── VelocityConstraintPoint.cs
├── TimeStep.cs
└── World.cs
├── Extensions
├── Controllers
│ ├── Buoyancy
│ │ └── BuoyancyController.cs
│ ├── ControllerBase
│ │ ├── Controller.cs
│ │ ├── ControllerFilter.cs
│ │ └── ControllerType.cs
│ ├── Gravity
│ │ ├── GravityController.cs
│ │ └── GravityType.cs
│ ├── Velocity
│ │ └── VelocityLimitController.cs
│ └── Wind
│ │ ├── AbstractForceController.cs
│ │ └── SimpleWindForce.cs
├── DebugView
│ ├── DebugViewBase.cs
│ └── DebugViewFlags.cs
└── PhysicsLogics
│ ├── Explosion
│ ├── RayDataComparer.cs
│ ├── RealExplosion.cs
│ └── SimpleExplosion.cs
│ └── PhysicsLogicBase
│ ├── FilterData.cs
│ ├── PhysicsLogic.cs
│ ├── PhysicsLogicFilter.cs
│ ├── PhysicsLogicType.cs
│ └── ShapeData.cs
├── Factories
├── BodyFactory.cs
├── FixtureFactory.cs
└── JointFactory.cs
├── Interfaces
└── IDebugView.cs
├── Primitives
├── Color.cs
├── Curve.cs
├── CurveContinuity.cs
├── CurveKey.cs
├── CurveKeyCollection.cs
├── CurveLoopType.cs
├── CurveTangent.cs
├── MathHelper.cs
├── Matrix.cs
├── Vector2.cs
└── Vector3.cs
├── Settings.cs
├── Shared
├── AABB.cs
├── Contracts
│ ├── Contract.cs
│ ├── EnsuresException.cs
│ └── RequiredException.cs
├── Graph.cs
├── GraphNode.cs
├── Mat22.cs
├── Mat33.cs
├── Optimization
│ ├── FixedArray2.cs
│ ├── FixedArray3.cs
│ └── IPoolable.cs
├── PolygonError.cs
├── Pool.cs
├── Rot.cs
├── Transform.cs
└── Vertices.cs
├── Tools
├── ConvexHull
│ ├── ChainHull
│ │ └── ChainHull.cs
│ ├── GiftWrap
│ │ └── GiftWrap.cs
│ └── Melkman
│ │ └── Melkman.cs
├── Cutting
│ ├── Simple
│ │ ├── CuttingTools.cs
│ │ ├── PolyClipError.cs
│ │ └── PolyClipType.cs
│ └── YuPengClipper.cs
├── PathGenerator
│ ├── LinkFactory.cs
│ ├── Path.cs
│ └── PathManager.cs
├── PolygonManipulation
│ ├── SimpleCombiner.cs
│ └── SimplifyTools.cs
├── TextureTools
│ ├── MarchingSquares.cs
│ ├── Terrain.cs
│ ├── TextureConverter.cs
│ └── VerticesDetectionType.cs
└── Triangulation
│ ├── Bayazit
│ └── BayazitDecomposer.cs
│ ├── Delaunay
│ ├── CDTDecomposer.cs
│ ├── Delaunay
│ │ ├── DelaunayTriangle.cs
│ │ └── Sweep
│ │ │ ├── AdvancingFront.cs
│ │ │ ├── AdvancingFrontNode.cs
│ │ │ ├── DTSweep.cs
│ │ │ ├── DTSweepConstraint.cs
│ │ │ ├── DTSweepContext.cs
│ │ │ ├── DTSweepPointComparator.cs
│ │ │ └── PointOnEdgeException.cs
│ ├── Orientation.cs
│ ├── Polygon
│ │ ├── Polygon.cs
│ │ ├── PolygonPoint.cs
│ │ └── PolygonSet.cs
│ ├── Sets
│ │ ├── ConstrainedPointSet.cs
│ │ └── PointSet.cs
│ ├── Triangulatable.cs
│ ├── TriangulationConstraint.cs
│ ├── TriangulationContext.cs
│ ├── TriangulationMode.cs
│ ├── TriangulationPoint.cs
│ ├── TriangulationUtil.cs
│ └── Util
│ │ ├── PointGenerator.cs
│ │ └── PolygonGenerator.cs
│ ├── Earclip
│ ├── EarclipDecomposer.cs
│ └── Triangle.cs
│ ├── FlipCode
│ └── FlipcodeDecomposer.cs
│ ├── Seidel
│ ├── Edge.cs
│ ├── MonotoneMountain.cs
│ ├── Node.cs
│ ├── Point.cs
│ ├── QueryGraph.cs
│ ├── SeidelDecomposer.cs
│ ├── Sink.cs
│ ├── Trapezoid.cs
│ ├── TrapezoidalMap.cs
│ ├── Triangulator.cs
│ ├── XNode.cs
│ └── YNode.cs
│ └── TriangulationBase
│ ├── Triangulate.cs
│ └── TriangulationAlgorithm.cs
├── Utilities
├── ConvertUnits.cs
├── JointHelper.cs
├── LineUtils.cs
├── MathConstants.cs
├── MathUtils.cs
└── PolygonUtils.cs
├── VelcroPhysics.MonoGame.csproj
└── VelcroPhysics.csproj
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Linux scripts
5 | *.sh text merge=text diff=text eol=lf
6 | *.py text merge=text diff=python eol=lf
7 |
8 | # Linux configs
9 | *.conf text merge=text diff=text eol=lf
10 | *.yml text merge=text diff=text eol=lf
11 |
12 | # Source code files
13 | *.cs text merge=text diff=csharp eol=crlf
14 | *.cshtml text merge=text diff=text eol=crlf
15 | *.json text merge=text diff=text eol=crlf
16 | *.xml text merge=text diff=text eol=crlf
17 | *.scss text merge=text diff=css eol=crlf
18 | *.js text merge=text diff=text eol=crlf
19 | *.csproj text merge=text diff=text eol=crlf
20 | *.targets text merge=text diff=text eol=crlf ident
21 | *.sln text merge=text diff=text eol=crlf
22 |
23 | # Text files
24 | *.txt text merge=text diff=text eol=crlf
25 |
26 | # Binary files
27 | *.jpg binary
28 | *.png binary
29 | *.gif binary
30 |
31 | *.req text merge=text diff=text eol=lf
32 | *.creq text merge=text diff=text eol=lf
33 | *.sts text merge=text diff=text eol=lf
34 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [Genbox]
2 | custom: http://paypal.me/IanQvist
3 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Report a bug
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | * [ ] I hereby verify that I am a sponsor.
11 | Sponsorship is required before you can submit bug reports. See https://github.com/sponsors/Genbox
12 |
13 | **Describe the bug**
14 | What is the bug about?
15 |
16 | **How to reproduce?**
17 | Describe steps to reproduce the bug. Please include code to reproduce if possible.
18 |
19 | **Expected behavior**
20 | Describe what you expected to happen.
21 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest a feature for this project
4 | title: ''
5 | labels: enhancement
6 | assignees: ''
7 |
8 | ---
9 |
10 | * [ ] I hereby verify that I am a sponsor.
11 | Sponsorship is required before you can submit feature requests. See https://github.com/sponsors/Genbox
12 |
13 | **Describe the feature**
14 | Provide a short description of the feature. Why would you like the feature?
15 | If the feature makes changes to an existing or new API please provide an example.
16 |
--------------------------------------------------------------------------------
/.github/workflows/generic-build.yml:
--------------------------------------------------------------------------------
1 | name: Generic build
2 |
3 | on: [push]
4 |
5 | jobs:
6 | build:
7 | runs-on: ubuntu-latest
8 |
9 | steps:
10 | - uses: actions/checkout@v2
11 | - name: Setup .NET Core 5.0.x
12 | uses: actions/setup-dotnet@v1
13 | with:
14 | dotnet-version: '5.0.x'
15 | - name: Setup .NET Core 3.1.x
16 | uses: actions/setup-dotnet@v1
17 | with:
18 | dotnet-version: '3.1.x'
19 | - name: Build VelcroPhysics and samples
20 | run: dotnet build -c LinuxRelease src/VelcroPhysics.All.sln
--------------------------------------------------------------------------------
/.github/workflows/nuget-release.yml:
--------------------------------------------------------------------------------
1 | name: Nuget release
2 |
3 | on:
4 | push:
5 | tags:
6 | - '[0-9]+.[0-9]+.[0-9]+'
7 | - '[0-9]+.[0-9]+.[0-9]+-alpha**'
8 | - '[0-9]+.[0-9]+.[0-9]+-beta**'
9 |
10 | jobs:
11 | build:
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Setup .NET Core 5.0.x
17 | uses: actions/setup-dotnet@v1
18 | with:
19 | dotnet-version: '5.0.x'
20 | - name: Pack VelcroPhysics
21 | run: dotnet pack -c LinuxRelease src/VelcroPhysics.All.sln -o Temp
22 | - name: Upload to nuget
23 | run: dotnet nuget push --skip-duplicate -k ${{secrets.NUGET_KEY}} -s https://api.nuget.org/v3/index.json Temp/*
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Environment artifacts
2 |
3 | # Build results
4 | [Dd]ebug/
5 | [Rr]elease/
6 | [Bb]in/
7 | [Oo]bj/
8 | [Ll]og/
9 | [Bb]uild/
10 | .tmp/
11 |
12 | # User specific
13 | *.suo
14 | *.user
15 | *.userosscache
16 | *.sln.docstates
17 |
18 | # Visual Studio
19 | .vs/
20 |
21 | # Visual Studio profiler
22 | *.psess
23 | *.vsp
24 | *.vspx
25 | *.sap
26 |
27 | # Benchmark Results
28 | BenchmarkDotNet.Artifacts/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # ReSharper
35 | _ReSharper*/
36 | *.[Rr]e[Ss]harper
37 | *.DotSettings.user
38 |
39 | # Visual Studio code coverage results
40 | *.coverage
41 | *.coveragexml
42 |
43 | # Publish Web Output
44 | *.[Pp]ublish.xml
45 | *.pubxml
46 | *.publishproj
47 |
48 | # Backup & report files from converting an old project file to a newer Visual Studio version.
49 | _UpgradeReport_Files/
50 | Backup*/
51 | UpgradeLog*.XML
52 | UpgradeLog*.htm
53 | ServiceFabricBackup/
54 |
55 | # MSBuild
56 | *.binlog
57 |
58 | TempRelease
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Ian Qvist
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/DummyStopWatch.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Benchmarks.Code
2 | {
3 | public class DummyStopWatch
4 | {
5 | public void Start()
6 | {
7 | }
8 |
9 | public long ElapsedMilliseconds => 0;
10 |
11 | public void Stop()
12 | {
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/MeasuredBenchmark.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Attributes;
2 | using BenchmarkDotNet.Exporters.Csv;
3 |
4 | namespace Genbox.VelcroPhysics.Benchmarks.Code
5 | {
6 | /// This class sets the defaults for benchmarks that should be measured on a continuous basis.
7 | [CsvMeasurementsExporter(CsvSeparator.Comma)]
8 | [RPlotExporter]
9 | [InProcess]
10 | [MemoryDiagnoser]
11 | public abstract class MeasuredBenchmark { }
12 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/TestClasses/Class32.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Benchmarks.Code.TestClasses
2 | {
3 | public class Class32
4 | {
5 | public Class8 Value1;
6 | public Class8 Value2;
7 | public Class8 Value3;
8 | public Class8 Value4;
9 | }
10 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/TestClasses/Class64.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Benchmarks.Code.TestClasses
2 | {
3 | public class Class64
4 | {
5 | public Class32 Value1;
6 | public Class32 Value2;
7 | }
8 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/TestClasses/Class8.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Benchmarks.Code.TestClasses
2 | {
3 | public class Class8
4 | {
5 | public int Value1;
6 | public int Value2;
7 | }
8 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/TestClasses/Dummy.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Benchmarks.Code.TestClasses
2 | {
3 | public class Dummy
4 | {
5 | public Struct32 ValueProperty { get; set; }
6 | public Struct32 ValueField;
7 |
8 | public Struct32 ValueMethod()
9 | {
10 | return ValueField;
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/TestClasses/PoolObject.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Benchmarks.Code.TestClasses
2 | {
3 | internal sealed class PoolObject
4 | {
5 | public string TestString { get; set; }
6 | public int TestInteger { get; set; }
7 |
8 | public void Reset() { }
9 | }
10 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/TestClasses/Struct32.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Benchmarks.Code.TestClasses
2 | {
3 | public struct Struct32
4 | {
5 | public Struct8 Value1;
6 | public Struct8 Value2;
7 | public Struct8 Value3;
8 | public Struct8 Value4;
9 | }
10 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/TestClasses/Struct64.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Benchmarks.Code.TestClasses
2 | {
3 | public struct Struct64
4 | {
5 | public Struct32 Value1;
6 | public Struct32 Value2;
7 | }
8 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/TestClasses/Struct8.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Benchmarks.Code.TestClasses
2 | {
3 | public struct Struct8
4 | {
5 | public int Value1;
6 | public int Value2;
7 | }
8 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Code/UnmeasuredBenchmark.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Attributes;
2 |
3 | namespace Genbox.VelcroPhysics.Benchmarks.Code
4 | {
5 | /// This class sets the defaults for benchmarks that don't have to be measured
6 | [InProcess]
7 | [MemoryDiagnoser]
8 | public abstract class UnmeasuredBenchmark { }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Program.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Running;
2 |
3 | namespace Genbox.VelcroPhysics.Benchmarks
4 | {
5 | internal class Program
6 | {
7 | public static void Main()
8 | {
9 | BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run();
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Tests/CLR/FieldPropertyBenchmarks.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Attributes;
2 | using Genbox.VelcroPhysics.Benchmarks.Code;
3 | using Genbox.VelcroPhysics.Benchmarks.Code.TestClasses;
4 |
5 | namespace Genbox.VelcroPhysics.Benchmarks.Tests.CLR
6 | {
7 | public class FieldPropertyBenchmarks : UnmeasuredBenchmark
8 | {
9 | private readonly Dummy _dummy = new Dummy { ValueField = new Struct32() };
10 |
11 | [Benchmark]
12 | public Struct32 PropertyGetTest()
13 | {
14 | return _dummy.ValueProperty;
15 | }
16 |
17 | [Benchmark]
18 | public Struct32 FieldGetTest()
19 | {
20 | return _dummy.ValueField;
21 | }
22 |
23 | [Benchmark]
24 | public Struct32 MethodGetTest()
25 | {
26 | return _dummy.ValueMethod();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Tests/Collision/DistanceBenchmark.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Attributes;
2 | using Genbox.VelcroPhysics.Benchmarks.Code;
3 | using Genbox.VelcroPhysics.Collision.Distance;
4 | using Genbox.VelcroPhysics.Collision.Shapes;
5 | using Genbox.VelcroPhysics.Shared;
6 | using Genbox.VelcroPhysics.Utilities;
7 | using Microsoft.Xna.Framework;
8 |
9 | namespace Genbox.VelcroPhysics.Benchmarks.Tests.Collision
10 | {
11 | public class DistanceBenchmark : MeasuredBenchmark
12 | {
13 | private PolygonShape _polygonA;
14 | private PolygonShape _polygonB;
15 | private Transform _transformA;
16 | private Transform _transformB;
17 |
18 | [GlobalSetup]
19 | public void Setup()
20 | {
21 | _transformA.SetIdentity();
22 | _transformA.p = new Vector2(0.0f, -0.2f);
23 | _polygonA = new PolygonShape(PolygonUtils.CreateRectangle(10.0f, 0.2f), 0);
24 |
25 | _transformB.Set(new Vector2(12.017401f, 0.13678508f), -0.0109265f);
26 | _polygonB = new PolygonShape(PolygonUtils.CreateRectangle(2.0f, 0.1f), 0);
27 | }
28 |
29 | [Benchmark]
30 | public void Distance()
31 | {
32 | DistanceInput input = new DistanceInput();
33 | input.ProxyA = new DistanceProxy(_polygonA, 0);
34 | input.ProxyB = new DistanceProxy(_polygonB, 0);
35 | input.TransformA = _transformA;
36 | input.TransformB = _transformB;
37 | input.UseRadii = true;
38 | DistanceGJK.ComputeDistance(ref input, out _, out _);
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Tests/Collision/TOIBenchmark.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Attributes;
2 | using Genbox.VelcroPhysics.Benchmarks.Code;
3 | using Genbox.VelcroPhysics.Collision.Distance;
4 | using Genbox.VelcroPhysics.Collision.Shapes;
5 | using Genbox.VelcroPhysics.Collision.TOI;
6 | using Genbox.VelcroPhysics.Utilities;
7 | using Microsoft.Xna.Framework;
8 |
9 | namespace Genbox.VelcroPhysics.Benchmarks.Tests.Collision
10 | {
11 | public class ToiBenchmark : MeasuredBenchmark
12 | {
13 | private PolygonShape _shapeA;
14 | private PolygonShape _shapeB;
15 | private Sweep _sweepA;
16 | private Sweep _sweepB;
17 |
18 | [GlobalSetup]
19 | public void Setup()
20 | {
21 | _shapeA = new PolygonShape(PolygonUtils.CreateRectangle(25.0f, 5.0f), 0);
22 | _shapeB = new PolygonShape(PolygonUtils.CreateRectangle(2.5f, 2.5f), 0);
23 |
24 | _sweepA = new Sweep();
25 | _sweepA.C0 = new Vector2(24.0f, -60.0f);
26 | _sweepA.A0 = 2.95f;
27 | _sweepA.C = _sweepA.C0;
28 | _sweepA.A = _sweepA.A0;
29 | _sweepA.LocalCenter = Vector2.Zero;
30 |
31 | _sweepB = new Sweep();
32 | _sweepB.C0 = new Vector2(53.474274f, -50.252514f);
33 | _sweepB.A0 = 513.36676f;
34 | _sweepB.C = new Vector2(54.595478f, -51.083473f);
35 | _sweepB.A = 513.62781f;
36 | _sweepB.LocalCenter = Vector2.Zero;
37 | }
38 |
39 | [Benchmark]
40 | public void Distance()
41 | {
42 | TOIInput input = new TOIInput();
43 | input.ProxyA = new DistanceProxy(_shapeA, 0);
44 | input.ProxyB = new DistanceProxy(_shapeB, 0);
45 | input.SweepA = _sweepA;
46 | input.SweepB = _sweepB;
47 | input.TMax = 1.0f;
48 |
49 | TimeOfImpact.CalculateTimeOfImpact(ref input, out _);
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Tests/Primitives/Vector2Benchmark.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Attributes;
2 | using Genbox.VelcroPhysics.Benchmarks.Code;
3 | using Vector2 = Microsoft.Xna.Framework.Vector2;
4 |
5 | namespace Genbox.VelcroPhysics.Benchmarks.Tests.Primitives
6 | {
7 | public class Vector2Benchmark : UnmeasuredBenchmark
8 | {
9 | [Benchmark]
10 | public Vector2 CreateWithCtor()
11 | {
12 | return new Vector2(1, 2);
13 | }
14 |
15 | [Benchmark]
16 | public Vector2 CreateWithNoInit()
17 | {
18 | Vector2 v;
19 | v.X = 1;
20 | v.Y = 2;
21 | return v;
22 | }
23 |
24 | [Benchmark]
25 | public Vector2 CreateWithZero()
26 | {
27 | Vector2 v = Vector2.Zero;
28 | v.X = 1;
29 | v.Y = 2;
30 | return v;
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Tests/Shared/PoolBenchmarks.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using BenchmarkDotNet.Attributes;
3 | using Genbox.VelcroPhysics.Benchmarks.Code;
4 | using Genbox.VelcroPhysics.Benchmarks.Code.TestClasses;
5 | using Genbox.VelcroPhysics.Shared;
6 |
7 | namespace Genbox.VelcroPhysics.Benchmarks.Tests.Shared
8 | {
9 | public class PoolBenchmarks : UnmeasuredBenchmark
10 | {
11 | private readonly Pool _pool;
12 |
13 | public PoolBenchmarks()
14 | {
15 | _pool = new Pool(() => new PoolObject(), o => o.Reset(), 1000);
16 | }
17 |
18 | [Benchmark]
19 | public void NewObject()
20 | {
21 | for (int i = 0; i < 1000; i++)
22 | {
23 | PoolObject obj = new PoolObject();
24 | obj.TestInteger = 5;
25 | obj.TestString = "test";
26 | }
27 | }
28 |
29 | [Benchmark]
30 | public void NewPooledObject()
31 | {
32 | for (int i = 0; i < 1000; i++)
33 | {
34 | PoolObject obj = _pool.GetFromPool();
35 | obj.TestInteger = 5;
36 | obj.TestString = "test";
37 |
38 | _pool.ReturnToPool(obj);
39 | }
40 | }
41 |
42 | [Benchmark]
43 | public void NewPooledObjectMany()
44 | {
45 | IEnumerable many = _pool.GetManyFromPool(1000);
46 | foreach (PoolObject obj in many)
47 | {
48 | obj.TestInteger = 5;
49 | obj.TestString = "test";
50 | _pool.ReturnToPool(obj);
51 | }
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/Utilities/RandomExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Benchmarks.Utilities
4 | {
5 | public static class RandomExtensions
6 | {
7 | /// Random number in range [-1,1]
8 | public static float RandomFloat(this Random random)
9 | {
10 | return (float)(random.NextDouble() * 2.0 - 1.0);
11 | }
12 |
13 | /// Random floating point number in range [lo, hi]
14 | public static float RandomFloat(this Random random, float lo, float hi)
15 | {
16 | float r = (float)random.NextDouble();
17 | r = (hi - lo) * r + lo;
18 | return r;
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Benchmarks/VelcroPhysics.Benchmarks.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | Exe
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.ContentPipelines.SVGImport/Objects/PathDefinition.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Content.SVGImport.Objects
4 | {
5 | public class PathDefinition
6 | {
7 | public string Id;
8 | public string Path;
9 | public Matrix Transformation;
10 | }
11 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.ContentPipelines.SVGImport/Objects/VerticesContainer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Content.SVGImport.Objects
4 | {
5 | public class VerticesContainer : Dictionary> { }
6 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.ContentPipelines.SVGImport/Objects/VerticesExt.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Content.SVGImport.Objects
4 | {
5 | public class VerticesExt : Vertices
6 | {
7 | public bool Closed;
8 |
9 | public VerticesExt() { }
10 |
11 | public VerticesExt(Vertices v, bool closed) : base(v)
12 | {
13 | Closed = closed;
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.ContentPipelines.SVGImport/VelcroPhysics.MonoGame.Content.SVGImport.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | ..\bin\
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.ContentPipelines.SVGImport/VerticesContainerReader.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Genbox.VelcroPhysics.MonoGame.Content.SVGImport.Objects;
3 | using Genbox.VelcroPhysics.Shared;
4 | using Microsoft.Xna.Framework.Content;
5 |
6 | namespace Genbox.VelcroPhysics.MonoGame.Content.SVGImport
7 | {
8 | public class VerticesContainerReader : ContentTypeReader
9 | {
10 | protected override VerticesContainer Read(ContentReader input, VerticesContainer existingInstance)
11 | {
12 | VerticesContainer container = existingInstance ?? new VerticesContainer();
13 |
14 | int count = input.ReadInt32(); //container.Count
15 | for (int i = 0; i < count; i++)
16 | {
17 | string name = input.ReadString();
18 | int listCount = input.ReadInt32();
19 |
20 | List exts = new List();
21 |
22 | for (int j = 0; j < listCount; j++)
23 | {
24 | bool closed = input.ReadBoolean();
25 | int vertCount = input.ReadInt32();
26 |
27 | Vertices verts = new Vertices(vertCount);
28 | for (int x = 0; x < vertCount; x++)
29 | {
30 | verts.Add(input.ReadVector2());
31 | }
32 |
33 | exts.Add(new VerticesExt(verts, closed));
34 | }
35 |
36 | container.Add(name, exts);
37 | }
38 |
39 | return container;
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.ContentPipelines.SVGImport/VerticesContainerWriter.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Genbox.VelcroPhysics.MonoGame.Content.SVGImport.Objects;
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Content.Pipeline;
5 | using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
6 |
7 | namespace Genbox.VelcroPhysics.MonoGame.Content.SVGImport
8 | {
9 | [ContentTypeWriter]
10 | public class VerticesContainerWriter : ContentTypeWriter
11 | {
12 | protected override void Write(ContentWriter output, VerticesContainer container)
13 | {
14 | output.Write(container.Count);
15 | foreach (KeyValuePair> p in container)
16 | {
17 | output.Write(p.Key);
18 | output.Write(p.Value.Count);
19 |
20 | foreach (VerticesExt ext in p.Value)
21 | {
22 | output.Write(ext.Closed);
23 | output.Write(ext.Count);
24 |
25 | foreach (Vector2 vec in ext)
26 | {
27 | output.Write(vec);
28 | }
29 | }
30 | }
31 | }
32 |
33 | public override string GetRuntimeReader(TargetPlatform targetPlatform)
34 | {
35 | return typeof(VerticesContainerReader).AssemblyQualifiedName;
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.ContentPipelines.TextureToVertices/TextureToVerticesProcessor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using Genbox.VelcroPhysics.Shared;
4 | using Genbox.VelcroPhysics.Utilities;
5 | using Microsoft.Xna.Framework;
6 | using Microsoft.Xna.Framework.Content.Pipeline;
7 | using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
8 |
9 | namespace Genbox.VelcroPhysics.MonoGame.Content.TextureToVertices
10 | {
11 | [ContentProcessor(DisplayName = "Texture to Vertices")]
12 | public class TextureToVerticesProcessor : ContentProcessor
13 | {
14 | private float _scaleFactor = 1f;
15 |
16 | [DisplayName("Pixel to meter ratio")]
17 | [Description("The length of one physics simulation unit in pixels.")]
18 | [DefaultValue(1)]
19 | public int ScaleFactor
20 | {
21 | get => (int)(1f / _scaleFactor);
22 | set => _scaleFactor = 1f / value;
23 | }
24 |
25 | [DisplayName("Hole detection")]
26 | [Description("Detect holes in the traced texture.")]
27 | [DefaultValue(false)]
28 | public bool HoleDetection { get; set; }
29 |
30 | public override Vertices Process(Texture2DContent input, ContentProcessorContext context)
31 | {
32 | if (ScaleFactor < 1)
33 | throw new Exception("Pixel to meter ratio must be greater than zero.");
34 |
35 | PixelBitmapContent bitmapContent = (PixelBitmapContent)input.Faces[0][0];
36 | uint[] colorData = new uint[bitmapContent.Width * bitmapContent.Height];
37 | for (int i = 0; i < bitmapContent.Height; i++)
38 | {
39 | for (int j = 0; j < bitmapContent.Width; j++)
40 | {
41 | Color c = bitmapContent.GetPixel(j, i);
42 | c.R *= c.A;
43 | c.G *= c.A;
44 | c.B *= c.A;
45 | colorData[i * bitmapContent.Width + j] = c.PackedValue;
46 | }
47 | }
48 |
49 | Vertices outline = PolygonUtils.CreatePolygon(colorData, bitmapContent.Width, HoleDetection);
50 |
51 | Vector2 centroid = -outline.GetCentroid();
52 | outline.Translate(ref centroid);
53 |
54 | Vector2 scale = new Vector2(_scaleFactor);
55 | outline.Scale(ref scale);
56 |
57 | return outline;
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.ContentPipelines.TextureToVertices/VelcroPhysics.MonoGame.Content.TextureToVertices.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | ..\bin\
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.DebugView/Content/Font.xnb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.DebugView/Content/Font.xnb
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.DebugView/VelcroPhysics.MonoGame.DebugView.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | PreserveNewest
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Common/Buttons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Common/Buttons.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Common/Checkmark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Common/Checkmark.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Common/Cursor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Common/Cursor.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Common/SamplesLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Common/SamplesLogo.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Car.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Car.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Club.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Club.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Cookie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Cookie.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Diamond.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Diamond.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Goo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Goo.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Heart.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Link.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Link.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Spade.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Spade.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Wheel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/Wheel.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/cookie_orig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoGFX/cookie_orig.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoSFX/Click.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/DemoSFX/Click.wav
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Fonts/DetailsFont.spritefont:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Roboto-Regular
5 | 12
6 | 1
7 | true
8 |
9 |
10 |
11 |
12 | ~
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Fonts/MenuFont.spritefont:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Roboto-Regular
5 | 23
6 | 0
7 | true
8 |
9 |
10 |
11 |
12 | ~
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Fonts/Roboto-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Fonts/Roboto-Regular.ttf
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Materials/Square.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Materials/Square.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Materials/Stripe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Demo/Content/Materials/Stripe.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Demos/D12_WebOfGoo.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 | using Genbox.VelcroPhysics.MonoGame.Samples.Demo.Demos.Prefabs;
3 | using Genbox.VelcroPhysics.MonoGame.Samples.Demo.Screens;
4 | using Genbox.VelcroPhysics.Utilities;
5 | using Microsoft.Xna.Framework;
6 |
7 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.Demos
8 | {
9 | internal class D12_WebOfGoo : PhysicsDemoScreen
10 | {
11 | private WebOfGoo _webOfGoo;
12 |
13 | public override void LoadContent()
14 | {
15 | base.LoadContent();
16 |
17 | World.Gravity = new Vector2(0, 9.82f);
18 |
19 | _webOfGoo = new WebOfGoo(World, Vector2.Zero, ConvertUnits.ToSimUnits(12), 5, 12);
20 | }
21 |
22 | public override void Draw()
23 | {
24 | Sprites.Begin(0, null, null, null, null, null, Camera.View);
25 | _webOfGoo.Draw(Sprites);
26 | Sprites.End();
27 |
28 | base.Draw();
29 | }
30 |
31 | public override string GetTitle()
32 | {
33 | return "Advanced dynamics";
34 | }
35 |
36 | public override string GetDetails()
37 | {
38 | StringBuilder sb = new StringBuilder();
39 | sb.AppendLine("This demo shows a web made of distance joints. The joints are configured");
40 | sb.AppendLine("to break under stress, so that the web can be torn apart.");
41 | #if WINDOWS
42 | sb.AppendLine();
43 | sb.AppendLine("Keyboard:");
44 | sb.AppendLine(" - Exit to demo selection: Escape");
45 | sb.AppendLine();
46 | sb.AppendLine("Mouse:");
47 | sb.AppendLine(" - Grab object (beneath cursor): Left click");
48 | sb.AppendLine(" - Drag grabbed object: Move mouse");
49 | #elif XBOX
50 | sb.AppendLine();
51 | sb.AppendLine("GamePad:");
52 | sb.AppendLine(" - Move cursor: Left thumbstick");
53 | sb.AppendLine(" - Grab object (beneath cursor): A button");
54 | sb.AppendLine(" - Drag grabbed object: Left thumbstick");
55 | sb.AppendLine(" - Exit to demo selection: Back button");
56 | #endif
57 | return sb.ToString();
58 | }
59 | }
60 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Demos/Prefabs/ObjectType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.Demos.Prefabs
2 | {
3 | public enum ObjectType
4 | {
5 | Circle,
6 | Rectangle,
7 | Gear,
8 | Star
9 | }
10 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Demos/Prefabs/Pyramid.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Genbox.VelcroPhysics.Collision.Shapes;
3 | using Genbox.VelcroPhysics.Dynamics;
4 | using Genbox.VelcroPhysics.Factories;
5 | using Genbox.VelcroPhysics.MonoGame.Samples.Demo.MediaSystem;
6 | using Genbox.VelcroPhysics.MonoGame.Samples.Demo.MediaSystem.Graphics;
7 | using Genbox.VelcroPhysics.Shared;
8 | using Genbox.VelcroPhysics.Utilities;
9 | using Microsoft.Xna.Framework;
10 | using Microsoft.Xna.Framework.Graphics;
11 |
12 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.Demos.Prefabs
13 | {
14 | public class Pyramid
15 | {
16 | private readonly Sprite _box;
17 | private readonly List _boxes;
18 |
19 | public Pyramid(World world, Vector2 position, int count, float density)
20 | {
21 | Vertices rect = PolygonUtils.CreateRectangle(0.5f, 0.5f);
22 | PolygonShape shape = new PolygonShape(rect, density);
23 |
24 | Vector2 rowStart = position;
25 | rowStart.Y -= 0.5f + count * 1.1f;
26 |
27 | Vector2 deltaRow = new Vector2(-0.625f, 1.1f);
28 | const float spacing = 1.25f;
29 |
30 | // Physics
31 | _boxes = new List();
32 |
33 | for (int i = 0; i < count; i++)
34 | {
35 | Vector2 pos = rowStart;
36 |
37 | for (int j = 0; j < i + 1; j++)
38 | {
39 | Body body = BodyFactory.CreateBody(world);
40 | body.BodyType = BodyType.Dynamic;
41 | body.Position = pos;
42 | body.AddFixture(shape);
43 | _boxes.Add(body);
44 |
45 | pos.X += spacing;
46 | }
47 |
48 | rowStart += deltaRow;
49 | }
50 |
51 | //GFX
52 | _box = new Sprite(Managers.TextureManager.PolygonTexture(rect, "Square", Colors.Blue, Colors.Gold, Colors.Black, 1f));
53 | }
54 |
55 | public void Draw(SpriteBatch batch)
56 | {
57 | foreach (Body body in _boxes)
58 | {
59 | batch.Draw(_box.Image, ConvertUnits.ToDisplayUnits(body.Position), null, Color.White, body.Rotation, _box.Origin, 1f, SpriteEffects.None, 0f);
60 | }
61 | }
62 | }
63 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Managers.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.MonoGame.Samples.Demo.MediaSystem;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo
4 | {
5 | public static class Managers
6 | {
7 | public static TextureManager TextureManager { get; internal set; }
8 | public static SoundManager SoundManager { get; internal set; }
9 | public static FontManager FontManager { get; internal set; }
10 | }
11 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/MediaSystem/Colors.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.MediaSystem
4 | {
5 | public static class Colors
6 | {
7 | public static Color Gold = new Color(246, 187, 53);
8 | public static Color Red = new Color(215, 1, 51);
9 | public static Color Green = new Color(102, 158, 68);
10 | public static Color Orange = new Color(218, 114, 44);
11 | public static Color Brown = new Color(123, 40, 11);
12 |
13 | public static Color Beige = new Color(233, 229, 217);
14 | public static Color Cream = new Color(246, 87, 84);
15 | public static Color Lime = new Color(146, 201, 43);
16 | public static Color Teal = new Color(66, 126, 120);
17 | public static Color Grey = new Color(73, 69, 69);
18 |
19 | public static Color Black = new Color(28, 19, 11);
20 | public static Color Sunset = new Color(194, 73, 24);
21 | public static Color Sky = new Color(185, 216, 221);
22 |
23 | public static Color Cyan = new Color(50, 201, 251);
24 | public static Color Blue = new Color(44, 138, 153);
25 | public static Color Ocean = new Color(57, 143, 171);
26 | }
27 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/MediaSystem/FontManager.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using Microsoft.Xna.Framework.Content;
4 | using Microsoft.Xna.Framework.Graphics;
5 |
6 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.MediaSystem
7 | {
8 | public class FontManager
9 | {
10 | private readonly Dictionary _fontList = new Dictionary();
11 |
12 | public FontManager(ContentManager content)
13 | {
14 | // Add samples fonts
15 | DirectoryInfo currentAssetFolder = new DirectoryInfo(content.RootDirectory + "/Fonts");
16 | FileInfo[] currentFileList = currentAssetFolder.GetFiles("*.xnb");
17 |
18 | for (int i = 0; i < currentFileList.Length; i++)
19 | {
20 | string fontName = Path.GetFileNameWithoutExtension(currentFileList[i].Name);
21 | _fontList[fontName] = content.Load("Fonts/" + fontName);
22 | }
23 | }
24 |
25 | public SpriteFont GetFont(string fontName)
26 | {
27 | if (_fontList.TryGetValue(fontName, out SpriteFont font))
28 | return font;
29 |
30 | throw new FileNotFoundException($"The font \"{fontName}\" was not found");
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/MediaSystem/Graphics/Sprite.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Graphics;
3 |
4 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.MediaSystem.Graphics
5 | {
6 | public class Sprite
7 | {
8 | private Texture2D _image;
9 | private Vector2 _origin;
10 |
11 | public Sprite(Texture2D image, Vector2 origin)
12 | {
13 | _image = image;
14 | _origin = origin;
15 | }
16 |
17 | public Sprite(Texture2D image)
18 | {
19 | Image = image;
20 | }
21 |
22 | public Vector2 Origin
23 | {
24 | get => _origin;
25 | set => _origin = value;
26 | }
27 |
28 | public Texture2D Image
29 | {
30 | get => _image;
31 | set
32 | {
33 | _image = value;
34 | _origin = new Vector2(_image.Width / 2f, _image.Height / 2f);
35 | }
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo
4 | {
5 | public static class Program
6 | {
7 | [STAThread]
8 | private static void Main()
9 | {
10 | using (Game1 game = new Game1())
11 | game.Run();
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/ScreenSystem/FrameRateCounter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 |
6 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.ScreenSystem
7 | {
8 | public class FrameRateCounter
9 | {
10 | private readonly NumberFormatInfo _format;
11 | private readonly Vector2 _position;
12 | private TimeSpan _elapsedTime = TimeSpan.Zero;
13 | private SpriteFont _font;
14 | private int _frameCounter;
15 | private int _frameRate;
16 |
17 | public FrameRateCounter()
18 | {
19 | _format = new NumberFormatInfo();
20 | _format.NumberDecimalSeparator = ".";
21 | _position = new Vector2(30, 30);
22 | }
23 |
24 | public void LoadContent()
25 | {
26 | _font = Managers.FontManager.GetFont("DetailsFont");
27 | }
28 |
29 | public void Update(GameTime gameTime)
30 | {
31 | _elapsedTime += gameTime.ElapsedGameTime;
32 |
33 | if (_elapsedTime > TimeSpan.FromSeconds(1.0))
34 | {
35 | _elapsedTime -= TimeSpan.FromSeconds(1.0);
36 | _frameRate = _frameCounter;
37 | _frameCounter = 0;
38 | }
39 | }
40 |
41 | public void Draw(SpriteBatch batch)
42 | {
43 | _frameCounter++;
44 |
45 | string fps = string.Format(_format, "{0} fps", _frameRate);
46 |
47 | batch.Begin();
48 | batch.DrawString(_font, fps, _position + Vector2.One, Color.Black);
49 | batch.DrawString(_font, fps, _position, Color.White);
50 | batch.End();
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/ScreenSystem/MouseButtons.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.ScreenSystem
2 | {
3 | /// an enum of all available mouse buttons.
4 | public enum MouseButtons
5 | {
6 | LeftButton,
7 | MiddleButton,
8 | RightButton,
9 | ExtraButton1,
10 | ExtraButton2
11 | }
12 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/ScreenSystem/ScreenState.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.ScreenSystem
2 | {
3 | /// Enum describes the screen transition state.
4 | public enum ScreenState
5 | {
6 | TransitionOn,
7 | Active,
8 | TransitionOff,
9 | Hidden
10 | }
11 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Screens/BackgroundScreen.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Genbox.VelcroPhysics.MonoGame.Samples.Demo.MediaSystem;
3 | using Microsoft.Xna.Framework;
4 |
5 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.Screens
6 | {
7 | /// The background screen sits behind all the other menu screens. It draws a background image that remains fixed
8 | /// in place regardless of whatever transitions the screens on top of it may be doing.
9 | public class BackgroundScreen : GameScreen
10 | {
11 | private Vector2 _viewportSize;
12 |
13 | public BackgroundScreen()
14 | {
15 | TransitionOnTime = TimeSpan.FromSeconds(0.5);
16 | TransitionOffTime = TimeSpan.FromSeconds(0.5);
17 | }
18 |
19 | public override void LoadContent()
20 | {
21 | _viewportSize = new Vector2(Framework.GraphicsDevice.Viewport.Width, Framework.GraphicsDevice.Viewport.Height);
22 | }
23 |
24 | /// Updates the background screen. Unlike most screens, this should not transition off even if it has been covered
25 | /// by another screen: it is supposed to be covered, after all! This overload forces the coveredByOtherScreen parameter to
26 | /// false in order to stop the base Update method wanting to transition off.
27 | public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
28 | {
29 | base.Update(gameTime, otherScreenHasFocus, false);
30 | }
31 |
32 | /// Draws the background screen.
33 | public override void Draw()
34 | {
35 | Quads.Begin();
36 | Quads.Render(Vector2.Zero, _viewportSize, null, Colors.Cyan, Colors.Ocean, Colors.Cyan, Colors.Sky);
37 | Quads.End();
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/Screens/MenuSlider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Genbox.VelcroPhysics.MonoGame.Samples.Demo.MediaSystem;
3 | using Microsoft.Xna.Framework;
4 |
5 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Demo.Screens
6 | {
7 | public sealed class MenuSlider
8 | {
9 | private const float MaxTranslation = 15f;
10 | private const double HighlightTime = 0.3;
11 | private Vector2 _currentPosition;
12 | private double _hoverFade;
13 | private double _selectionFade;
14 | private float _targetY;
15 |
16 | public MenuSlider(Vector2 position)
17 | {
18 | _currentPosition = position;
19 | _targetY = _currentPosition.Y;
20 | }
21 |
22 | public Vector2 Position => _currentPosition;
23 |
24 | public float Target
25 | {
26 | set => _targetY = value;
27 | }
28 |
29 | public Color TileColor { get; private set; }
30 |
31 | public void Update(bool isHovered, bool isSelected, GameTime gameTime)
32 | {
33 | if (isHovered)
34 | _hoverFade = Math.Min(_hoverFade + gameTime.ElapsedGameTime.TotalSeconds / HighlightTime, 1.0);
35 | else
36 | _hoverFade = Math.Max(_hoverFade - gameTime.ElapsedGameTime.TotalSeconds / HighlightTime, 0.0);
37 |
38 | if (isSelected)
39 | _selectionFade = Math.Min(_selectionFade + gameTime.ElapsedGameTime.TotalSeconds / HighlightTime, 1.0);
40 | else
41 | _selectionFade = Math.Max(_selectionFade - gameTime.ElapsedGameTime.TotalSeconds / HighlightTime, 0.0);
42 |
43 | TileColor = Color.Lerp(Colors.Sky * 0.6f, Colors.Grey * 0.6f, (float)_hoverFade);
44 | TileColor = Color.Lerp(TileColor, Colors.Gold, (float)_selectionFade);
45 |
46 | float deltaY = _targetY - _currentPosition.Y;
47 | if (Math.Abs(deltaY) > MaxTranslation)
48 | _currentPosition.Y += MaxTranslation * Math.Sign(deltaY);
49 | else
50 | _currentPosition.Y += deltaY;
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Demo/VelcroPhysics.MonoGame.Samples.Demo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0
6 | false
7 | false
8 | false
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.HelloWorld/Content/CircleSprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.HelloWorld/Content/CircleSprite.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.HelloWorld/Content/Content.mgcb:
--------------------------------------------------------------------------------
1 |
2 | #----------------------------- Global Properties ----------------------------#
3 |
4 | /outputDir:bin/$(Platform)
5 | /intermediateDir:obj/$(Platform)
6 | /platform:Windows
7 | /config:
8 | /profile:Reach
9 | /compress:False
10 |
11 | #-------------------------------- References --------------------------------#
12 |
13 |
14 | #---------------------------------- Content ---------------------------------#
15 |
16 | #begin Font.spritefont
17 | /importer:FontDescriptionImporter
18 | /processor:FontDescriptionProcessor
19 | /processorParam:PremultiplyAlpha=True
20 | /processorParam:TextureFormat=Compressed
21 | /build:Font.spritefont
22 |
23 | #begin CircleSprite.png
24 | /importer:TextureImporter
25 | /processor:TextureProcessor
26 | /processorParam:ColorKeyColor=255,0,255,255
27 | /processorParam:ColorKeyEnabled=True
28 | /processorParam:GenerateMipmaps=False
29 | /processorParam:PremultiplyAlpha=True
30 | /processorParam:ResizeToPowerOfTwo=False
31 | /processorParam:MakeSquare=False
32 | /processorParam:TextureFormat=Color
33 | /build:CircleSprite.png
34 |
35 | #begin GroundSprite.png
36 | /importer:TextureImporter
37 | /processor:TextureProcessor
38 | /processorParam:ColorKeyColor=255,0,255,255
39 | /processorParam:ColorKeyEnabled=True
40 | /processorParam:GenerateMipmaps=False
41 | /processorParam:PremultiplyAlpha=True
42 | /processorParam:ResizeToPowerOfTwo=False
43 | /processorParam:MakeSquare=False
44 | /processorParam:TextureFormat=Color
45 | /build:GroundSprite.png
46 |
47 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.HelloWorld/Content/Font.spritefont:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Roboto-Regular
5 | 12
6 | 0
7 | true
8 |
9 |
10 |
11 |
12 | ~
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.HelloWorld/Content/GroundSprite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.HelloWorld/Content/GroundSprite.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.HelloWorld/Content/Roboto-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.HelloWorld/Content/Roboto-Regular.ttf
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.HelloWorld/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Samples.HelloWorld
4 | {
5 | public static class Program
6 | {
7 | [STAThread]
8 | private static void Main()
9 | {
10 | using (Game1 game = new Game1())
11 | game.Run();
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.HelloWorld/VelcroPhysics.MonoGame.Samples.HelloWorld.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0
6 | false
7 | false
8 | false
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Content.mgcb:
--------------------------------------------------------------------------------
1 |
2 | #----------------------------- Global Properties ----------------------------#
3 |
4 | /outputDir:bin/$(Platform)
5 | /intermediateDir:obj/$(Platform)
6 | /platform:DesktopGL
7 | /config:
8 | /profile:Reach
9 | /compress:False
10 |
11 | #-------------------------------- References --------------------------------#
12 |
13 |
14 | #---------------------------------- Content ---------------------------------#
15 |
16 | #begin Font.spritefont
17 | /importer:FontDescriptionImporter
18 | /processor:FontDescriptionProcessor
19 | /processorParam:PremultiplyAlpha=True
20 | /processorParam:TextureFormat=Compressed
21 | /build:Font.spritefont
22 |
23 | #begin Rock.png
24 | /importer:TextureImporter
25 | /processor:TextureProcessor
26 | /processorParam:ColorKeyColor=255,0,255,255
27 | /processorParam:ColorKeyEnabled=True
28 | /processorParam:GenerateMipmaps=False
29 | /processorParam:PremultiplyAlpha=True
30 | /processorParam:ResizeToPowerOfTwo=False
31 | /processorParam:MakeSquare=False
32 | /processorParam:TextureFormat=Color
33 | /build:Rock.png
34 |
35 | #begin Terrain.png
36 | /importer:TextureImporter
37 | /processor:TextureProcessor
38 | /processorParam:ColorKeyColor=255,0,255,255
39 | /processorParam:ColorKeyEnabled=True
40 | /processorParam:GenerateMipmaps=False
41 | /processorParam:PremultiplyAlpha=True
42 | /processorParam:ResizeToPowerOfTwo=False
43 | /processorParam:MakeSquare=False
44 | /processorParam:TextureFormat=Color
45 | /build:Terrain.png
46 |
47 | #begin Texture.png
48 | /importer:TextureImporter
49 | /processor:TextureProcessor
50 | /processorParam:ColorKeyColor=255,0,255,255
51 | /processorParam:ColorKeyEnabled=True
52 | /processorParam:GenerateMipmaps=False
53 | /processorParam:PremultiplyAlpha=True
54 | /processorParam:ResizeToPowerOfTwo=False
55 | /processorParam:MakeSquare=False
56 | /processorParam:TextureFormat=Color
57 | /build:Texture.png
58 |
59 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Font.spritefont:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Roboto-Regular
5 | 12
6 | 0
7 | true
8 |
9 |
10 |
11 |
12 | ~
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Roboto-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Roboto-Regular.ttf
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Rock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Rock.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Terrain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Terrain.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Texture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Genbox/VelcroPhysics/ddf8292da6bc59ec5875a91f1d61f1523b4aab34/src/VelcroPhysics.MonoGame.Samples.Testbed/Content/Texture.png
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Data/2.dat:
--------------------------------------------------------------------------------
1 | 5.510646 -6.312136
2 | 5.510646 -9.534955
3 | -6.016356 -9.534955
4 | -6.016356 -6.837597
5 | -1.933609 -0.7320573
6 | -0.6714239 1.242431
7 | 0.07130214 2.498066
8 | 0.4939168 3.344996
9 | 0.7957863 4.093408
10 | 0.9769094 4.743301
11 | 1.037288 5.294677
12 | 0.9643505 5.967545
13 | 0.7455474 6.44485
14 | 0.5806286 6.610869
15 | 0.3776243 6.729462
16 | 0.1365345 6.80062
17 | -0.1426414 6.824349
18 | -0.4218241 6.798073
19 | -0.6629166 6.719252
20 | -0.8659183 6.587883
21 | -1.030829 6.403981
22 | -1.158469 6.141973
23 | -1.249639 5.776335
24 | -1.32257 4.734189
25 | -1.32257 2.935948
26 | -6.016356 2.935948
27 | -6.016356 3.624884
28 | -5.970973 5.045072
29 | -5.834826 6.129576
30 | -5.710837 6.586056
31 | -5.520398 7.0389
32 | -5.263501 7.488094
33 | -4.940154 7.933653
34 | -4.556844 8.350358
35 | -4.120041 8.71307
36 | -3.629755 9.02178
37 | -3.085981 9.276493
38 | -2.487104 9.475718
39 | -1.8315 9.618026
40 | -1.119165 9.703418
41 | -0.3501012 9.731889
42 | 1.117107 9.644661
43 | 1.779295 9.535644
44 | 2.393876 9.383026
45 | 2.960846 9.186799
46 | 3.480206 8.946972
47 | 3.951957 8.663539
48 | 4.376098 8.336502
49 | 5.076675 7.592458
50 | 5.577088 6.755733
51 | 5.877342 5.82633
52 | 5.977431 4.804249
53 | 5.921109 3.981021
54 | 5.752138 3.134446
55 | 5.470524 2.264521
56 | 5.076274 1.371247
57 | 4.406482 0.2123121
58 | 3.298271 -1.454563
59 | 1.751642 -3.629379
60 | -0.233405 -6.312136
61 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Data/diamond.dat:
--------------------------------------------------------------------------------
1 | -0.1 -4.5
2 | 2.9 -3
3 | 5.9 -1.5
4 | 8.9 0
5 | 11.9 1.5
6 | 1.4 3
7 | -12.1 1.5
8 | -9.1 0
9 | -6.1 -1.5
10 | -3.1 -3
11 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Data/dude.dat:
--------------------------------------------------------------------------------
1 | -2.540775 -6.523775
2 | -2.219346 -7.229125
3 | -3.394328 -7.14317
4 | -3.443085 -7.655005
5 | -4.031846 -7.934485
6 | -4.031846 -8.255915
7 | -3.737204 -8.3452
8 | -1.701489 -7.559485
9 | -2.094346 -6.559485
10 | -2.308632 -5.66663
11 | -2.308632 -4.523771
12 | -1.915774 -3.345197
13 | -1.237203 -2.273772
14 | -0.3800602 -1.523772
15 | 0.405653 -1.345198
16 | 1.334226 -1.452341
17 | 2.191368 -1.595198
18 | 3.012796 -2.488056
19 | 3.655653 -3.523772
20 | 4.11994 -4.702341
21 | 4.298512 -5.488055
22 | 5.36994 -5.04163
23 | 5.343155 -5.0327
24 | 5.31637 -4.559486
25 | 4.789583 -4.577341
26 | 4.673512 -4.863056
27 | 4.43244 -4.836271
28 | 4.459227 -4.336271
29 | 4.861012 -4.005913
30 | 5.334225 -4.068413
31 | 5.61994 -4.773771
32 | 5.977085 -4.595201
33 | 5.012795 -2.845197
34 | 3.727083 -1.595198
35 | 2.084227 -0.8094865
36 | 0.905653 -0.666628
37 | 0.7627965 -0.1666279
38 | 0.7627965 0.3333721
39 | 0.977083 1.083372
40 | 1.834226 2.083372
41 | 2.298512 2.869086
42 | 2.727083 3.6548
43 | 2.86994 5.690515
44 | 1.441368 8.29766
45 | 0.2985115 9.619085
46 | -0.0229168 9.190515
47 | 0.7985115 8.190515
48 | 0.3342266 7.4048
49 | 0.1199398 7.940515
50 | -0.594346 8.261945
51 | -0.9157745 7.58337
52 | 0.977083 6.54766
53 | 1.86994 5.511945
54 | 2.227083 4.333372
55 | 2.048512 3.190516
56 | 1.762797 2.797659
57 | 1.084226 2.797659
58 | 0.2627964 3.083372
59 | 0.0842266 3.97623
60 | 0.3699398 4.726231
61 | 0.3699398 5.33337
62 | -0.1657734 5.619085
63 | -0.522917 5.54766
64 | -0.772917 4.761944
65 | -0.844346 3.9048
66 | -0.3086319 3.5298
67 | -0.3175602 2.869086
68 | -0.6657745 2.386944
69 | -1.344346 1.726231
70 | -2.201489 1.351231
71 | -3.406846 0.985159
72 | -3.978275 0.761944
73 | -3.996132 -0.764841
74 | -3.522917 -0.764841
75 | -2.915775 -0.505913
76 | -2.255059 -0.01484108
77 | -1.692559 0.5030155
78 | -1.665774 0.547659
79 | -1.638989 0.5923005
80 | -1.201489 1.083372
81 | -0.9247035 1.333372
82 | -0.692559 0.761944
83 | -0.4336319 0.2083721
84 | -0.281847 -0.1398411
85 | -0.2014885 -0.3719864
86 | -0.2104168 -0.8362715
87 | -0.969346 -1.086272
88 | -2.005059 -1.720198
89 | -2.817559 -2.505913
90 | -3.603275 -3.729128
91 | -3.844346 -4.309486
92 | -4.00506 -5.13984
93 | -4.031846 -6.541625
94 | -3.148857 -6.80234
95 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Data/funny.dat:
--------------------------------------------------------------------------------
1 | 5.12884 4.497508
2 | 7.427565 4.037312
3 | 6.58944 3.679338
4 | 4.881284 3.587903
5 | 4.551455 3.357898
6 | 5.247345 2.829246
7 | 7.23398 1.678099
8 | 6.72482 1.386204
9 | 6.815245 0.8128995
10 | 6.17534 0.650207
11 | 7.12237 -0.5951205
12 | 6.31419 -0.63259
13 | 6.099315 -1.124049
14 | 7.35435 -3.213781
15 | 7.90099 -4.916594
16 | 7.46028 -5.615205
17 | 6.8108 -6.05659
18 | 6.134885 -6.456325
19 | 5.289895 -6.504025
20 | 4.649079 -6.959405
21 | 3.975678 -7.3907
22 | 2.855519 -6.18403
23 | 2.455232 -7.781085
24 | 1.679631 -7.903925
25 | 0.8978475 -7.977825
26 | 0.1129662 -8.002495
27 | -0.5615475 -6.223575
28 | -1.380208 -7.32218
29 | -2.126749 -7.24349
30 | -2.395637 -5.272855
31 | -3.354605 -6.17458
32 | -3.673241 -5.06536
33 | -4.689016 -5.707225
34 | -5.908955 -6.456325
35 | -6.242925 -5.517775
36 | -5.85294 -3.713859
37 | -6.404895 -3.381232
38 | -5.48746 -1.466341
39 | -7.02129 -2.202006
40 | -5.76986 -0.3691902
41 | -6.168145 -0.0659857
42 | -5.59906 0.872545
43 | -7.935025 0.0730872
44 | -6.811825 1.238948
45 | -5.036545 2.458673
46 | -6.96125 2.198955
47 | -4.78215 3.240655
48 | -5.732615 3.382404
49 | -7.166395 3.57791
50 | -9.078655 3.919219
51 | -9.39346 4.497508
52 | -7.77108 4.99353
53 | -9.196035 5.67351
54 | -7.923125 6.030475
55 | -7.06896 6.341515
56 | -7.043145 6.82267
57 | -4.816876 6.44937
58 | -4.231605 6.541905
59 | -4.078031 6.80153
60 | -1.997854 5.837075
61 | -1.909577 5.96697
62 | -1.813317 6.091065
63 | -2.213663 6.68236
64 | -1.598402 6.31993
65 | -1.787933 6.7953
66 | -1.356497 6.52005
67 | -1.226601 6.608325
68 | -1.458543 7.35607
69 | -0.9890445 6.8394
70 | -1.274948 8.00298
71 | -1.232087 8.637155
72 | -0.572711 7.168045
73 | -0.4077884 7.2274
74 | -0.2003669 6.977795
75 | -0.04401016 6.992575
76 | 0.1129662 6.99751
77 | 0.2882522 7.2836
78 | 0.4262992 6.977795
79 | 0.8266735 8.238895
80 | 1.10079 8.344825
81 | 1.347829 8.29802
82 | 1.353338 7.63033
83 | 1.527081 7.502655
84 | 1.968096 7.871975
85 | 2.706897 8.58489
86 | 2.417588 7.66955
87 | 1.829667 6.572645
88 | 1.824334 6.31993
89 | 2.29568 6.54721
90 | 2.039249 6.091065
91 | 2.135509 5.96697
92 | 2.223786 5.837075
93 | 2.74639 5.945245
94 | 4.432265 6.530015
95 | 6.458825 7.01001
96 | 4.273882 5.84947
97 | 5.601705 5.906775
98 | 5.385965 5.503385
99 | 6.095985 5.25334
100 | 3.828126 4.731246
101 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Data/star.dat:
--------------------------------------------------------------------------------
1 | -7.629395E-06 -12.53631
2 | 2.899994 -3.93631
3 | 11.89999 -3.93631
4 | 4.699993 1.46369
5 | 7.299992 10.06369
6 | -7.629395E-06 4.96369
7 | -7.300007 10.06369
8 | -4.700006 1.46369
9 | -11.90001 -3.93631
10 | -2.900005 -3.93631
11 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Data/strange.dat:
--------------------------------------------------------------------------------
1 | 1.374089 8.641284
2 | 5.374088 5.441284
3 | 6.174088 0.6412848
4 | 3.774089 -0.9587151
5 | 8.574088 -1.758715
6 | 4.574088 -4.158716
7 | -0.2259109 -3.358715
8 | -0.2259109 -8.158716
9 | -2.625911 -5.758716
10 | -6.625912 -8.958716
11 | -9.825912 -6.558716
12 | -6.625912 -7.358716
13 | -1.025911 0.6412848
14 | -6.305912 -1.758715
15 | -7.425912 3.841285
16 | -2.625911 2.241285
17 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Framework/GameSettings.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Framework
2 | {
3 | public class GameSettings
4 | {
5 | public float Hz;
6 | public bool Pause;
7 | public bool SingleStep;
8 |
9 | public GameSettings()
10 | {
11 | Hz = 60.0f;
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Framework/Input/GamePadManager.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Input;
3 |
4 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Framework.Input
5 | {
6 | public class GamePadManager
7 | {
8 | public GamePadState OldState;
9 | public GamePadState NewState;
10 |
11 | public GamePadManager()
12 | {
13 | OldState = NewState = GamePad.GetState(PlayerIndex.One);
14 | }
15 |
16 | public bool IsConnected => NewState.IsConnected;
17 |
18 | public bool IsNewButtonPress(Buttons button)
19 | {
20 | return NewState.IsButtonDown(button) && OldState.IsButtonUp(button);
21 | }
22 |
23 | public void Update()
24 | {
25 | OldState = NewState;
26 | NewState = GamePad.GetState(PlayerIndex.One);
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Framework/Input/KeyboardManager.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework.Input;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Framework.Input
4 | {
5 | public class KeyboardManager
6 | {
7 | internal KeyboardState _oldState;
8 | internal KeyboardState _newState;
9 |
10 | public KeyboardManager()
11 | {
12 | _oldState = _newState = Keyboard.GetState();
13 | }
14 |
15 | public void Update()
16 | {
17 | _oldState = _newState;
18 | _newState = Keyboard.GetState();
19 | }
20 |
21 | public bool IsNewKeyPress(Keys key)
22 | {
23 | return _newState.IsKeyDown(key) && _oldState.IsKeyUp(key);
24 | }
25 |
26 | public bool IsKeyDown(Keys key)
27 | {
28 | return _newState.IsKeyDown(key);
29 | }
30 |
31 | internal bool IsKeyUp(Keys key)
32 | {
33 | return _newState.IsKeyUp(key);
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Framework/Input/MouseButton.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Framework.Input
2 | {
3 | public enum MouseButton
4 | {
5 | Left,
6 | Right,
7 | Middle
8 | }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Framework/Rand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Framework
4 | {
5 | public static class Rand
6 | {
7 | private static readonly Random _random = new Random();
8 |
9 | /// Random number in range [-1,1]
10 | public static float RandomFloat()
11 | {
12 | return (float)(_random.NextDouble() * 2.0 - 1.0);
13 | }
14 |
15 | /// Random floating point number in range [lo, hi]
16 | /// The lo.
17 | /// The hi.
18 | public static float RandomFloat(float lo, float hi)
19 | {
20 | float r = (float)_random.NextDouble();
21 | r = (hi - lo) * r + lo;
22 | return r;
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed
4 | {
5 | public static class Program
6 | {
7 | [STAThread]
8 | private static void Main()
9 | {
10 | using (Game1 game = new Game1())
11 | {
12 | game.Run();
13 | }
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Tests/Velcro/BuoyancyTest.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 | using Genbox.VelcroPhysics.Extensions.Controllers.Buoyancy;
3 | using Genbox.VelcroPhysics.Factories;
4 | using Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Framework;
5 | using Genbox.VelcroPhysics.Shared;
6 | using Microsoft.Xna.Framework;
7 |
8 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Tests.Velcro
9 | {
10 | public class BuoyancyTest : Test
11 | {
12 | private BuoyancyTest()
13 | {
14 | World.Gravity = new Vector2(0, -9.82f);
15 |
16 | BodyFactory.CreateEdge(World, new Vector2(-40, 0), new Vector2(40, 0));
17 |
18 | float offset = 5;
19 | for (int i = 0; i < 3; i++)
20 | {
21 | Body rectangle = BodyFactory.CreateRectangle(World, 2, 2, 1, new Vector2(-30 + offset, 20));
22 | rectangle.Rotation = Rand.RandomFloat(0, 3.14f);
23 | rectangle.BodyType = BodyType.Dynamic;
24 | offset += 7;
25 | }
26 |
27 | for (int i = 0; i < 3; i++)
28 | {
29 | Body rectangle = BodyFactory.CreateCircle(World, 1, 1, new Vector2(-30 + offset, 20));
30 | rectangle.Rotation = Rand.RandomFloat(0, 3.14f);
31 | rectangle.BodyType = BodyType.Dynamic;
32 | offset += 7;
33 | }
34 |
35 | AABB container = new AABB(new Vector2(0, 10), 60, 10);
36 | BuoyancyController buoyancy = new BuoyancyController(container, 2, 2, 1, World.Gravity);
37 | World.AddController(buoyancy);
38 | }
39 |
40 | internal static Test Create()
41 | {
42 | return new BuoyancyTest();
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Tests/Velcro/CirclePenetrationTest.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Genbox.VelcroPhysics.Dynamics;
3 | using Genbox.VelcroPhysics.Factories;
4 | using Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Framework;
5 | using Genbox.VelcroPhysics.Shared;
6 | using Genbox.VelcroPhysics.Utilities;
7 | using Microsoft.Xna.Framework;
8 |
9 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Tests.Velcro
10 | {
11 | public class CirclePenetrationTest : Test
12 | {
13 | private CirclePenetrationTest()
14 | {
15 | World.Gravity = Vector2.Zero;
16 |
17 | List borders = new List(4);
18 |
19 | const float borderWidth = 0.2f;
20 | const float width = 40f;
21 | const float height = 25f;
22 |
23 | //Bottom
24 | borders.Add(PolygonUtils.CreateRectangle(width, borderWidth, new Vector2(0, height), 0));
25 |
26 | //Left
27 | borders.Add(PolygonUtils.CreateRectangle(borderWidth, height, new Vector2(-width, 0), 0));
28 |
29 | //Top
30 | borders.Add(PolygonUtils.CreateRectangle(width, borderWidth, new Vector2(0, -height), 0));
31 |
32 | //Right
33 | borders.Add(PolygonUtils.CreateRectangle(borderWidth, height, new Vector2(width, 0), 0));
34 |
35 | Body body = BodyFactory.CreateCompoundPolygon(World, borders, 1, new Vector2(0, 20));
36 |
37 | foreach (Fixture fixture in body.FixtureList)
38 | {
39 | fixture.Restitution = 1f;
40 | fixture.Friction = 0;
41 | }
42 |
43 | Body circle = BodyFactory.CreateCircle(World, 0.32f, 1);
44 | circle.BodyType = BodyType.Dynamic;
45 | circle.Restitution = 1f;
46 | circle.Friction = 0;
47 |
48 | circle.ApplyLinearImpulse(new Vector2(200, 50));
49 | }
50 |
51 | internal static Test Create()
52 | {
53 | return new CirclePenetrationTest();
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Tests/Velcro/DeletionTest.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 | using Genbox.VelcroPhysics.Dynamics;
3 | using Genbox.VelcroPhysics.Factories;
4 | using Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Framework;
5 | using Microsoft.Xna.Framework;
6 |
7 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Tests.Velcro
8 | {
9 | public class DeletionTest : Test
10 | {
11 | private DeletionTest()
12 | {
13 | //Ground body
14 | Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
15 | ground.OnCollision += OnCollision;
16 | ground.OnSeparation += OnSeparation;
17 | }
18 |
19 | private void OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact) { }
20 |
21 | private void OnSeparation(Fixture fixtureA, Fixture fixtureB, Contact contact)
22 | {
23 | fixtureB.Body.RemoveFromWorld();
24 | }
25 |
26 | public override void Update(GameSettings settings, GameTime gameTime)
27 | {
28 | Body body = BodyFactory.CreateCircle(World, 0.4f, 1);
29 | body.Position = new Vector2(Rand.RandomFloat(-35, 35), 10);
30 | body.BodyType = BodyType.Dynamic;
31 | body.Restitution = 1f;
32 |
33 | base.Update(settings, gameTime);
34 | }
35 |
36 | internal static Test Create()
37 | {
38 | return new DeletionTest();
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/Tests/Velcro/LockTest.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 | using Genbox.VelcroPhysics.Dynamics;
3 | using Genbox.VelcroPhysics.Factories;
4 | using Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Framework;
5 | using Microsoft.Xna.Framework;
6 |
7 | namespace Genbox.VelcroPhysics.MonoGame.Samples.Testbed.Tests.Velcro
8 | {
9 | public class LockTest : Test
10 | {
11 | private readonly Body _rectangle;
12 |
13 | private LockTest()
14 | {
15 | BodyFactory.CreateEdge(World, new Vector2(-20, 0), new Vector2(20, 0));
16 |
17 | _rectangle = BodyFactory.CreateRectangle(World, 2, 2, 1);
18 | _rectangle.BodyType = BodyType.Dynamic;
19 | _rectangle.Position = new Vector2(0, 10);
20 | _rectangle.OnCollision += OnCollision;
21 |
22 | //Properties and methods that were checking for lock before
23 | //Body.Enabled
24 | //Body.LocalCenter
25 | //Body.Mass
26 | //Body.Inertia
27 | //Fixture.DestroyFixture()
28 | //Body.SetTransformIgnoreContacts()
29 | //Fixture()
30 | }
31 |
32 | private void OnCollision(Fixture fixturea, Fixture fixtureb, Contact manifold)
33 | {
34 | //_rectangle.CreateFixture(_rectangle.Shape); //Calls the constructor in Fixture
35 | //_rectangle.DestroyFixture(_rectangle);
36 | //_rectangle.Inertia = 40;
37 | //_rectangle.LocalCenter = new Vector2(-1, -1);
38 | //_rectangle.Mass = 10;
39 | _rectangle.Enabled = false;
40 | }
41 |
42 | internal static Test Create()
43 | {
44 | return new LockTest();
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/VelcroPhysics.MonoGame.Samples.Testbed.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0
6 | false
7 | false
8 | false
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | PreserveNewest
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.MonoGame.Samples.Testbed/app.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | true/pm
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.Tests/Code/Dummy.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Tests.Code
2 | {
3 | public class Dummy { }
4 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Tests/Code/PoolObject.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared.Optimization;
2 |
3 | namespace Genbox.VelcroPhysics.Tests.Code
4 | {
5 | internal sealed class PoolObject : IPoolable
6 | {
7 | public PoolObject()
8 | {
9 | IsNew = true;
10 | }
11 |
12 | public bool IsNew { get; private set; }
13 |
14 | public void Dispose() { }
15 |
16 | public void Reset()
17 | {
18 | IsNew = false;
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Tests/Tests/MathTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Genbox.VelcroPhysics.Collision.TOI;
3 | using Genbox.VelcroPhysics.Shared;
4 | using Microsoft.Xna.Framework;
5 | using Xunit;
6 |
7 | namespace Genbox.VelcroPhysics.Tests.Tests
8 | {
9 | public class MathTest
10 | {
11 | [Fact]
12 | public void SweepGetTransform()
13 | {
14 | // From issue https://github.com/erincatto/box2d/issues/447
15 | Sweep sweep = new Sweep();
16 | sweep.LocalCenter = Vector2.Zero;
17 | sweep.C0 = new Vector2(-2.0f, 4.0f);
18 | sweep.C = new Vector2(3.0f, 8.0f);
19 | sweep.A0 = 0.5f;
20 | sweep.A = 5.0f;
21 | sweep.Alpha0 = 0.0f;
22 |
23 | sweep.GetTransform(out Transform transform, 0.0f);
24 | Assert.Equal(transform.p.X, sweep.C0.X);
25 | Assert.Equal(transform.p.Y, sweep.C0.Y);
26 | Assert.Equal(transform.q.c, (float)Math.Cos(sweep.A0));
27 | Assert.Equal(transform.q.s, (float)Math.Sin(sweep.A0));
28 |
29 | sweep.GetTransform(out transform, 1.0f);
30 | Assert.Equal(transform.p.X, sweep.C.X);
31 | Assert.Equal(transform.p.Y, sweep.C.Y);
32 | Assert.Equal(transform.q.c, (float)Math.Cos(sweep.A));
33 | Assert.Equal(transform.q.s, (float)Math.Sin(sweep.A));
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Tests/Tests/Shared/AABBTests.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared;
2 | using Microsoft.Xna.Framework;
3 | using Xunit;
4 |
5 | namespace Genbox.VelcroPhysics.Tests.Tests.Shared
6 | {
7 | public class AABBTests
8 | {
9 | [Fact]
10 | public void TestOverlap()
11 | {
12 | {
13 | AABB bb1 = new AABB(new Vector2(-2, -3), new Vector2(-1, 0));
14 | Assert.True(AABB.TestOverlap(ref bb1, ref bb1));
15 | }
16 | {
17 | Vector2 vec = new Vector2(-2, -3);
18 | AABB bb1 = new AABB(vec, vec);
19 | Assert.True(AABB.TestOverlap(ref bb1, ref bb1));
20 | }
21 | {
22 | AABB bb1 = new AABB(new Vector2(-2, -3), new Vector2(-1, 0));
23 | AABB bb2 = new AABB(new Vector2(-1, -1), new Vector2(1, 2));
24 | Assert.True(AABB.TestOverlap(ref bb1, ref bb2));
25 | }
26 | {
27 | AABB bb1 = new AABB(new Vector2(-99, -3), new Vector2(-1, 0));
28 | AABB bb2 = new AABB(new Vector2(76, -1), new Vector2(-2, 2));
29 | Assert.True(AABB.TestOverlap(ref bb1, ref bb2));
30 | }
31 | {
32 | AABB bb1 = new AABB(new Vector2(-20, -3), new Vector2(-18, 0));
33 | AABB bb2 = new AABB(new Vector2(-1, -1), new Vector2(1, 2));
34 | Assert.False(AABB.TestOverlap(ref bb1, ref bb2));
35 | }
36 | {
37 | AABB bb1 = new AABB(new Vector2(-2, -3), new Vector2(-1, 0));
38 | AABB bb2 = new AABB(new Vector2(-1, +1), new Vector2(1, 2));
39 | Assert.False(AABB.TestOverlap(ref bb1, ref bb2));
40 | }
41 | {
42 | AABB bb1 = new AABB(new Vector2(-2, +3), new Vector2(-1, 0));
43 | AABB bb2 = new AABB(new Vector2(-1, -1), new Vector2(0, -2));
44 | Assert.False(AABB.TestOverlap(ref bb1, ref bb2));
45 | }
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics.Tests/VelcroPhysics.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | false
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/VelcroPhysics.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio Version 16
3 | VisualStudioVersion = 16.0.31129.286
4 | MinimumVisualStudioVersion = 15.0.26124.0
5 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VelcroPhysics", "VelcroPhysics\VelcroPhysics.csproj", "{CA4BCD54-BEAC-4390-8881-B7FB9DE16D3F}"
6 | EndProject
7 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VelcroPhysics.Benchmarks", "VelcroPhysics.Benchmarks\VelcroPhysics.Benchmarks.csproj", "{6870463C-D00A-49C6-9CDE-21BB838C3750}"
8 | EndProject
9 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VelcroPhysics.Tests", "VelcroPhysics.Tests\VelcroPhysics.Tests.csproj", "{61187505-7CCE-4E78-9272-A971C556BF82}"
10 | EndProject
11 | Global
12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
13 | Debug|Any CPU = Debug|Any CPU
14 | Release|Any CPU = Release|Any CPU
15 | EndGlobalSection
16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
17 | {CA4BCD54-BEAC-4390-8881-B7FB9DE16D3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {CA4BCD54-BEAC-4390-8881-B7FB9DE16D3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {CA4BCD54-BEAC-4390-8881-B7FB9DE16D3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {CA4BCD54-BEAC-4390-8881-B7FB9DE16D3F}.Release|Any CPU.Build.0 = Release|Any CPU
21 | {6870463C-D00A-49C6-9CDE-21BB838C3750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {6870463C-D00A-49C6-9CDE-21BB838C3750}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {6870463C-D00A-49C6-9CDE-21BB838C3750}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {6870463C-D00A-49C6-9CDE-21BB838C3750}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {61187505-7CCE-4E78-9272-A971C556BF82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {61187505-7CCE-4E78-9272-A971C556BF82}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {61187505-7CCE-4E78-9272-A971C556BF82}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {61187505-7CCE-4E78-9272-A971C556BF82}.Release|Any CPU.Build.0 = Release|Any CPU
29 | EndGlobalSection
30 | GlobalSection(SolutionProperties) = preSolution
31 | HideSolutionNode = FALSE
32 | EndGlobalSection
33 | GlobalSection(ExtensibilityGlobals) = postSolution
34 | SolutionGuid = {AA5AE6EB-9A14-4231-B366-D2C70B630712}
35 | EndGlobalSection
36 | EndGlobal
37 |
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/AABBHelper.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared;
2 | using Genbox.VelcroPhysics.Utilities;
3 | using Microsoft.Xna.Framework;
4 |
5 | namespace Genbox.VelcroPhysics.Collision
6 | {
7 | public static class AABBHelper
8 | {
9 | public static void ComputeEdgeAABB(ref Vector2 start, ref Vector2 end, ref Transform transform, out AABB aabb)
10 | {
11 | Vector2 v1 = MathUtils.Mul(ref transform, ref start);
12 | Vector2 v2 = MathUtils.Mul(ref transform, ref end);
13 |
14 | aabb.LowerBound = Vector2.Min(v1, v2);
15 | aabb.UpperBound = Vector2.Max(v1, v2);
16 |
17 | Vector2 r = new Vector2(Settings.PolygonRadius, Settings.PolygonRadius);
18 | aabb.LowerBound -= r;
19 | aabb.UpperBound += r;
20 | }
21 |
22 | public static void ComputeCircleAABB(ref Vector2 pos, float radius, ref Transform transform, out AABB aabb)
23 | {
24 | Vector2 p = transform.p + MathUtils.Mul(transform.q, pos);
25 | aabb.LowerBound = new Vector2(p.X - radius, p.Y - radius);
26 | aabb.UpperBound = new Vector2(p.X + radius, p.Y + radius);
27 | }
28 |
29 | public static void ComputePolygonAABB(Vertices vertices, ref Transform transform, out AABB aabb)
30 | {
31 | Vector2 lower = MathUtils.Mul(ref transform, vertices[0]);
32 | Vector2 upper = lower;
33 |
34 | for (int i = 1; i < vertices.Count; ++i)
35 | {
36 | Vector2 v = MathUtils.Mul(ref transform, vertices[i]);
37 | lower = Vector2.Min(lower, v);
38 | upper = Vector2.Max(upper, v);
39 | }
40 |
41 | Vector2 r = new Vector2(Settings.PolygonRadius, Settings.PolygonRadius);
42 | aabb.LowerBound = lower - r;
43 | aabb.UpperBound = upper + r;
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Broadphase/IBroadPhase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Genbox.VelcroPhysics.Collision.Handlers;
3 | using Genbox.VelcroPhysics.Collision.RayCast;
4 | using Genbox.VelcroPhysics.Dynamics;
5 | using Genbox.VelcroPhysics.Shared;
6 | using Microsoft.Xna.Framework;
7 |
8 | namespace Genbox.VelcroPhysics.Collision.Broadphase
9 | {
10 | public interface IBroadPhase
11 | {
12 | int ProxyCount { get; }
13 |
14 | void UpdatePairs(BroadphaseHandler callback);
15 |
16 | bool TestOverlap(int proxyIdA, int proxyIdB);
17 |
18 | int AddProxy(ref FixtureProxy proxy);
19 |
20 | void RemoveProxy(int proxyId);
21 |
22 | void MoveProxy(int proxyId, ref AABB aabb, Vector2 displacement);
23 |
24 | FixtureProxy GetProxy(int proxyId);
25 |
26 | void TouchProxy(int proxyId);
27 |
28 | void GetFatAABB(int proxyId, out AABB aabb);
29 |
30 | void Query(Func callback, ref AABB aabb);
31 |
32 | void RayCast(Func callback, ref RayCastInput input);
33 |
34 | void ShiftOrigin(ref Vector2 newOrigin);
35 | }
36 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Broadphase/Pair.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.Broadphase
2 | {
3 | internal struct Pair
4 | {
5 | public int ProxyIdA;
6 | public int ProxyIdB;
7 | }
8 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Broadphase/TreeNode.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Broadphase
4 | {
5 | /// A node in the dynamic tree. The client does not interact with this directly.
6 | internal class TreeNode
7 | {
8 | /// Enlarged AABB
9 | internal AABB AABB;
10 |
11 | internal int Child1;
12 | internal int Child2;
13 |
14 | internal int Height;
15 | internal int ParentOrNext;
16 | internal T? UserData;
17 | internal bool Moved;
18 |
19 | internal bool IsLeaf()
20 | {
21 | return Child1 == DynamicTree.NullNode;
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/ContactSystem/ContactEdge.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.ContactSystem
4 | {
5 | ///
6 | /// A contact edge is used to connect bodies and contacts together in a contact graph where each body is a node
7 | /// and each contact is an edge. A contact edge belongs to a doubly linked list maintained in each attached body. Each
8 | /// contact has two contact nodes, one for each attached body.
9 | ///
10 | public sealed class ContactEdge
11 | {
12 | /// The contact
13 | public Contact? Contact;
14 |
15 | /// The next contact edge in the body's contact list
16 | public ContactEdge? Next;
17 |
18 | /// Provides quick access to the other body attached.
19 | public Body? Other;
20 |
21 | /// The previous contact edge in the body's contact list
22 | public ContactEdge? Prev;
23 | }
24 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/ContactSystem/ContactFeature.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.ContactSystem
2 | {
3 | /// The features that intersect to form the contact point This must be 4 bytes or less.
4 | public struct ContactFeature
5 | {
6 | /// Feature index on ShapeA
7 | public byte IndexA;
8 |
9 | /// Feature index on ShapeB
10 | public byte IndexB;
11 |
12 | /// The feature type on ShapeA
13 | public ContactFeatureType TypeA;
14 |
15 | /// The feature type on ShapeB
16 | public ContactFeatureType TypeB;
17 | }
18 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/ContactSystem/ContactFeatureType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.ContactSystem
2 | {
3 | public enum ContactFeatureType : byte
4 | {
5 | Vertex = 0,
6 | Face = 1
7 | }
8 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/ContactSystem/ContactFlags.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.ContactSystem
4 | {
5 | [Flags]
6 | internal enum ContactFlags : byte
7 | {
8 | Unknown = 0,
9 |
10 | /// Used when crawling contact graph when forming islands.
11 | IslandFlag = 1,
12 |
13 | /// Set when the shapes are touching.
14 | TouchingFlag = 2,
15 |
16 | /// This contact can be disabled (by user)
17 | EnabledFlag = 4,
18 |
19 | /// This contact needs filtering because a fixture filter was changed.
20 | FilterFlag = 8,
21 |
22 | /// This bullet contact had a TOI event
23 | BulletHitFlag = 16,
24 |
25 | /// This contact has a valid TOI in m_toi
26 | TOIFlag = 32
27 | }
28 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/ContactSystem/ContactId.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.ContactSystem
4 | {
5 | /// Contact ids to facilitate warm starting.
6 | [StructLayout(LayoutKind.Explicit)]
7 | public struct ContactId
8 | {
9 | /// The features that intersect to form the contact point
10 | [FieldOffset(0)]
11 | public ContactFeature ContactFeature;
12 |
13 | /// Used to quickly compare contact ids.
14 | [FieldOffset(0)]
15 | public uint Key;
16 | }
17 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/ContactSystem/ContactType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.ContactSystem
2 | {
3 | public enum ContactType : byte
4 | {
5 | NotSupported,
6 | Polygon,
7 | PolygonAndCircle,
8 | Circle,
9 | EdgeAndPolygon,
10 | EdgeAndCircle,
11 | ChainAndPolygon,
12 | ChainAndCircle
13 | }
14 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Distance/DistanceInput.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Distance
4 | {
5 | /// Input for Distance.ComputeDistance(). You have to option to use the shape radii in the computation.
6 | public struct DistanceInput
7 | {
8 | public DistanceProxy ProxyA;
9 | public DistanceProxy ProxyB;
10 | public Transform TransformA;
11 | public Transform TransformB;
12 | public bool UseRadii;
13 | }
14 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Distance/DistanceOutput.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Distance
4 | {
5 | /// Output for Distance.ComputeDistance().
6 | public struct DistanceOutput
7 | {
8 | public float Distance;
9 |
10 | /// Number of GJK iterations used
11 | public int Iterations;
12 |
13 | /// Closest point on shapeA
14 | public Vector2 PointA;
15 |
16 | /// Closest point on shapeB
17 | public Vector2 PointB;
18 | }
19 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Distance/ShapeCastInput.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Collision.Distance
5 | {
6 | /// Input parameters for b2ShapeCast
7 | public struct ShapeCastInput
8 | {
9 | public DistanceProxy ProxyA;
10 | public DistanceProxy ProxyB;
11 | public Transform TransformA;
12 | public Transform TransformB;
13 | public Vector2 TranslationB;
14 | }
15 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Distance/ShapeCastOutput.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Distance
4 | {
5 | /// Output results for b2ShapeCast
6 | public struct ShapeCastOutput
7 | {
8 | public Vector2 Point;
9 | public Vector2 Normal;
10 | public float Lambda;
11 | public int Iterations;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Filtering/Category.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Filtering
4 | {
5 | [Flags]
6 | public enum Category
7 | {
8 | None = 0,
9 | All = int.MaxValue,
10 | Cat1 = 1,
11 | Cat2 = 2,
12 | Cat3 = 4,
13 | Cat4 = 8,
14 | Cat5 = 16,
15 | Cat6 = 32,
16 | Cat7 = 64,
17 | Cat8 = 128,
18 | Cat9 = 256,
19 | Cat10 = 512,
20 | Cat11 = 1024,
21 | Cat12 = 2048,
22 | Cat13 = 4096,
23 | Cat14 = 8192,
24 | Cat15 = 16384,
25 | Cat16 = 32768,
26 | Cat17 = 65536,
27 | Cat18 = 131072,
28 | Cat19 = 262144,
29 | Cat20 = 524288,
30 | Cat21 = 1048576,
31 | Cat22 = 2097152,
32 | Cat23 = 4194304,
33 | Cat24 = 8388608,
34 | Cat25 = 16777216,
35 | Cat26 = 33554432,
36 | Cat27 = 67108864,
37 | Cat28 = 134217728,
38 | Cat29 = 268435456,
39 | Cat30 = 536870912,
40 | Cat31 = 1073741824
41 | }
42 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Filtering/Filter.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.Filtering
2 | {
3 | public class Filter
4 | {
5 | public Filter()
6 | {
7 | Group = Settings.DefaultCollisionGroup;
8 | Category = Settings.DefaultFixtureCollisionCategories;
9 | CategoryMask = Settings.DefaultFixtureCollidesWith;
10 | }
11 |
12 | public Filter(short group, Category category, Category mask)
13 | {
14 | Group = group;
15 | Category = category;
16 | CategoryMask = mask;
17 | }
18 |
19 | /// Collision groups allow a certain group of objects to never collide(negative) or always collide (positive).
20 | /// Zero means no collision group. Non-zero group filtering always wins against the mask bits.
21 | public short Group { get; set; }
22 |
23 | /// The collision category bits. Normally you would just set one bit.
24 | public Category Category { get; set; }
25 |
26 | /// The collision mask bits. This states the categories that this shape would accept for collision.
27 | public Category CategoryMask { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Handlers/AfterCollisionHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 | using Genbox.VelcroPhysics.Dynamics;
3 | using Genbox.VelcroPhysics.Dynamics.Solver;
4 |
5 | namespace Genbox.VelcroPhysics.Collision.Handlers
6 | {
7 | public delegate void AfterCollisionHandler(Fixture fixtureA, Fixture fixtureB, Contact contact, ContactVelocityConstraint impulse);
8 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Handlers/BeforeCollisionHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Handlers
4 | {
5 | public delegate bool BeforeCollisionHandler(Fixture fixtureA, Fixture fixtureB);
6 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Handlers/BeginContactHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Handlers
4 | {
5 | /// This delegate is called when a contact is created
6 | public delegate void BeginContactHandler(Contact contact);
7 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Handlers/BroadphaseHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Handlers
4 | {
5 | public delegate void BroadphaseHandler(ref FixtureProxy proxyA, ref FixtureProxy proxyB);
6 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Handlers/CollisionFilterHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Handlers
4 | {
5 | public delegate bool CollisionFilterHandler(Fixture fixtureA, Fixture fixtureB);
6 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Handlers/EndContactHandler.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Velcro Physics:
3 | * Copyright (c) 2017 Ian Qvist
4 | *
5 | * Original source Box2D:
6 | * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
7 | *
8 | * This software is provided 'as-is', without any express or implied
9 | * warranty. In no event will the authors be held liable for any damages
10 | * arising from the use of this software.
11 | * Permission is granted to anyone to use this software for any purpose,
12 | * including commercial applications, and to alter it and redistribute it
13 | * freely, subject to the following restrictions:
14 | * 1. The origin of this software must not be misrepresented; you must not
15 | * claim that you wrote the original software. If you use this software
16 | * in a product, an acknowledgment in the product documentation would be
17 | * appreciated but is not required.
18 | * 2. Altered source versions must be plainly marked as such, and must not be
19 | * misrepresented as being the original software.
20 | * 3. This notice may not be removed or altered from any source distribution.
21 | */
22 |
23 | using Genbox.VelcroPhysics.Collision.ContactSystem;
24 |
25 | namespace Genbox.VelcroPhysics.Collision.Handlers
26 | {
27 | /// This delegate is called when a contact is deleted
28 | public delegate void EndContactHandler(Contact contact);
29 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Handlers/OnCollisionHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 | using Genbox.VelcroPhysics.Dynamics;
3 |
4 | namespace Genbox.VelcroPhysics.Collision.Handlers
5 | {
6 | public delegate void OnCollisionHandler(Fixture fixtureA, Fixture fixtureB, Contact contact);
7 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Handlers/OnSeparationHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 | using Genbox.VelcroPhysics.Dynamics;
3 |
4 | namespace Genbox.VelcroPhysics.Collision.Handlers
5 | {
6 | public delegate void OnSeparationHandler(Fixture fixtureA, Fixture fixtureB, Contact contact);
7 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/ClipVertex.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
5 | {
6 | /// Used for computing contact manifolds.
7 | internal struct ClipVertex
8 | {
9 | public ContactId Id;
10 | public Vector2 V;
11 | }
12 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/EPAxis.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
4 | {
5 | /// This structure is used to keep track of the best separating axis.
6 | public struct EPAxis
7 | {
8 | public Vector2 Normal;
9 | public int Index;
10 | public float Separation;
11 | public EPAxisType Type;
12 | }
13 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/EPAxisType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
2 | {
3 | public enum EPAxisType
4 | {
5 | Unknown,
6 | EdgeA,
7 | EdgeB
8 | }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/Manifold.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared.Optimization;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
5 | {
6 | ///
7 | /// A manifold for two touching convex Shapes.
8 | /// Box2D supports multiple types of contact:
9 | /// - Clip point versus plane with radius
10 | /// - Point versus point with radius (circles)
11 | /// The local point usage depends on the manifold type:
12 | /// - ShapeType.Circles: the local center of circleA
13 | /// - SeparationFunction.FaceA: the center of faceA
14 | /// - SeparationFunction.FaceB: the center of faceB
15 | /// Similarly the local normal usage:
16 | /// - ShapeType.Circles: not used
17 | /// - SeparationFunction.FaceA: the normal on polygonA
18 | /// - SeparationFunction.FaceB: the normal on polygonB
19 | /// We store contacts in this way so that position correction can
20 | /// account for movement, which is critical for continuous physics.
21 | /// All contact scenarios must be expressed in one of these types.
22 | /// This structure is stored across time steps, so we keep it small.
23 | ///
24 | public struct Manifold
25 | {
26 | /// Not use for Type.SeparationFunction.Points
27 | public Vector2 LocalNormal;
28 |
29 | /// Usage depends on manifold type
30 | public Vector2 LocalPoint;
31 |
32 | /// The number of manifold points
33 | public int PointCount;
34 |
35 | /// The points of contact
36 | public FixedArray2 Points;
37 |
38 | public ManifoldType Type;
39 | }
40 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/ManifoldPoint.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
5 | {
6 | ///
7 | /// A manifold point is a contact point belonging to a contact
8 | /// manifold. It holds details related to the geometry and dynamics
9 | /// of the contact points.
10 | /// The local point usage depends on the manifold type:
11 | /// -ShapeType.Circles: the local center of circleB
12 | /// -SeparationFunction.FaceA: the local center of cirlceB or the clip point of polygonB
13 | /// -SeparationFunction.FaceB: the clip point of polygonA
14 | /// This structure is stored across time steps, so we keep it small.
15 | /// Note: the impulses are used for internal caching and may not
16 | /// provide reliable contact forces, especially for high speed collisions.
17 | ///
18 | public struct ManifoldPoint
19 | {
20 | /// Uniquely identifies a contact point between two Shapes
21 | public ContactId Id;
22 |
23 | /// Usage depends on manifold type
24 | public Vector2 LocalPoint;
25 |
26 | /// The non-penetration impulse
27 | public float NormalImpulse;
28 |
29 | /// The friction impulse
30 | public float TangentImpulse;
31 | }
32 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/ManifoldType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
2 | {
3 | public enum ManifoldType
4 | {
5 | Circles,
6 | FaceA,
7 | FaceB
8 | }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/PointState.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
2 | {
3 | /// This is used for determining the state of contact points.
4 | public enum PointState
5 | {
6 | /// Point does not exist
7 | Null,
8 |
9 | /// Point was added in the update
10 | Add,
11 |
12 | /// Point persisted across the update
13 | Persist,
14 |
15 | /// Point was removed in the update
16 | Remove
17 | }
18 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/ReferenceFace.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
4 | {
5 | /// Reference face used for clipping
6 | public struct ReferenceFace
7 | {
8 | public int i1, i2;
9 | public Vector2 v1, v2;
10 | public Vector2 Normal;
11 |
12 | public Vector2 SideNormal1;
13 | public float SideOffset1;
14 |
15 | public Vector2 SideNormal2;
16 | public float SideOffset2;
17 | }
18 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/SimplexCache.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared.Optimization;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
4 | {
5 | /// Used to warm start ComputeDistance. Set count to zero on first call.
6 | public struct SimplexCache
7 | {
8 | /// Length or area
9 | public ushort Count;
10 |
11 | /// Vertices on shape A
12 | public FixedArray3 IndexA;
13 |
14 | /// Vertices on shape B
15 | public FixedArray3 IndexB;
16 |
17 | public float Metric;
18 | }
19 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Narrowphase/SimplexVertex.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.Narrowphase
4 | {
5 | internal struct SimplexVertex
6 | {
7 | /// Barycentric coordinate for closest point
8 | public float A;
9 |
10 | /// wA index
11 | public int IndexA;
12 |
13 | /// wB index
14 | public int IndexB;
15 |
16 | /// wB - wA
17 | public Vector2 W;
18 |
19 | /// Support point in proxyA
20 | public Vector2 WA;
21 |
22 | /// Support point in proxyB
23 | public Vector2 WB;
24 | }
25 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/RayCast/RayCastInput.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.RayCast
4 | {
5 | /// Ray-cast input data.
6 | public struct RayCastInput
7 | {
8 | ///
9 | /// The ray extends from p1 to p1 + maxFraction * (p2 - p1). If you supply a max fraction of 1, the ray extends
10 | /// from p1 to p2. A max fraction of 0.5 makes the ray go from p1 and half way to p2.
11 | ///
12 | public float MaxFraction;
13 |
14 | /// The starting point of the ray.
15 | public Vector2 Point1;
16 |
17 | /// The ending point of the ray.
18 | public Vector2 Point2;
19 | }
20 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/RayCast/RayCastOutput.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.RayCast
4 | {
5 | /// Ray-cast output data.
6 | public struct RayCastOutput
7 | {
8 | ///
9 | /// The ray hits at p1 + fraction * (p2 - p1), where p1 and p2 come from RayCastInput. Contains the actual
10 | /// fraction of the ray where it has the intersection point.
11 | ///
12 | public float Fraction;
13 |
14 | /// The normal of the face of the shape the ray has hit.
15 | public Vector2 Normal;
16 | }
17 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/Shapes/ShapeType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.Shapes
2 | {
3 | public enum ShapeType
4 | {
5 | Unknown = -1,
6 | Circle = 0,
7 | Edge = 1,
8 | Polygon = 2,
9 | Chain = 3,
10 | TypeCount = 4
11 | }
12 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/TOI/SeparationFunctionType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.TOI
2 | {
3 | public enum SeparationFunctionType
4 | {
5 | Points,
6 | FaceA,
7 | FaceB
8 | }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/TOI/TOIInput.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Distance;
2 |
3 | namespace Genbox.VelcroPhysics.Collision.TOI
4 | {
5 | /// Input parameters for CalculateTimeOfImpact
6 | public struct TOIInput
7 | {
8 | public DistanceProxy ProxyA;
9 | public DistanceProxy ProxyB;
10 | public Sweep SweepA;
11 | public Sweep SweepB;
12 | public float TMax; // defines sweep interval [0, tMax]
13 | }
14 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/TOI/TOIOutput.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.TOI
2 | {
3 | public struct TOIOutput
4 | {
5 | public TOIOutputState State;
6 | public float T;
7 | }
8 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/TOI/TOIOutputState.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Collision.TOI
2 | {
3 | public enum TOIOutputState
4 | {
5 | Unknown,
6 | Failed,
7 | Overlapped,
8 | Touching,
9 | Seperated
10 | }
11 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Collision/TestPointHelper.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared;
2 | using Genbox.VelcroPhysics.Utilities;
3 | using Microsoft.Xna.Framework;
4 |
5 | namespace Genbox.VelcroPhysics.Collision
6 | {
7 | public static class TestPointHelper
8 | {
9 | public static bool TestPointCircle(ref Vector2 pos, float radius, ref Vector2 point, ref Transform transform)
10 | {
11 | Vector2 center = transform.p + MathUtils.Mul(transform.q, pos);
12 | Vector2 d = point - center;
13 | return Vector2.Dot(d, d) <= radius * radius;
14 | }
15 |
16 | public static bool TestPointPolygon(Vertices vertices, Vertices normals, ref Vector2 point, ref Transform transform)
17 | {
18 | Vector2 pLocal = MathUtils.MulT(transform.q, point - transform.p);
19 |
20 | for (int i = 0; i < vertices.Count; ++i)
21 | {
22 | float dot = Vector2.Dot(normals[i], pLocal - vertices[i]);
23 | if (dot > 0.0f)
24 | return false;
25 | }
26 |
27 | return true;
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/FixtureDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Filtering;
2 | using Genbox.VelcroPhysics.Collision.Shapes;
3 |
4 | namespace Genbox.VelcroPhysics.Definitions
5 | {
6 | public class FixtureDef : IDef
7 | {
8 | public FixtureDef()
9 | {
10 | SetDefaults();
11 | }
12 |
13 | //Velcro: removed density from fixtures. It is only present on shapes
14 |
15 | /// Contact filtering data.
16 | public Filter Filter { get; set; }
17 |
18 | /// The friction coefficient, usually in the range [0,1].
19 | public float Friction { get; set; }
20 |
21 | /// A sensor shape collects contact information but never generates a collision response.
22 | public bool IsSensor { get; set; }
23 |
24 | /// The restitution (elasticity) usually in the range [0,1].
25 | public float Restitution { get; set; }
26 |
27 | ///
28 | /// Restitution velocity threshold, usually in m/s. Collisions above this speed have restitution applied (will bounce).
29 | ///
30 | public float RestitutionThreshold { get; set; }
31 |
32 | /// The shape, this must be set. The shape will be cloned, so you can create the shape on the stack.
33 | public Shape Shape { get; set; }
34 |
35 | /// Use this to store application specific fixture data.
36 | public object? UserData { get; set; }
37 |
38 | public void SetDefaults()
39 | {
40 | Shape = null;
41 | Friction = 0.2f;
42 | Restitution = 0.0f;
43 | RestitutionThreshold = 1.0f;
44 | IsSensor = false;
45 | Filter = new Filter();
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/IDef.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Definitions
2 | {
3 | public interface IDef
4 | {
5 | void SetDefaults();
6 | }
7 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Joints/FixedMouseJointDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics.Joints.Misc;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Definitions.Joints
5 | {
6 | /// Mouse joint definition. This requires a world target point, tuning parameters, and the time step.
7 | public sealed class FixedMouseJointDef : JointDef
8 | {
9 | public FixedMouseJointDef() : base(JointType.FixedMouse)
10 | {
11 | SetDefaults();
12 | }
13 |
14 | /// The linear damping in N*s/m
15 | public float Damping { get; set; }
16 |
17 | /// The linear stiffness in N/m
18 | public float Stiffness { get; set; }
19 |
20 | /// The maximum constraint force that can be exerted to move the candidate body. Usually you will express as some
21 | /// multiple of the weight (multiplier * mass * gravity).
22 | public float MaxForce { get; set; }
23 |
24 | /// The initial world target point. This is assumed to coincide with the body anchor initially.
25 | public Vector2 Target { get; set; }
26 |
27 | public override void SetDefaults()
28 | {
29 | Target = Vector2.Zero;
30 | MaxForce = 0.0f;
31 | Stiffness = 0.0f;
32 | Damping = 0.0f;
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Joints/FrictionJointDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics.Joints.Misc;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Definitions.Joints
5 | {
6 | public sealed class FrictionJointDef : JointDef
7 | {
8 | public FrictionJointDef() : base(JointType.Friction)
9 | {
10 | SetDefaults();
11 | }
12 |
13 | /// The local anchor point relative to bodyA's origin.
14 | public Vector2 LocalAnchorA { get; set; }
15 |
16 | /// The local anchor point relative to bodyB's origin.
17 | public Vector2 LocalAnchorB { get; set; }
18 |
19 | /// The maximum friction force in N.
20 | public float MaxForce { get; set; }
21 |
22 | /// The maximum friction torque in N-m.
23 | public float MaxTorque { get; set; }
24 |
25 | public override void SetDefaults()
26 | {
27 | LocalAnchorA = Vector2.Zero;
28 | LocalAnchorB = Vector2.Zero;
29 | MaxForce = 0.0f;
30 | MaxTorque = 0.0f;
31 |
32 | base.SetDefaults();
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Joints/GearJointDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics.Joints;
2 | using Genbox.VelcroPhysics.Dynamics.Joints.Misc;
3 |
4 | namespace Genbox.VelcroPhysics.Definitions.Joints
5 | {
6 | public sealed class GearJointDef : JointDef
7 | {
8 | public GearJointDef() : base(JointType.Gear)
9 | {
10 | SetDefaults();
11 | }
12 |
13 | /// The first revolute/prismatic joint attached to the gear joint.
14 | public Joint JointA { get; set; }
15 |
16 | /// The second revolute/prismatic joint attached to the gear joint.
17 | public Joint JointB { get; set; }
18 |
19 | /// The gear ratio.
20 | public float Ratio { get; set; }
21 |
22 | public override void SetDefaults()
23 | {
24 | JointA = null;
25 | JointB = null;
26 | Ratio = 1.0f;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Joints/JointDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 | using Genbox.VelcroPhysics.Dynamics.Joints.Misc;
3 |
4 | namespace Genbox.VelcroPhysics.Definitions.Joints
5 | {
6 | public abstract class JointDef : IDef
7 | {
8 | protected JointDef(JointType type)
9 | {
10 | Type = type;
11 | }
12 |
13 | /// The first attached body.
14 | public Body BodyA { get; set; }
15 |
16 | /// The second attached body.
17 | public Body BodyB { get; set; }
18 |
19 | /// Set this flag to true if the attached bodies should collide.
20 | public bool CollideConnected { get; set; }
21 |
22 | /// The joint type is set automatically for concrete joint types.
23 | public JointType Type { get; }
24 |
25 | /// Use this to attach application specific data.
26 | public object UserData { get; set; }
27 |
28 | public virtual void SetDefaults()
29 | {
30 | BodyA = null;
31 | BodyB = null;
32 | CollideConnected = false;
33 | UserData = null;
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Joints/MotorJointDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 | using Genbox.VelcroPhysics.Dynamics.Joints.Misc;
3 | using Microsoft.Xna.Framework;
4 |
5 | namespace Genbox.VelcroPhysics.Definitions.Joints
6 | {
7 | public sealed class MotorJointDef : JointDef
8 | {
9 | public MotorJointDef() : base(JointType.Motor)
10 | {
11 | SetDefaults();
12 | }
13 |
14 | /// The bodyB angle minus bodyA angle in radians.
15 | public float AngularOffset { get; set; }
16 |
17 | /// Position correction factor in the range [0,1].
18 | public float CorrectionFactor { get; set; }
19 |
20 | /// Position of bodyB minus the position of bodyA, in bodyA's frame, in meters.
21 | public Vector2 LinearOffset { get; set; }
22 |
23 | /// The maximum motor force in N.
24 | public float MaxForce { get; set; }
25 |
26 | /// The maximum motor torque in N-m.
27 | public float MaxTorque { get; set; }
28 |
29 | public void Initialize(Body bA, Body bB)
30 | {
31 | BodyA = bA;
32 | BodyB = bB;
33 | Vector2 xB = BodyB.Position;
34 | LinearOffset = BodyA.GetLocalPoint(xB);
35 |
36 | float angleA = BodyA.Rotation;
37 | float angleB = BodyB.Rotation;
38 | AngularOffset = angleB - angleA;
39 | }
40 |
41 | public override void SetDefaults()
42 | {
43 | LinearOffset = Vector2.Zero;
44 | AngularOffset = 0.0f;
45 | MaxForce = 1.0f;
46 | MaxTorque = 1.0f;
47 | CorrectionFactor = 0.3f;
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Joints/WeldJointDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 | using Genbox.VelcroPhysics.Dynamics.Joints.Misc;
3 | using Microsoft.Xna.Framework;
4 |
5 | namespace Genbox.VelcroPhysics.Definitions.Joints
6 | {
7 | /// Weld joint definition. You need to specify local anchor points where they are attached and the relative body
8 | /// angle. The position of the anchor points is important for computing the reaction torque.
9 | public sealed class WeldJointDef : JointDef
10 | {
11 | public WeldJointDef() : base(JointType.Weld)
12 | {
13 | SetDefaults();
14 | }
15 |
16 | /// The rotational damping in N*m*s
17 | public float Damping { get; set; }
18 |
19 | /// The rotational stiffness in N*m. Disable softness with a value of 0
20 | public float Stiffness { get; set; }
21 |
22 | /// The local anchor point relative to bodyA's origin.
23 | public Vector2 LocalAnchorA { get; set; }
24 |
25 | /// The local anchor point relative to bodyB's origin.
26 | public Vector2 LocalAnchorB { get; set; }
27 |
28 | /// The bodyB angle minus bodyA angle in the reference state (radians).
29 | public float ReferenceAngle { get; set; }
30 |
31 | public void Initialize(Body bA, Body bB, Vector2 anchor)
32 | {
33 | BodyA = bA;
34 | BodyB = bB;
35 | LocalAnchorA = BodyA.GetLocalPoint(anchor);
36 | LocalAnchorB = BodyB.GetLocalPoint(anchor);
37 | ReferenceAngle = BodyB.Rotation - BodyA.Rotation;
38 | }
39 |
40 | public override void SetDefaults()
41 | {
42 | LocalAnchorA = Vector2.Zero;
43 | LocalAnchorB = Vector2.Zero;
44 | ReferenceAngle = 0.0f;
45 | Stiffness = 0.0f;
46 | Damping = 0.0f;
47 |
48 | base.SetDefaults();
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Shapes/ChainShapeDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Shapes;
2 | using Genbox.VelcroPhysics.Shared;
3 | using Microsoft.Xna.Framework;
4 |
5 | namespace Genbox.VelcroPhysics.Definitions.Shapes
6 | {
7 | /// A chain shape is a free form sequence of line segments. The chain has two-sided collision, so you can use
8 | /// inside and outside collision. Therefore, you may use any winding order. Connectivity information is used to create
9 | /// smooth collisions.
10 | /// WARNING: The chain will not collide properly if there are self-intersections.
11 | ///
12 | public sealed class ChainShapeDef : ShapeDef
13 | {
14 | public ChainShapeDef() : base(ShapeType.Chain)
15 | {
16 | SetDefaults();
17 | }
18 |
19 | /// Establish connectivity to a vertex that follows the last vertex.
20 | /// Don't call this for loops.
21 | ///
22 | public Vector2 NextVertex { get; set; }
23 |
24 | /// Establish connectivity to a vertex that precedes the first vertex.
25 | /// Don't call this for loops.
26 | ///
27 | public Vector2 PrevVertex { get; set; }
28 |
29 | /// The vertices. These are not owned/freed by the chain Shape.
30 | public Vertices Vertices { get; set; }
31 |
32 | public override void SetDefaults()
33 | {
34 | NextVertex = Vector2.Zero;
35 | PrevVertex = Vector2.Zero;
36 | Vertices = null;
37 |
38 | base.SetDefaults();
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Shapes/CircleShapeDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Shapes;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Definitions.Shapes
5 | {
6 | public sealed class CircleShapeDef : ShapeDef
7 | {
8 | public CircleShapeDef() : base(ShapeType.Circle)
9 | {
10 | SetDefaults();
11 | }
12 |
13 | /// Get or set the position of the circle
14 | public Vector2 Position { get; set; }
15 |
16 | public override void SetDefaults()
17 | {
18 | Position = Vector2.Zero;
19 | base.SetDefaults();
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Shapes/EdgeShapeDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Shapes;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Definitions.Shapes
5 | {
6 | /// A line segment (edge) shape. These can be connected in chains or loops to other edge shapes. The connectivity
7 | /// information is used to ensure correct contact normals.
8 | public sealed class EdgeShapeDef : ShapeDef
9 | {
10 | public EdgeShapeDef() : base(ShapeType.Edge)
11 | {
12 | SetDefaults();
13 | }
14 |
15 | /// Is true if the edge is connected to an adjacent vertex before vertex 1.
16 | public bool HasVertex0 { get; set; }
17 |
18 | /// Is true if the edge is connected to an adjacent vertex after vertex2.
19 | public bool HasVertex3 { get; set; }
20 |
21 | /// Optional adjacent vertices. These are used for smooth collision.
22 | public Vector2 Vertex0 { get; set; }
23 |
24 | /// These are the edge vertices
25 | public Vector2 Vertex1 { get; set; }
26 |
27 | /// These are the edge vertices
28 | public Vector2 Vertex2 { get; set; }
29 |
30 | /// Optional adjacent vertices. These are used for smooth collision.
31 | public Vector2 Vertex3 { get; set; }
32 |
33 | public override void SetDefaults()
34 | {
35 | HasVertex0 = false;
36 | HasVertex3 = false;
37 | Vertex0 = Vector2.Zero;
38 | Vertex1 = Vector2.Zero;
39 | Vertex2 = Vector2.Zero;
40 | Vertex3 = Vector2.Zero;
41 |
42 | base.SetDefaults();
43 | }
44 | }
45 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Shapes/PolygonShapeDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Shapes;
2 | using Genbox.VelcroPhysics.Shared;
3 |
4 | namespace Genbox.VelcroPhysics.Definitions.Shapes
5 | {
6 | public sealed class PolygonShapeDef : ShapeDef
7 | {
8 | public PolygonShapeDef() : base(ShapeType.Polygon)
9 | {
10 | SetDefaults();
11 | }
12 |
13 | public Vertices Vertices { get; set; }
14 |
15 | public override void SetDefaults()
16 | {
17 | Vertices = null;
18 | base.SetDefaults();
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Definitions/Shapes/ShapeDef.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Shapes;
2 |
3 | namespace Genbox.VelcroPhysics.Definitions.Shapes
4 | {
5 | public abstract class ShapeDef : IDef
6 | {
7 | protected ShapeDef(ShapeType type)
8 | {
9 | ShapeType = type;
10 | }
11 |
12 | /// Gets or sets the density.
13 | public float Density { get; set; }
14 |
15 | /// Radius of the Shape
16 | public float Radius { get; set; }
17 |
18 | /// Get the type of this shape.
19 | public ShapeType ShapeType { get; }
20 |
21 | public virtual void SetDefaults()
22 | {
23 | Density = 0;
24 | Radius = 0;
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/BodyFlags.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Dynamics
4 | {
5 | [Flags]
6 | public enum BodyFlags : byte
7 | {
8 | Unknown = 0,
9 | IslandFlag = 1,
10 | AwakeFlag = 2,
11 | AutoSleepFlag = 4,
12 | BulletFlag = 8,
13 | FixedRotationFlag = 16,
14 | Enabled = 32,
15 | IgnoreCCD = 64
16 | }
17 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/BodyType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Dynamics
2 | {
3 | /// The body type.
4 | public enum BodyType
5 | {
6 | /// Zero velocity, may be manually moved. Note: even static bodies have mass.
7 | Static,
8 |
9 | /// Zero mass, non-zero velocity set by user, moved by solver
10 | Kinematic,
11 |
12 | /// Positive mass, non-zero velocity determined by forces, moved by solver
13 | Dynamic
14 | }
15 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/FixtureProxy.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Broadphase;
2 | using Genbox.VelcroPhysics.Shared;
3 |
4 | namespace Genbox.VelcroPhysics.Dynamics
5 | {
6 | /// This proxy is used internally to connect fixtures to the broad-phase.
7 | public struct FixtureProxy
8 | {
9 | public AABB AABB;
10 | public int ChildIndex;
11 | public Fixture Fixture;
12 | public int ProxyId;
13 | }
14 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Handlers/BodyHandler.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Dynamics.Handlers
2 | {
3 | public delegate void BodyHandler(Body body);
4 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Handlers/ControllerHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Extensions.Controllers.ControllerBase;
2 |
3 | namespace Genbox.VelcroPhysics.Dynamics.Handlers
4 | {
5 | public delegate void ControllerHandler(Controller controller);
6 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Handlers/FixtureHandler.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Dynamics.Handlers
2 | {
3 | public delegate void FixtureHandler(Fixture fixture);
4 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Handlers/JointHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics.Joints;
2 |
3 | namespace Genbox.VelcroPhysics.Dynamics.Handlers
4 | {
5 | public delegate void JointHandler(Joint joint);
6 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Handlers/PostSolveHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 | using Genbox.VelcroPhysics.Dynamics.Solver;
3 |
4 | namespace Genbox.VelcroPhysics.Dynamics.Handlers
5 | {
6 | public delegate void PostSolveHandler(Contact contact, ContactVelocityConstraint impulse);
7 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Handlers/PreSolveHandler.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.ContactSystem;
2 | using Genbox.VelcroPhysics.Collision.Narrowphase;
3 |
4 | namespace Genbox.VelcroPhysics.Dynamics.Handlers
5 | {
6 | public delegate void PreSolveHandler(Contact contact, ref Manifold oldManifold);
7 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Joints/Misc/JointEdge.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Dynamics.Joints.Misc
2 | {
3 | ///
4 | /// A joint edge is used to connect bodies and joints together in a joint graph where each body is a node and each
5 | /// joint is an edge. A joint edge belongs to a doubly linked list maintained in each attached body. Each joint has two
6 | /// joint nodes, one for each attached body.
7 | ///
8 | public sealed class JointEdge
9 | {
10 | /// The joint.
11 | public Joint Joint;
12 |
13 | /// The next joint edge in the body's joint list.
14 | public JointEdge Next;
15 |
16 | /// Provides quick access to the other body attached.
17 | public Body Other;
18 |
19 | /// The previous joint edge in the body's joint list.
20 | public JointEdge Prev;
21 | }
22 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Joints/Misc/JointType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Dynamics.Joints.Misc
2 | {
3 | public enum JointType
4 | {
5 | Unknown,
6 | Revolute,
7 | Prismatic,
8 | Distance,
9 | Pulley,
10 |
11 | //Mouse, <- We have fixed mouse
12 | Gear,
13 | Wheel,
14 | Weld,
15 | Friction,
16 | Motor,
17 |
18 | //Velcro note: From here on and down, it is only FPE joints
19 | Angle,
20 | FixedMouse,
21 | FixedRevolute,
22 | FixedDistance,
23 | FixedLine,
24 | FixedPrismatic,
25 | FixedAngle,
26 | FixedFriction
27 | }
28 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Joints/Misc/LimitState.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Dynamics.Joints.Misc
2 | {
3 | public enum LimitState
4 | {
5 | Inactive,
6 | AtLower,
7 | AtUpper,
8 | Equal
9 | }
10 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Profile.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Dynamics
2 | {
3 | public struct Profile
4 | {
5 | ///
6 | /// The time it takes to complete the full World.Step()
7 | ///
8 | public long Step;
9 |
10 | ///
11 | /// The time it takes to find collisions in the CollisionManager
12 | ///
13 | public long Collide;
14 |
15 | ///
16 | /// The time it takes to solve integration of velocities, constraints and integrate positions
17 | ///
18 | public long Solve;
19 |
20 | ///
21 | /// Timings from the island solver. The time it takes to initialize velocity constraints.
22 | ///
23 | public long SolveInit;
24 |
25 | ///
26 | /// Timings from the island solver. It includes the time it takes to solve joint velocity constraints.
27 | ///
28 | public long SolveVelocity;
29 |
30 | ///
31 | /// Timings from the island solver. In includes the time it takes to solve join positions.
32 | ///
33 | public long SolvePosition;
34 |
35 | ///
36 | /// The time it takes for the broad-phase to update
37 | ///
38 | public long Broadphase;
39 |
40 | ///
41 | /// The time it takes for the time-of-impact solver
42 | ///
43 | public long SolveTOI;
44 |
45 | ///
46 | /// Time it takes to process newly added and removed bodies/joints/controllers from the world
47 | ///
48 | public long AddRemoveTime;
49 |
50 | ///
51 | /// The time it takes for the contact manager to find new contacts in the world
52 | ///
53 | public long NewContactsTime;
54 |
55 | ///
56 | /// The time it takes to update controller logic
57 | ///
58 | public long ControllersUpdateTime;
59 |
60 | ///
61 | /// The time it takes to update breakable bodies
62 | ///
63 | public long BreakableBodies;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Solver/ContactPositionConstraint.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Narrowphase;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Dynamics.Solver
5 | {
6 | public sealed class ContactPositionConstraint
7 | {
8 | public int IndexA;
9 | public int IndexB;
10 | public float InvIA, InvIB;
11 | public float InvMassA, InvMassB;
12 | public Vector2 LocalCenterA, LocalCenterB;
13 | public Vector2 LocalNormal;
14 | public Vector2 LocalPoint;
15 | public Vector2[] LocalPoints = new Vector2[Settings.MaxManifoldPoints];
16 | public int PointCount;
17 | public float RadiusA, RadiusB;
18 | public ManifoldType Type;
19 | }
20 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Solver/ContactVelocityConstraint.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Dynamics.Solver
5 | {
6 | public sealed class ContactVelocityConstraint
7 | {
8 | public int ContactIndex;
9 | public float Friction;
10 | public int IndexA;
11 | public int IndexB;
12 | public float InvIA, InvIB;
13 | public float InvMassA, InvMassB;
14 | public Mat22 K;
15 | public Vector2 Normal;
16 | public Mat22 NormalMass;
17 | public int PointCount;
18 | public VelocityConstraintPoint[] Points = new VelocityConstraintPoint[Settings.MaxManifoldPoints];
19 | public float Restitution;
20 | public float Threshold;
21 | public float TangentSpeed;
22 |
23 | public ContactVelocityConstraint()
24 | {
25 | for (int i = 0; i < Settings.MaxManifoldPoints; i++)
26 | {
27 | Points[i] = new VelocityConstraintPoint();
28 | }
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Solver/Position.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Dynamics.Solver
4 | {
5 | /// This is an internal structure.
6 | public struct Position
7 | {
8 | public Vector2 C;
9 | public float A;
10 | }
11 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Solver/SolverData.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Dynamics.Solver
2 | {
3 | internal struct SolverData
4 | {
5 | public TimeStep Step;
6 | public Position[] Positions;
7 | public Velocity[] Velocities;
8 | }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Solver/Velocity.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Dynamics.Solver
4 | {
5 | /// This is an internal structure.
6 | public struct Velocity
7 | {
8 | public Vector2 V;
9 | public float W;
10 | }
11 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/Solver/VelocityConstraintPoint.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Dynamics.Solver
4 | {
5 | public sealed class VelocityConstraintPoint
6 | {
7 | public float NormalImpulse;
8 | public float NormalMass;
9 | public Vector2 rA;
10 | public Vector2 rB;
11 | public float TangentImpulse;
12 | public float TangentMass;
13 | public float VelocityBias;
14 | }
15 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Dynamics/TimeStep.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Original source Box2D:
3 | * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
4 | *
5 | * This software is provided 'as-is', without any express or implied
6 | * warranty. In no event will the authors be held liable for any damages
7 | * arising from the use of this software.
8 | * Permission is granted to anyone to use this software for any purpose,
9 | * including commercial applications, and to alter it and redistribute it
10 | * freely, subject to the following restrictions:
11 | * 1. The origin of this software must not be misrepresented; you must not
12 | * claim that you wrote the original software. If you use this software
13 | * in a product, an acknowledgment in the product documentation would be
14 | * appreciated but is not required.
15 | * 2. Altered source versions must be plainly marked as such, and must not be
16 | * misrepresented as being the original software.
17 | * 3. This notice may not be removed or altered from any source distribution.
18 | */
19 |
20 | namespace Genbox.VelcroPhysics.Dynamics
21 | {
22 | /// This is an internal structure.
23 | internal struct TimeStep
24 | {
25 | /// Time step (Delta time)
26 | public float DeltaTime;
27 |
28 | /// dt * inv_dt0
29 | public float DeltaTimeRatio;
30 |
31 | /// Inverse time step (0 if dt == 0).
32 | public float InvertedDeltaTime;
33 |
34 | public int VelocityIterations;
35 |
36 | public int PositionIterations;
37 |
38 | public bool WarmStarting;
39 | }
40 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/Controllers/ControllerBase/Controller.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 | using Genbox.VelcroPhysics.Extensions.PhysicsLogics.PhysicsLogicBase;
3 |
4 | namespace Genbox.VelcroPhysics.Extensions.Controllers.ControllerBase
5 | {
6 | public abstract class Controller : FilterData
7 | {
8 | private ControllerType _type;
9 | public bool Enabled;
10 | public World World;
11 |
12 | protected Controller(ControllerType controllerType)
13 | {
14 | _type = controllerType;
15 | }
16 |
17 | public override bool IsActiveOn(Body body)
18 | {
19 | if (body.ControllerFilter.IsControllerIgnored(_type))
20 | return false;
21 |
22 | return base.IsActiveOn(body);
23 | }
24 |
25 | public abstract void Update(float dt);
26 | }
27 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/Controllers/ControllerBase/ControllerFilter.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Extensions.Controllers.ControllerBase
2 | {
3 | public struct ControllerFilter
4 | {
5 | public ControllerType ControllerFlags;
6 |
7 | /// Ignores the controller. The controller has no effect on this body.
8 | /// The controller type.
9 | public void IgnoreController(ControllerType controller)
10 | {
11 | ControllerFlags |= controller;
12 | }
13 |
14 | /// Restore the controller. The controller affects this body.
15 | /// The controller type.
16 | public void RestoreController(ControllerType controller)
17 | {
18 | ControllerFlags &= ~controller;
19 | }
20 |
21 | /// Determines whether this body ignores the specified controller.
22 | /// The controller type.
23 | /// true if the body has the specified flag; otherwise, false.
24 | public bool IsControllerIgnored(ControllerType controller)
25 | {
26 | return (ControllerFlags & controller) == controller;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/Controllers/ControllerBase/ControllerType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Extensions.Controllers.ControllerBase
4 | {
5 | [Flags]
6 | public enum ControllerType
7 | {
8 | GravityController = 1 << 0,
9 | VelocityLimitController = 1 << 1,
10 | AbstractForceController = 1 << 2,
11 | BuoyancyController = 1 << 3
12 | }
13 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/Controllers/Gravity/GravityType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Extensions.Controllers.Gravity
2 | {
3 | public enum GravityType
4 | {
5 | Linear,
6 | DistanceSquared
7 | }
8 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/DebugView/DebugViewBase.cs:
--------------------------------------------------------------------------------
1 | /*
2 | * Velcro Physics:
3 | * Copyright (c) 2017 Ian Qvist
4 | */
5 |
6 | using Genbox.VelcroPhysics.Dynamics;
7 | using Genbox.VelcroPhysics.Shared;
8 | using Microsoft.Xna.Framework;
9 |
10 | namespace Genbox.VelcroPhysics.Extensions.DebugView
11 | {
12 | /// Implement and register this class with a World to provide debug drawing of physics entities in your game.
13 | public abstract class DebugViewBase
14 | {
15 | protected DebugViewBase(World world)
16 | {
17 | World = world;
18 | }
19 |
20 | protected World World { get; }
21 |
22 | /// Gets or sets the debug view flags.
23 | /// The flags.
24 | public DebugViewFlags Flags { get; set; }
25 |
26 | /// Append flags to the current flags.
27 | /// The flags.
28 | public void AppendFlags(DebugViewFlags flags)
29 | {
30 | Flags |= flags;
31 | }
32 |
33 | /// Remove flags from the current flags.
34 | /// The flags.
35 | public void RemoveFlags(DebugViewFlags flags)
36 | {
37 | Flags &= ~flags;
38 | }
39 |
40 | /// Draw a closed polygon provided in CCW order.
41 | public abstract void DrawPolygon(Vector2[] vertices, int count, Color color, bool closed = true);
42 |
43 | /// Draw a solid closed polygon provided in CCW order.
44 | public abstract void DrawSolidPolygon(Vector2[] vertices, int count, Color color, bool outline = true);
45 |
46 | /// Draw a circle.
47 | public abstract void DrawCircle(Vector2 center, float radius, Color color);
48 |
49 | /// Draw a solid circle.
50 | public abstract void DrawSolidCircle(Vector2 center, float radius, Vector2 axis, Color color);
51 |
52 | /// Draw a line segment.
53 | public abstract void DrawSegment(Vector2 start, Vector2 end, Color color);
54 |
55 | /// Draw a transform. Choose your own length scale.
56 | /// The transform.
57 | public abstract void DrawTransform(ref Transform transform);
58 | }
59 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/DebugView/DebugViewFlags.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Extensions.DebugView
4 | {
5 | [Flags]
6 | public enum DebugViewFlags
7 | {
8 | /// Do not draw anything
9 | None = 0,
10 |
11 | /// Draw shapes.
12 | Shape = 1 << 0,
13 |
14 | /// Draw joint connections.
15 | Joint = 1 << 1,
16 |
17 | /// Draw axis aligned bounding boxes.
18 | AABB = 1 << 2,
19 |
20 | /// Draw broad-phase pairs.
21 | Pair = (1 << 3),
22 |
23 | /// Draw center of mass frame.
24 | CenterOfMass = 1 << 4,
25 |
26 | /// Draw useful debug data such as timings and number of bodies, joints, contacts and more.
27 | DebugPanel = 1 << 5,
28 |
29 | /// Draw contact points between colliding bodies.
30 | ContactPoints = 1 << 6,
31 |
32 | /// Draw contact normals. Need ContactPoints to be enabled first.
33 | ContactNormals = 1 << 7,
34 |
35 | /// Draws the vertices of polygons.
36 | PolygonPoints = 1 << 8,
37 |
38 | /// Draws the performance graph.
39 | PerformanceGraph = 1 << 9,
40 |
41 | /// Draws controllers.
42 | Controllers = 1 << 10
43 | }
44 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/PhysicsLogics/Explosion/RayDataComparer.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Genbox.VelcroPhysics.Extensions.PhysicsLogics.Explosion
4 | {
5 | /// This is a comparer used for detecting angle difference between rays
6 | internal class RayDataComparer : IComparer
7 | {
8 | int IComparer.Compare(float a, float b)
9 | {
10 | float diff = a - b;
11 | if (diff > 0)
12 | return 1;
13 | if (diff < 0)
14 | return -1;
15 | return 0;
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/PhysicsLogics/PhysicsLogicBase/PhysicsLogic.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 |
3 | namespace Genbox.VelcroPhysics.Extensions.PhysicsLogics.PhysicsLogicBase
4 | {
5 | public abstract class PhysicsLogic : FilterData
6 | {
7 | private PhysicsLogicType _type;
8 | public World World;
9 |
10 | protected PhysicsLogic(World world, PhysicsLogicType type)
11 | {
12 | _type = type;
13 | World = world;
14 | }
15 |
16 | public override bool IsActiveOn(Body body)
17 | {
18 | if (body.PhysicsLogicFilter.IsPhysicsLogicIgnored(_type))
19 | return false;
20 |
21 | return base.IsActiveOn(body);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/PhysicsLogics/PhysicsLogicBase/PhysicsLogicFilter.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Extensions.PhysicsLogics.PhysicsLogicBase
2 | {
3 | public struct PhysicsLogicFilter
4 | {
5 | public PhysicsLogicType ControllerIgnores;
6 |
7 | /// Ignores the controller. The controller has no effect on this body.
8 | /// The logic type.
9 | public void IgnorePhysicsLogic(PhysicsLogicType type)
10 | {
11 | ControllerIgnores |= type;
12 | }
13 |
14 | /// Restore the controller. The controller affects this body.
15 | /// The logic type.
16 | public void RestorePhysicsLogic(PhysicsLogicType type)
17 | {
18 | ControllerIgnores &= ~type;
19 | }
20 |
21 | /// Determines whether this body ignores the specified controller.
22 | /// The logic type.
23 | /// true if the body has the specified flag; otherwise, false.
24 | public bool IsPhysicsLogicIgnored(PhysicsLogicType type)
25 | {
26 | return (ControllerIgnores & type) == type;
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/PhysicsLogics/PhysicsLogicBase/PhysicsLogicType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Extensions.PhysicsLogics.PhysicsLogicBase
4 | {
5 | [Flags]
6 | public enum PhysicsLogicType
7 | {
8 | Explosion = 1 << 0
9 | }
10 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Extensions/PhysicsLogics/PhysicsLogicBase/ShapeData.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 |
3 | namespace Genbox.VelcroPhysics.Extensions.PhysicsLogics.PhysicsLogicBase
4 | {
5 | public struct ShapeData
6 | {
7 | public Body Body;
8 | public float Max;
9 | public float Min; // absolute angles
10 | }
11 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Interfaces/IDebugView.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Collision.Shapes;
2 | using Genbox.VelcroPhysics.Dynamics.Joints;
3 | using Genbox.VelcroPhysics.Shared;
4 | using Microsoft.Xna.Framework;
5 |
6 | namespace Genbox.VelcroPhysics.Interfaces
7 | {
8 | public interface IDebugView
9 | {
10 | void DrawJoint(Joint joint);
11 | void DrawShape(Shape shape, ref Transform transform, Color color);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Primitives/CurveContinuity.cs:
--------------------------------------------------------------------------------
1 | #if STANDARD_IMPLEMENTATION
2 |
3 | // MIT License - Copyright (C) The Mono.Xna Team
4 | // This file is subject to the terms and conditions defined in
5 | // file 'MONOGAME LICENSE.txt', which is part of this source code package.
6 |
7 | // ReSharper disable once CheckNamespace
8 | namespace Microsoft.Xna.Framework
9 | {
10 | /// Defines the continuity of keys on a .
11 | public enum CurveContinuity
12 | {
13 | /// Interpolation can be used between this key and the next.
14 | Smooth,
15 | /// Interpolation cannot be used. A position between the two points returns this point.
16 | Step
17 | }
18 | }
19 | #endif
--------------------------------------------------------------------------------
/src/VelcroPhysics/Primitives/CurveLoopType.cs:
--------------------------------------------------------------------------------
1 | #if STANDARD_IMPLEMENTATION
2 |
3 | // MIT License - Copyright (C) The Mono.Xna Team
4 | // This file is subject to the terms and conditions defined in
5 | // file 'MONOGAME LICENSE.txt', which is part of this source code package.
6 |
7 | // ReSharper disable once CheckNamespace
8 | namespace Microsoft.Xna.Framework
9 | {
10 | ///
11 | /// Defines how the value is determined for position before first point or after the end
12 | /// point on the .
13 | ///
14 | public enum CurveLoopType
15 | {
16 | ///
17 | /// The value of will be evaluated as first point for positions before the beginning and end
18 | /// point for positions after the end.
19 | ///
20 | Constant,
21 | /// The positions will wrap around from the end to beginning of the for determined the value.
22 | Cycle,
23 | ///
24 | /// The positions will wrap around from the end to beginning of the . The value will be offset
25 | /// by the difference between the values of first and end multiplied by the wrap amount. If the
26 | /// position is before the beginning of the the difference will be subtracted from its value;
27 | /// otherwise the difference will be added.
28 | ///
29 | CycleOffset,
30 | ///
31 | /// The value at the end of the act as an offset from the same side of the
32 | /// toward the opposite side.
33 | ///
34 | Oscillate,
35 | /// The linear interpolation will be performed for determined the value.
36 | Linear
37 | }
38 | }
39 | #endif
--------------------------------------------------------------------------------
/src/VelcroPhysics/Primitives/CurveTangent.cs:
--------------------------------------------------------------------------------
1 | #if STANDARD_IMPLEMENTATION
2 |
3 | // MonoGame - Copyright (C) The MonoGame Team
4 | // This file is subject to the terms and conditions defined in
5 | // file 'MONOGAME LICENSE.txt', which is part of this source code package.
6 |
7 | // ReSharper disable once CheckNamespace
8 | namespace Microsoft.Xna.Framework
9 | {
10 | ///
11 | /// Defines the different tangent types to be calculated for points in a
12 | /// .
13 | ///
14 | public enum CurveTangent
15 | {
16 | /// The tangent which always has a value equal to zero.
17 | Flat,
18 | ///
19 | /// The tangent which contains a difference between current tangent value and the tangent value from the previous
20 | /// .
21 | ///
22 | Linear,
23 | ///
24 | /// The smoouth tangent which contains the inflection between and
25 | /// by taking into account the values of both neighbors of the .
26 | ///
27 | Smooth
28 | }
29 | }
30 | #endif
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/Contracts/Contract.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Linq;
5 |
6 | namespace Genbox.VelcroPhysics.Shared.Contracts
7 | {
8 | public static class Contract
9 | {
10 | [Conditional("DEBUG")]
11 | public static void RequireNotNull(object? obj, string message)
12 | {
13 | if (obj != null)
14 | return;
15 |
16 | message = BuildMessage("REQUIRED", message);
17 | throw new RequiredException(message);
18 | }
19 |
20 | [Conditional("DEBUG")]
21 | public static void Requires(bool condition, string message)
22 | {
23 | if (condition)
24 | return;
25 |
26 | message = BuildMessage("REQUIRED", message);
27 | throw new RequiredException(message);
28 | }
29 |
30 | [Conditional("DEBUG")]
31 | public static void Warn(bool condition, string message)
32 | {
33 | message = BuildMessage("WARNING", message);
34 | Debug.WriteLineIf(!condition, message);
35 | }
36 |
37 | [Conditional("DEBUG")]
38 | public static void Ensures(bool condition, string message)
39 | {
40 | if (condition)
41 | return;
42 |
43 | message = BuildMessage("ENSURANCE", message);
44 | throw new EnsuresException(message);
45 | }
46 |
47 | [Conditional("DEBUG")]
48 | public static void RequireForAll(IEnumerable value, Predicate check)
49 | {
50 | foreach (T item in value)
51 | {
52 | Requires(check(item), "Failed on: " + item);
53 | }
54 | }
55 |
56 | [Conditional("DEBUG")]
57 | public static void Fail(string message)
58 | {
59 | message = BuildMessage("FAILURE", message);
60 | throw new RequiredException(message);
61 | }
62 |
63 | private static string BuildMessage(string type, string message)
64 | {
65 | string stackTrace = string.Join(Environment.NewLine, Environment.StackTrace.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Skip(3));
66 | return message == null ? string.Empty : type + ": " + message + Environment.NewLine + stackTrace;
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/Contracts/EnsuresException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Shared.Contracts
4 | {
5 | public class EnsuresException : Exception
6 | {
7 | public EnsuresException(string message) : base(message) { }
8 | }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/Contracts/RequiredException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Shared.Contracts
4 | {
5 | public class RequiredException : Exception
6 | {
7 | public RequiredException(string message) : base(message) { }
8 | }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/GraphNode.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Shared
2 | {
3 | public class GraphNode
4 | {
5 | public GraphNode(T item = default)
6 | {
7 | Item = item;
8 | }
9 |
10 | /// The item.
11 | public T Item { get; set; }
12 |
13 | /// The next item in the list.
14 | public GraphNode Next { get; set; }
15 |
16 | /// The previous item in the list.
17 | public GraphNode Prev { get; set; }
18 |
19 | internal void Invalidate()
20 | {
21 | Next = null;
22 | Prev = null;
23 | }
24 |
25 | public void Clear()
26 | {
27 | Item = default;
28 | Invalidate();
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/Optimization/FixedArray2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | namespace Genbox.VelcroPhysics.Shared.Optimization
6 | {
7 | public struct FixedArray2 : IEnumerable
8 | {
9 | public T Value0, Value1;
10 |
11 | public T this[int index]
12 | {
13 | get
14 | {
15 | switch (index)
16 | {
17 | case 0:
18 | return Value0;
19 | case 1:
20 | return Value1;
21 | default:
22 | throw new IndexOutOfRangeException(nameof(index));
23 | }
24 | }
25 | set
26 | {
27 | switch (index)
28 | {
29 | case 0:
30 | Value0 = value;
31 | break;
32 | case 1:
33 | Value1 = value;
34 | break;
35 | default:
36 | throw new IndexOutOfRangeException(nameof(index));
37 | }
38 | }
39 | }
40 |
41 | public IEnumerator GetEnumerator()
42 | {
43 | return Enumerate().GetEnumerator();
44 | }
45 |
46 | IEnumerator IEnumerable.GetEnumerator()
47 | {
48 | return GetEnumerator();
49 | }
50 |
51 | public int IndexOf(T value)
52 | {
53 | for (int i = 0; i < 2; ++i)
54 | {
55 | if (this[i].Equals(value))
56 | return i;
57 | }
58 | return -1;
59 | }
60 |
61 | public void Clear()
62 | {
63 | Value0 = Value1 = default;
64 | }
65 |
66 | private IEnumerable Enumerate()
67 | {
68 | for (int i = 0; i < 2; ++i)
69 | {
70 | yield return this[i];
71 | }
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/Optimization/FixedArray3.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 |
5 | namespace Genbox.VelcroPhysics.Shared.Optimization
6 | {
7 | public struct FixedArray3 : IEnumerable
8 | {
9 | public T Value0, Value1, Value2;
10 |
11 | public T this[int index]
12 | {
13 | get
14 | {
15 | switch (index)
16 | {
17 | case 0:
18 | return Value0;
19 | case 1:
20 | return Value1;
21 | case 2:
22 | return Value2;
23 | default:
24 | throw new IndexOutOfRangeException(nameof(index));
25 | }
26 | }
27 | set
28 | {
29 | switch (index)
30 | {
31 | case 0:
32 | Value0 = value;
33 | break;
34 | case 1:
35 | Value1 = value;
36 | break;
37 | case 2:
38 | Value2 = value;
39 | break;
40 | default:
41 | throw new IndexOutOfRangeException(nameof(index));
42 | }
43 | }
44 | }
45 |
46 | public IEnumerator GetEnumerator()
47 | {
48 | return Enumerate().GetEnumerator();
49 | }
50 |
51 | IEnumerator IEnumerable.GetEnumerator()
52 | {
53 | return GetEnumerator();
54 | }
55 |
56 | public int IndexOf(T value)
57 | {
58 | for (int i = 0; i < 3; ++i)
59 | {
60 | if (this[i].Equals(value))
61 | return i;
62 | }
63 | return -1;
64 | }
65 |
66 | public void Clear()
67 | {
68 | Value0 = Value1 = Value2 = default;
69 | }
70 |
71 | private IEnumerable Enumerate()
72 | {
73 | for (int i = 0; i < 3; ++i)
74 | {
75 | yield return this[i];
76 | }
77 | }
78 | }
79 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/Optimization/IPoolable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Shared.Optimization
4 | {
5 | public interface IPoolable : IDisposable where T : IPoolable
6 | {
7 | void Reset();
8 | }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/PolygonError.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Shared
2 | {
3 | public enum PolygonError
4 | {
5 | /// There were no errors in the polygon
6 | NoError,
7 |
8 | /// Polygon must have between 3 and Settings.MaxPolygonVertices vertices.
9 | InvalidAmountOfVertices,
10 |
11 | /// Polygon must be simple. This means no overlapping edges.
12 | NotSimple,
13 |
14 | /// Polygon must have a counter clockwise winding.
15 | NotCounterClockWise,
16 |
17 | /// The polygon is concave, it needs to be convex.
18 | NotConvex,
19 |
20 | /// Polygon area is too small.
21 | AreaTooSmall,
22 |
23 | /// The polygon has a side that is too short.
24 | SideTooSmall
25 | }
26 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/Pool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 |
5 | namespace Genbox.VelcroPhysics.Shared
6 | {
7 | public class Pool
8 | {
9 | private readonly Func _objectCreator;
10 | private readonly Action _objectReset;
11 | private readonly Queue _queue;
12 |
13 | public Pool(Func objectCreator, Action objectReset = null, int capacity = 16, bool preCreateInstances = true)
14 | {
15 | _objectCreator = objectCreator;
16 | _objectReset = objectReset;
17 | _queue = new Queue(capacity);
18 |
19 | if (!preCreateInstances)
20 | return;
21 |
22 | for (int i = 0; i < capacity; i++)
23 | {
24 | T obj = objectCreator();
25 | _queue.Enqueue(obj);
26 | }
27 | }
28 |
29 | public int LeftInPool => _queue.Count;
30 |
31 | public T GetFromPool(bool reset = false)
32 | {
33 | if (_queue.Count == 0)
34 | return _objectCreator();
35 |
36 | T obj = _queue.Dequeue();
37 |
38 | if (reset)
39 | _objectReset?.Invoke(obj);
40 |
41 | return obj;
42 | }
43 |
44 | public IEnumerable GetManyFromPool(int count)
45 | {
46 | Debug.Assert(count != 0);
47 |
48 | for (int i = 0; i < count; i++)
49 | {
50 | yield return GetFromPool();
51 | }
52 | }
53 |
54 | public void ReturnToPool(T obj, bool reset = true)
55 | {
56 | if (reset)
57 | _objectReset?.Invoke(obj);
58 |
59 | _queue.Enqueue(obj);
60 | }
61 |
62 | public void ReturnToPool(IEnumerable objs, bool reset = true)
63 | {
64 | foreach (T obj in objs)
65 | {
66 | ReturnToPool(obj, reset);
67 | }
68 | }
69 | }
70 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/Rot.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Shared
5 | {
6 | /// Rotation
7 | public struct Rot
8 | {
9 | /// Sine and cosine
10 | public float s,
11 | c;
12 |
13 | /// Initialize from an angle in radians
14 | /// Angle in radians
15 | public Rot(float angle)
16 | {
17 | // TODO_ERIN optimize
18 | s = (float)Math.Sin(angle);
19 | c = (float)Math.Cos(angle);
20 | }
21 |
22 | /// Set using an angle in radians.
23 | ///
24 | public void Set(float angle)
25 | {
26 | //Velcro: Optimization
27 | if (angle == 0)
28 | {
29 | s = 0;
30 | c = 1;
31 | }
32 | else
33 | {
34 | // TODO_ERIN optimize
35 | s = (float)Math.Sin(angle);
36 | c = (float)Math.Cos(angle);
37 | }
38 | }
39 |
40 | /// Set to the identity rotation
41 | public void SetIdentity()
42 | {
43 | s = 0.0f;
44 | c = 1.0f;
45 | }
46 |
47 | /// Get the angle in radians
48 | public float GetAngle()
49 | {
50 | return (float)Math.Atan2(s, c);
51 | }
52 |
53 | /// Get the x-axis
54 | public Vector2 GetXAxis()
55 | {
56 | return new Vector2(c, s);
57 | }
58 |
59 | /// Get the y-axis
60 | public Vector2 GetYAxis()
61 | {
62 | return new Vector2(-s, c);
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Shared/Transform.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 |
3 | namespace Genbox.VelcroPhysics.Shared
4 | {
5 | ///
6 | /// A transform contains translation and rotation. It is used to represent the position and orientation of rigid
7 | /// frames.
8 | ///
9 | public struct Transform
10 | {
11 | public Vector2 p;
12 | public Rot q;
13 |
14 | /// Initialize using a position vector and a rotation matrix.
15 | /// The position.
16 | /// The r.
17 | public Transform(ref Vector2 position, ref Rot rotation)
18 | {
19 | p = position;
20 | q = rotation;
21 | }
22 |
23 | /// Set this to the identity transform.
24 | public void SetIdentity()
25 | {
26 | p = Vector2.Zero;
27 | q.SetIdentity();
28 | }
29 |
30 | /// Set this based on the position and angle.
31 | /// The position.
32 | /// The angle.
33 | public void Set(Vector2 position, float angle)
34 | {
35 | p = position;
36 | q.Set(angle);
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Cutting/Simple/PolyClipError.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Tools.Cutting.Simple
2 | {
3 | public enum PolyClipError
4 | {
5 | None,
6 | DegeneratedOutput,
7 | NonSimpleInput,
8 | BrokenResult
9 | }
10 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Cutting/Simple/PolyClipType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Tools.Cutting.Simple
2 | {
3 | internal enum PolyClipType
4 | {
5 | Intersect,
6 | Union,
7 | Difference
8 | }
9 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/TextureTools/VerticesDetectionType.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Tools.TextureTools
2 | {
3 | /// The detection type affects the resulting polygon data.
4 | public enum VerticesDetectionType
5 | {
6 | /// Holes are integrated into the main polygon.
7 | Integrated = 0,
8 |
9 | /// The data of the main polygon and hole polygons is returned separately.
10 | Separated = 1
11 | }
12 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Delaunay/Delaunay/Sweep/DTSweepPointComparator.cs:
--------------------------------------------------------------------------------
1 | /* Poly2Tri
2 | * Copyright (c) 2009-2010, Poly2Tri Contributors
3 | * http://code.google.com/p/poly2tri/
4 | *
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * * Neither the name of Poly2Tri nor the names of its contributors may be
16 | * used to endorse or promote products derived from this software without specific
17 | * prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 | using System.Collections.Generic;
33 |
34 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Delaunay.Delaunay.Sweep
35 | {
36 | internal class DTSweepPointComparator : IComparer
37 | {
38 | public int Compare(TriangulationPoint p1, TriangulationPoint p2)
39 | {
40 | if (p1.Y < p2.Y)
41 | return -1;
42 | if (p1.Y > p2.Y)
43 | return 1;
44 | if (p1.X < p2.X)
45 | return -1;
46 | if (p1.X > p2.X)
47 | return 1;
48 | return 0;
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Delaunay/Delaunay/Sweep/PointOnEdgeException.cs:
--------------------------------------------------------------------------------
1 | /* Poly2Tri
2 | * Copyright (c) 2009-2010, Poly2Tri Contributors
3 | * http://code.google.com/p/poly2tri/
4 | *
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * * Neither the name of Poly2Tri nor the names of its contributors may be
16 | * used to endorse or promote products derived from this software without specific
17 | * prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 | using System;
33 |
34 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Delaunay.Delaunay.Sweep
35 | {
36 | internal class PointOnEdgeException : NotImplementedException
37 | {
38 | public PointOnEdgeException(string message)
39 | : base(message) { }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Delaunay/Orientation.cs:
--------------------------------------------------------------------------------
1 | /* Poly2Tri
2 | * Copyright (c) 2009-2010, Poly2Tri Contributors
3 | * http://code.google.com/p/poly2tri/
4 | *
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * * Neither the name of Poly2Tri nor the names of its contributors may be
16 | * used to endorse or promote products derived from this software without specific
17 | * prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Delaunay
33 | {
34 | internal enum Orientation
35 | {
36 | CW,
37 | CCW,
38 | Collinear
39 | }
40 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Delaunay/Polygon/PolygonPoint.cs:
--------------------------------------------------------------------------------
1 | /* Poly2Tri
2 | * Copyright (c) 2009-2010, Poly2Tri Contributors
3 | * http://code.google.com/p/poly2tri/
4 | *
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * * Neither the name of Poly2Tri nor the names of its contributors may be
16 | * used to endorse or promote products derived from this software without specific
17 | * prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 | // Changes from the Java version
33 | // Replaced get/set Next/Previous with attributes
34 | // Future possibilities
35 | // Documentation!
36 |
37 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Delaunay.Polygon
38 | {
39 | internal class PolygonPoint : TriangulationPoint
40 | {
41 | public PolygonPoint(double x, double y) : base(x, y) { }
42 |
43 | public PolygonPoint Next { get; set; }
44 | public PolygonPoint Previous { get; set; }
45 | }
46 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Delaunay/Triangulatable.cs:
--------------------------------------------------------------------------------
1 | /* Poly2Tri
2 | * Copyright (c) 2009-2010, Poly2Tri Contributors
3 | * http://code.google.com/p/poly2tri/
4 | *
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * * Neither the name of Poly2Tri nor the names of its contributors may be
16 | * used to endorse or promote products derived from this software without specific
17 | * prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 | using System.Collections.Generic;
33 | using Genbox.VelcroPhysics.Tools.Triangulation.Delaunay.Delaunay;
34 |
35 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Delaunay
36 | {
37 | internal interface Triangulatable
38 | {
39 | IList Points { get; } // MM: Neither of these are used via interface (yet?)
40 | IList Triangles { get; }
41 | TriangulationMode TriangulationMode { get; }
42 | void PrepareTriangulation(TriangulationContext tcx);
43 |
44 | void AddTriangle(DelaunayTriangle t);
45 | void AddTriangles(IEnumerable list);
46 | void ClearTriangles();
47 | }
48 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Delaunay/TriangulationConstraint.cs:
--------------------------------------------------------------------------------
1 | /* Poly2Tri
2 | * Copyright (c) 2009-2010, Poly2Tri Contributors
3 | * http://code.google.com/p/poly2tri/
4 | *
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * * Neither the name of Poly2Tri nor the names of its contributors may be
16 | * used to endorse or promote products derived from this software without specific
17 | * prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 | /**
33 | * Forces a triangle edge between two points p and q
34 | * when triangulating. For example used to enforce
35 | * Polygon Edges during a polygon triangulation.
36 | *
37 | * @author Thomas Åhlén, thahlen@gmail.com
38 | */
39 |
40 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Delaunay
41 | {
42 | internal class TriangulationConstraint
43 | {
44 | public TriangulationPoint P;
45 | public TriangulationPoint Q;
46 | }
47 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Delaunay/TriangulationMode.cs:
--------------------------------------------------------------------------------
1 | /* Poly2Tri
2 | * Copyright (c) 2009-2010, Poly2Tri Contributors
3 | * http://code.google.com/p/poly2tri/
4 | *
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without modification,
8 | * are permitted provided that the following conditions are met:
9 | *
10 | * * Redistributions of source code must retain the above copyright notice,
11 | * this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above copyright notice,
13 | * this list of conditions and the following disclaimer in the documentation
14 | * and/or other materials provided with the distribution.
15 | * * Neither the name of Poly2Tri nor the names of its contributors may be
16 | * used to endorse or promote products derived from this software without specific
17 | * prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Delaunay
33 | {
34 | internal enum TriangulationMode
35 | {
36 | Unconstrained,
37 | Constrained,
38 | Polygon
39 | }
40 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Delaunay/Util/PointGenerator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Delaunay.Util
5 | {
6 | internal class PointGenerator
7 | {
8 | private static readonly Random RNG = new Random();
9 |
10 | public static List UniformDistribution(int n, double scale)
11 | {
12 | List points = new List();
13 | for (int i = 0; i < n; i++)
14 | {
15 | points.Add(new TriangulationPoint(scale * (0.5 - RNG.NextDouble()), scale * (0.5 - RNG.NextDouble())));
16 | }
17 | return points;
18 | }
19 |
20 | public static List UniformGrid(int n, double scale)
21 | {
22 | double x = 0;
23 | double size = scale / n;
24 | double halfScale = 0.5 * scale;
25 |
26 | List points = new List();
27 | for (int i = 0; i < n + 1; i++)
28 | {
29 | x = halfScale - i * size;
30 | for (int j = 0; j < n + 1; j++)
31 | {
32 | points.Add(new TriangulationPoint(x, halfScale - j * size));
33 | }
34 | }
35 | return points;
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Earclip/Triangle.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Shared;
2 | using Microsoft.Xna.Framework;
3 |
4 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Earclip
5 | {
6 | public class Triangle : Vertices
7 | {
8 | //Constructor automatically fixes orientation to ccw
9 | public Triangle(float x1, float y1, float x2, float y2, float x3, float y3)
10 | {
11 | float cross = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
12 | if (cross > 0)
13 | {
14 | Add(new Vector2(x1, y1));
15 | Add(new Vector2(x2, y2));
16 | Add(new Vector2(x3, y3));
17 | }
18 | else
19 | {
20 | Add(new Vector2(x1, y1));
21 | Add(new Vector2(x3, y3));
22 | Add(new Vector2(x2, y2));
23 | }
24 | }
25 |
26 | public bool IsInside(float x, float y)
27 | {
28 | Vector2 a = this[0];
29 | Vector2 b = this[1];
30 | Vector2 c = this[2];
31 |
32 | if (x < a.X && x < b.X && x < c.X) return false;
33 | if (x > a.X && x > b.X && x > c.X) return false;
34 | if (y < a.Y && y < b.Y && y < c.Y) return false;
35 | if (y > a.Y && y > b.Y && y > c.Y) return false;
36 |
37 | float vx2 = x - a.X;
38 | float vy2 = y - a.Y;
39 | float vx1 = b.X - a.X;
40 | float vy1 = b.Y - a.Y;
41 | float vx0 = c.X - a.X;
42 | float vy0 = c.Y - a.Y;
43 |
44 | float dot00 = vx0 * vx0 + vy0 * vy0;
45 | float dot01 = vx0 * vx1 + vy0 * vy1;
46 | float dot02 = vx0 * vx2 + vy0 * vy2;
47 | float dot11 = vx1 * vx1 + vy1 * vy1;
48 | float dot12 = vx1 * vx2 + vy1 * vy2;
49 | float invDenom = 1.0f / (dot00 * dot11 - dot01 * dot01);
50 | float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
51 | float v = (dot00 * dot12 - dot01 * dot02) * invDenom;
52 |
53 | return u > 0 && v > 0 && u + v < 1;
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Seidel/Edge.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Seidel
4 | {
5 | internal class Edge
6 | {
7 | // Pointers used for building trapezoidal map
8 | public Trapezoid Above;
9 |
10 | public float B;
11 | public Trapezoid Below;
12 |
13 | // Montone mountain points
14 | public HashSet MPoints;
15 |
16 | public Point P;
17 | public Point Q;
18 |
19 | // Slope of the line (m)
20 | public float Slope;
21 |
22 | public Edge(Point p, Point q)
23 | {
24 | P = p;
25 | Q = q;
26 |
27 | if (q.X - p.X != 0)
28 | Slope = (q.Y - p.Y) / (q.X - p.X);
29 | else
30 | Slope = 0;
31 |
32 | B = p.Y - p.X * Slope;
33 | Above = null;
34 | Below = null;
35 | MPoints = new HashSet();
36 | MPoints.Add(p);
37 | MPoints.Add(q);
38 | }
39 |
40 | public bool IsAbove(Point point)
41 | {
42 | return P.Orient2D(Q, point) < 0;
43 | }
44 |
45 | public bool IsBelow(Point point)
46 | {
47 | return P.Orient2D(Q, point) > 0;
48 | }
49 |
50 | public void AddMpoint(Point point)
51 | {
52 | foreach (Point mp in MPoints)
53 | {
54 | if (!mp.Neq(point))
55 | return;
56 | }
57 |
58 | MPoints.Add(point);
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Seidel/Node.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Seidel
4 | {
5 | // Node for a Directed Acyclic graph (DAG)
6 | internal abstract class Node
7 | {
8 | protected Node LeftChild;
9 | public List ParentList;
10 | protected Node RightChild;
11 |
12 | protected Node(Node left, Node right)
13 | {
14 | ParentList = new List();
15 | LeftChild = left;
16 | RightChild = right;
17 |
18 | if (left != null)
19 | left.ParentList.Add(this);
20 | if (right != null)
21 | right.ParentList.Add(this);
22 | }
23 |
24 | public abstract Sink Locate(Edge s);
25 |
26 | // Replace a node in the graph with this node
27 | // Make sure parent pointers are updated
28 | public void Replace(Node node)
29 | {
30 | foreach (Node parent in node.ParentList)
31 | {
32 | // Select the correct node to replace (left or right child)
33 | if (parent.LeftChild == node)
34 | parent.LeftChild = this;
35 | else
36 | parent.RightChild = this;
37 | }
38 | ParentList.AddRange(node.ParentList);
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Seidel/Point.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Seidel
2 | {
3 | internal class Point
4 | {
5 | // Pointers to next and previous points in Monontone Mountain
6 | public Point Next, Prev;
7 |
8 | public float X, Y;
9 |
10 | public Point(float x, float y)
11 | {
12 | X = x;
13 | Y = y;
14 | Next = null;
15 | Prev = null;
16 | }
17 |
18 | public static Point operator -(Point p1, Point p2)
19 | {
20 | return new Point(p1.X - p2.X, p1.Y - p2.Y);
21 | }
22 |
23 | public static Point operator +(Point p1, Point p2)
24 | {
25 | return new Point(p1.X + p2.X, p1.Y + p2.Y);
26 | }
27 |
28 | public static Point operator -(Point p1, float f)
29 | {
30 | return new Point(p1.X - f, p1.Y - f);
31 | }
32 |
33 | public static Point operator +(Point p1, float f)
34 | {
35 | return new Point(p1.X + f, p1.Y + f);
36 | }
37 |
38 | public float Cross(Point p)
39 | {
40 | return X * p.Y - Y * p.X;
41 | }
42 |
43 | public float Dot(Point p)
44 | {
45 | return X * p.X + Y * p.Y;
46 | }
47 |
48 | public bool Neq(Point p)
49 | {
50 | return p.X != X || p.Y != Y;
51 | }
52 |
53 | public float Orient2D(Point pb, Point pc)
54 | {
55 | float acx = X - pc.X;
56 | float bcx = pb.X - pc.X;
57 | float acy = Y - pc.Y;
58 | float bcy = pb.Y - pc.Y;
59 | return acx * bcy - acy * bcx;
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Seidel/Sink.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Seidel
2 | {
3 | internal class Sink : Node
4 | {
5 | public Trapezoid Trapezoid;
6 |
7 | private Sink(Trapezoid trapezoid)
8 | : base(null, null)
9 | {
10 | Trapezoid = trapezoid;
11 | trapezoid.Sink = this;
12 | }
13 |
14 | public static Sink Isink(Trapezoid trapezoid)
15 | {
16 | if (trapezoid.Sink == null)
17 | return new Sink(trapezoid);
18 |
19 | return trapezoid.Sink;
20 | }
21 |
22 | public override Sink Locate(Edge edge)
23 | {
24 | return this;
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Seidel/XNode.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Seidel
2 | {
3 | internal class XNode : Node
4 | {
5 | private Point _point;
6 |
7 | public XNode(Point point, Node lChild, Node rChild)
8 | : base(lChild, rChild)
9 | {
10 | _point = point;
11 | }
12 |
13 | public override Sink Locate(Edge edge)
14 | {
15 | if (edge.P.X >= _point.X)
16 | return RightChild.Locate(edge); // Move to the right in the graph
17 |
18 | return LeftChild.Locate(edge); // Move to the left in the graph
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Tools/Triangulation/Seidel/YNode.cs:
--------------------------------------------------------------------------------
1 | namespace Genbox.VelcroPhysics.Tools.Triangulation.Seidel
2 | {
3 | internal class YNode : Node
4 | {
5 | private Edge _edge;
6 |
7 | public YNode(Edge edge, Node lChild, Node rChild)
8 | : base(lChild, rChild)
9 | {
10 | _edge = edge;
11 | }
12 |
13 | public override Sink Locate(Edge edge)
14 | {
15 | if (_edge.IsAbove(edge.P))
16 | return RightChild.Locate(edge); // Move down the graph
17 |
18 | if (_edge.IsBelow(edge.P))
19 | return LeftChild.Locate(edge); // Move up the graph
20 |
21 | // s and segment share the same endpoint, p
22 | if (edge.Slope < _edge.Slope)
23 | return RightChild.Locate(edge); // Move down the graph
24 |
25 | // Move up the graph
26 | return LeftChild.Locate(edge);
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/VelcroPhysics/Utilities/JointHelper.cs:
--------------------------------------------------------------------------------
1 | using Genbox.VelcroPhysics.Dynamics;
2 |
3 | namespace Genbox.VelcroPhysics.Utilities
4 | {
5 | public static class JointHelper
6 | {
7 | public static void LinearStiffness(float frequencyHertz, float dampingRatio, Body bodyA, Body bodyB, out float stiffness, out float damping)
8 | {
9 | float massA = bodyA.Mass;
10 |
11 | float massB = 0;
12 |
13 | if (bodyB != null)
14 | massB = bodyB.Mass;
15 |
16 | float mass;
17 |
18 | if (massA > 0.0f && massB > 0.0f)
19 | mass = massA * massB / (massA + massB);
20 | else if (massA > 0.0f)
21 | mass = massA;
22 | else
23 | mass = massB;
24 |
25 | float omega = MathConstants.TwoPi * frequencyHertz;
26 | stiffness = mass * omega * omega;
27 | damping = 2.0f * mass * dampingRatio * omega;
28 | }
29 |
30 | public static void AngularStiffness(float frequencyHertz, float dampingRatio, Body bodyA, Body bodyB, out float stiffness, out float damping)
31 | {
32 | float inertiaA = bodyA.Inertia;
33 | float inertiaB = bodyB.Inertia;
34 | float I;
35 |
36 | if (inertiaA > 0.0f && inertiaB > 0.0f)
37 | I = inertiaA * inertiaB / (inertiaA + inertiaB);
38 | else if (inertiaA > 0.0f)
39 | I = inertiaA;
40 | else
41 | I = inertiaB;
42 |
43 | float omega = MathConstants.TwoPi * frequencyHertz;
44 | stiffness = I * omega * omega;
45 | damping = 2.0f * I * dampingRatio * omega;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/VelcroPhysics/Utilities/MathConstants.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Genbox.VelcroPhysics.Utilities
4 | {
5 | public static class MathConstants
6 | {
7 | public const float Pi = (float)Math.PI;
8 | public const float TwoPi = Pi * 2.0f;
9 | public const float MaxFloat = float.MaxValue;
10 | public const float Epsilon = 1.192092896e-07f;
11 | public const float Euler = 2.7182818284590452354f;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/VelcroPhysics/VelcroPhysics.MonoGame.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | Genbox.VelcroPhysics
6 |
7 |
8 |
9 | $(DefineConstants);MONOGAME
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/VelcroPhysics/VelcroPhysics.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | $(DefineConstants);STANDARD_IMPLEMENTATION
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------