nightshade-api 0.43.0

Procedural high level API for the nightshade game engine
Documentation
//! One call interaction: what is under the cursor, what did the user click.

use crate::input::{mouse_clicked, mouse_position};
use crate::scene::is_reserved;
use nightshade::prelude::*;

/// The closest entity under the cursor, if any. The api's own scaffolding
/// (draw pools, cameras, lights) is never returned.
pub fn entity_under_cursor(world: &World) -> Option<Entity> {
    pick_entities(world, mouse_position(world), PickingOptions::default())
        .into_iter()
        .map(|result| result.entity)
        .find(|&entity| !is_reserved(world, entity))
}

/// The entity the user clicked this frame with the left mouse button, if any.
pub fn clicked_entity(world: &World) -> Option<Entity> {
    if !mouse_clicked(world, MouseButton::Left) {
        return None;
    }
    entity_under_cursor(world)
}

/// Where the cursor's ray meets the ground plane at y zero, if it does.
pub fn cursor_on_ground(world: &World) -> Option<Vec3> {
    get_ground_position_from_screen(world, mouse_position(world), 0.0)
}