Skip to content

Commit f632122

Browse files
committed
Added class methods position and look_at to Light
1 parent d0285b9 commit f632122

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

crates/processing_pyo3/examples/lights.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@ def setup():
1111

1212
# Point Lights
1313
point_light_a = create_point_light(1.0, 0.5, 0.25, 1000000.0, 200.0, 0.5)
14+
point_light_a.position(-25.0, 5.0, 51.0)
15+
point_light_a.look_at(0.0, 0.0, 0.0)
16+
1417
point_light_b = create_point_light(0.0, 0.5, 0.75, 2000000.0, 200.0, 0.25)
18+
point_light_b.position(0.0, 5.0, 50.5)
19+
point_light_b.look_at(0.0, 0.0, 0.0)
1520

1621
# Spot Light
1722
spot_light = create_spot_light(0.25, 0.8, 0.19, 15.0 * 1000000.0, 200.0, 0.84, 0.0, 0.7854)
23+
spot_light.position(40.0, 0.0, 70.0)
24+
spot_light.look_at(0.0, 0.0, 0.0)
1825

1926
def draw():
2027
global angle

crates/processing_pyo3/src/graphics.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ pub struct Light {
2929
entity: Entity,
3030
}
3131

32+
#[pymethods]
33+
impl Light {
34+
pub fn position(&self, x: f32, y: f32, z: f32) -> PyResult<()> {
35+
transform_set_position(self.entity, x, y, z)
36+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
37+
}
38+
39+
pub fn look_at(&self, x: f32, y: f32, z: f32) -> PyResult<()> {
40+
transform_look_at(self.entity, x, y, z).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
41+
}
42+
}
43+
3244
// TODO: implement `light_destroy`
3345
// impl Drop for Light {
3446
// fn drop(&mut self) {

0 commit comments

Comments
 (0)