Skip to content

Commit 77b3417

Browse files
committed
add disabling of matrices without deleting them
1 parent ad7f986 commit 77b3417

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/application/state.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct ApplicationState {
1919
pub renderer: Renderer,
2020
input: Input,
2121

22-
matrix_stack: Vec<(Mat4<f32>, MatrixInteractionType)>,
22+
matrix_stack: Vec<(Mat4<f32>, MatrixInteractionType, bool)>,
2323
show_full_matrix: bool,
2424
model: Model,
2525
}
@@ -57,7 +57,7 @@ impl ApplicationState {
5757
_renderable,
5858
transform: Mat4::identity()
5959
};
60-
let matrix_stack = vec![(Mat4::identity(),MatrixInteractionType::CustomMatrix)];
60+
let matrix_stack = vec![(Mat4::identity(),MatrixInteractionType::CustomMatrix, true)];
6161
let camera = Camera::new();
6262
renderer.add_global_buffer(
6363
"camera".into(),
@@ -110,6 +110,8 @@ impl ApplicationState {
110110
.input_state
111111
.egui_ctx()
112112
.run(raw_input, |ctx| {
113+
#[cfg(debug_assertions)] // doesn't exclusively mean we're building in debug mode,
114+
// but close enough
113115
egui::Window::new( "Debug").show(ctx, |ui| {
114116
ui.label(format!("Camera position: {}", self.camera.position));
115117
ui.label(format!("Camera zoom: {}", self.camera.zoom));
@@ -135,24 +137,28 @@ impl ApplicationState {
135137
let row_height = 5.5 + (self.show_full_matrix as u8 as f32) * ui.text_style_height(&egui::TextStyle::Body);
136138
let total_rows = self.matrix_stack.len();
137139
egui::ScrollArea::vertical().show_rows(ui, row_height, total_rows,|ui, row_range| {
138-
for (idx, (mat, interaction_type)) in self.matrix_stack[row_range].iter_mut().enumerate() {
140+
for (idx, (mat, interaction_type, enabled)) in self.matrix_stack[row_range].iter_mut().enumerate() {
139141
let frame = egui::Frame::default().inner_margin(1.0);
140142
// specify zone for drag n drop
141143
let (_, _dropped_payload) = ui.dnd_drop_zone::<usize, ()>(frame, |ui| {
142144
let item_id = egui::Id::new(("matrix_stack_drag_and_drop", idx));
143145
// track dragging events
144146
let response = ui.group(|ui| {
145147
// make list elements draggable by their names
146-
ui.dnd_drag_source(item_id, idx, |ui| {
147-
ui.label(
148-
match interaction_type {
149-
MatrixInteractionType::CustomMatrix => "Custom matrix",
150-
MatrixInteractionType::RotationMatrixZ(_) => "Rotation",
151-
MatrixInteractionType::ScaleMatrix2D(_) => "Scale",
152-
MatrixInteractionType::TranslationMatrix2D(_) => "Translation",
148+
ui.horizontal(|ui| {
149+
ui.dnd_drag_source(item_id, idx, |ui| {
150+
ui.label(
151+
match interaction_type {
152+
MatrixInteractionType::CustomMatrix => "Custom matrix",
153+
MatrixInteractionType::RotationMatrixZ(_) => "Rotation",
154+
MatrixInteractionType::ScaleMatrix2D(_) => "Scale",
155+
MatrixInteractionType::TranslationMatrix2D(_) => "Translation",
156+
});
153157
});
158+
if idx > 0 {
159+
ui.checkbox(enabled, "Active?");
160+
}
154161
});
155-
156162
// matrix list entry
157163
ui.group(|ui| {
158164
let values = mat.as_mut_col_slice();
@@ -234,16 +240,16 @@ impl ApplicationState {
234240
let translation_clicked = ui.button("Translation").clicked();
235241
let any_clicked = custom_clicked || rotation_clicked || scale_clicked || translation_clicked;
236242
if custom_clicked {
237-
self.matrix_stack.push((Mat4::identity(), MatrixInteractionType::CustomMatrix));
243+
self.matrix_stack.push((Mat4::identity(), MatrixInteractionType::CustomMatrix, true));
238244
}
239245
else if rotation_clicked {
240-
self.matrix_stack.push((Mat4::identity(), MatrixInteractionType::RotationMatrixZ(0.0)));
246+
self.matrix_stack.push((Mat4::identity(), MatrixInteractionType::RotationMatrixZ(0.0), true));
241247
}
242248
else if scale_clicked {
243-
self.matrix_stack.push((Mat4::identity(), MatrixInteractionType::ScaleMatrix2D(Vec2::new(1.0,1.0))));
249+
self.matrix_stack.push((Mat4::identity(), MatrixInteractionType::ScaleMatrix2D(Vec2::new(1.0,1.0)), true));
244250
}
245251
else if translation_clicked {
246-
self.matrix_stack.push((Mat4::identity(), MatrixInteractionType::TranslationMatrix2D(Vec2::new(0.0,0.0))));
252+
self.matrix_stack.push((Mat4::identity(), MatrixInteractionType::TranslationMatrix2D(Vec2::new(0.0,0.0)), true));
247253
}
248254
if any_clicked {
249255
ui.close_menu();
@@ -273,7 +279,7 @@ impl ApplicationState {
273279
let view_proj = self.camera.get_matrix(self.renderer.aspect());
274280
let mat = view_proj;
275281

276-
self.model.transform = self.matrix_stack.iter().fold(Mat4::identity(), |acc, m| {acc * m.0});
282+
self.model.transform = self.matrix_stack.iter().fold(Mat4::identity(), |acc, m| {acc * if m.2 {m.0} else {Mat4::identity()}});
277283

278284
self.renderer.write_buffer("camera", bytemuck::cast_slice(mat.as_col_slice()));
279285

src/renderer/pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl DefaultPass {
130130
let mut builder = PipelineBuilder::new(&v_shader_spv, Some("main"), true);
131131
let pipeline = builder
132132
.with_fragment_shader(&f_shader_spv, Some("main"))
133-
.with_cull_mode(wgpu::Face::Back)
133+
//.with_cull_mode(wgpu::Face::Back)
134134
.add_fragment_target(Some(wgpu::ColorTargetState {
135135
format: config.format,
136136
blend: Some(BlendState::REPLACE),

0 commit comments

Comments
 (0)