Skip to main content

TrailBuffer

Struct TrailBuffer 

Source
pub struct TrailBuffer { /* private fields */ }
Expand description

Historique borné de positions, utile pour tracer une trajectoire (draw_trail) sans laisser le buffer grandir indéfiniment.

Implementations§

Source§

impl TrailBuffer

Source

pub fn new(capacity: usize) -> Self

Examples found in repository?
examples/orbit_viewer.rs (line 35)
30    fn default() -> Self {
31        Self {
32            engine: Engine3D::default(),
33            mesh: Mesh3D::unit_cube(1.2),
34            state: TelemetryState::default(),
35            trail: TrailBuffer::new(200),
36            altitude_history: Vec::with_capacity(200),
37            time: 0.0,
38            orbit_speed: 1.0,
39            orbit_radius: 2.0,
40            paused: false,
41        }
42    }
Source

pub fn push(&mut self, p: Vec3)

Examples found in repository?
examples/orbit_viewer.rs (line 69)
46    fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
47        let ctx = ui.ctx().clone();
48
49        // 1. Simulation physique / télémétrie
50        if !self.paused {
51            let dt = ctx.input(|i| i.stable_dt).min(0.1); // Pas de temps fluide
52            self.time += dt * self.orbit_speed;
53
54            // Orbite circulaire avec oscillation verticale (altitude)
55            self.state.position = [
56                self.time.cos() * self.orbit_radius,
57                (self.time * 1.5).sin() * 0.6,
58                self.time.sin() * self.orbit_radius,
59            ];
60
61            // Attachement d'attitude (Roll, Pitch, Yaw dynamiques)
62            self.state.rotation = Rotation3D::new(
63                (self.time * 2.0).sin() * 0.2, // Léger roulis
64                (self.time * 1.5).cos() * 0.3, // Tangage
65                self.time * 0.5,               // Lacet continu
66            );
67
68            // Mise à jour des historiques
69            self.trail.push(self.state.position);
70
71            self.altitude_history.push(self.state.position[1]);
72            if self.altitude_history.len() > 200 {
73                self.altitude_history.remove(0);
74            }
75        }
76
77        // 2. Panneau de contrôle latéral (IHM)
78        egui::Panel::left("control_panel")
79            .resizable(true)
80            .default_size(240.0)
81            .show(ui, |ui| {
82                ui.heading("🛰️ Orbit Viewer");
83                ui.small("Station de sol & Télémétrie");
84                ui.separator();
85
86                // Contrôles de simulation
87                ui.label("Contrôles de l'orbite :");
88                ui.checkbox(&mut self.paused, "Pause simulation");
89                ui.add(egui::Slider::new(&mut self.orbit_speed, 0.1..=3.0).text("Vitesse"));
90                ui.add(egui::Slider::new(&mut self.orbit_radius, 0.5..=4.0).text("Rayon"));
91
92                if ui.button("🗑️ Effacer la trajectoire").clicked() {
93                    self.trail.clear();
94                    self.altitude_history.clear();
95                }
96
97                ui.separator();
98
99                // Telemetry Data Box
100                ui.label("Données en direct :");
101                egui::Frame::group(ui.style()).show(ui, |ui| {
102                    ui.monospace(format!("Pos X: {:+.2} m", self.state.position[0]));
103                    ui.monospace(format!("Alt Y: {:+.2} m", self.state.position[1]));
104                    ui.monospace(format!("Pos Z: {:+.2} m", self.state.position[2]));
105                    ui.separator();
106                    ui.monospace(format!("Pitch: {:+.2} rad", self.state.rotation.pitch));
107                    ui.monospace(format!("Yaw:   {:+.2} rad", self.state.rotation.yaw));
108                });
109
110                ui.separator();
111                ui.collapsing("🖱️ Contrôles Caméra", |ui| {
112                    ui.small("• Clic Gauche + Glisser : Orbite");
113                    ui.small("• Molette : Zoom");
114                    ui.small("• Clic Droit / Molette : Panoramique");
115                });
116            });
117
118        // 3. Zone de rendu 3D
119        egui::CentralPanel::default().show(ui, |ui| {
120            // Calcul préalable du rectangle du graphe pour éviter tout conflit de borrow avec `ui`
121            let avail_rect = ui.available_rect_before_wrap();
122            let chart_rect = egui::Rect::from_min_size(
123                egui::pos2(avail_rect.max.x - 230.0, avail_rect.min.y + 15.0),
124                egui::vec2(215.0, 90.0),
125            );
126
127            self.engine.render(ui, |r| {
128                // Rendu du maillage fil de fer du cube
129                r.draw_mesh(
130                    &self.mesh,
131                    self.state.position,
132                    self.state.rotation,
133                    egui::Color32::from_rgb(100, 200, 255),
134                );
135
136                // Repère d'axes XYZ sur l'objet
137                r.draw_axes(self.state.position, self.state.rotation, 1.2);
138
139                // Trajectoire historique
140                r.draw_trail(self.trail.as_slice(), egui::Color32::GOLD);
141
142                // Overlay Graphe 2D de télémétrie (Altitude)
143                r.draw_chart(
144                    chart_rect,
145                    &self.altitude_history,
146                    -1.0, // Min Y
147                    1.0,  // Max Y
148                    egui::Color32::GREEN,
149                );
150            });
151        });
152
153        // Demande le rafraîchissement continu de l'affichage
154        ctx.request_repaint();
155    }
Source

