Struct gemini_engine::elements3d::view3d::Transform3D

source ·
pub struct Transform3D {
    pub translation: Vec3D,
    pub rotation: Vec3D,
    pub scale: Vec3D,
}
Expand description

The Transform3D struct is used to manipulate the position of objects in 3D space

Fields§

§translation: Vec3D

The position of the object in 3D space

§rotation: Vec3D

The rotation of the object, applied in radians

§scale: Vec3D

The object’s scale

Implementations§

source§

impl Transform3D

source

pub const DEFAULT: Self = _

The default transform - no translation, no rotation and 1x scaling

source

pub const fn new_trs(translation: Vec3D, rotation: Vec3D, scale: Vec3D) -> Self

Create a Transform3D with chosen translation, rotation and scale

source

pub const fn new_tr(translation: Vec3D, rotation: Vec3D) -> Self

Create a Transform3D with chosen translation and rotation

Examples found in repository?
examples/spinning-cube.rs (line 14)
10
11
12
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
fn main() {
    let mut view = View::new(200, 90, ColChar::BACKGROUND);

    let viewport = Viewport::new(
        Transform3D::new_tr(Vec3D::new(0.0, 1.5, 4.0), Vec3D::new(-0.4, 0.0, 0.0)),
        FOV,
        view.center(),
    );

    let mut cube = Mesh3D::default_cube();

    fps_gameloop!(
        {
            view.clear();
            cube.transform.rotation.y -= 0.05;
        },
        {
            view.blit(
                &viewport.render(vec![&cube], DisplayMode::Solid),
                Wrapping::Ignore,
            );
            let _ = view.display_render();
        },
        FPS,
        |elapsed: gameloop::Duration, frame_skip| {
            println!(
                "Elapsed: {:.2?}µs | Frame skip: {}",
                elapsed.as_micros(),
                frame_skip
            );
        }
    );
}
More examples
Hide additional examples
examples/donut.rs (line 17)
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
fn main() {
    let mut view = View::new(82, 32, ColChar::EMPTY);
    let viewport = Viewport::new(
        Transform3D::new_tr(Vec3D::new(0.0, 0.0, 20.0), Vec3D::ZERO),
        FOV,
        view.center(),
    );

    let lights = vec![
        Light::new_ambient(0.3),
        Light::new_directional(0.7, Vec3D::new(1.0, -1.0, -1.0)),
    ];

    let mut donut = Mesh3D::torus(1.8, 1.0, 32, 16);

    fps_gameloop!(
        {
            donut.transform.rotation.x += 0.05;
            donut.transform.rotation.z += 0.05;
        },
        {
            view.clear();
            view.blit(
                &viewport.render(
                    vec![&donut],
                    DisplayMode::Illuminated {
                        lights: lights.clone(),
                    },
                ),
                Wrapping::Ignore,
            );
            let _ = view.display_render();
        },
        FPS
    );
}
source

pub const fn new_t(translation: Vec3D) -> Self

Create a Transform3D with chosen translation

source

pub const fn new_r(rotation: Vec3D) -> Self

Create a Transform3D with chosen rotation

source

pub fn apply_to(&self, vertices: &[Vec3D]) -> Vec<Vec3D>

Apply the transform to a slice of vertices

source

pub fn rotate(&self, value: Vec3D) -> Vec3D

Rotate the given Vec3D using the Transform3D’s rotation field

Trait Implementations§

source§

impl Clone for Transform3D

source§

fn clone(&self) -> Transform3D

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 Transform3D

source§

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

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

impl Default for Transform3D

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Mul<Vec3D> for Transform3D

source§

fn mul(self, rhs: Vec3D) -> Self::Output

Apply the transform to the Vec3D

§

type Output = Vec3D

The resulting type after applying the * operator.
source§

impl Mul for Transform3D

§

type Output = Transform3D

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign for Transform3D

source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
source§

impl Neg for Transform3D

§

type Output = Transform3D

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl Copy for Transform3D

Auto Trait Implementations§

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

§

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

§

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

§

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.