Skip to content

Commit a3cddd3

Browse files
committed
add translation
1 parent 071899f commit a3cddd3

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

crates/processing_pyo3/src/graphics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ impl Graphics {
233233
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
234234
}
235235

236+
pub fn translate_3d(&self, x: f32, y: f32, z: f32) -> PyResult<()> {
237+
graphics_record_command(self.entity, DrawCommand::Translate3D { x, y, z })
238+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
239+
}
240+
236241
pub fn rotate(&self, angle: f32) -> PyResult<()> {
237242
graphics_record_command(self.entity, DrawCommand::Rotate { angle })
238243
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))

crates/processing_pyo3/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ fn processing(m: &Bound<'_, PyModule>) -> PyResult<()> {
3030
m.add_function(wrap_pyfunction!(push_matrix, m)?)?;
3131
m.add_function(wrap_pyfunction!(pop_matrix, m)?)?;
3232
m.add_function(wrap_pyfunction!(rotate, m)?)?;
33+
m.add_function(wrap_pyfunction!(translate, m)?)?;
34+
m.add_function(wrap_pyfunction!(translate_3d, m)?)?;
3335
m.add_function(wrap_pyfunction!(draw_box, m)?)?;
3436
m.add_function(wrap_pyfunction!(background, m)?)?;
3537
m.add_function(wrap_pyfunction!(fill, m)?)?;
@@ -151,6 +153,18 @@ fn rotate(module: &Bound<'_, PyModule>, angle: f32) -> PyResult<()> {
151153
get_graphics(module)?.rotate(angle)
152154
}
153155

156+
#[pyfunction]
157+
#[pyo3(pass_module)]
158+
fn translate(module: &Bound<'_, PyModule>, x: f32, y: f32) -> PyResult<()> {
159+
get_graphics(module)?.translate(x, y)
160+
}
161+
162+
#[pyfunction]
163+
#[pyo3(pass_module)]
164+
fn translate_3d(module: &Bound<'_, PyModule>, x: f32, y: f32, z: f32) -> PyResult<()> {
165+
get_graphics(module)?.translate_3d(x, y, z)
166+
}
167+
154168
#[pyfunction]
155169
#[pyo3(pass_module)]
156170
fn draw_box(module: &Bound<'_, PyModule>, x: f32, y: f32, z: f32) -> PyResult<()> {

crates/processing_render/src/render/command.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ pub enum DrawCommand {
2323
x: f32,
2424
y: f32,
2525
},
26+
Translate3D {
27+
x: f32,
28+
y: f32,
29+
z: f32,
30+
},
2631
Rotate {
2732
angle: f32,
2833
},

crates/processing_render/src/render/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ pub fn flush_draw_commands(
202202
DrawCommand::PopMatrix => state.transform.pop(),
203203
DrawCommand::ResetMatrix => state.transform.reset(),
204204
DrawCommand::Translate { x, y } => state.transform.translate(x, y),
205+
DrawCommand::Translate3D { x, y, z } => state.transform.translate_3d(x, y, z),
205206
DrawCommand::Rotate { angle } => state.transform.rotate(angle),
206207
DrawCommand::Scale { x, y } => state.transform.scale(x, y),
207208
DrawCommand::ShearX { angle } => state.transform.shear_x(angle),

0 commit comments

Comments
 (0)