pub fn as_slice(&self) -> &[Vec3]

Examples found in repository?
examples/orbit_viewer.rs (line 140)
46    fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
47        let ctx = ui.ctx().clone();
48
49        // 1. Simulation physique / télémétrie
50        if !self.paused {
51            let dt = ctx.input(|i| i.stable_dt).min(0.1); // Pas de temps fluide
52            self.time += dt * self.orbit_speed;
53
54            // Orbite circulaire avec oscillation verticale (altitude)
55            self.state.position = [
56                self.time.cos() * self.orbit_radius,
57                (self.time * 1.5).sin() * 0.6,
58                self.time.sin() * self.orbit_radius,
59            ];
60
61            // Attachement d'attitude (Roll, Pitch, Yaw dynamiques)
62            self.state.rotation = Rotation3D::new(
63                (self.time * 2.0).sin() * 0.2, // Léger roulis
64                (self.time * 1.5).cos() * 0.3, // Tangage
65                self.time * 0.5,               // Lacet continu
66            );
67
68            // Mise à jour des historiques
69            self.trail.push(self.state.position);
70
71            self.altitude_history.push(self.state.position[1]);
72            if self.altitude_history.len() > 200 {
73                self.altitude_history.remove(0);
74            }
75        }
76
77        // 2. Panneau de contrôle latéral (IHM)
78        egui::Panel::left("control_panel")
79            .resizable(true)
80            .default_size(240.0)
81            .show(ui, |ui| {
82                ui.heading("🛰️ Orbit Viewer");
83                ui.small("Station de sol & Télémétrie");
84                ui.separator();
85
86                // Contrôles de simulation
87                ui.label("Contrôles de l'orbite :");
88                ui.checkbox(&mut self.paused, "Pause simulation");
89                ui.add(egui::Slider::new(&mut self.orbit_speed, 0.1..=3.0).text("Vitesse"));
90                ui.add(egui::Slider::new(&mut self.orbit_radius, 0.5..=4.0).text("Rayon"));
91
92                if ui.button("🗑️ Effacer la trajectoire").clicked() {
93                    self.trail.clear();
94                    self.altitude_history.clear();
95                }
96
97                ui.separator();
98
99                // Telemetry Data Box
100                ui.label("Données en direct :");
101                egui::Frame::group(ui.style()).show(ui, |ui| {
102                    ui.monospace(format!("Pos X: {:+.2} m", self.state.position[0]));
103                    ui.monospace(format!("Alt Y: {:+.2} m", self.state.position[1]));
104                    ui.monospace(format!("Pos Z: {:+.2} m", self.state.position[2]));
105                    ui.separator();
106                    ui.monospace(format!("Pitch: {:+.2} rad", self.state.rotation.pitch));
107                    ui.monospace(format!("Yaw:   {:+.2} rad", self.state.rotation.yaw));
108                });
109
110                ui.separator();
111                ui.collapsing("🖱️ Contrôles Caméra", |ui| {
112                    ui.small("• Clic Gauche + Glisser : Orbite");
113                    ui.small("• Molette : Zoom");
114                    ui.small("• Clic Droit / Molette : Panoramique");
115                });
116            });
117
118        // 3. Zone de rendu 3D
119        egui::CentralPanel::default().show(ui, |ui| {
120            // Calcul préalable du rectangle du graphe pour éviter tout conflit de borrow avec `ui`
121            let avail_rect = ui.available_rect_before_wrap();
122            let chart_rect = egui::Rect::from_min_size(
123                egui::pos2(avail_rect.max.x - 230.0, avail_rect.min.y + 15.0),
124                egui::vec2(215.0, 90.0),
125            );
126
127            self.engine.render(ui, |r| {
128                // Rendu du maillage fil de fer du cube
129                r.draw_mesh(
130                    &self.mesh,
131                    self.state.position,
132                    self.state.rotation,
133                    egui::Color32::from_rgb(100, 200, 255),
134                );
135
136                // Repère d'axes XYZ sur l'objet
137                r.draw_axes(self.state.position, self.state.rotation, 1.2);
138
139                // Trajectoire historique
140                r.draw_trail(self.trail.as_slice(), egui::Color32::GOLD);
141
142                // Overlay Graphe 2D de télémétrie (Altitude)
143                r.draw_chart(
144                    chart_rect,
145                    &self.altitude_history,
146                    -1.0, // Min Y
147                    1.0,  // Max Y
148                    egui::Color32::GREEN,
149                );
150            });
151        });
152
153        // Demande le rafraîchissement continu de l'affichage
154        ctx.request_repaint();
155    }
Source

