Vector4

Struct Vector4 

Source
#[repr(C)]
pub struct Vector4<T> { pub x: T, pub y: T, pub z: T, pub w: T, }

Fields§

§x: T§y: T§z: T§w: T

Implementations§

Source§

impl<T> Vector4<T>
where T: Scalar,

Source

pub fn new(x: T, y: T, z: T, w: T) -> Vector4<T>

Examples found in repository?
examples/triangle.rs (line 141)
111fn main() {
112    // initialize GLFW3 with OpenGL ES 3.0
113    let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS).unwrap();
114    glfw.window_hint(glfw::WindowHint::ContextCreationApi(
115        glfw::ContextCreationApi::Egl,
116    ));
117    glfw.window_hint(glfw::WindowHint::ClientApi(glfw::ClientApiHint::OpenGlEs));
118    glfw.window_hint(glfw::WindowHint::ContextVersion(3, 0));
119    glfw.window_hint(glfw::WindowHint::OpenGlProfile(
120        glfw::OpenGlProfileHint::Core,
121    ));
122    glfw.window_hint(glfw::WindowHint::DoubleBuffer(true));
123    glfw.window_hint(glfw::WindowHint::Resizable(true));
124    glfw.window_hint(glfw::WindowHint::Floating(true));
125
126    let (mut window, events) = glfw
127        .create_window(1024, 900, "Triangle", glfw::WindowMode::Windowed)
128        .expect("Failed to create GLFW window.");
129
130    window.set_char_polling(true);
131    window.set_cursor_pos_polling(true);
132    window.set_key_polling(true);
133    window.set_mouse_button_polling(true);
134    window.make_current();
135    glfw.set_swap_interval(glfw::SwapInterval::Sync(1));
136
137    let mut driver = renderer::get_driver();
138
139    let vertices = vec![
140        Vertex {
141            position: Vec4f::new(-0.5, -0.5, 0.0, 1.0),
142            color: Vec4f::new(1.0, 0.0, 0.0, 1.0),
143        },
144        Vertex {
145            position: Vec4f::new(0.5, -0.5, 0.0, 1.0),
146            color: Vec4f::new(0.0, 0.0, 1.0, 1.0),
147        },
148        Vertex {
149            position: Vec4f::new(0.0, 0.5, 0.0, 1.0),
150            color: Vec4f::new(0.0, 1.0, 0.0, 1.0),
151        },
152    ];
153
154    let mut vertex_buffer = driver
155        .create_device_buffer(DeviceBufferDesc::Vertex(Usage::Dynamic(
156            3 * std::mem::size_of::<Vertex>(),
157        )))
158        .unwrap();
159    let pipeline = init_render_objects(&mut driver);
160
161    let mut quit = false;
162    while !window.should_close() {
163        let (width, height) = window.get_framebuffer_size();
164
165        let mut pass = Pass::new(
166            width as usize,
167            height as usize,
168            None,
169            [
170                ColorPassAction::Clear(color4b(0x00, 0x00, 0x00, 0x00)),
171                ColorPassAction::Previous,
172                ColorPassAction::Previous,
173                ColorPassAction::Previous,
174            ],
175            DepthPassAction::Clear(1.0),
176        );
177
178        let bindings = Bindings {
179            vertex_buffers: vec![vertex_buffer.clone()],
180            index_buffer: None,
181
182            vertex_images: Vec::new(),
183            pixel_images: Vec::new(),
184        };
185
186        pass.update_device_buffer(&mut vertex_buffer, 0, Arc::new(vertices.to_vec()));
187        pass.draw(&pipeline, &bindings, Arc::new(Vec::<Vec3f>::new()), 1, 1);
188        driver.render_pass(&mut pass);
189        window.swap_buffers();
190
191        glfw.poll_events();
192        for (_, event) in glfw::flush_messages(&events) {
193            match event {
194                glfw::WindowEvent::Key(glfw::Key::Escape, _, _, _) | glfw::WindowEvent::Close => {
195                    quit = true
196                }
197                _ => (),
198            }
199        }
200
201        if quit {
202            window.set_should_close(true)
203        }
204    }
205}

Trait Implementations§

Source§

impl<T> Add for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector4<T>) -> <Vector4<T> as Add>::Output

Performs the + operation. Read more
Source§

impl AttributeDataTypeGetter for Vector4<f32>

Source§

impl AttributeDataTypeGetter for Vector4<i16>

Source§

impl AttributeDataTypeGetter for Vector4<i32>

Source§

impl AttributeDataTypeGetter for Vector4<i8>

Source§

impl AttributeDataTypeGetter for Vector4<u32>

Source§

impl AttributeDataTypeGetter for Vector4<u8>

Source§

impl<T> Clone for Vector4<T>
where T: Clone,

Source§

fn clone(&self) -> Vector4<T>

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<T> Debug for Vector4<T>
where T: Debug,

Source§

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

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

impl<T> Default for Vector4<T>
where T: Default,

Source§

fn default() -> Vector4<T>

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

impl<T> Div<T> for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> <Vector4<T> as Div<T>>::Output

Performs the / operation. Read more
Source§

impl<T> Div for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Vector4<T>) -> <Vector4<T> as Div>::Output

Performs the / operation. Read more
Source§

impl<T> FloatVector<T> for Vector4<T>
where T: FloatScalar,

Source§

fn length(&self) -> T

Computes the Euclidean length (magnitude) of the vector. Read more
Source§

fn normalize(&self) -> Vector4<T>

Returns a unit vector in the same direction. Read more
Source§

fn distance(l: &Vector4<T>, r: &Vector4<T>) -> T

Computes the Euclidean distance between two vectors. Read more
Source§

