GithubHelp home page GithubHelp logo

tjstretchalot / sharpmath2 Goto Github PK

View Code? Open in Web Editor NEW
49.0 5.0 5.0 153 KB

2D math / geometry collision library for C#, compatable with monogame.

License: MIT License

C# 100.00%
math csharp 2d collision polygon math2d mtv minimumtranslationvector library geometry

sharpmath2's Issues

About rotation and a request.

Hey there,

This library is bloody amazing. Easily implemented it (I already had a polygon/shape class ready so it really was a surprise I didn't have to change much!)

I have a two requests - one of them is that if you could make it possible I could just reset the Rotation2 cos/sin instead of making a new object every time (and the same would go for a Polygon2.)

Also I'm wondering how I'd change the rotation based on the example collision between polygons (I probably missed something really obvious.)

`
Tuple<Vector2, float> mtv;
///


/// Upon collision with another quad object
///

/// The object we've colldied with.
public virtual void OnCollision(QuadObject @object)
{
mtv = Polygon2.IntersectMTV(
Shape.CollisionBox, @object.Shape.CollisionBox, Position, @object.Position, Shape.CollisionBoxRotation, @object.Shape.CollisionBoxRotation);

        if (mtv != null)
        {
            Position += mtv.Item1 * mtv.Item2;
            // Rotation += ?
        }

    }`

As for re-using the existing polygon, I mean something along the lines of:
/// <summary> /// The shape of the object. /// </summary> private Vector2[] Points { get { return _Points; } set { OrderClockwise(ref _Points); CollisionBox = new Polygon2(_Points); // CollisionBox.SetPoints(_Points); } }

Polygon-polygon minimum translation vector appears invalid

Calling IntersectMTV with two rotated polygons leads to strange behaviour:

  • MTV is not normalized
  • MTV orientation may be incorrect depending on the orientation of the collision
  • Depending on orientation of intersection, the MTV only gets calculated if poly2 completely contains poly1, or at least it appears the center point of poly1 must be contained by poly2

https://imgur.com/a/CSnDjWi

Let me know what more information you need, if any. I'm using a modified version of 4ed1885 adapted to use Unity.Mathematics types and math functions. I'm also avoiding allocations by reusing cached objects rather than constructing new ones, but other than that, the code should be the same.

Circle2 IntersectMTV not working correctly

Hello guys,

I dont know whether someone will read this, but could you please fix the IntersectMTV-method of the Circle2 class? It does not give the right results if the circles overlap. The Intersects method is broken too, if there are two circles with different radii.

Thank you :)

---Edit: Circle and Polygon is broken too :(---
Edit2: I dont have see that there a two methods.. Circle-Polygon and Polygon-Circle :(

The line-class has a bug for calculating the Horizontal and Vertical

That fixed it... buts still broken on the resolving of the collisions
var k = Math.Abs(this.End.Y - this.Start.Y) / Math.Abs(this.End.X - this.Start.X);
this.Horizontal = k == 0;
this.Vertical = float.IsInfinity(k);

Request for a scale function on the shape

Hey there!

Is it possible we can have an argument for scale in the Intersects function? If not, what would be your recommendation about changing the scales of shapes? Just create a new shape for each scale or?

With friendly regards.

Buggy collision upon going left, or up.

Hey there!

It's me again,

There seems to be an issue when colliding with numerous objects going left, and up. I've re-written my code a few times, even tried it without the quad tree but the problem persists. I'm unsure at this point where the problem is so I'm hoping you could shed some light on it, as I'm not very familiar with your code.

da6da46c462dd04fd8cddc4a2c13f678

I first thought it had to do with the quad tree (as the tree wasn't dynamically expanding), but it then turns out that by just pushing one block at a time there was no issue. This issue does not exist for moving to the right or the bottom so I'm assuming it's a form of rounding error.

I've included a copy of my source in case you need it.
Engine.zip

Update: I've adjusted the following zip to exclude quad trees, and strangely enough - now it does somewhat work better, but it seems to just pick and choose which ones to push away and which ones not to. Is the pushing away suppose to be happening? I know it happens because I also check collisions for the non player-boxes, but still. It seems to pick and choose.

80bec15aacfe79e95fa051a427cef348

I got a feeling it's me not understanding the library that is the issue.
Engine No Trees.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.