bevy_gizmos/cross.rs
1//! Additional [`GizmoBuffer`] Functions -- Crosses
2//!
3//! Includes the implementation of [`GizmoBuffer::cross`] and [`GizmoBuffer::cross_2d`],
4//! and assorted support items.
5
6use crate::{gizmos::GizmoBuffer, prelude::GizmoConfigGroup};
7use bevy_color::Color;
8use bevy_math::{Isometry2d, Isometry3d, Vec2, Vec3};
9
10impl<Config, Clear> GizmoBuffer<Config, Clear>
11where
12 Config: GizmoConfigGroup,
13 Clear: 'static + Send + Sync,
14{
15 /// Draw a cross in 3D with the given `isometry` applied.
16 ///
17 /// If `isometry == Isometry3d::IDENTITY` then
18 ///
19 /// - the center is at `Vec3::ZERO`
20 /// - the `half_size`s are aligned with the `Vec3::X`, `Vec3::Y` and `Vec3::Z` axes.
21 ///
22 /// # Example
23 /// ```
24 /// # use bevy_gizmos::prelude::*;
25 /// # use bevy_math::prelude::*;
26 /// # use bevy_color::palettes::basic::WHITE;
27 /// fn system(mut gizmos: Gizmos) {
28 /// gizmos.cross(Isometry3d::IDENTITY, 0.5, WHITE);
29 /// }
30 /// # bevy_ecs::system::assert_is_system(system);
31 /// ```
32 pub fn cross(
33 &mut self,
34 isometry: impl Into<Isometry3d>,
35 half_size: f32,
36 color: impl Into<Color>,
37 ) {
38 let isometry = isometry.into();
39 let color: Color = color.into();
40 [Vec3::X, Vec3::Y, Vec3::Z]
41 .map(|axis| axis * half_size)
42 .into_iter()
43 .for_each(|axis| {
44 self.line(isometry * axis, isometry * (-axis), color);
45 });
46 }
47
48 /// Draw a cross in 2D with the given `isometry` applied.
49 ///
50 /// If `isometry == Isometry2d::IDENTITY` then
51 ///
52 /// - the center is at `Vec3::ZERO`
53 /// - the `half_size`s are aligned with the `Vec3::X` and `Vec3::Y` axes.
54 ///
55 /// # Example
56 /// ```
57 /// # use bevy_gizmos::prelude::*;
58 /// # use bevy_math::prelude::*;
59 /// # use bevy_color::palettes::basic::WHITE;
60 /// fn system(mut gizmos: Gizmos) {
61 /// gizmos.cross_2d(Isometry2d::IDENTITY, 0.5, WHITE);
62 /// }
63 /// # bevy_ecs::system::assert_is_system(system);
64 /// ```
65 pub fn cross_2d(
66 &mut self,
67 isometry: impl Into<Isometry2d>,
68 half_size: f32,
69 color: impl Into<Color>,
70 ) {
71 let isometry = isometry.into();
72 let color: Color = color.into();
73 [Vec2::X, Vec2::Y]
74 .map(|axis| axis * half_size)
75 .into_iter()
76 .for_each(|axis| {
77 self.line_2d(isometry * axis, isometry * (-axis), color);
78 });
79 }
80}