impl<T> Mul<Matrix4<T>> for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix4<T>) -> Vector4<T>

Performs the * operation. Read more
Source§

impl<T> Mul<T> for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> <Vector4<T> as Mul<T>>::Output

Performs the * operation. Read more
Source§

impl<T> Mul<Vector4<T>> for Matrix4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector4<T>) -> Vector4<T>

Performs the * operation. Read more
Source§

impl<T> Mul for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vector4<T>) -> <Vector4<T> as Mul>::Output

Performs the * operation. Read more
Source§

impl<T> Neg for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> <Vector4<T> as Neg>::Output

Performs the unary - operation. Read more
Source§

impl<T> Rem<T> for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: T) -> <Vector4<T> as Rem<T>>::Output

Performs the % operation. Read more
Source§

impl<T> Rem for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Vector4<T>) -> <Vector4<T> as Rem>::Output

Performs the % operation. Read more
Source§

impl<T> Sub for Vector4<T>
where T: Scalar,

Source§

type Output = Vector4<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector4<T>) -> <Vector4<T> as Sub>::Output

Performs the - operation. Read more
Source§

impl<T> Swizzle2<T> for Vector4<T>
where T: Scalar,

Source§

fn xx(&self) -> Vector2<T>

Source§

fn xy(&self) -> Vector2<T>

Source§

fn xz(&self) -> Vector2<T>

Source§

fn yx(&self) -> Vector2<T>

Source§

fn yy(&self) -> Vector2<T>

Source§

fn yz(&self) -> Vector2<T>

Source§

fn zx(&self) -> Vector2<T>

Source§

fn zy(&self) -> Vector2<T>

Source§

fn zz(&self) -> Vector2<T>

Source§

impl<T> Swizzle3<T> for Vector4<T>
where T: Scalar,

Source§

fn xxx(&self) -> Vector3<T>

Source§

fn xxy(&self) -> Vector3<T>

Source§

fn xxz(&self) -> Vector3<T>

Source§

fn xyx(&self) -> Vector3<T>

Source§

fn xyy(&self) -> Vector3<T>

Source§

fn xyz(&self) -> Vector3<T>

Source§

fn xzx(&self) -> Vector3<T>

Source§

fn xzy(&self) -> Vector3<T>

Source§

fn xzz(&self) -> Vector3<T>

Source§

fn yxx(&self) -> Vector3<T>

Source§

fn yxy(&self) -> Vector3<T>

Source§

fn yxz(&self) -> Vector3<T>

Source§

fn yyx(&self) -> Vector3<T>

Source§

fn yyy(&self) -> Vector3<T>

Source§

fn yyz(&self) -> Vector3<T>

Source§

fn yzx(&self) -> Vector3<T>

Source§

fn yzy(&self) -> Vector3<T>

Source§

fn yzz(&self) -> Vector3<T>

Source§

fn zxx(&self) -> Vector3<T>

Source§

fn zxy(&self) -> Vector3<T>

Source§

fn zxz(&self) -> Vector3<T>

Source§

fn zyx(&self) -> Vector3<T>

Source§

fn zyy(&self) -> Vector3<T>

Source§

fn zyz(&self) -> Vector3<T>

Source§

fn zzx(&self) -> Vector3<T>

Source§

fn zzy(&self) -> Vector3<T>

Source§

fn zzz(&self) -> Vector3<T>

Source§

impl UniformDataTypeGetter for Vector4<f32>

Source§

impl UniformDataTypeGetter for Vector4<i32>

Source§

impl UniformDataTypeGetter for Vector4<u32>

Source§

impl<T> Vector<T> for Vector4<T>
where T: Scalar,

Source§

fn zero() -> Vector4<T>

Returns the zero vector (all components are zero).
Source§

fn dot(l: &Vector4<T>, r: &Vector4<T>) -> T

Computes the dot product of two vectors. Read more
Source§

fn add_vv(l: &Vector4<T>, r: &Vector4<T>) -> Vector4<T>

Adds two vectors component-wise.
Source§

fn sub_vv(l: &Vector4<T>, r: &Vector4<T>) -> Vector4<T>

Subtracts two vectors component-wise.
Source§

fn mul_vv(l: &Vector4<T>, r: &Vector4<T>) -> Vector4<T>

Multiplies two vectors component-wise (Hadamard product).
Source§

fn div_vv(l: &Vector4<T>, r: &Vector4<T>) -> Vector4<T>

Divides two vectors component-wise.
Source§

fn mul_vs(l: &Vector4<T>, r: T) -> Vector4<T>

Multiplies a vector by a scalar.
Source§

fn div_vs(l: &Vector4<T>, r: T) -> Vector4<T>

Divides a vector by a scalar.
Source§

fn rem_vv(l: &Vector4<T>, r: &Vector4<T>) -> Vector4<T>

Computes the remainder of component-wise division.
Source§

fn min(l: &Vector4<T>, r: &Vector4<T>) -> Vector4<T>

Returns a vector with the minimum components from both vectors.
Source§

fn max(l: &Vector4<T>, r: &Vector4<T>) -> Vector4<T>

Returns a vector with the maximum components from both vectors.
Source§

impl<T> Copy for Vector4<T>
where T: Copy,

Auto Trait Implementations§

§

impl<T> Freeze for Vector4<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Vector4<T>
where T: RefUnwindSafe,

§

impl<T> Send for Vector4<T>
where T: Send,

§

impl<T> Sync for Vector4<T>
where T: Sync,

§

impl<T> Unpin for Vector4<T>
where T: Unpin,

§

impl<T> UnwindSafe for Vector4<T>
where T: 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.
Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,