Struct vec_2_10_10_10::Vector
[−]
[src]
#[repr(C, packed)]pub struct Vector { /* fields omitted */ }
Four dimensional 2-10-10-10 vector.
The binary data is mapped into floating point values from 0.0
to 1.0
.
The values outside this range are clamped.
The w
dimension takes 2 bits, and can have values 0.0
, 0.3(3)
, 0.6(6)
and 1.0
.
The x
, y
and z
dimensions take 10 bits, each.
The internal format is equivalent to GL_UNSIGNED_INT_2_10_10_10_REV
OpenGL
vertex attribute type.
Methods
impl Vector
[src]
fn new(x: f32, y: f32, z: f32, w: f32) -> Vector
[src]
Creates a new Vector.
First x
, y
, z
values are stored in 10-bits, each.
The w
value is stored in 2 bits.
Everything is packed internally into 4 bytes.
The stored values are a bit wonky precisely because of low stored precision.
let value = vec_2_10_10_10::Vector::new(0.444, 0.555, 0.666, 0.2); assert!(approx_equal(value.x(), 0.444)); assert!(approx_equal(value.y(), 0.555)); assert!(approx_equal(value.z(), 0.666)); // 2 bits means only possible values are 0, 0.3(3), 0.6(6) and 1. assert!(approx_equal(value.w(), 0.333)); fn approx_equal(a: f32, b: f32) -> bool { const DELTA: f32 = 0.001; a > b - DELTA && a < b + DELTA }
fn from_raw(data: u32) -> Vector
[src]
Creates a vector from raw 4-byte data.
The vector can be used to inspect such data if it was created by other means.
let other_value = *vec_2_10_10_10::Vector::new(0.444, 0.555, 0.666, 0.333).raw_value(); let value = vec_2_10_10_10::Vector::from_raw(other_value); assert!(approx_equal(value.x(), 0.444)); assert!(approx_equal(value.y(), 0.555)); assert!(approx_equal(value.z(), 0.666)); assert!(approx_equal(value.w(), 0.333)); fn approx_equal(a: f32, b: f32) -> bool { const DELTA: f32 = 0.001; a > b - DELTA && a < b + DELTA }
fn x(&self) -> f32
[src]
Get x
value.
fn y(&self) -> f32
[src]
Get y
value.
fn z(&self) -> f32
[src]
Get z
value.
fn w(&self) -> f32
[src]
Get w
value.
fn set_x(&mut self, x: f32)
[src]
Update x
value.
This changes internal 4-byte representation.
let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0); value.set_x(0.333); assert!(approx_equal(value.x(), 0.333)); assert!(approx_equal(value.y(), 0.0)); assert!(approx_equal(value.z(), 0.0)); assert!(approx_equal(value.w(), 0.0));
fn set_y(&mut self, y: f32)
[src]
Update y
value.
This changes internal 4-byte representation.
let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0); value.set_y(0.333); assert!(approx_equal(value.x(), 0.0)); assert!(approx_equal(value.y(), 0.333)); assert!(approx_equal(value.z(), 0.0)); assert!(approx_equal(value.w(), 0.0));
fn set_z(&mut self, z: f32)
[src]
Update z
value.
This changes internal 4-byte representation.
let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0); value.set_z(0.333); assert!(approx_equal(value.x(), 0.0)); assert!(approx_equal(value.y(), 0.0)); assert!(approx_equal(value.z(), 0.333)); assert!(approx_equal(value.w(), 0.0));
fn set_xyz(&mut self, x: f32, y: f32, z: f32)
[src]
Update x
, y
and z
.
This changes internal 4-byte representation.
let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0); value.set_xyz(0.333, 0.444, 0.555); assert!(approx_equal(value.x(), 0.333)); assert!(approx_equal(value.y(), 0.444)); assert!(approx_equal(value.z(), 0.555)); assert!(approx_equal(value.w(), 0.0));
fn set_w(&mut self, w: f32)
[src]
Update w
.
This changes internal 4-byte representation.
let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0); value.set_w(0.333); assert!(approx_equal(value.x(), 0.0)); assert!(approx_equal(value.y(), 0.0)); assert!(approx_equal(value.z(), 0.0)); assert!(approx_equal(value.w(), 0.333));
fn raw_value(&self) -> &u32
[src]
Return raw internal value.
Trait Implementations
impl Copy for Vector
[src]
impl Clone for Vector
[src]
fn clone(&self) -> Vector
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more