pub struct Light {
pub coords: Vec3,
pub color: Rgb,
pub brightness: f32,
pub light_type: LightType,
}Expand description
Light used in shadowing calculations.
§Examples
let light = Light::directional("#ffffff", [-1.0, 1.0, 0.0]);
t.light(light);Fields§
§coords: Vec3either direction or position of the light
color: Rgbcolor of the light
brightness: f32brightness of the light, multiplied with the color in shaders
light_type: LightTypethe type of the light
Implementations§
Source§impl Light
impl Light
Sourcepub fn directional(color: impl Into<Rgb>, direction: impl Into<Vec3>) -> Self
pub fn directional(color: impl Into<Rgb>, direction: impl Into<Vec3>) -> Self
Create directional light
Examples found in repository?
examples/3d-examples/rotating_cube.rs (line 22)
14fn main() -> Result<()> {
15 // create duku context and window
16 let (mut duku, window) = Duku::windowed(500, 500)?;
17
18 // create 3D camera with 90 fov
19 let camera = Camera::perspective(90);
20
21 // create directional light
22 let light = Light::directional("#ffffff", [-1.0, -1.0, 1.0]);
23
24 // start timer for rotation and color
25 let timer = Instant::now();
26
27 // start window loop
28 window.while_open(move |_| {
29 // start drawing on window
30 duku.draw(Some(&camera), |t| {
31 // setup scene
32 t.background("#ababab");
33 t.light(light);
34
35 // get elapsed time since start
36 let elapsed = timer.elapsed().as_secs_f32();
37
38 // transform scene
39 let angle = elapsed * 45.0;
40 t.rotate_x(angle);
41 t.rotate_y(angle);
42 t.translate_z(2.0);
43
44 // draw cube
45 let hue = (elapsed * 60.0) as u16;
46 t.tint(Hsb::new(hue, 70, 80));
47 t.cube([1.0, 1.0, 1.0]);
48 });
49 });
50
51 Ok(())
52}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Light
impl RefUnwindSafe for Light
impl Send for Light
impl Sync for Light
impl Unpin for Light
impl UnwindSafe for Light
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more