RandyGaul / cute_headers

Collection of cross-platform one-file C/C++ libraries with no dependencies, primarily used for games
4.26k stars 265 forks source link

cute_c2 c2TOI rotation allowed or not? #161

Closed roig closed 4 years ago

roig commented 4 years ago

Hello!

I'm thinking to use cute_c2 or not and looking at c2TOI function and in the comments of that function it says:

"The shapes are *not* allowed to rotate over time."

Is this correct? Can we c2TOI with a translation and a rotation? My use case is, cast a shape from a position XP and a rotation XR, to a position YP and a rotation YR.

Thank you for your great cute headers :stuck_out_tongue:

RandyGaul commented 4 years ago

That's right, no rotation allowed during the sweep!

Of course you can rotate your shapes however you like outside of the sweep. It's just that when you call c2TOI it takes a linear velocity but assumes angular velocity is zero.

roig commented 4 years ago

Hello RandyGaul!

Mmmmm, so how would you do it if you have to rotate during a sweep? Or you never rotate during a sweep? :question: Will this feature be implemented? I think box2d TOI, supports it, but I'm not sure.

RandyGaul commented 4 years ago

If you really need it then use Box2D. But you likely don’t need it, and in my opinion it’s not a very important feature for most games.

roig commented 4 years ago

No problem, thank you Randy! I Will think if I really need that feature or not. But I think, this would be a good addition to cute_c2 if you decide to implement it. Maybe in another function for performance reasons but I think it would be useful in some scenarios.

RandyGaul commented 4 years ago

It would be a lot of work without much of a benefit. Yes, you're right that it would be nice to be able to do rotational sweeps, but in reality there are a few big problems for cute_c2. It would be quite a bit of code. This means more bugs and more things to maintain + test. I have limited time, so there would need to be a big benefit to justify the maintenance cost. I barely have enough time as-is to make sure the linear TOI function is in working order.

Since Box2D has already implemented a good TOI solver that supports rotational sweeps, anyone can simply use Box2D. Or, alternatively, they can rip out the bilateral advancement root finder from Box2D and use that in isolation. I would be happy to pull in Box2D's bilateral advancement solver here, but there are license problems I don't want to deal with, and I also don't want to maintain that code and deal with removing all of it's Box2D internal dependencies/cleaning up the API.

These costs aren't just my own personal costs either. If someone wants to use cute_c2 in their game they inherit these costs directly. This means including a complicated function like a rotational sweeper would overall harm anyone using cute_c2.h more than it would help.

I'm not writing this down just to blast a bunch of info at you @roig, but also for anyone else poking around the GitHub issues later :)

Feel free to open this issue up again (or just post even if it's closed) if you want to talk more!