Vector3D

Struct Vector3D 

Source
pub struct Vector3D<S = f32, U = ()> {
    pub x: S,
    pub y: S,
    pub z: S,
    /* private fields */
}
Expand description

3D vector.

Fields§

§x: S§y: S§z: S

Implementations§

Source§

impl<S, U> Vector3D<S, U>

Source

pub const fn new(x: S, y: S, z: S) -> Self

Examples found in repository?
examples/screenshot.rs (line 167)
163    fn frame(&mut self) -> Result<(), T::Error> {
164        let (width, height) = (self.width as f32, self.height as f32);
165        let proj = Transform3D::perspective(60.0f32, width / height, 0.01, 30.0);
166        let view = Transform3D::<f32>::look_at(
167            Vector3D::new(0.0, 1.5, 9.0),
168            Vector3D::new(0.0, 0.0, 0.0),
169            Vector3D::new(0.0, 1.0, 0.0),
170        );
171        let view_proj = proj * view;
172
173        self.rx += 0.01;
174        self.ry += 0.03;
175
176        let model = Transform3D::rotation(self.ry, Vector3D::new(0., 1.0, 0.))
177            * Transform3D::<f32>::rotation(self.rx, Vector3D::new(1.0, 0., 0.));
178
179        let vs_params = display_shader::Uniforms {
180            mvp: view_proj * model,
181        };
182        let mut frame = self.backend.frame();
183
184        frame.begin_pass(
185            self.offscreen_pass,
186            gfx::PassAction::clear(gfx::color::Rgba::BLACK),
187        );
188        frame.apply_pipeline(&self.offscreen_pipeline)?;
189        frame.apply_bindings(&self.offscreen_bind)?;
190        frame.apply_uniforms(&vs_params)?;
191        frame.draw(0, 3, 1)?;
192        frame.end_pass();
193
194        frame.begin_default_pass(gfx::PassAction::clear(gfx::color::Rgba::BLACK));
195        frame.apply_pipeline(&self.display_pipeline)?;
196        frame.apply_bindings(&self.display_bind)?;
197        frame.draw(0, 6, 1)?;
198        frame.end_pass();
199        frame.commit();
200
201        Ok(())
202    }
More examples
Hide additional examples
examples/offscreen.rs (line 32)
28    fn frame(&mut self) -> Result<(), Self::Error> {
29        let (width, height) = (self.width as f32, self.height as f32);
30        let proj = Transform3D::perspective(60.0f32, width / height, 0.01, 100.);
31        let view = Transform3D::<f32>::look_at(
32            Vector3D::new(0.0, 1.5, 9.0),
33            Vector3D::new(0.0, 0.0, 0.0),
34            Vector3D::new(0.0, 1.0, 0.0),
35        );
36        let view_proj = proj * view;
37
38        self.rx += 0.01;
39        self.ry += 0.03;
40
41        let model = Transform3D::rotation(self.ry, Vector3D::new(0., 1.0, 0.))
42            * Transform3D::<f32>::rotation(self.rx, Vector3D::new(1.0, 0., 0.));
43        let vs_params = display_shader::Uniforms {
44            mvp: view_proj * model,
45        };
46        let mut frame = self.backend.frame();
47
48        // Offscreen pass.
49        frame.begin_pass(
50            self.offscreen_pass,
51            gfx::PassAction::clear(gfx::color::Rgba::WHITE),
52        );
53        frame.apply_pipeline(&self.offscreen_pipeline)?;
54        frame.apply_bindings(&self.offscreen_bind)?;
55        frame.apply_uniforms(&vs_params)?;
56        frame.draw(0, 36, 1)?;
57        frame.end_pass();
58
59        // Display pass.
60        frame.begin_default_pass(gfx::PassAction::clear(gfx::color::Rgba::new(
61            0.0, 0., 0.45, 1.,
62        )));
63        frame.apply_pipeline(&self.display_pipeline)?;
64        frame.apply_bindings(&self.display_bind)?;
65        frame.apply_uniforms(&vs_params)?;
66        frame.draw(0, 36, 1)?;
67        frame.end_pass();
68        frame.commit();
69
70        Ok(())
71    }
Source

