gemini_engine::view3d

Struct Light

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

The type of light and the way it affects faces based on their normals

§intensity: f64

The intensity of the light

Implementations§

Source§

impl Light

Source

pub const fn new_ambient(intensity: f64) -> Self

Create a new ambient light

Examples found in repository?
examples/donut.rs (line 23)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
fn main() {
    let mut view = View::new(100, 45, ColChar::EMPTY);
    let mut viewport = Viewport::new(
        Transform3D::look_at_lh(Vec3D::new(0.0, -3.0, 6.0), Vec3D::ZERO, Vec3D::Y),
        FOV,
        view.center(),
    );

    viewport.display_mode = DisplayMode::Illuminated {
        lights: vec![
            Light::new_ambient(0.3),
            Light::new_directional(0.7, Vec3D::new(1.0, 1.0, 1.0)),
        ],
    };

    viewport.objects.push(Mesh3D::torus(1.8, 1.0, 32, 16));

    fps_gameloop!(
        {
            let donut_tr = &mut viewport.objects[0].transform;
            *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_y(-0.03));
            *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_x(0.03));
        },
        {
            view.clear();
            view.draw(&viewport);
            let _ = view.display_render();
        },
        FPS
    );
}
More examples
Hide additional examples
examples/spinning-cube.rs (line 26)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let mut view = View::new(100, 50, ColChar::EMPTY);

    let mut viewport = Viewport::new(
        Transform3D::look_at_lh(Vec3D::new(0.0, -1.5, 4.3), Vec3D::ZERO, Vec3D::Y),
        FOV,
        view.center(),
    );
    viewport.objects.push(Mesh3D::default_cube());

    viewport.display_mode = DisplayMode::Illuminated {
        lights: vec![
            Light::new_ambient(0.3),
            Light::new_directional(0.6, Vec3D::new(0.5, 1.0, 1.0)),
        ],
    };

    fps_gameloop!(
        {
            viewport.objects[0].transform = viewport.objects[0]
                .transform
                .mul_mat4(&Transform3D::from_rotation_y(-0.05));
        },
        {
            view.clear();
            view.draw(&viewport);
            let _ = view.display_render();
        },
        FPS,
        |elapsed: Duration, frame_skip| {
            println!(
                "Elapsed: {:.2?}µs | Frame skip: {}",
                elapsed.as_micros(),
                frame_skip
            );
        }
    );
}
Source

pub const fn new_directional(intensity: f64, direction: Vec3D) -> Self

Create a new directional light

Examples found in repository?
examples/donut.rs (line 24)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
fn main() {
    let mut view = View::new(100, 45, ColChar::EMPTY);
    let mut viewport = Viewport::new(
        Transform3D::look_at_lh(Vec3D::new(0.0, -3.0, 6.0), Vec3D::ZERO, Vec3D::Y),
        FOV,
        view.center(),
    );

    viewport.display_mode = DisplayMode::Illuminated {
        lights: vec![
            Light::new_ambient(0.3),
            Light::new_directional(0.7, Vec3D::new(1.0, 1.0, 1.0)),
        ],
    };

    viewport.objects.push(Mesh3D::torus(1.8, 1.0, 32, 16));

    fps_gameloop!(
        {
            let donut_tr = &mut viewport.objects[0].transform;
            *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_y(-0.03));
            *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_x(0.03));
        },
        {
            view.clear();
            view.draw(&viewport);
            let _ = view.display_render();
        },
        FPS
    );
}
More examples
Hide additional examples
examples/spinning-cube.rs (line 27)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
fn main() {
    let mut view = View::new(100, 50, ColChar::EMPTY);

    let mut viewport = Viewport::new(
        Transform3D::look_at_lh(Vec3D::new(0.0, -1.5, 4.3), Vec3D::ZERO, Vec3D::Y),
        FOV,
        view.center(),
    );
    viewport.objects.push(Mesh3D::default_cube());

    viewport.display_mode = DisplayMode::Illuminated {
        lights: vec![
            Light::new_ambient(0.3),
            Light::new_directional(0.6, Vec3D::new(0.5, 1.0, 1.0)),
        ],
    };

    fps_gameloop!(
        {
            viewport.objects[0].transform = viewport.objects[0]
                .transform
                .mul_mat4(&Transform3D::from_rotation_y(-0.05));
        },
        {
            view.clear();
            view.draw(&viewport);
            let _ = view.display_render();
        },
        FPS,
        |elapsed: Duration, frame_skip| {
            println!(
                "Elapsed: {:.2?}µs | Frame skip: {}",
                elapsed.as_micros(),
                frame_skip
            );
        }
    );
}
Source

pub const fn new_point(intensity: f64, position: Vec3D) -> Self

Create a new point light

Source

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§

Source§

impl Clone for Light

Source§

fn clone(&self) -> Light

Returns a copy 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 PartialEq for Light

Source§

fn eq(&self, other: &Light) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Light

Source§

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> 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.