Light

Struct Light 

Source
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: Vec3

either direction or position of the light

§color: Rgb

color of the light

§brightness: f32

brightness of the light, multiplied with the color in shaders

§light_type: LightType

the type of the light

Implementations§

Source§

impl Light

Source

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}
Source

pub fn point(color: impl Into<Rgb>, position: impl Into<Vec3>) -> Self

Create point light

Trait Implementations§

Source§

impl Clone for Light

Source§

fn clone(&self) -> Light

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Light

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for Light

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> 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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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.