pub fn extend(self, w: S) -> Vector4D<S, U>

Extend vector to four dimensions.

Source

pub fn dot(a: Self, b: Self) -> <S as Add>::Output
where S: Mul<Output = S> + Add<Output = S> + Copy,

Dot product of two vectors.

Source

pub fn cross(a: Self, b: Self) -> Self
where S: Mul<Output = S> + Sub<Output = S> + Copy,

Vector cross product.

Source§

impl<S: Copy> Vector3D<S>

Source

pub fn magnitude(self) -> S
where S: Float,

The distance from the tail to the tip of the vector.

Source

pub fn normalize(self) -> Self
where S: One + Float + Div + Mul,

Returns a vector with the same direction and a given magnitude.

Trait Implementations§

Source§

impl<S, U> Add for Vector3D<S, U>
where S: Add<Output = S> + Copy,

Source§

type Output = Vector3D<S, U>

The resulting type after applying the + operator.
Source§

fn add(self, other: Vector3D<S, U>) -> Self

Performs the + operation. Read more
Source§

impl<S: Clone, U: Clone> Clone for Vector3D<S, U>

Source§

fn clone(&self) -> Vector3D<S, U>

Returns a duplicate 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<S: Debug, U: Debug> Debug for Vector3D<S, U>

Source§

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

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

impl<T: Copy> From<[T; 3]> for Vector3D<T>

Source§

fn from(array: [T; 3]) -> Self

Converts to this type from the input type.
Source§

impl<S: Zero, U: Copy> From<Vector2D<S, U>> for Vector3D<S, U>

Source§

fn from(other: Vector2D<S, U>) -> Self

Converts to this type from the input type.
Source§

impl<S, U: Copy> From<Vector3D<S, U>> for Vector2D<S, U>

Source§

fn from(other: Vector3D<S, U>) -> Self

Converts to this type from the input type.
Source§

impl From<Vector3D> for Vector4D<f32>

Source§

fn from(other: Vector3D<f32>) -> Self

Converts to this type from the input type.
Source§

impl<S: Hash, U: Hash> Hash for Vector3D<S, U>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<S, U> Mul<S> for Vector3D<S, U>
where S: Mul<Output = S> + Copy,

Source§

type Output = Vector3D<S, U>

The resulting type after applying the * operator.
Source§

fn mul(self, s: S) -> Self

Performs the * operation. Read more
Source§

impl Mul<Vector3D> for Transform3D<f32>

Transform a Vector3D with a Transform3D.

use ombre::math::*;
let m = Transform3D::from_translation(Vector3D::new(8., 8., 0.));
let v = Vector3D::new(1., 1., 0.);

assert_eq!(m * v, Vector3D::new(9., 9., 0.));
Source§

type Output = Vector3D

The resulting type after applying the * operator.
Source§

fn mul(self, vec: Vector3D<f32>) -> Vector3D<f32>

Performs the * operation. Read more
Source§

impl<S: PartialEq, U: PartialEq> PartialEq for Vector3D<S, U>

Source§

fn eq(&self, other: &Vector3D<S, U>) -> 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<S, U> Sub for Vector3D<S, U>
where S: Sub<Output = S> + Copy,

Source§

type Output = Vector3D<S, U>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Vector3D<S, U>) -> Self

Performs the - operation. Read more
Source§

impl<S: Copy, U: Copy> Copy for Vector3D<S, U>

Source§

impl<S: Eq, U: Eq> Eq for Vector3D<S, U>

Source§

impl<S, U> StructuralPartialEq for Vector3D<S, U>

Auto Trait Implementations§

§

impl<S, U> Freeze for Vector3D<S, U>
where S: Freeze,

§

impl<S, U> RefUnwindSafe for Vector3D<S, U>

§

impl<S, U> Send for Vector3D<S, U>
where S: Send, U: Send,

§

impl<S, U> Sync for Vector3D<S, U>
where S: Sync, U: Sync,

§

impl<S, U> Unpin for Vector3D<S, U>
where S: Unpin, U: Unpin,

§

impl<S, U> UnwindSafe for Vector3D<S, U>
where S: UnwindSafe, U: UnwindSafe,

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