Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cone -> Sphere and segment overlap #14

Open
dungeon2567 opened this issue Sep 19, 2023 · 19 comments
Open

Cone -> Sphere and segment overlap #14

dungeon2567 opened this issue Sep 19, 2023 · 19 comments

Comments

@dungeon2567
Copy link

Is there any way to implement cone -> sphere and segment overlap system?

@mreinstein
Copy link
Owner

mreinstein commented Sep 19, 2023

I'm not sure I understand the ask. Are you saying you want to overlap a cone against a set of spheres and segments, or do you want separate checks like coneSphere(...), coneSegment(...) ?

@dungeon2567
Copy link
Author

dungeon2567 commented Sep 19, 2023

I want to overlap a cone against a set of spheres and segments

But both works

@dungeon2567
Copy link
Author

this is for a topdown game, for visibility checks

@mreinstein
Copy link
Owner

We would need to add coneSphereOverlap and coneSegmentOverlaptests. I don't have any links to existing implementations for these, but I'm open to adding them.

this is for a topdown game, for visibility checks

Cool!

@dungeon2567
Copy link
Author

dungeon2567 commented Sep 19, 2023

bool overlapsWith(const Cone& cone) const {
    if (isCircle()) {
        float dist = std::sqrt(Math::sqr(position.x - cone.position.x) + Math::sqr(position.y - cone.position.y));

        if (dist + radius() < cone.minDistance || dist - radius() > cone.maxDistance) {
            return false;
        }

        // Calculate the direction vector from the cone's position to the circle center
        Vector2 toCircle = { position.x - cone.position.x, position.y - cone.position.y };

        // Calculate the angle between the direction vector and the cone's rotation vector
        float dotProduct = toCircle.x * cone.rotation.x + toCircle.y * cone.rotation.y;
        float angle = std::acos(dotProduct / (dist * 1.0));

        return angle <= cone.fieldOfView / 2.0f;
    }

    return false;
}
I have generated this using ChatGPT for cone and circle but for segment i have no idea (and chatgpt can`t do it)

@mreinstein
Copy link
Owner

and chatgpt can`t do it

Why not?

@mreinstein
Copy link
Owner

I suspect that chatgpt generated function may not catching all intersection cases, because it only seems to compare the angle of the cone against the vector going through the center point of the sphere.

It would be nice to generate visual test for this, like we have for the other collision functions. That would give me some confidence that this code is actually working.

@dungeon2567
Copy link
Author

dungeon2567 commented Sep 19, 2023

image
It is not working, only range check is working

@dungeon2567
Copy link
Author

and chatgpt can`t do it

Why not?

I have tried but all codes he generate is broken.

@mreinstein
Copy link
Owner

I would imagine somewhere on the web are high quality cone-sphere and cone-segment intersection tests. If you find any I'm happy to integrate them into this library. :)

@mreinstein
Copy link
Owner

PRs also welcome!

@dungeon2567
Copy link
Author

image

Im thing about doing that for cone sphere (reducing it cone-circle). but im not sure how yet.

@mreinstein
Copy link
Owner

This might be good. It looks like it may be robust: https://github.com/mosra/magnum/blob/53c1549e69af552d28d5da8fc4dcdd0e9a1cad60/src/Magnum/Math/Intersection.h#L529-L556

@mreinstein
Copy link
Owner

Let me know how this works for you, if the routine seems robust I'm happy to include it in this module.

@dungeon2567
Copy link
Author

Ok, i think it should work. As my game is using a BVH and i still don`t have a code to calculate AABB of frustrum i have not tested it visually (except some values)

@mreinstein
Copy link
Owner

just out of curiosity what are you using for a renderer?

@dungeon2567
Copy link
Author

Nothing, it is a mmorpg backend. But for the frontend i`m using unreal engine 5

@mreinstein
Copy link
Owner

that's a really interesting architecture, have yet to encounter that. Are you keeping a devlog anywhere?

@dungeon2567
Copy link
Author

No, i have just started. But i will do it soon.

https://streamable.com/7vo4vd

This is my mmorpg on unity using same architecture but ... unity is dead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants