Struct anima_engine::math::Vector [] [src]

pub struct Vector {
    pub x: f32,
    pub y: f32,
    pub z: f32,
}

A simple vector struct tailored specifically for graphics.

Examples

let v1 = Vector::zero();
let v2 = Vector::one();

assert_eq!(v1 + v2, Vector::one());
assert_eq!(v1 * v2, Vector::zero());
assert_eq!(v1.dot(v2), 0.0);

let v3 = v1;

assert_eq!(v1.dot(v2), 0.0);
assert_eq!((v3 + Vector::one() * 2.0).dot(v2), 6.0);

Fields

x

f32 x coordinate value

y

f32 y coordinate value

z

f32 z coordinate value

Methods

impl Vector

fn new(x: f32, y: f32, z: f32) -> Vector

Creates a vector using 3 values.

Examples

let v = Vector::new(0.0, 1.0, 2.0);

assert_eq!(v, Vector { x: 0.0, y: 1.0, z: 2.0 });

fn new_arr(array: [f32; 3]) -> Vector

Creates a vector using an array.

Examples

let v = Vector::new_arr([0.0, 1.0, 2.0]);

assert_eq!(v, Vector { x: 0.0, y: 1.0, z: 2.0 });

fn new_unf(v: f32) -> Vector

Creates a uniform vector using 1 value.

Examples

let v = Vector::new_unf(1.0);

assert_eq!(v, Vector { x: 1.0, y: 1.0, z: 1.0 });

fn zero() -> Vector

Creates a zero (0.0, 0.0, 0.0) Vector.

Examples

assert_eq!(Vector::zero(), Vector { x: 0.0, y: 0.0, z: 0.0 });

fn one() -> Vector

Creates a one (1.0, 1.0, 1.0) Vector.

Examples

assert_eq!(Vector::one(), Vector { x: 1.0, y: 1.0, z: 1.0 });

fn back() -> Vector

Creates a back (0.0, 0.0, -1.0) Vector.

Examples

assert_eq!(Vector::back(), Vector { x: 0.0, y: 0.0, z: -1.0 });

fn down() -> Vector

Creates a down (0.0, -1.0, 0.0) Vector.

Examples

assert_eq!(Vector::down(), Vector { x: 0.0, y: -1.0, z: 0.0 });

fn forward() -> Vector

Creates a forward (0.0, 0.0, 1.0) Vector.

Examples

assert_eq!(Vector::forward(), Vector { x: 0.0, y: 0.0, z: 1.0 });

fn left() -> Vector

Creates a left (-1.0, 0.0, 0.0) Vector.

Examples

assert_eq!(Vector::left(), Vector { x: 1.0, y: 0.0, z: 0.0 });

fn right() -> Vector

Creates a right (1.0, 0.0, 0.0) Vector.

Examples

assert_eq!(Vector::right(), Vector { x: -1.0, y: 0.0, z: 0.0 });

fn up() -> Vector

Creates an up (0.0, 1.0, 0.0) Vector.

Examples

assert_eq!(Vector::up(), Vector { x: 0.0, y: 1.0, z: 0.0 });

fn len(&self) -> f32

Computes the length of a vector.

Examples

let v = Vector::new(1.0, 2.0, 2.0);

assert_eq!(v.len(), 3.0);

fn norm(&self) -> Vector

Computes the normalized version of a vector.

Examples

let v = Vector::new(1.0, 2.0, 2.0);
let n = v.norm();

assert_eq!(n.len(), 1.0); // Keep precision in mind when comparing floats.

fn dot(&self, other: Vector) -> f32

Computes the dot product between two vectors.

Examples

let v1 = Vector::new(1.0, 2.0, 2.0);
let v2 = Vector::new(3.0, 3.0, 1.0);

assert_eq!(v1.dot(v2), 11.0);

fn cross(&self, other: Vector) -> Vector

Computes the cross product between two vectors.

Examples

let v1 = Vector::new(1.0, 2.0, 2.0);
let v2 = Vector::new(3.0, 3.0, 1.0);

assert_eq!(v1.cross(v2), Vector { x: -4.0, y: 5.0, z: -3.0 });

fn rot(&self, quaternion: Quaternion) -> Vector

Rotates a vector according to the rotation represented by a quaternion.

Examples

let q = Quaternion::new(0.0, 1.0, 0.0, 0.0);
let v = Vector::new(1.0, 0.0, 0.0);

assert_eq!(v.rot(q), Vector { x: -1.0, y: 0.0, z: 0.0 });

fn rot_around(self, quaternion: Quaternion, point: Vector) -> Vector

Rotates a vector according to the rotation represented by the quaternion around a point.

Examples

let q = Quaternion::new(0.0, 1.0, 0.0, 0.0);
let v = Vector::new(1.0, 0.0, 0.0);
let p = Vector::new(2.0, 0.0, 0.0);

assert_eq!(v.rot_around(q, p), Vector { x: 3.0, y: 0.0, z: 0.0 });

fn angle(&self, other: Vector) -> f32

Computes the angle in radians between two vectors.

Examples

let v1 = Vector::new(1.0, 0.0, 0.0);
let v2 = Vector::new(0.0, 2.0, 0.0);

assert_eq!(v1.angle(v2), consts::PI / 2.0);

fn dist(self, other: Vector) -> f32

Computes the distance between two vectors.

Examples

let v1 = Vector::new(0.0, 0.0, 0.0);
let v2 = Vector::new(0.0, 1.0, 0.0);

assert_eq!(v1.dist(v2), 1.0);

Trait Implementations

impl Add for Vector

type Output = Vector

fn add(self, other: Vector) -> Vector

impl Sub for Vector

type Output = Vector

fn sub(self, other: Vector) -> Vector

impl Mul<Vector> for Vector

type Output = Vector

fn mul(self, other: Vector) -> Vector

impl Mul<f32> for Vector

type Output = Vector

fn mul(self, scalar: f32) -> Vector

impl Neg for Vector

type Output = Vector

fn neg(self) -> Vector

impl PartialOrd for Vector

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

1.0.0fn lt(&self, other: &Rhs) -> bool

1.0.0fn le(&self, other: &Rhs) -> bool

1.0.0fn gt(&self, other: &Rhs) -> bool

1.0.0fn ge(&self, other: &Rhs) -> bool

impl Interpolate for Vector

fn interpolate(&self, other: Vector, ratio: f32) -> Vector

impl MrubyFile for Vector

fn require(mruby: MrubyType)

Derived Implementations

impl PartialEq for Vector

fn eq(&self, __arg_0: &Vector) -> bool

fn ne(&self, __arg_0: &Vector) -> bool

impl Debug for Vector

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Copy for Vector

impl Clone for Vector

fn clone(&self) -> Vector

1.0.0fn clone_from(&mut self, source: &Self)