Comments (5)
If you have a fixed number of scales (i.e., less than 10) it's definitely best to just create a shape for each scale. If you don't have a fixed number of scales I'll need a bit more context to know if this function would be helpful, as it's not obvious if there's a fast way to implement this
from sharpmath2.
Ideally I'd just be able to pass in a Vector2:
Polygon2.Intersects(triangle, triangle, position1, position2, scale1, scale2, rotation1, rotation2, true);
This is because I have a wrapper class that takes in a shape, creates a Polygon2 with it, but also allows for the rendering of said shape with a given scale:
for (var i = 0; i < Polygon2.Vertices.Length; i++)
{
var a = Polygon2.Vertices[i] * scale + position - Polygon2.Center * scale;
var b = Polygon2.Vertices[(i + 1) % Polygon2.Vertices.Length] * scale + position - Polygon2.Center * scale;
// subtract center so we rotate around the center instead of 0,0
a = a.RotateAround(position, rotation);
b = b.RotateAround(position, rotation);
manaBatch.DrawLine(
a,
b,
Color.White,
1f
);
}
// this is now a rectangle shape
public ManaSprite Shape = new ManaSprite(new []{ Vector2.Zero, new Vector2(1, 0), new Vector2(1, 1), new Vector2(0, 1), });
Shape.Draw(
manaBatch,
Position,
Size,
Rotation
);
// contains and intersection code for now.
public bool Contains(Vector2 position, Vector2 scale, float x, float y)
{
var min = Polygon2.AABB.Min * scale + position - Polygon2.AABB.Center * scale;
var max = Polygon2.AABB.Max * scale + position - Polygon2.AABB.Center * scale;
return x > min.X && x < max.X && y > min.Y && y < max.Y;
}
from sharpmath2.
Thinking about this, the only fast way to make this work would be if the normals of the polygon are preserved under scaling. That is to say - none of the lines rotate. This isn't true if the scale factor on the X is different from the scale factor on the Y, for example, since the lines get squeezed and the polygon normals need to be recalculated. I think that you need at most some fairly loose constraints to guarantee that if the scale factors are the same then the normals are the same.
Are you doing arbitrary x-y scaling? Do you always scale at the same ratio of x to y? If this is a varying scale of x-to-y you might need to resort to creating new polygons and, if that is too slow, perform some kind of granulation of the space (i.e., restrict yourself to certain rescalings)
from sharpmath2.
Just in case you felt I wasn't listening, I'm definitely open to any suggestions for the implementation and I think this is a use-case that could be helpful. I was just asking some questions that would ensure that if I did add something it wouldn't perform any astonishing behavior - especially in terms of performance
from sharpmath2.
Not at all! I've thought it through and in the current project I'm working on there's not a direct need to change the scale on the fly.
Sorry about not adding that it was late yesterday and it seems I forgot.
Still a big thank you for providing this library I've used it in almost every project in the last year it's just so useful.
from sharpmath2.
Related Issues (8)
- About rotation and a request. HOT 5
- Replace intersection verification with GJK HOT 1
- Buggy collision upon going left, or up. HOT 12
- Circle2 IntersectMTV not working correctly HOT 5
- Polygon2.Contains doesn't work properly HOT 4
- Polygon-polygon minimum translation vector appears invalid HOT 4
- How to use SharpMath2 with Mono
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharpmath2.