Skip to main content

Transform3D

Struct Transform3D 

Source
pub struct Transform3D { /* private fields */ }
Expand description

A 3D transform with position, rotation (Euler angles in degrees), and scale.

The transform maintains a 4×4 TRS matrix (translate × rotate × scale). Call calc_matrix after mutating to recompute it.

§Operations

CategoryMethods
Position — getterpos
Position — absolute setterset_pos_all, set_pos_x, set_pos_y, set_pos_z
Position — relative movemove_all, move_x, move_y, move_z
Rotation — getterrot
Rotation — absolute setterset_rot_all, set_rot_x, set_rot_y, set_rot_z
Rotation — relative addrotate_all, rotate_x, rotate_y, rotate_z
Scale — getterscale
Scale — absolute setterset_scale_all, set_scale_same, set_scale_x, set_scale_y, set_scale_z
Scale — relative addscale_all, scale_same, scale_x, scale_y, scale_z
Matrixmatrix, calc_matrix

§Example

use optic_render::Transform3D;

let mut t = Transform3D::default();
t.set_pos_all(10.0, 0.0, 0.0);
t.rotate_y(90.0);
t.calc_matrix();

Implementations§

Source§

impl Transform3D

Source

pub fn calc_matrix(&mut self)

Recomputes the transformation matrix from the current pos/rot/scale.

Source

pub fn pos(&self) -> Vector3<f32>

Returns the position.

Source

pub fn rot(&self) -> Vector3<f32>

Returns the rotation (Euler angles in degrees).

Source

pub fn scale(&self) -> Vector3<f32>

Returns the scale.

Source

pub fn matrix(&self) -> Matrix4<f32>

Returns the cached 4×4 transformation matrix.

Source

pub fn move_all(&mut self, x: f32, y: f32, z: f32)

Translates by (x, y, z).

Source

pub fn move_x(&mut self, x: f32)

Translates along the X axis.

Source

pub fn move_y(&mut self, y: f32)

Translates along the Y axis.

Source

pub fn move_z(&mut self, z: f32)

Translates along the Z axis.

Source

pub fn set_pos_all(&mut self, x: f32, y: f32, z: f32)

Sets the position to (x, y, z).

Source

pub fn set_pos_x(&mut self, x: f32)

Sets the X coordinate.

Source

pub fn set_pos_y(&mut self, y: f32)

Sets the Y coordinate.

Source

pub fn set_pos_z(&mut self, z: f32)

Sets the Z coordinate.

Source

pub fn rotate_all(&mut self, x: f32, y: f32, z: f32)

Rotates by (x, y, z) degrees.

Source

pub fn rotate_x(&mut self, x: f32)

Rotates around the X axis.

Source

pub fn rotate_y(&mut self, y: f32)

Rotates around the Y axis.

Source

pub fn rotate_z(&mut self, z: f32)

Rotates around the Z axis.

Source

pub fn set_rot_all(&mut self, x: f32, y: f32, z: f32)

Sets the rotation to (x, y, z) degrees.

Source

pub fn set_rot_x(&mut self, x: f32)

Sets the X rotation.

Source

pub fn set_rot_y(&mut self, y: f32)

Sets the Y rotation.

Source

pub fn set_rot_z(&mut self, z: f32)

Sets the Z rotation.

Source

pub fn scale_all(&mut self, x: f32, y: f32, z: f32)

Adds (x, y, z) to the scale.

Source

pub fn scale_same(&mut self, xyz: f32)

Adds xyz to all three scale components.

Source

pub fn scale_x(&mut self, x: f32)

Adds x to the scale X component.

Source

pub fn scale_y(&mut self, y: f32)

Adds y to the scale Y component.

Source

pub fn scale_z(&mut self, z: f32)

Adds z to the scale Z component.

Source

pub fn set_scale_all(&mut self, x: f32, y: f32, z: f32)

Sets the scale to (x, y, z).

Source

pub fn set_scale_same(&mut self, xyz: f32)

Sets all three scale components to xyz.

Source

pub fn set_scale_x(&mut self, x: f32)

Sets the scale X component.

Source

pub fn set_scale_y(&mut self, y: f32)

Sets the scale Y component.

Source

pub fn set_scale_z(&mut self, z: f32)

Sets the scale Z component.

Trait Implementations§

Source§

impl Clone for Transform3D

Source§

fn clone(&self) -> Transform3D

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where 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> 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.
Source§

impl<T> Upcast<T> for T

Source§

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