pub fn clear(&mut self)

Examples found in repository?
examples/orbit_viewer.rs (line 93)
46    fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
47        let ctx = ui.ctx().clone();
48
49        // 1. Simulation physique / télémétrie
50        if !self.paused {
51            let dt = ctx.input(|i| i.stable_dt).min(0.1); // Pas de temps fluide
52            self.time += dt * self.orbit_speed;
53
54            // Orbite circulaire avec oscillation verticale (altitude)
55            self.state.position = [
56                self.time.cos() * self.orbit_radius,
57                (self.time * 1.5).sin() * 0.6,
58                self.time.sin() * self.orbit_radius,
59            ];
60
61            // Attachement d'attitude (Roll, Pitch, Yaw dynamiques)
62            self.state.rotation = Rotation3D::new(
63                (self.time * 2.0).sin() * 0.2, // Léger roulis
64                (self.time * 1.5).cos() * 0.3, // Tangage
65                self.time * 0.5,               // Lacet continu
66            );
67
68            // Mise à jour des historiques
69            self.trail.push(self.state.position);
70
71            self.altitude_history.push(self.state.position[1]);
72            if self.altitude_history.len() > 200 {
73                self.altitude_history.remove(0);
74            }
75        }
76
77        // 2. Panneau de contrôle latéral (IHM)
78        egui::Panel::left("control_panel")
79            .resizable(true)
80            .default_size(240.0)
81            .show(ui, |ui| {
82                ui.heading("🛰️ Orbit Viewer");
83                ui.small("Station de sol & Télémétrie");
84                ui.separator();
85
86                // Contrôles de simulation
87                ui.label("Contrôles de l'orbite :");
88                ui.checkbox(&mut self.paused, "Pause simulation");
89                ui.add(egui::Slider::new(&mut self.orbit_speed, 0.1..=3.0).text("Vitesse"));
90                ui.add(egui::Slider::new(&mut self.orbit_radius, 0.5..=4.0).text("Rayon"));
91
92                if ui.button("🗑️ Effacer la trajectoire").clicked() {
93                    self.trail.clear();
94                    self.altitude_history.clear();
95                }
96
97                ui.separator();
98
99                // Telemetry Data Box
100                ui.label("Données en direct :");
101                egui::Frame::group(ui.style()).show(ui, |ui| {
102                    ui.monospace(format!("Pos X: {:+.2} m", self.state.position[0]));
103                    ui.monospace(format!("Alt Y: {:+.2} m", self.state.position[1]));
104                    ui.monospace(format!("Pos Z: {:+.2} m", self.state.position[2]));
105                    ui.separator();
106                    ui.monospace(format!("Pitch: {:+.2} rad", self.state.rotation.pitch));
107                    ui.monospace(format!("Yaw:   {:+.2} rad", self.state.rotation.yaw));
108                });
109
110                ui.separator();
111                ui.collapsing("🖱️ Contrôles Caméra", |ui| {
112                    ui.small("• Clic Gauche + Glisser : Orbite");
113                    ui.small("• Molette : Zoom");
114                    ui.small("• Clic Droit / Molette : Panoramique");
115                });
116            });
117
118        // 3. Zone de rendu 3D
119        egui::CentralPanel::default().show(ui, |ui| {
120            // Calcul préalable du rectangle du graphe pour éviter tout conflit de borrow avec `ui`
121            let avail_rect = ui.available_rect_before_wrap();
122            let chart_rect = egui::Rect::from_min_size(
123                egui::pos2(avail_rect.max.x - 230.0, avail_rect.min.y + 15.0),
124                egui::vec2(215.0, 90.0),
125            );
126
127            self.engine.render(ui, |r| {
128                // Rendu du maillage fil de fer du cube
129                r.draw_mesh(
130                    &self.mesh,
131                    self.state.position,
132                    self.state.rotation,
133                    egui::Color32::from_rgb(100, 200, 255),
134                );
135
136                // Repère d'axes XYZ sur l'objet
137                r.draw_axes(self.state.position, self.state.rotation, 1.2);
138
139                // Trajectoire historique
140                r.draw_trail(self.trail.as_slice(), egui::Color32::GOLD);
141
142                // Overlay Graphe 2D de télémétrie (Altitude)
143                r.draw_chart(
144                    chart_rect,
145                    &self.altitude_history,
146                    -1.0, // Min Y
147                    1.0,  // Max Y
148                    egui::Color32::GREEN,
149                );
150            });
151        });
152
153        // Demande le rafraîchissement continu de l'affichage
154        ctx.request_repaint();
155    }

Trait Implementations§

Source§

impl Clone for TrailBuffer

Source§

fn clone(&self) -> TrailBuffer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TrailBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more