pub struct Light {
    pub light_type: LightType,
    pub intensity: f64,
}Expand description
A light object used to define a scene’s lighting. Used by DisplayMode::Illuminated
Fields§
§light_type: LightTypeThe type of light and the way it affects faces based on their normals
intensity: f64The intensity of the light
Implementations§
Source§impl Light
 
impl Light
Sourcepub const fn new_ambient(intensity: f64) -> Self
 
pub const fn new_ambient(intensity: f64) -> Self
Create a new ambient light
Examples found in repository?
examples/donut.rs (line 23)
13fn main() {
14    let mut view = View::new(100, 45, ColChar::EMPTY);
15    let mut viewport = Viewport::new(
16        Transform3D::look_at_lh(Vec3D::new(0.0, -3.0, 6.0), Vec3D::ZERO, Vec3D::Y),
17        FOV,
18        view.center(),
19    );
20
21    viewport.display_mode = DisplayMode::Illuminated {
22        lights: vec![
23            Light::new_ambient(0.3),
24            Light::new_directional(0.7, Vec3D::new(1.0, 1.0, 1.0)),
25        ],
26    };
27
28    viewport.objects.push(Mesh3D::torus(1.8, 1.0, 32, 16));
29
30    loop {
31        let donut_tr = &mut viewport.objects[0].transform;
32        *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_y(-0.03));
33        *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_x(0.03));
34
35        view.clear();
36        view.draw(&viewport);
37        let _ = view.display_render();
38
39        thread::sleep(Duration::from_secs_f32(1.0 / FPS));
40    }
41}More examples
examples/spinning-cube.rs (line 26)
14fn main() {
15    let mut view = View::new(100, 50, ColChar::EMPTY);
16
17    let mut viewport = Viewport::new(
18        Transform3D::look_at_lh(Vec3D::new(0.0, -1.5, 4.3), Vec3D::ZERO, Vec3D::Y),
19        FOV,
20        view.center(),
21    );
22    viewport.objects.push(Mesh3D::default_cube());
23
24    viewport.display_mode = DisplayMode::Illuminated {
25        lights: vec![
26            Light::new_ambient(0.3),
27            Light::new_directional(0.6, Vec3D::new(0.5, 1.0, 1.0)),
28        ],
29    };
30
31    fps_gameloop!(
32        {
33            viewport.objects[0].transform = viewport.objects[0]
34                .transform
35                .mul_mat4(&Transform3D::from_rotation_y(-0.05));
36        },
37        {
38            view.clear();
39            view.draw(&viewport);
40            let _ = view.display_render();
41        },
42        FPS,
43        |elapsed: Duration, frame_skip| {
44            println!(
45                "Elapsed: {:.2?}µs | Frame skip: {}",
46                elapsed.as_micros(),
47                frame_skip
48            );
49        }
50    );
51}Sourcepub const fn new_directional(intensity: f64, direction: Vec3D) -> Self
 
pub const fn new_directional(intensity: f64, direction: Vec3D) -> Self
Create a new directional light
Examples found in repository?
examples/donut.rs (line 24)
13fn main() {
14    let mut view = View::new(100, 45, ColChar::EMPTY);
15    let mut viewport = Viewport::new(
16        Transform3D::look_at_lh(Vec3D::new(0.0, -3.0, 6.0), Vec3D::ZERO, Vec3D::Y),
17        FOV,
18        view.center(),
19    );
20
21    viewport.display_mode = DisplayMode::Illuminated {
22        lights: vec![
23            Light::new_ambient(0.3),
24            Light::new_directional(0.7, Vec3D::new(1.0, 1.0, 1.0)),
25        ],
26    };
27
28    viewport.objects.push(Mesh3D::torus(1.8, 1.0, 32, 16));
29
30    loop {
31        let donut_tr = &mut viewport.objects[0].transform;
32        *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_y(-0.03));
33        *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_x(0.03));
34
35        view.clear();
36        view.draw(&viewport);
37        let _ = view.display_render();
38
39        thread::sleep(Duration::from_secs_f32(1.0 / FPS));
40    }
41}More examples
examples/spinning-cube.rs (line 27)
14fn main() {
15    let mut view = View::new(100, 50, ColChar::EMPTY);
16
17    let mut viewport = Viewport::new(
18        Transform3D::look_at_lh(Vec3D::new(0.0, -1.5, 4.3), Vec3D::ZERO, Vec3D::Y),
19        FOV,
20        view.center(),
21    );
22    viewport.objects.push(Mesh3D::default_cube());
23
24    viewport.display_mode = DisplayMode::Illuminated {
25        lights: vec![
26            Light::new_ambient(0.3),
27            Light::new_directional(0.6, Vec3D::new(0.5, 1.0, 1.0)),
28        ],
29    };
30
31    fps_gameloop!(
32        {
33            viewport.objects[0].transform = viewport.objects[0]
34                .transform
35                .mul_mat4(&Transform3D::from_rotation_y(-0.05));
36        },
37        {
38            view.clear();
39            view.draw(&viewport);
40            let _ = view.display_render();
41        },
42        FPS,
43        |elapsed: Duration, frame_skip| {
44            println!(
45                "Elapsed: {:.2?}µs | Frame skip: {}",
46                elapsed.as_micros(),
47                frame_skip
48            );
49        }
50    );
51}Sourcepub fn calculate_intensity(&self, point: Vec3D, normal: Vec3D) -> f64
 
pub fn calculate_intensity(&self, point: Vec3D, normal: Vec3D) -> f64
Calculate the intensity of the light as it affects a surface with the given normal
Trait Implementations§
impl Copy for Light
impl StructuralPartialEq 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> 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