GithubHelp home page GithubHelp logo

bevy_rei's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

bevy_rei's Issues

More flexible interaction area than boundary box

I have tried to create an interaction area that is more flexible than a simple boundary box. Implementing a first extension in bevy_interact_2d, I got as far as the code below, but I assume this is much easier done with better support for a ‘contains’ method on the lyon side, so I raised an issue at bevy_prototype_lyon. i don't think what I do here is perfect, I would feel much better about re-using an existing geometry type.

pub enum InteractionArea {
  BoundingBox(Vec2, Vec2),
  Triangle(Vec2, Vec2, Vec2),
}

/// A convenience thing, so existing bounding boxes just need `.into()`
impl From<(Vec2, Vec2)> for InteractionArea {
  fn from((corner1, corner2): (Vec2, Vec2)) -> Self {
    InteractionArea::BoundingBox(corner1, corner2)
  }
}

/// This component makes an entity interactable with the mouse cursor
#[derive(Component)]
pub struct Interactable {
  /// The interaction groups this interactable entity belongs to
  pub groups: Vec<Group>,
  /// The interaction area for the interactable entity
  pub interaction_area: InteractionArea,
}

impl Interactable {
  fn contains(&self, cursor: &Vec2) -> bool {
    match self.interaction_area {
      InteractionArea::BoundingBox(corner1, corner2) => {
        (corner1.x..corner2.x).contains(&cursor.x) && (corner1.y..corner2.y).contains(&cursor.y)
      }
      InteractionArea::Triangle(a, b, c) => Triangle {
        a: point2(a.x, a.y),
        b: point2(b.x, b.y),
        c: point2(c.x, c.y),
      }
      .contains_point(point2(cursor.x, cursor.y)),
    }
  }
}


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.