1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//! Drawing methods for 2D and 3D primitives.
use std::sync::Arc;
use glamx::{Vec2, Vec3};
use crate::color::Color;
use crate::renderer::{Polyline2d, Polyline3d};
use crate::text::Font;
use super::Window;
impl Window {
/// Draws a 3D line for the current frame.
///
/// The line is only drawn during the next frame. To keep a line visible,
/// call this method every frame from within your render loop.
///
/// # Arguments
/// * `a` - The starting point of the line in 3D space
/// * `b` - The ending point of the line in 3D space
/// * `color` - RGBA color (each component from 0.0 to 1.0)
/// * `width` - Line width in pixels
/// * `perspective` - Indicates if the rendered line size is affected by perspective (gets
/// smaller as camera gets further)
///
/// # Example
/// ```no_run
/// # use kiss3d::window::Window;
/// # use kiss3d::color::RED;
/// # use glamx::Vec3;
/// # #[kiss3d::main]
/// # async fn main() {
/// # let mut window = Window::new("Example").await;
/// let start = Vec3::new(0.0, 0.0, 0.0);
/// let end = Vec3::new(1.0, 1.0, 1.0);
/// window.draw_line(start, end, RED, 2.0, false);
/// # }
/// ```
#[inline]
pub fn draw_line(&mut self, a: Vec3, b: Vec3, color: Color, width: f32, perspective: bool) {
self.polyline_renderer
.draw_line(a, b, color, width, perspective);
}
/// Draws a 2D line for the current frame.
///
/// The line is only drawn during the next frame. To keep a line visible,
/// call this method every frame from within your render loop.
///
/// # Arguments
/// * `a` - The starting point of the line in 2D space
/// * `b` - The ending point of the line in 2D space
/// * `color` - RGBA color (each component from 0.0 to 1.0)
/// * `width` - Line width in pixels
#[inline]
pub fn draw_line_2d(&mut self, a: Vec2, b: Vec2, color: Color, width: f32) {
self.polyline_renderer_2d.draw_line(a, b, color, width);
}
/// Draws a 2D polyline (connected line segments) with configurable width.
///
/// The polyline is only drawn during the next frame. To keep it visible,
/// call this method every frame from within your render loop.
///
/// Takes a reference to avoid allocations - segments are built immediately.
///
/// # Arguments
/// * `polyline` - The 2D polyline to draw
///
/// # Example
/// ```no_run
/// # use kiss3d::prelude::*;
/// # #[kiss3d::main]
/// # async fn main() {
/// # let mut window = Window::new("Example").await;
/// # let mut camera = OrbitCamera3d::default();
/// # let mut scene = SceneNode3d::empty();
/// let polyline = Polyline2d::new(vec![
/// Vec2::new(0.0, 0.0),
/// Vec2::new(100.0, 100.0),
/// Vec2::new(200.0, 0.0),
/// ])
/// .with_color(RED)
/// .with_width(5.0);
/// window.draw_polyline_2d(&polyline);
/// # }
/// ```
#[inline]
pub fn draw_polyline_2d(&mut self, polyline: &Polyline2d) {
self.polyline_renderer_2d.draw_polyline(polyline);
}
/// Draws a 2D point for the current frame.
///
/// The point is only drawn during the next frame. To keep a point visible,
/// call this method every frame from within your render loop.
///
/// # Arguments
/// * `pt` - The position of the point in 2D space
/// * `color` - RGBA color (each component from 0.0 to 1.0)
/// * `size` - The point size in pixels
#[inline]
pub fn draw_point_2d(&mut self, pt: Vec2, color: Color, size: f32) {
self.point_renderer_2d.draw_point(pt, color, size);
}
/// Draws a 3D point for the current frame.
///
/// The point is only drawn during the next frame. To keep a point visible,
/// call this method every frame from within your render loop.
///
/// # Arguments
/// * `pt` - The position of the point in 3D space
/// * `color` - RGBA color (each component from 0.0 to 1.0)
/// * `size` - The point size in pixels
#[inline]
pub fn draw_point(&mut self, pt: Vec3, color: Color, size: f32) {
self.point_renderer.draw_point(pt, color, size);
}
/// Draws a polyline (connected line segments) with configurable width.
///
/// The polyline is only drawn during the next frame. To keep it visible,
/// call this method every frame from within your render loop.
///
/// # Arguments
/// * `polyline` - The polyline to draw
///
/// # Example
/// ```no_run
/// # use kiss3d::prelude::*;
/// # use kiss3d::renderer::Polyline3d;
/// # use glamx::Vec3;
/// # #[kiss3d::main]
/// # async fn main() {
/// # let mut window = Window::new("Example").await;
/// let polyline = Polyline3d::new(vec![
/// Vec3::new(0.0, 0.0, 0.0),
/// Vec3::new(1.0, 1.0, 0.0),
/// Vec3::new(2.0, 0.0, 0.0),
/// ])
/// .with_color(RED)
/// .with_width(5.0);
/// window.draw_polyline(&polyline);
/// # }
/// ```
#[inline]
pub fn draw_polyline(&mut self, polyline: &Polyline3d) {
self.polyline_renderer.draw_polyline(polyline);
}
/// Draws text for the current frame.
///
/// The text is only drawn during the next frame. To keep text visible,
/// call this method every frame from within your render loop.
///
/// # Arguments
/// * `text` - The string to display
/// * `pos` - The position in 2D screen coordinates
/// * `scale` - The text scale factor
/// * `font` - A reference to the font to use
/// * `color` - RGBA color (each component from 0.0 to 1.0)
#[inline]
pub fn draw_text(&mut self, text: &str, pos: Vec2, scale: f32, font: &Arc<Font>, color: Color) {
self.text_renderer.draw_text(text, pos, scale, font, color);
}
}