项目作者: tedigc

项目描述 :
a monogame implementation of the separating axis theorem for convex polygon intersection
高级语言: C#
项目地址: git://github.com/tedigc/mgsat.git
创建时间: 2020-11-13T15:29:55Z
项目社区:https://github.com/tedigc/mgsat

开源协议:

下载


SeparatingAxisTheorem

A Monogame implementation of the Separating Axis Theorem for convex polygon intersection.

View on nuget or install directly with:

  1. dotnet add package Halfcut.SeparatingAxisTheorem.Lib --version 0.0.2

Usage

  1. using Halfcut.SeparatingAxisTheorem.Lib;
  2. class Game {
  3. private Polygon _polygon1;
  4. private Polygon _polygon2;
  5. public Game() {
  6. _polygon1 = PolygonFactory.CreateRectangle(x1, y1, w1, h2);
  7. _polygon2 = PolygonFactory.CreateRectangle(x2, y2, w2, h2);
  8. }
  9. public void Update(float dt) {
  10. var isIntersecting = _polygon1.IntersectsWith(_polygon2);
  11. }
  12. }

Demo

Run the demo code with:

  1. git clone git@github.com:tedigc/SeparatingAxisTheorem.git
  2. cd SeparatingAxisTheorem
  3. dotnet build
  4. dotnet run --project SeparatingAxisTheorem.Demo/SeparatingAxisTheorem.Demo.csproj

You can move the rotating square with WASD.

Extensions

  • Circle collision
  • Improve api for translating and rotating polygons
  • Publish as a nuget package
  • Calculate the minimum translation vector (MTV)
  • Convex decomposition for non-convex polygons
  • Exception handling

Created by Ted Cater (tedigc)