2024-06-17 15:45:32 +00:00
|
|
|
//! Additional [`Gizmos`] Functions -- Crosses
|
|
|
|
//!
|
|
|
|
//! Includes the implementation of [`Gizmos::cross`] and [`Gizmos::cross_2d`],
|
|
|
|
//! and assorted support items.
|
|
|
|
|
|
|
|
use crate::prelude::{GizmoConfigGroup, Gizmos};
|
|
|
|
use bevy_color::Color;
|
2024-08-28 01:37:19 +00:00
|
|
|
use bevy_math::{Isometry2d, Isometry3d, Vec2, Vec3};
|
2024-06-17 15:45:32 +00:00
|
|
|
|
|
|
|
impl<Config> Gizmos<'_, '_, Config>
|
|
|
|
where
|
|
|
|
Config: GizmoConfigGroup,
|
|
|
|
{
|
2024-08-28 01:37:19 +00:00
|
|
|
/// Draw a cross in 3D with the given `isometry` applied.
|
|
|
|
///
|
|
|
|
/// If `isometry == Isometry3d::IDENTITY` then
|
|
|
|
///
|
|
|
|
/// - the center is at `Vec3::ZERO`
|
|
|
|
/// - the `half_size`s are aligned with the `Vec3::X`, `Vec3::Y` and `Vec3::Z` axes.
|
2024-06-17 15:45:32 +00:00
|
|
|
///
|
|
|
|
/// This should be called for each frame the cross needs to be rendered.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
/// ```
|
|
|
|
/// # use bevy_gizmos::prelude::*;
|
|
|
|
/// # use bevy_math::prelude::*;
|
|
|
|
/// # use bevy_color::palettes::basic::WHITE;
|
|
|
|
/// fn system(mut gizmos: Gizmos) {
|
2024-08-28 01:37:19 +00:00
|
|
|
/// gizmos.cross(Isometry3d::IDENTITY, 0.5, WHITE);
|
2024-06-17 15:45:32 +00:00
|
|
|
/// }
|
|
|
|
/// # bevy_ecs::system::assert_is_system(system);
|
|
|
|
/// ```
|
2024-08-28 01:37:19 +00:00
|
|
|
pub fn cross(&mut self, isometry: Isometry3d, half_size: f32, color: impl Into<Color>) {
|
2024-06-17 15:45:32 +00:00
|
|
|
let color: Color = color.into();
|
2024-08-28 01:37:19 +00:00
|
|
|
[Vec3::X, Vec3::Y, Vec3::Z]
|
|
|
|
.map(|axis| axis * half_size)
|
|
|
|
.into_iter()
|
|
|
|
.for_each(|axis| {
|
|
|
|
self.line(isometry * axis, isometry * (-axis), color);
|
|
|
|
});
|
2024-06-17 15:45:32 +00:00
|
|
|
}
|
|
|
|
|
2024-08-28 01:37:19 +00:00
|
|
|
/// Draw a cross in 2D with the given `isometry` applied.
|
|
|
|
///
|
|
|
|
/// If `isometry == Isometry2d::IDENTITY` then
|
|
|
|
///
|
|
|
|
/// - the center is at `Vec3::ZERO`
|
|
|
|
/// - the `half_size`s are aligned with the `Vec3::X` and `Vec3::Y` axes.
|
2024-06-17 15:45:32 +00:00
|
|
|
///
|
|
|
|
/// This should be called for each frame the cross needs to be rendered.
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
/// ```
|
|
|
|
/// # use bevy_gizmos::prelude::*;
|
|
|
|
/// # use bevy_math::prelude::*;
|
|
|
|
/// # use bevy_color::palettes::basic::WHITE;
|
|
|
|
/// fn system(mut gizmos: Gizmos) {
|
2024-08-28 01:37:19 +00:00
|
|
|
/// gizmos.cross_2d(Isometry2d::IDENTITY, 0.5, WHITE);
|
2024-06-17 15:45:32 +00:00
|
|
|
/// }
|
|
|
|
/// # bevy_ecs::system::assert_is_system(system);
|
|
|
|
/// ```
|
2024-08-28 01:37:19 +00:00
|
|
|
pub fn cross_2d(&mut self, isometry: Isometry2d, half_size: f32, color: impl Into<Color>) {
|
2024-06-17 15:45:32 +00:00
|
|
|
let color: Color = color.into();
|
2024-08-28 01:37:19 +00:00
|
|
|
[Vec2::X, Vec2::Y]
|
|
|
|
.map(|axis| axis * half_size)
|
|
|
|
.into_iter()
|
|
|
|
.for_each(|axis| {
|
|
|
|
self.line_2d(isometry * axis, isometry * (-axis), color);
|
|
|
|
});
|
2024-06-17 15:45:32 +00:00
|
|
|
}
|
|
|
|
}
|