jcornaz / heron

[DISCONTINUED] An ergonomic physics API for bevy games
MIT License
292 stars 44 forks source link

HeightField Collision shape #62

Closed jcornaz closed 3 years ago

elegaanz commented 3 years ago

Hi, I would like to help implement that, would a PR be accepted? (edit: I just saw the "up-for-grabs" label) If yes, do you have any tip or things I need to know about the code base or this issue before I get started?

jcornaz commented 3 years ago

Hi, thanks @elegaanz!

Adding a new collision shape shouldn't be too hard. Add the new variant to Body (in core crate) and let the compiler tells you what else you need to change.

However.... I am currently making some big changes (see: https://github.com/jcornaz/heron/issues/31#issuecomment-845079342). So you might want to wait 2-3 days, to avoid unnecessary conflicts. (I plan to merge theses changes this weekend)

jcornaz commented 3 years ago

Ah, and if you need help, you can either open a draft PR and/or contact me on discord (@Jomag)

elegaanz commented 3 years ago

I started something, just to get a bit more familiar with the code, even if I need to redo it in a few days, and I have a question: in 2D heightfields are defined by a single-dimension array, but for 3D you need a matrix/two dimensional array. Is something like that a good idea?

enum Body {
    // ...
    HeightField {
        #[cfg(feature = "2d")]
        heigths: Vec<f32>,

        #[cfg(feature = "3d")]
        heigths: Vec<Vec<f32>>,
}

Or is there a better way?

jcornaz commented 3 years ago

I merged the changes I was talking about. So you can take the latest version of main and work from there.

Yes, you can use #[cfg(feature = ...)]. It looks like the best option in this case.

The Vec<Vec<f32>> is acceptable too. I'm don't know a nice dynamically sized matrix type that could replace this.

You'll also needs a scale member that tells the distance separating each height value of the vector/matrix.

In 2d it's a f32, and in 3d it's a Vec2. But, we may simplify it by forcing the user to use the same scale for both axis in 3d. This is anyway the most common, and as a matter of fact, I've never seen a height map with a different scale in x than in y. That means the scale could always be a f32 in both 2d and 3d.

enum CollisionShape {
    // ...

    #[cfg(not(all(feature = "2d", feature = "3d")))]
    HeightField {

        scale: f32,

        #[cfg(feature = "2d")]
        heigths: Vec<f32>,

        #[cfg(feature = "3d")]
        heigths: Vec<Vec<f32>>,
   }
}

P.S. The enum is now named "CollisionShape" ;-)