Struct tridify_rs::Transform

source ·
pub struct Transform { /* private fields */ }
Expand description

Representation for position, rotation and scale.

Implementations§

source§

impl Transform

source

pub fn new(position: Vec3, rotation: Quat, scale: Vec3) -> Self

source

pub fn from_pos(position: Vec3) -> Self

Create transform based only on position. Rotation and scale will have default values.

source

pub fn from_look_to(eye: Vec3, forward: Vec3, up: Vec3) -> Self

Create transform based on position and view direction.

source

pub fn from_look_at(eye: Vec3, center: Vec3, up: Vec3) -> Self

Create transform based on position and view point.

Examples found in repository?
examples/texture_cube/main.rs (line 22)
6
7
8
9
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
fn main() -> Result<(), Box<dyn Error>> {
    //Create app and main window.
    let mut app = Tridify::new();
    let window = app.create_window()?;
    let gpu_ctx = window.ctx();

    //Load texture from path.
    let texture = Texture::from_path(
        gpu_ctx,
        Path::new(r#"D:\Development\Rust Crates\LDrawy\examples\draw_cube\texture.png"#),
    );

    //Sampler defines how the texture will be rendered in shapes.
    let sampler = Sampler::new_default(gpu_ctx);

    let camera = Camera::new(
        Transform::from_look_at(Vec3::NEG_Z * 10.0 + Vec3::Y * 10.0, Vec3::ZERO, Vec3::Y),
        Projection::default(),
    );
    let mut camera_buf = camera.build_buffer(gpu_ctx);

    //Create brush to draw the shapes.
    let mut brush = Brush::from_source(
        BrushDesc::default(),
        gpu_ctx,
        include_str!("shader.wgsl").to_string(),
    )?;
    //Bind camera, sampler and texture to the brush. Make sure group_index and loc_index are the same as
    //in the shader.
    brush.bind(0, 0, camera_buf.clone());
    brush.bind(1, 0, texture);
    brush.bind(1, 1, sampler);

    //Create and bake a shape batch with a cube in it.
    let shape_buffer = ShapeBatch::new()
        .add_cube(
            Vec3::ZERO,
            Quat::from_rotation_x(35.) * Quat::from_rotation_y(35.),
            Vec3::ONE * 5.,
            Color::WHITE,
        )
        .bake_buffers(gpu_ctx);

    //Setup the window render loop.
    window.set_render_loop(move |gpu, frame_ctx| {
        let model = Mat4::from_rotation_y(frame_ctx.elapsed_time as f32);
        let mvp = camera.build_camera_matrix() * model;

        //Updating the gpu buffer will update all brushes binded as well.
        camera_buf.write(gpu, bytemuck::cast_slice(&mvp.to_cols_array()));

        //Render frame as usual.
        let mut pass_builder = gpu.create_render_builder();
        let mut render_pass = pass_builder.build_render_pass(RenderOptions::default());
        render_pass.render_shapes(gpu, &mut brush, &shape_buffer);
        render_pass.finish();
        pass_builder.finish_render(gpu);
    });

    // Start program.
    app.start(());
}
source

pub fn build_matrix(&self) -> Mat4

Trait Implementations§

source§

impl Default for Transform

source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for Pwhere R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>