-
Notifications
You must be signed in to change notification settings - Fork 44
Provide 2d oriented constructors for CollisionShape #72
Comments
Thanks for the proposition. I think having aliases for creating 2d shapes might indeed be more user-friendly. But I am not so entousiast about having a different component type, because it quickly adds new edge-cases and maintenance costs. Instead I'd like to propose providing 2d oriented constructors on impl Body {
#[cfg(feature = "2d")]
pub fn circle(radius: f32) -> Self {
Self::Sphere { radius }
}
#[cfg(feature = "2d")]
pub fn rectangle(half_extends: Vec2) -> Self {
Self::Cuboid { half_extends: half_extends.extend(0.0) }
}
} That as the advandage to not require writing/maintaining any special systems. What do you think @faassen? |
To be honest, I'm also wondering if it is not against the disign principle of "it should look like it is part of Bevy". After all, Bevy doesn't really have first-class concept of 2d. It is a 3d oriented game engine, and 2d is only achieved by pointing an orthographic camera toward the |
I think we're confusing API with implementation if we argue Heron shouldn't expose 'Circle' and 'Rectangle' as a concept because 2d graphics are implemented with 3d graphics. Bevy talks about 2d support right on its homepage. It exposes a Vec2. Let's look at another library, bevy_prototype_lyon. It's talking about rectangles and circles too. What else could it do? It's a 2d library. It uses Vec2 throughout, which makes sense. Bevy's breakout example is in 2d, and uses Vec2 a lot, for sprites for instance. It also uses Vec3 with z set to 0, for transforms. That's not an awesome API but it may be a reasonable compromise. So Heron is in the same position as Bevy: it supports both 2d and 3d. It should expose the best APIs for both. For 2d in Bevy, that's Circles and Rectangles and Vec2 and possibly some compromises. |
Concerning using a feature toggle, see also the comments in my PR. I think, it would be the simplest if there were only a Body to worry about, not a Body2. I only need to figure out a way to convince rust analyzer to give me information about the code for 2d, as it's completely ignored by default. |
A possibly relevant discussion: bevyengine/bevy#1275 This hints that the z coordinate is used in graphics to prioritize layers. Though of course it argues that's not an ideal solution. |
When something is only useful for 2d (like sprites) then it uses 2d terminology and types. But it doesn't duplicate APIs. One of cart's moto is to not provide 2 different ways of doing the same thing. Which is why, by design the transform uses
That's still follow the bevy philosophy, because
Well that's the point indeed. Heron is in the same position as Of course for shapes that only exist in a 2d space, then heron should provide a 2d-oriented API (like bevy does for sprite). But when it is used for both 2d and 3d (like capsulse, cuboid, sphere, etc.)... well, we can still do whatever we want, because heron is not bevy. But let's at least reckognise that bevy does not provide 2 different APIs when something is used for both 2d and 3d. Anyway, I think that adding sugars to create 2d shapes maybe fine, if it makes usage of heron more intuitive in 2d. What I am not entousiast about is to add new components and systems for that. Which is why I propose to provide constructory on
Yes, I think that's what I suggested in a previous comment. To not introduce a new |
Yes, I agree that adding constructors to Body makes the most sense, also from an implementation perspective. |
Here are some proposed convenience shapes for 2d that mostly don't exist directly in Rapier but are easy to implement. The argument to have them is because when dealing with 2d, people think in 2d terms. It's weird to refer to a circle as a "sphere", for instance. We can also use Vec2 instead of Vec3 to define them where vecs are involved.
I think we can make them in a special
Body2
enum that gets translated intoBody
underneath.The text was updated successfully, but these errors were encountered: