Silk.NET icon indicating copy to clipboard operation
Silk.NET copied to clipboard

Overlapping test methods for math shape types.

Open vpenades opened this issue 4 years ago • 8 comments

Summary of feature

Math library has 2D and 3D common shape types like Ray2D, Ray3D, Cube, Sphere, etc

It could be useful to have Ray2D and Ray3D to have methods to return the intesection with shapes and volumes.

Also, test methods to get whether shapes and volumens overlap.

Comments

Area/volume overlapping is a very common practice for graphics development in areas like frutum culling, collision detection, etc

Does this have a proposal?

no

vpenades avatar Feb 01 '22 15:02 vpenades

While this may be useful, it is quite out of the scope of our maths library. Frustum culling, Collision detection, etc. should all not be done by directly using these types anyways, either this should be deferred to the GPU or done using some optimization system on the CPU - likely the job of another library (for example Bepu Physics for physics/collision detection)

HurricanKai avatar Feb 01 '22 16:02 HurricanKai

It could be useful to have Ray2D and Ray3D to have methods to return the intesection with shapes and volumes.

This doesn't seem like a bad idea (the other stuff in Comments though is out of scope as Kai suggested), @HurricanKai we could just leave this open to see if anyone from the community picks up on it?

Perksey avatar Feb 01 '22 16:02 Perksey

Although I agree that frustum culling and collision detection require ultra-optimized types, this doesn't mean the types provided by Silk don't implement some commom methods.

If Matrix4x4 has multiply, Inverse, etc.... I don't see why Sphere can't have a DistanceTo(Sphere), or an OverlapsWith(Sphere) or Intersects method, which are common use cases for shapes and volumes. Then the users can choose whether to use these types for their scenarios or not.

I understand the concern about adding methods to these types, because once you open the box, the number of methods you can add is countless, but I think there's some stuff that can be added without harm.

vpenades avatar Feb 01 '22 16:02 vpenades

@vpenades for our reference, would you be willing to implement these methods if we said we're happy to have them?

Perksey avatar Feb 01 '22 16:02 Perksey

I could give a try, I am new to Silk, but I have some of these methods already implemented in similar types (using float)

There's also public, well known implementations in other projects, like the old XNA.

vpenades avatar Feb 01 '22 16:02 vpenades

@HurricanKai free contribution? iirc we have IntersectsWith methods elsewhere; raycasting APIs seem in scope for silk.net as other maths libraries have this (e.g. unity's maths lib). I agree anything more, like Full-blown culling, is defo out-of-scope.

Perksey avatar Feb 01 '22 16:02 Perksey

Basic .IntersectsWith methods seem fine to me

HurricanKai avatar Feb 01 '22 16:02 HurricanKai

So if I understand the architecture correctly, it would be something like this?

Ray2D.Intersections.cs

  • IntersectsWith(Circle)
  • IntersectsWith(Rectangle)
  • IntersectsWith(Box2D)

Ray3D.Intersections.cs

  • IntersectsWith(Plane)
  • IntersectsWith(Sphere)
  • IntersectsWith(Cube)
  • IntersectsWith(Box3D)

Also, I understand the common grammar would be like this:

bool IntersectsWith(shape, out Scalar distanceFactor);

vpenades avatar Feb 01 '22 17:02 vpenades